]> source.dussan.org Git - poi.git/commitdiff
Start on more XSLF support
authorNick Burch <nick@apache.org>
Tue, 5 Aug 2008 17:51:04 +0000 (17:51 +0000)
committerNick Burch <nick@apache.org>
Tue, 5 Aug 2008 17:51:04 +0000 (17:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@682833 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java [new file with mode: 0644]

index ce66aefe9a595f1d6161357998276480827c0a8b..c029490bb5fe5dd12928f8a510057761af4ad39a 100644 (file)
@@ -26,6 +26,7 @@ import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 import org.openxml4j.opc.PackageRelationship;
 import org.openxml4j.opc.PackageRelationshipCollection;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
@@ -34,6 +35,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument;
 import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
 import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
 import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
@@ -56,6 +58,7 @@ public class XSLFSlideShow extends POIXMLDocument {
        public static final String SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
        public static final String SLIDE_LAYOUT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout";
        public static final String NOTES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide";
+       public static final String COMMENT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
 
        private PresentationDocument presentationDoc;
        
@@ -106,49 +109,55 @@ public class XSLFSlideShow extends POIXMLDocument {
                return getPresentation().getSldMasterIdLst();
        }
        
+       public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException {
+               try {
+                       return getTargetPart(
+                               getCorePart().getRelationship(master.getId2())
+                       );
+               } catch(InvalidFormatException e) {
+                       throw new XmlException(e);
+               }
+       }
        /**
         * Returns the low level slide master object from
         *  the supplied slide master reference
         */
        public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
+               PackagePart masterPart = getSlideMasterPart(master);
+               SldMasterDocument masterDoc =
+                       SldMasterDocument.Factory.parse(masterPart.getInputStream());
+               return masterDoc.getSldMaster();
+       }
+
+       public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException {
                try {
-                       PackagePart masterPart =
-                               getTargetPart(getCorePart().getRelationship(master.getId2()));
-                               
-                       SldMasterDocument masterDoc =
-                               SldMasterDocument.Factory.parse(masterPart.getInputStream());
-                       return masterDoc.getSldMaster();
+                       return getTargetPart(
+                                       getCorePart().getRelationship(slide.getId2())
+                       );
                } catch(InvalidFormatException e) {
                        throw new XmlException(e);
                }
        }
-       
        /**
         * Returns the low level slide object from
         *  the supplied slide reference
         */
        public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
-               try {
-                       PackagePart slidePart =
-                               getTargetPart(getCorePart().getRelationship(slide.getId2()));
-                       SldDocument slideDoc =
-                               SldDocument.Factory.parse(slidePart.getInputStream());
-                       return slideDoc.getSld();
-               } catch(InvalidFormatException e) {
-                       throw new XmlException(e);
-               }
+               PackagePart slidePart = getSlidePart(slide);
+               SldDocument slideDoc =
+                       SldDocument.Factory.parse(slidePart.getInputStream());
+               return slideDoc.getSld();
        }
-       
+
        /**
-        * Returns the low level notes object for the given
-        *  slide, as found from the supplied slide reference
+        * Gets the PackagePart of the notes for the
+        *  given slide, or null if there isn't one.
         */
-       public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
+       public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException {
                PackageRelationshipCollection notes;
-               try {
-                       PackagePart slidePart =
-                               getTargetPart(getCorePart().getRelationship(slide.getId2()));
+               PackagePart slidePart = getSlidePart(parentSlide);
                
+               try {
                        notes = slidePart.getRelationshipsByType(NOTES_RELATION_TYPE);
                } catch(InvalidFormatException e) {
                        throw new IllegalStateException(e);
@@ -163,12 +172,54 @@ public class XSLFSlideShow extends POIXMLDocument {
                }
                
                try {
-                       PackagePart notesPart =
-                               getTargetPart(notes.getRelationship(0));
-                       NotesDocument notesDoc =
-                               NotesDocument.Factory.parse(notesPart.getInputStream());
-                       
-                       return notesDoc.getNotes();
+                       return getTargetPart(notes.getRelationship(0));
+               } catch(InvalidFormatException e) {
+                       throw new IllegalStateException(e);
+               }
+       }
+       /**
+        * Returns the low level notes object for the given
+        *  slide, as found from the supplied slide reference
+        */
+       public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
+               PackagePart notesPart = getNodesPart(slide);
+               if(notesPart == null)
+                       return null;
+               
+               NotesDocument notesDoc =
+                       NotesDocument.Factory.parse(notesPart.getInputStream());
+               
+               return notesDoc.getNotes();
+       }
+       
+       /**
+        * Returns all the comments for the given slide
+        */
+       public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException {
+               PackageRelationshipCollection commentRels;
+               PackagePart slidePart = getSlidePart(slide);
+               
+               try {
+                       commentRels = slidePart.getRelationshipsByType(COMMENT_RELATION_TYPE);
+               } catch(InvalidFormatException e) {
+                       throw new IllegalStateException(e);
+               }
+               
+               if(commentRels.size() == 0) {
+                       // No comments for this slide
+                       return null;
+               }
+               if(commentRels.size() > 1) {
+                       throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size());
+               }
+               
+               try {
+                       PackagePart cPart = getTargetPart(
+                                       commentRels.getRelationship(0)
+                       );
+                       CmLstDocument commDoc = 
+                               CmLstDocument.Factory.parse(cPart.getInputStream());
+                       return commDoc.getCmLst();
                } catch(InvalidFormatException e) {
                        throw new IllegalStateException(e);
                }
index 5bc1cf8737db4f47a6b26b558f5a42a12722fd1b..ae8d7229c41feb1675481b692d8b9d8fc3d1c5f8 100644 (file)
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
+import java.io.IOException;
+
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Resources;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
 
 /**
  * High level representation of a ooxml slideshow.
@@ -24,17 +34,52 @@ import org.apache.poi.xslf.XSLFSlideShow;
  *  they are reading or writing a slideshow. It is also the
  *  top level object for creating new slides/etc.
  */
-public class XMLSlideShow {
+public class XMLSlideShow implements SlideShow {
        private XSLFSlideShow slideShow;
+       private XSLFSlide[] slides;
        
-       public XMLSlideShow(XSLFSlideShow xml) {
+       public XMLSlideShow(XSLFSlideShow xml) throws XmlException, IOException {
                this.slideShow = xml;
+               
+               // Build the main masters list - TODO
+               
+               // Build the slides list
+               CTSlideIdList slideIds = slideShow.getSlideReferences();
+               slides = new XSLFSlide[slideIds.getSldIdArray().length];
+               for(int i=0; i<slides.length; i++) {
+                       CTSlideIdListEntry slideId = slideIds.getSldIdArray(i);
+                       CTSlide slide = slideShow.getSlide(slideId);
+                       slides[i] = new XSLFSlide(slide, slideId, this);
+               }
+               
+               // Build the notes list - TODO
        }
        
        public XSLFSlideShow _getXSLFSlideShow() {
                return slideShow;
        }
 
-       // TODO: Get slides
-       // TODO: Get notes
+       public MasterSheet createMasterSheet() throws IOException {
+               throw new IllegalStateException("Not implemented yet!");
+       }
+       public Slide createSlide() throws IOException {
+               throw new IllegalStateException("Not implemented yet!");
+       }
+
+       public MasterSheet[] getMasterSheet() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /**
+        * Return all the slides in the slideshow
+        */
+       public XSLFSlide[] getSlides() {
+               return slides;
+       }
+       
+       public Resources getResources() {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
new file mode 100644 (file)
index 0000000..3bbd099
--- /dev/null
@@ -0,0 +1,59 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.xslf.usermodel;
+
+import org.apache.poi.sl.usermodel.Background;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.Sheet;
+import org.apache.poi.sl.usermodel.SlideShow;
+
+public abstract class XSLFSheet implements Sheet {
+       private SlideShow slideShow;
+       protected XSLFSheet(SlideShow parent) {
+               this.slideShow = parent;
+       }
+
+       public Background getBackground() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public MasterSheet getMasterSheet() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public SlideShow getSlideShow() {
+               return slideShow;
+       }
+
+       public void addShape(Shape shape) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public Shape[] getShapes() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public boolean removeShape(Shape shape) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+}
\ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
new file mode 100644 (file)
index 0000000..e4e96e6
--- /dev/null
@@ -0,0 +1,88 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.xslf.usermodel;
+
+import org.apache.poi.sl.usermodel.Notes;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
+
+public class XSLFSlide extends XSLFSheet implements Slide {
+       private CTSlide slide;
+       private CTSlideIdListEntry slideId;
+       
+       public XSLFSlide(CTSlide slide, CTSlideIdListEntry slideId, SlideShow parent) {
+               super(parent);
+               this.slide = slide;
+               this.slideId = slideId;
+       }
+       
+       /**
+        * While developing only!
+        */
+       public CTSlide _getCTSlide() {
+               return slide;
+       }
+       /**
+        * While developing only!
+        */
+       public CTSlideIdListEntry _getCTSlideId() {
+               return slideId;
+       }
+       
+
+       public boolean getFollowMasterBackground() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public boolean getFollowMasterColourScheme() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public boolean getFollowMasterObjects() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public Notes getNotes() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public void setFollowMasterBackground(boolean follow) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void setFollowMasterColourScheme(boolean follow) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void setFollowMasterObjects(boolean follow) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void setNotes(Notes notes) {
+               // TODO Auto-generated method stub
+
+       }
+}