mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
bade89b292
commit
586645ade8
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta4" date="2011-??-??">
|
<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">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="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>
|
<action dev="poi-developers" type="fix">51431 - Avoid IndexOutOfBoundException when removing freeze panes in XSSF </action>
|
||||||
|
|
|
@ -31,4 +31,8 @@ public class OpenXML4JRuntimeException extends RuntimeException {
|
||||||
public OpenXML4JRuntimeException(String msg) {
|
public OpenXML4JRuntimeException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OpenXML4JRuntimeException(String msg, Throwable reason) {
|
||||||
|
super(msg, reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,24 @@ public interface PackageRelationshipTypes {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core properties relationship type.
|
* 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";
|
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.
|
* Digital signature relationship type.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.zip.ZipOutputStream;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
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.ContentTypeManager;
|
||||||
import org.apache.poi.openxml4j.opc.internal.FileHelper;
|
import org.apache.poi.openxml4j.opc.internal.FileHelper;
|
||||||
import org.apache.poi.openxml4j.opc.internal.MemoryPackagePart;
|
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,
|
// If the core properties part does not exist in the part list,
|
||||||
// we save it as well
|
// we save it as well
|
||||||
if (this.getPartsByRelationshipType(
|
if (this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size() == 0 &&
|
||||||
PackageRelationshipTypes.CORE_PROPERTIES).size() == 0) {
|
this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size() == 0 ) {
|
||||||
logger.log(POILogger.DEBUG,"Save core properties part");
|
logger.log(POILogger.DEBUG,"Save core properties part");
|
||||||
|
|
||||||
// We have to save the core properties part ...
|
// We have to save the core properties part ...
|
||||||
new ZipPackagePropertiesMarshaller().marshall(
|
new ZipPackagePropertiesMarshaller().marshall(
|
||||||
this.packageProperties, zos);
|
this.packageProperties, zos);
|
||||||
// ... and to add its relationship ...
|
// ... and to add its relationship ...
|
||||||
this.relationships.addRelationship(this.packageProperties
|
this.relationships.addRelationship(this.packageProperties
|
||||||
.getPartName().getURI(), TargetMode.INTERNAL,
|
.getPartName().getURI(), TargetMode.INTERNAL,
|
||||||
|
@ -445,9 +446,9 @@ public final class ZipPackage extends Package {
|
||||||
}
|
}
|
||||||
zos.close();
|
zos.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger
|
throw new OpenXML4JRuntimeException(
|
||||||
.log(POILogger.ERROR,"Fail to save: an error occurs while saving the package : "
|
"Fail to save: an error occurs while saving the package : "
|
||||||
+ e.getMessage());
|
+ e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.poi.openxml4j.opc;
|
package org.apache.poi.openxml4j.opc;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
|
@ -180,4 +182,19 @@ public final class TestPackageCoreProperties extends TestCase {
|
||||||
assertEquals(date, props.getModifiedProperty().getValue());
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue