From 793d119eed95781a67f0098af236a576625235d5 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 30 Jun 2011 15:39:47 +0000 Subject: [PATCH] Bug 51444 - Prevent corrupted output when saving files created by LibreOffice 3.3 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1141576 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../exceptions/OpenXML4JRuntimeException.java | 4 ++++ .../opc/PackageRelationshipTypes.java | 15 +++++++++++++++ .../apache/poi/openxml4j/opc/ZipPackage.java | 13 +++++++------ .../opc/TestPackageCoreProperties.java | 17 +++++++++++++++++ test-data/openxml4j/51444.xlsx | Bin 0 -> 4598 bytes 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 test-data/openxml4j/51444.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 5be12f315..69572844b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51444 - Prevent corrupted output when saving files created by LibreOffice 3.3 51422 - Support using RecalcIdRecord to trigger a full formula recalculation on load 50474 - Example demonstrating how to update Excel workbook embedded in a WordprocessingML document 51431 - Avoid IndexOutOfBoundException when removing freeze panes in XSSF diff --git a/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java b/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java index 7e95153fa..40086aa9f 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/exceptions/OpenXML4JRuntimeException.java @@ -31,4 +31,8 @@ public class OpenXML4JRuntimeException extends RuntimeException { public OpenXML4JRuntimeException(String msg) { super(msg); } + + public OpenXML4JRuntimeException(String msg, Throwable reason) { + super(msg, reason); + } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java index 01ed54c96..9344a64ab 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipTypes.java @@ -27,9 +27,24 @@ public interface PackageRelationshipTypes { /** * Core properties relationship type. + * + *

+ * The standard specifies a source relations ship for the Core File Properties part as follows: + * http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties. + *

+ *

+ * Office uses the following source relationship for the Core File Properties part: + * http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties. + *

+ * 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. */ diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 52a871411..bc65412bc 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -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 Package { // 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 Package { } 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); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java index f2b2f7e1c..d5ca8936d 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java @@ -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 TestPackageCoreProperties extends TestCase { 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"); + } + } diff --git a/test-data/openxml4j/51444.xlsx b/test-data/openxml4j/51444.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5047dbf440548b4938f156079232fd6696a71f76 GIT binary patch literal 4598 zcmaJ^2{_d2+qUm(#*zt1ipai3*(Z@**|Im*$%x68B_WIvh7mGkmtDxd$FZleQ`Rgo z4B0FBW=`k-@%8;X&s?)y*Syd3d*AzgmiyM%CM5$9QBhG5fwVu~AUb8V_}|tZV2G!v z2;s9B`QD{nj4m7(K$G=&p)yPylxo%Us#>CsauC8V9(iozYO%K`X#gC)}RtQ|bA;giifKD)D{48d| zixgF|)MThtG!o@oWqypDs%wh-qCh%Hn=8jj{>4e=`~WmAu${ruQJU*%px5Wao(P^u z)y`oSp`^=)oR|YZn<=Y6*P6&wb6pZS`%MJJ*&K$*QE^sHJMF{X0$941e9*k9hXlvJ+GUSu=)Q>&5?5$XRC7iRp5`%rs*52(ARs6EsJ zEaLM35{=Y@ww>n)$9)IT@3Z9x*=btD*ZQP%BWocO(Jh5%X!)PqZ9bYTKwo35-(APe zeJNFzxxOMX8M0jS~&VZF2s(hT5K| zv^4(15eUb&B`21rV2;P-#Qgynrd(vJ~llA2Hx7*XDlT8*~f*V#LIBahI-AwGORHc>CfOG+ADv>P}TW%=fi7ehHV&LU=B6!%-JTR z%7G!zMR?ei+DM0&Xyd6wY{;IC)<%1#d>e}7(7(a{cqzanAaMWq4WG=pnZ!o9x(f_@ z1&yZU>rGQJpJ0yz;5-EQFY1oGQYI!Mg8wW0OsC*~CKYF*n5}QV5NhQe zzfs`SohvYZYp{LPHL@E5>}Kz-gd8^-wC-UaE`^1AgNht+UCbWk;&iYH53TbnPLOeW znB)yv?*xExs{lJG-40n;$s)?9S6l@|8)nR#5WK-W1TW9rpS|Pkdd@|n1Is!pjx$ZY zR5&NN8WR4bXyHdC#c~j>$c)t>*m5Z}rx`JbJJF3=zyIU@@hy=hboFGmL`r zg{-4%i%~~io8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