]> source.dussan.org Git - poi.git/commitdiff
Bug 59273 - Unable to create pptx file by potx file using Apache POI
authorAndreas Beeker <kiwiwings@apache.org>
Thu, 10 Nov 2016 22:54:07 +0000 (22:54 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Thu, 10 Nov 2016 22:54:07 +0000 (22:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1769220 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/TestAllFiles.java
src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
test-data/slideshow/bug59273.potx [new file with mode: 0644]

index dcce6269f18f71e9d18292871ee9900e22a85b14..3974c0631950836054ada24abf79a1498a8418d1 100644 (file)
@@ -91,6 +91,7 @@ public class TestAllFiles {
         HANDLERS.put(".ppsm", new XSLFFileHandler());
         HANDLERS.put(".ppsx", new XSLFFileHandler());
         HANDLERS.put(".thmx", new XSLFFileHandler());
+        HANDLERS.put(".potx", new XSLFFileHandler());
 
         // Outlook
         HANDLERS.put(".msg", new HSMFFileHandler());
index 506344f93ca2341899b86145b23d503246d06acf..5220529fd3bc1bc2f1fa2f5d6e5548f0673d85ae 100644 (file)
@@ -1654,7 +1654,13 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
             if (packagePart.getContentType().equals(oldContentType)) {
                 PackagePartName partName = packagePart.getPartName();
                 contentTypeManager.addContentType(partName, newContentType);
+                try {
+                    packagePart.setContentType(newContentType);
+                } catch (InvalidFormatException e) {
+                    throw new OpenXML4JRuntimeException("invalid content type - "+newContentType, e);
+                }
                 success = true;
+                this.isDirty = true;
             }
         }
         return success;
index cd475fccedfe9b7e5be19f9905cff211a1db6b04..7c02ba282ba5af90e1405e99908397cdcb10615e 100644 (file)
@@ -31,10 +31,7 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.net.URI;
 import java.util.Collection;
 
@@ -43,6 +40,7 @@ import javax.imageio.ImageIO;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLDocumentPart.RelationPart;
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.sl.draw.DrawPaint;
 import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
@@ -52,8 +50,6 @@ import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.sl.usermodel.ShapeType;
 import org.apache.poi.sl.usermodel.VerticalAlignment;
 import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
-import org.apache.poi.xslf.usermodel.DrawingParagraph;
-import org.apache.poi.xslf.usermodel.DrawingTextBody;
 import org.apache.poi.xslf.usermodel.XMLSlideShow;
 import org.apache.poi.xslf.usermodel.XSLFAutoShape;
 import org.apache.poi.xslf.usermodel.XSLFHyperlink;
@@ -541,4 +537,23 @@ public class TestXSLFBugs {
         newPptx.close();
         srcPptx.close();
     }
+
+    @Test
+    public void bug59273() throws IOException {
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("bug59273.potx");
+        ppt.getPackage().replaceContentType(
+            XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType(), 
+            XSLFRelation.MAIN.getContentType()
+        );
+
+        XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+        OPCPackage pkg = rwPptx.getPackage();
+        int size = pkg.getPartsByContentType(XSLFRelation.MAIN.getContentType()).size();
+        assertEquals(1, size);
+        size = pkg.getPartsByContentType(XSLFRelation.PRESENTATIONML_TEMPLATE.getContentType()).size();
+        assertEquals(0, size);
+        
+        rwPptx.close();
+        ppt.close();
+    }
 }
diff --git a/test-data/slideshow/bug59273.potx b/test-data/slideshow/bug59273.potx
new file mode 100644 (file)
index 0000000..72815da
Binary files /dev/null and b/test-data/slideshow/bug59273.potx differ