Skip to content

Commit

Permalink
New property docx4j.model.datastorage.OpenDoPEReverter.Supported, whi…
Browse files Browse the repository at this point in the history
…ch can be set to false, to speed things up a little.
  • Loading branch information
plutext committed May 25, 2015
1 parent f72020f commit 97b6515
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.xml.bind.JAXBElement;

import org.apache.commons.lang.StringUtils;
import org.docx4j.Docx4jProperties;
import org.docx4j.TraversalUtil;
import org.docx4j.XmlUtils;
import org.docx4j.finders.TcFinder;
Expand All @@ -51,8 +52,6 @@
import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart;
import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
import org.docx4j.openpackaging.parts.opendope.ComponentsPart;
import org.docx4j.openpackaging.parts.opendope.ConditionsPart;
import org.docx4j.openpackaging.parts.opendope.XPathsPart;
import org.docx4j.openpackaging.parts.relationships.Namespaces;
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
import org.docx4j.relationships.Relationship;
Expand Down Expand Up @@ -792,8 +791,15 @@ private List<Object> processBindingRoleIfAny(
newContent.add(sdt);
return newContent;

} else {
} else if (reverterSupported){
return conditionFalse(sdt);
} else {
return new ArrayList<Object>(); // effectively, delete
// Potentially slightly faster processing, since
// the conditionFalse sdt doesn't need to be created.
// The document is only slightly smaller, since conditionFalse sdt doesn't have a lot of content.
// OpenDoPEIntegrity is responsible for handling the case where
// this creates an empty table cell
}

} else if (repeatId != null) {
Expand Down Expand Up @@ -828,6 +834,8 @@ private List<Object> processBindingRoleIfAny(
return null;
}

boolean reverterSupported = Docx4jProperties.getProperty("docx4j.model.datastorage.OpenDoPEReverter.Supported", true);

/**
* Insert an empty placeholder SDT, to facilitate round-tripping
* (ie ability to convert instance docx back to original template),
Expand Down Expand Up @@ -915,7 +923,7 @@ private List<Object> conditionFalse(Object sdt) {
// contentChildCount++;
// return contentChildCount;
// }

//
// private List<Object> obtainChildren(Object element) {
// Object unwrapped = XmlUtils.unwrap(element);
// if (unwrapped instanceof ContentAccessor) {
Expand Down Expand Up @@ -1041,10 +1049,17 @@ private List<Object> processRepeat(Object sdt,
log.debug("yields REPEATS: " + numRepeats);

if (numRepeats == 0) {
//return new ArrayList<Object>(); // effectively, delete

// Change tag to od:resultRepeatZero=id
return repeatZero(sdt);
if (reverterSupported){
// Change tag to od:resultRepeatZero=id
return repeatZero(sdt);
} else {
return new ArrayList<Object>(); // effectively, delete
// The document is only slightly smaller, since the repeatZero sdt doesn't have a lot of content.

// OpenDoPEIntegrity is responsible for handling the case where
// this creates an empty table cell
}
}

// duplicate content here ...
Expand Down
9 changes: 9 additions & 0 deletions src/samples/_resources/docx4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ docx4j.Convert.Out.HTML.OutputMethodXML=true
# defaults to anchor. @since 3.2.1
docx4j.Convert.Out.HTML.BookmarkStartWriter.mapTo=a

# use OL, UL in HTML output. Defaults to false for backwards compat.
# See further org.docx4j.convert.out.html.ListContext
# @since 3.2.2
docx4j.Convert.Out.HTML.Lists=true

# If false, throw an exception if something is encountered which
# output processing is unable to handle. TODO fully implement this.
docx4j.Convert.Out.Lossy=true
Expand Down Expand Up @@ -118,6 +123,10 @@ docx4j.model.datastorage.BindingTraverserXSLT.xslt=org/docx4j/model/datastorage/
# will fallback to org/docx4j/model/datastorage/placeholder.xml (which is in the docx4j jar)
#docx4j.model.datastorage.placeholder=OpenDoPE/placeholder.xml

# You can set this to false if you don't use OpenDoPEReverter; it omits some empty content controls from the BindlingHandler
# step, so it may speed processing up marginally, and make ODH's output easier to read. Defaults to true.
docx4j.model.datastorage.OpenDoPEReverter.Supported=true

# These affect the output of numbers in Arabic; see further RunFontSelector
# For further discussion, please see http://www.docx4java.org/forums/pdf-output-f27/arabic-number-digits-in-pdf-output-t1826.html
# Value can be 'Context'|'National'
Expand Down

0 comments on commit 97b6515

Please sign in to comment.