You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/05/27 16:35:45 UTC

svn commit: r1128324 - in /poi/trunk: src/ooxml/java/org/apache/poi/xslf/ src/ooxml/java/org/apache/poi/xslf/usermodel/ src/ooxml/testcases/org/apache/poi/xslf/ test-data/slideshow/

Author: nick
Date: Fri May 27 14:35:44 2011
New Revision: 1128324

URL: http://svn.apache.org/viewvc?rev=1128324&view=rev
Log:
Few XSLF tweaks, and add a unit test that shows that bug #51187 exists (problem with self references)

Added:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java
    poi/trunk/test-data/slideshow/51187.pptx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java?rev=1128324&r1=1128323&r2=1128324&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java Fri May 27 14:35:44 2011
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.util.Internal;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
 import org.apache.poi.xslf.usermodel.XSLFRelation;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
@@ -46,8 +47,9 @@ import org.openxmlformats.schemas.presen
 import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
 
 /**
- * Experimental class to do low level processing
- *  of pptx files.
+ * Experimental class to do low level processing of pptx files.
+ * 
+ * Most users should use the higher level {@link XMLSlideShow} instead.
  *  
  * If you are using these low level classes, then you
  *  will almost certainly need to refer to the OOXML
@@ -113,6 +115,7 @@ public class XSLFSlideShow extends POIXM
        }
        return getPresentation().getSldIdLst();
 	}
+    
 	/**
 	 * Returns the references from the presentation to its
 	 *  slide masters.

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1128324&r1=1128323&r2=1128324&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Fri May 27 14:35:44 2011
@@ -18,6 +18,8 @@ package org.apache.poi.xslf.usermodel;
 
 import java.io.IOException;
 
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.sl.usermodel.MasterSheet;
 import org.apache.poi.sl.usermodel.Resources;
 import org.apache.poi.sl.usermodel.Slide;
@@ -27,6 +29,7 @@ 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;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
 
 /**
  * High level representation of a ooxml slideshow.
@@ -42,6 +45,7 @@ public class XMLSlideShow implements Sli
 		this.slideShow = xml;
 		
 		// Build the main masters list - TODO
+		CTSlideMasterIdList masterIds = slideShow.getSlideMasterReferences();
 		
 		// Build the slides list
 		CTSlideIdList slideIds = slideShow.getSlideReferences();
@@ -55,6 +59,10 @@ public class XMLSlideShow implements Sli
 		// Build the notes list - TODO
 	}
 	
+	public XMLSlideShow(OPCPackage pkg) throws XmlException, IOException, OpenXML4JException {
+	   this(new XSLFSlideShow(pkg));
+	}
+	
 	public XSLFSlideShow _getXSLFSlideShow() {
 		return slideShow;
 	}

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1128324&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Fri May 27 14:35:44 2011
@@ -0,0 +1,58 @@
+/* ====================================================================
+   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;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+
+public class TestXSLFBugs extends TestCase {
+
+    public void test51187() throws Exception {
+       XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("51187.pptx");
+       
+       assertEquals(1, ss.getSlides().length);
+       XSLFSlide slide = ss.getSlides()[0];
+       
+       // Check the relations on it
+       // Note - rId3 is a self reference
+       PackagePart slidePart = ss._getXSLFSlideShow().getSlidePart(
+             ss._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
+       );
+       assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString());
+       assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
+       assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
+       assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
+       assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
+       
+       // Save and re-load
+       ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
+       assertEquals(1, ss.getSlides().length);
+       
+       slidePart = ss._getXSLFSlideShow().getSlidePart(
+             ss._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
+       );
+       assertEquals("/ppt/slides/slide1.xml", slidePart.getPartName().toString());
+       assertEquals("/ppt/slideLayouts/slideLayout12.xml", slidePart.getRelationship("rId1").getTargetURI().toString());
+       assertEquals("/ppt/notesSlides/notesSlide1.xml", slidePart.getRelationship("rId2").getTargetURI().toString());
+       // TODO Fix this
+//       assertEquals("/ppt/slides/slide1.xml", slidePart.getRelationship("rId3").getTargetURI().toString());
+       assertEquals("/ppt/media/image1.png", slidePart.getRelationship("rId4").getTargetURI().toString());
+    }
+}

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java?rev=1128324&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java Fri May 27 14:35:44 2011
@@ -0,0 +1,51 @@
+/* ====================================================================
+   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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class XSLFTestDataSamples {
+
+    public static XMLSlideShow openSampleDocument(String sampleName) {
+        InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream(sampleName);
+        try {
+            return new XMLSlideShow(OPCPackage.open(is));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+            doc._getXSLFSlideShow().write(baos);
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            return new XMLSlideShow(OPCPackage.open(bais));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Added: poi/trunk/test-data/slideshow/51187.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/51187.pptx?rev=1128324&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/51187.pptx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org