poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r958923 - in /poi/trunk: src/documentation/content/xdocs/ src/ooxml/java/org/apache/poi/ src/ooxml/java/org/apache/poi/openxml4j/opc/ src/ooxml/java/org/apache/poi/xslf/ src/ooxml/testcases/org/apache/poi/xslf/extractor/ test-data/slideshow/
Date Tue, 29 Jun 2010 11:07:27 GMT
Author: nick
Date: Tue Jun 29 11:07:27 2010
New Revision: 958923

URL: http://svn.apache.org/viewvc?rev=958923&view=rev
Log:
More XSLF tests for the less common extensions, and initial support for .thmx (theme) files
- currently just stretches to not breaking...

Added:
    poi/trunk/test-data/slideshow/testPPT.ppsm   (with props)
    poi/trunk/test-data/slideshow/testPPT.ppsx   (with props)
    poi/trunk/test-data/slideshow/testPPT.pptm   (with props)
    poi/trunk/test-data/slideshow/testPPT.pptx   (with props)
    poi/trunk/test-data/slideshow/testPPT.thmx   (with props)
    poi/trunk/test-data/slideshow/testPPT.xps   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Jun 29 11:07:27 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">XSLFSlideShow shouldn't break on
.thmx (theme) files. Support for them is still very limited though</action>
         </release>
         <release version="3.7-beta1" date="2010-06-20">
            <action dev="POI-DEVELOPERS" type="fix">49432 - Lazy caching of XSSFComment
CTComment objects by reference, to make repeated comment searching faster</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Tue Jun 29 11:07:27 2010
@@ -16,23 +16,30 @@
 ==================================================================== */
 package org.apache.poi;
 
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PushbackInputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
-import org.apache.poi.poifs.common.POIFSConstants;
-import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.PackageHelper;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.*;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.util.IOUtils;
 
 public abstract class POIXMLDocument extends POIXMLDocumentPart{
     public static final String DOCUMENT_CREATOR = "Apache POI";
 
-    public static final String CORE_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
-    public static final String EXTENDED_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
-    public static final String CUSTOM_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
-
     // OLE embeddings relation name
     public static final String OLE_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Tue Jun 29 11:07:27 2010
@@ -23,6 +23,7 @@ import java.net.URI;
 import org.apache.xmlbeans.XmlOptions;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.POILogFactory;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.*;
 
@@ -85,6 +86,24 @@ public class POIXMLDocumentPart {
         this.packagePart = part;
         this.packageRel = rel;
     }
+    
+    /**
+     * When you open something like a theme, call this to
+     *  re-base the XML Document onto the core child of the
+     *  current core document 
+     */
+    protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
+       PackageRelationshipCollection cores =
+          packagePart.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
+       if(cores.size() != 1) {
+          throw new IllegalStateException(
+                "Tried to rebase using " + PackageRelationshipTypes.CORE_DOCUMENT +
+                " but found " + cores.size() + " parts of the right type"
+          );
+       }
+       packageRel = cores.getRelationship(0);
+       packagePart = POIXMLDocument.getTargetPart(pkg, packageRel);
+    }
 
     /**
      * Provides access to the underlying PackagePart

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java Tue Jun 29 11:07:27 2010
@@ -28,6 +28,7 @@ import org.apache.poi.openxml4j.opc.OPCP
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
@@ -68,7 +69,7 @@ public class POIXMLProperties {
 
 		// Extended properties
 		PackageRelationshipCollection extRel =
-			pkg.getRelationshipsByType(POIXMLDocument.EXTENDED_PROPERTIES_REL_TYPE);
+			pkg.getRelationshipsByType(PackageRelationshipTypes.EXTENDED_PROPERTIES);
 		if(extRel.size() == 1) {
 			extPart = pkg.getPart( extRel.getRelationship(0));
 			org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument
props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse(
@@ -82,7 +83,7 @@ public class POIXMLProperties {
 
 		// Custom properties
 		PackageRelationshipCollection custRel =
-			pkg.getRelationshipsByType(POIXMLDocument.CUSTOM_PROPERTIES_REL_TYPE);
+			pkg.getRelationshipsByType(PackageRelationshipTypes.CUSTOM_PROPERTIES);
 		if(custRel.size() == 1) {
 			custPart = pkg.getPart( custRel.getRelationship(0));
 			org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props
= org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse(

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java Tue
Jun 29 11:07:27 2010
@@ -56,6 +56,11 @@ public interface PackageRelationshipType
 	String EXTENDED_PROPERTIES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
 
 	/**
+	 * Custom properties relationship type.
+	 */
+	String CUSTOM_PROPERTIES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
+	
+	/**
 	 * Core properties relationship type.
 	 */
 	String CORE_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";

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=958923&r1=958922&r2=958923&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 Tue Jun 29 11:07:27 2010
@@ -29,6 +29,7 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
 import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
@@ -57,11 +58,12 @@ import org.openxmlformats.schemas.presen
  */
 public class XSLFSlideShow extends POIXMLDocument {
 	public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
-        public static final String MACRO_CONTENT_TYPE = "application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml";
-        public static final String MACRO_TEMPLATE_CONTENT_TYPE = "application/vnd.ms-powerpoint.template.macroEnabled.main+xml";
-        public static final String PRESENTATIONML_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml";
-        public static final String PRESENTATIONML_TEMPLATE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml";
-        public static final String PRESENTATION_MACRO_CONTENT_TYPE = "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml";
+   public static final String MACRO_CONTENT_TYPE = "application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml";
+   public static final String MACRO_TEMPLATE_CONTENT_TYPE = "application/vnd.ms-powerpoint.template.macroEnabled.main+xml";
+   public static final String PRESENTATIONML_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml";
+   public static final String PRESENTATIONML_TEMPLATE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml";
+   public static final String PRESENTATION_MACRO_CONTENT_TYPE = "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml";
+   public static final String THEME_MANAGER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.themeManager+xml";
 	public static final String NOTES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml";
 	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";
@@ -77,11 +79,15 @@ public class XSLFSlideShow extends POIXM
 	public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException
{
 		super(container);
 		
+		if(getCorePart().getContentType().equals(THEME_MANAGER_CONTENT_TYPE)) {
+		   rebase(getPackage());
+		}
+		
 		presentationDoc =
 			PresentationDocument.Factory.parse(getCorePart().getInputStream());
 		
-        embedds = new LinkedList<PackagePart>();
-		for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
+      embedds = new LinkedList<PackagePart>();
+      for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
 	          PackagePart slidePart =
 	                getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
 	          
@@ -112,7 +118,12 @@ public class XSLFSlideShow extends POIXM
 	 */
     @Internal
 	public CTSlideIdList getSlideReferences() {
-		return getPresentation().getSldIdLst();
+       if(! getPresentation().isSetSldIdLst()) {
+          getPresentation().setSldIdLst(
+             CTSlideIdList.Factory.newInstance()   
+          );
+       }
+       return getPresentation().getSldIdLst();
 	}
 	/**
 	 * Returns the references from the presentation to its

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java?rev=958923&r1=958922&r2=958923&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
Tue Jun 29 11:07:27 2010
@@ -126,4 +126,53 @@ public class TestXSLFPowerPointExtractor
         // Check comments are there
         assertTrue("Unable to find expected word in text\n" + text, text.contains("TEST"));
     }
+    
+    /**
+     * Test that we can get the text from macro enabled,
+     *  template, theme, slide enabled etc formats, as 
+     *  well as from the normal file
+     */
+    public void testDifferentSubformats() throws Exception {
+       POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+       String[] extensions = new String[] {
+             "pptx", "pptm", "ppsm", "ppsx",
+             "thmx", 
+             //"xps" // Doesn't have a core document
+       };
+       for(String extension : extensions) {
+          String filename = "testPPT." + extension;
+          xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream(filename)));
+          XSLFPowerPointExtractor extractor =
+             new XSLFPowerPointExtractor(xmlA);
+
+         String text = extractor.getText();
+         if(extension.equals("thmx")) {
+            // Theme file doesn't have any textual content
+            assertEquals(0, text.length());
+            continue;
+         }
+         
+         assertTrue(text.length() > 0);
+         assertTrue(
+               "Text missing for " + filename + "\n" + text, 
+               text.contains("Attachment Test")
+         );
+         assertTrue(
+               "Text missing for " + filename + "\n" + text, 
+               text.contains("This is a test file data with the same content")
+         );
+         assertTrue(
+               "Text missing for " + filename + "\n" + text, 
+               text.contains("content parsing")
+         );
+         assertTrue(
+               "Text missing for " + filename + "\n" + text, 
+               text.contains("Different words to test against")
+         );
+         assertTrue(
+               "Text missing for " + filename + "\n" + text, 
+               text.contains("Mystery")
+         );
+       }
+    }
 }

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

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

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

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

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

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

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

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

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

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

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

Propchange: poi/trunk/test-data/slideshow/testPPT.xps
------------------------------------------------------------------------------
    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


Mime
View raw message