Author: yegor
Date: Thu Jun 30 15:39:47 2011
New Revision: 1141576

URL: http://svn.apache.org/viewvc?rev=1141576&view=rev
Log:
Bug 51444 -  Prevent corrupted output when saving files created by LibreOffice 
3.3

Added:
    poi/trunk/test-data/openxml4j/51444.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java
    
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.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=1141576&r1=1141575&r2=1141576&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jun 30 15:39:47 
2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="add">51444 - Prevent corrupted 
output when saving files created by LibreOffice 3.3 </action>
            <action dev="poi-developers" type="add">51422 - Support using 
RecalcIdRecord to trigger a full formula recalculation on load  </action>
            <action dev="poi-developers" type="add">50474 - Example 
demonstrating how to update Excel workbook embedded in a WordprocessingML 
document </action>
            <action dev="poi-developers" type="fix">51431 - Avoid 
IndexOutOfBoundException when removing freeze panes in XSSF </action>

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java?rev=1141576&r1=1141575&r2=1141576&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java
 (original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java
 Thu Jun 30 15:39:47 2011
@@ -31,4 +31,8 @@ public class OpenXML4JRuntimeException e
        public OpenXML4JRuntimeException(String msg) {
                super(msg);
        }
+
+    public OpenXML4JRuntimeException(String msg, Throwable reason) {
+        super(msg, reason);
+    }
 }

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=1141576&r1=1141575&r2=1141576&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
 Thu Jun 30 15:39:47 2011
@@ -27,9 +27,24 @@ public interface PackageRelationshipType
 
        /**
         * Core properties relationship type.
+     *
+     *  <p>
+     *  The standard specifies a source relations ship for the Core File 
Properties part as follows:
+     *  
<code>http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties.</code>
+     *  </p>
+     *  <p>
+     *   Office uses the following source relationship for the Core File 
Properties part:
+     *   
<code>http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties.</code>
+     * </p>
+     * See 2.1.33 Part 1 Section 15.2.11.1, Core File Properties Part in 
[MS-OE376].pdf
         */
        String CORE_PROPERTIES = 
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";;
 
+    /**
+     * Core properties relationship type as defiend in ECMA 376.
+      */
+    String CORE_PROPERTIES_ECMA376 = 
"http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties";;
+
        /**
         * Digital signature relationship type.
         */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1141576&r1=1141575&r2=1141576&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Thu 
Jun 30 15:39:47 2011
@@ -30,6 +30,7 @@ import java.util.zip.ZipOutputStream;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
 import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.FileHelper;
 import org.apache.poi.openxml4j.opc.internal.MemoryPackagePart;
@@ -384,13 +385,13 @@ public final class ZipPackage extends Pa
 
                        // If the core properties part does not exist in the 
part list,
                        // we save it as well
-                       if (this.getPartsByRelationshipType(
-                                       
PackageRelationshipTypes.CORE_PROPERTIES).size() == 0) {
+                       if 
(this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size()
 == 0 &&
+                
this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size()
 == 0    ) {
                                logger.log(POILogger.DEBUG,"Save core 
properties part");
 
                                // We have to save the core properties part ...
                                new ZipPackagePropertiesMarshaller().marshall(
-                                               this.packageProperties, zos);
+                        this.packageProperties, zos);
                                // ... and to add its relationship ...
                                
this.relationships.addRelationship(this.packageProperties
                                                .getPartName().getURI(), 
TargetMode.INTERNAL,
@@ -445,9 +446,9 @@ public final class ZipPackage extends Pa
                        }
                        zos.close();
                } catch (Exception e) {
-                       logger
-                                       .log(POILogger.ERROR,"Fail to save: an 
error occurs while saving the package : "
-                                                       + e.getMessage());
+            throw new OpenXML4JRuntimeException(
+                    "Fail to save: an error occurs while saving the package : "
+                                                       + e.getMessage(), e);
                }
        }
 

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java?rev=1141576&r1=1141575&r2=1141576&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
 (original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
 Thu Jun 30 15:39:47 2011
@@ -17,6 +17,8 @@
 
 package org.apache.poi.openxml4j.opc;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.text.ParsePosition;
@@ -180,4 +182,19 @@ public final class TestPackageCoreProper
         assertEquals(date, props.getModifiedProperty().getValue());
     }
 
+    public void testGetPropertiesLO() throws Exception {
+        // Open the package
+        OPCPackage pkg1 = 
OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("51444.xlsx"));
+        PackageProperties props1 = pkg1.getPackageProperties();
+        assertEquals(null, props1.getTitleProperty().getValue());
+        props1.setTitleProperty("Bug 51444 fixed");
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        pkg1.save(out);
+        out.close();
+
+        OPCPackage pkg2 = OPCPackage.open(new 
ByteArrayInputStream(out.toByteArray()));
+        PackageProperties props2 = pkg2.getPackageProperties();
+        props2.setTitleProperty("Bug 51444 fixed");
+    }
+
 }

Added: poi/trunk/test-data/openxml4j/51444.xlsx
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/openxml4j/51444.xlsx?rev=1141576&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/openxml4j/51444.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to