You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2019/09/26 17:51:45 UTC
svn commit: r1867597 - in /poi/trunk/src:
examples/src/org/apache/poi/xssf/usermodel/examples/
ooxml/java/org/apache/poi/ooxml/ ooxml/testcases/org/apache/poi/ooxml/
testcases/org/apache/poi/hpsf/extractor/
Author: fanningpj
Date: Thu Sep 26 17:51:45 2019
New Revision: 1867597
URL: http://svn.apache.org/viewvc?rev=1867597&view=rev
Log:
[bug-63774] adding lots of custom properties can cause performance issues due to way Pid is calculated
Modified:
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java
poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java
poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java?rev=1867597&r1=1867596&r2=1867597&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java Thu Sep 26 17:51:45 2019
@@ -34,19 +34,19 @@ public class WorkbookProperties {
POIXMLProperties props = workbook.getProperties();
- /*
- * Extended properties are a predefined set of metadata properties
- * that are specifically applicable to Office Open XML documents.
- * Extended properties consist of 24 simple properties and 3 complex properties stored in the
- * part targeted by the relationship of type
- */
+ /*
+ * Extended properties are a predefined set of metadata properties
+ * that are specifically applicable to Office Open XML documents.
+ * Extended properties consist of 24 simple properties and 3 complex properties stored in the
+ * part targeted by the relationship of type
+ */
POIXMLProperties.ExtendedProperties ext = props.getExtendedProperties();
ext.getUnderlyingProperties().setCompany("Apache Software Foundation");
ext.getUnderlyingProperties().setTemplate("XSSF");
- /*
- * Custom properties enable users to define custom metadata properties.
- */
+ /*
+ * Custom properties enable users to define custom metadata properties.
+ */
POIXMLProperties.CustomProperties cust = props.getCustomProperties();
cust.addProperty("Author", "John Smith");
Modified: poi/trunk/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java?rev=1867597&r1=1867596&r2=1867597&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java Thu Sep 26 17:51:45 2019
@@ -565,6 +565,8 @@ public class POIXMLProperties {
public static final String FORMAT_ID = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
private org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props;
+ private Integer lastPid = null;
+
private CustomProperties(org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props) {
this.props = props;
}
@@ -651,11 +653,23 @@ public class POIXMLProperties {
* @return next property id starting with 2
*/
protected int nextPid() {
+ int propid = lastPid == null ? getLastPid() : lastPid;
+ int nextid = propid + 1;
+ this.lastPid = nextid;
+ return nextid;
+ }
+
+ /**
+ * Find the highest Pid in use
+ *
+ * @return the highest Pid in use in the property set; returns 1 if no properties are set
+ */
+ protected int getLastPid() {
int propid = 1;
for(CTProperty p : props.getProperties().getPropertyList()) {
if(p.getPid() > propid) propid = p.getPid();
}
- return propid + 1;
+ return propid;
}
/**
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java?rev=1867597&r1=1867596&r2=1867597&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java Thu Sep 26 17:51:45 2019
@@ -316,6 +316,18 @@ public final class TestPOIXMLProperties
}
@Test
+ public void testAddProperty() throws IOException {
+ try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx")) {
+ POIXMLProperties.CustomProperties cps = doc.getProperties().getCustomProperties();
+ assertEquals(1, cps.getLastPid());
+ cps.addProperty("prop1", "abc");
+ assertEquals(2, cps.getLastPid());
+ assertEquals(2, cps.getProperty("prop1").getPid());
+ assertEquals("abc", cps.getProperty("prop1").getLpwstr());
+ }
+ }
+
+ @Test
public void testBug60977() throws IOException {
try (final XSSFWorkbook workbook = new XSSFWorkbook()) {
Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java?rev=1867597&r1=1867596&r2=1867597&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java Thu Sep 26 17:51:45 2019
@@ -86,7 +86,8 @@ public final class TestHPSFPropertiesExt
public void testCustomProperties() throws Exception {
try (InputStream is = _samples.openResourceAsStream("TestMickey.doc");
POIFSFileSystem fs = new POIFSFileSystem(is);
- HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs)) {
+ HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs)) {
+
// Custom properties are part of the document info stream
String dinfText = ext.getDocumentSummaryInformationText();
assertContains(dinfText, "Client = sample client");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org