]> source.dussan.org Git - poi.git/commitdiff
Start on XSLF notes master support, and add a XMLSlideShow basics test, along with...
authorNick Burch <nick@apache.org>
Sun, 4 Sep 2011 20:14:43 +0000 (20:14 +0000)
committerNick Burch <nick@apache.org>
Sun, 4 Sep 2011 20:14:43 +0000 (20:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1165104 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java [new file with mode: 0644]

diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
new file mode 100644 (file)
index 0000000..32bf5ac
--- /dev/null
@@ -0,0 +1,78 @@
+/* ====================================================================
+   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.POIXMLDocumentPart;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.util.Beta;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMaster;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
+import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
+import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+* Notes master object associated with this layout.
+* <p>
+*  Within a notes master slide are contained all elements
+* that describe the objects and their corresponding formatting
+* for within a presentation slide.
+* </p>
+* <p>
+* Within a nodes master slide are two main elements.
+* The cSld element specifies the common slide elements such as shapes and
+* their attached text bodies. Then the notesStyles element specifies the
+* formatting for the text within each of these shapes.
+* </p>
+ *
+ * @author Yegor Kozlov
+*/
+@Beta
+ public class XSLFNotesMaster extends XSLFSheet {
+        private CTNotesMaster _slide;
+    private Map<String, XSLFSlideLayout> _layouts;
+    private XSLFTheme _theme;
+
+    XSLFNotesMaster() {
+        super();
+        _slide = CTNotesMaster.Factory.newInstance();
+    }
+
+    protected XSLFNotesMaster(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
+        super(part, rel);
+        NotesMasterDocument doc =
+            NotesMasterDocument.Factory.parse(getPackagePart().getInputStream());
+        _slide = doc.getNotesMaster();
+        setCommonSlideData(_slide.getCSld());
+    }
+
+    @Override
+    public CTNotesMaster getXmlObject() {
+       return _slide;
+    }
+
+    @Override
+    protected String getRootElementName(){
+        return "notesMaster";
+    }
+}
\ No newline at end of file
index 15f91c6ec5a24c0f48cdd369f5287085a71abc94..5d0826510fb3d0612ea2ba7eccfbb13c359496c4 100644 (file)
@@ -90,12 +90,19 @@ public class XSLFRelation extends POIXMLRelation {
          XSLFSlideLayout.class
    );
    
-    public static final XSLFRelation SLIDE_MASTER = new XSLFRelation(
-          "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",
-          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster",
-          "/ppt/slideMasters/slideMaster#.xml",
-          XSLFSlideMaster.class
-    );
+   public static final XSLFRelation SLIDE_MASTER = new XSLFRelation(
+         "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",
+         "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster",
+         "/ppt/slideMasters/slideMaster#.xml",
+         XSLFSlideMaster.class
+   );
+
+   public static final XSLFRelation NOTES_MASTER = new XSLFRelation(
+         "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml",
+         "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster",
+         "/ppt/notesMasters/notesMaster#.xml",
+         XSLFNotesMaster.class
+   );
 
    public static final XSLFRelation COMMENTS = new XSLFRelation(
          "application/vnd.openxmlformats-officedocument.presentationml.comments+xml",
index d97600d398b575926893dfda1b86844c353f8be8..58e26eb8732d731cff3533f66d8bc38a2d152624 100644 (file)
@@ -24,11 +24,13 @@ import org.apache.poi.util.Beta;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
 
 import javax.xml.namespace.QName;
 import java.io.IOException;
@@ -41,11 +43,12 @@ import java.util.regex.Pattern;
 
 @Beta
 public abstract class XSLFSheet extends POIXMLDocumentPart {
+    private XSLFCommonSlideData _commonSlideData;
     private XSLFDrawing _drawing;
     private List<XSLFShape> _shapes;
     private CTGroupShape _spTree;
 
-    public XSLFSheet(){
+    public XSLFSheet() {
         super();
     }
 
@@ -53,9 +56,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart {
         super(part, rel);
     }
 
-       public XMLSlideShow getSlideShow() {
-               return (XMLSlideShow)getParent();
-       }
+    public XMLSlideShow getSlideShow() {
+       return (XMLSlideShow)getParent();
+    }
 
     protected List<XSLFShape> buildShapes(CTGroupShape spTree){
         List<XSLFShape> shapes = new ArrayList<XSLFShape>();
@@ -79,6 +82,16 @@ public abstract class XSLFSheet extends POIXMLDocumentPart {
 
     public abstract XmlObject getXmlObject();
 
+    public XSLFCommonSlideData getCommonSlideData() {
+       return _commonSlideData;
+    }
+    protected void setCommonSlideData(CTCommonSlideData data) {
+       if(data == null) {
+          _commonSlideData = null;
+       } else {
+          _commonSlideData = new XSLFCommonSlideData(data);
+       }
+    }
 
     private XSLFDrawing getDrawing(){
         if(_drawing == null) {
index ff4e64d308e51ee9e96e9c1ad4d0a6fd5c1d2b4b..228a51ae8596147c6113da559f7b97d6b6c83f0f 100644 (file)
@@ -70,6 +70,7 @@ public final class XSLFSlide extends XSLFSheet {
         SldDocument doc =
             SldDocument.Factory.parse(getPackagePart().getInputStream());
         _slide = doc.getSld();
+        setCommonSlideData(_slide.getCSld());
     }
 
 
index 871ece50dd193578647cb80f118bf342753b1f59..2d385382f517ace5288d9df750e7ffbde5c2e024 100755 (executable)
@@ -43,6 +43,7 @@ public class XSLFSlideLayout extends XSLFSheet {
         SldLayoutDocument doc =
             SldLayoutDocument.Factory.parse(getPackagePart().getInputStream());
         _layout = doc.getSldLayout();
+        setCommonSlideData(_layout.getCSld());
     }
 
 
index a0229f90173b370e2d66f503c4aecfa7ae5ab630..b7dcad7ce8beefbe91698492ddb5c012049e0bc7 100755 (executable)
@@ -64,6 +64,7 @@ import java.util.Map;
         SldMasterDocument doc =
             SldMasterDocument.Factory.parse(getPackagePart().getInputStream());
         _slide = doc.getSldMaster();
+        setCommonSlideData(_slide.getCSld());
     }
 
     @Override
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java
new file mode 100644 (file)
index 0000000..7625c84
--- /dev/null
@@ -0,0 +1,122 @@
+/* ====================================================================
+   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 junit.framework.TestCase;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFRelation;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
+
+public class TestXMLSlideShow extends TestCase {
+   private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+   private OPCPackage pack;
+
+   protected void setUp() throws Exception {
+      pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
+   }
+
+   public void testContainsMainContentType() throws Exception {
+      boolean found = false;
+      for(PackagePart part : pack.getParts()) {
+         if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
+            found = true;
+         }
+         //System.out.println(part);
+      }
+      assertTrue(found);
+   }
+
+   public void testOpen() throws Exception {
+      XMLSlideShow xml;
+
+      // With the finalised uri, should be fine
+      xml = new XMLSlideShow(pack);
+      // Check the core
+      assertNotNull(xml.getCTPresentation());
+
+      // Check it has some slides
+      assertNotNull(xml.getSlides().length);
+      assertTrue(xml.getSlides().length > 0);
+
+      assertNotNull(xml.getSlideMasters().length);
+      assertTrue(xml.getSlideMasters().length > 0);
+   }
+
+   public void testSlideBasics() throws Exception {
+      XMLSlideShow xml = new XMLSlideShow(pack);
+
+      // Should have 1 master
+      assertEquals(1, xml.getSlideMasters().length);
+
+      // Should have two sheets
+      assertEquals(2, xml.getSlides().length);
+
+      // Check they're as expected
+      CTSlideIdListEntry[] slides = new CTSlideIdListEntry[
+         xml.getCTPresentation().getSldIdLst().getSldIdList().size()];
+      xml.getCTPresentation().getSldIdLst().getSldIdList().toArray(slides);
+
+      assertEquals(256, slides[0].getId());
+      assertEquals(257, slides[1].getId());
+      assertEquals("rId2", slides[0].getId2());
+      assertEquals("rId3", slides[1].getId2());
+
+      // Now get those objects
+      assertNotNull(xml.getSlides()[0]);
+      assertNotNull(xml.getSlides()[0]);
+
+      // And check they have notes as expected
+      // TODO
+//    assertNotNull(xml.getNotes(slides[0]));
+//    assertNotNull(xml.getNotes(slides[1]));
+
+      // Next up look for the slide master
+      CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
+         xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().size()];
+      xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().toArray(masters);
+
+      assertEquals(2147483648l, masters[0].getId());
+      assertEquals("rId1", masters[0].getId2());
+      assertNotNull(xml.getSlideMasters()[0]);
+
+      // Finally look for the notes master
+      CTNotesMasterIdListEntry notesMaster =
+         xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
+      assertNotNull(notesMaster);
+      // TODO Get the wrapper
+       }
+       
+   public void testMetadataBasics() throws Exception {
+      XMLSlideShow xml = new XMLSlideShow(pack);
+
+      assertNotNull(xml.getProperties().getCoreProperties());
+      assertNotNull(xml.getProperties().getExtendedProperties());
+
+      assertEquals("Microsoft Office PowerPoint", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
+      assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
+      assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
+
+      assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
+      assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+   }
+}