timingSummary.append("\nOpenDoPEIntegrity: " + (endTime-startTime));
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
);
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
saver.save(filepathprefix + "_preprocessed.docx");
System.out.println("Saved: " + filepathprefix + "_preprocessed.docx");
// Apply the bindings
BindingHandler.setHyperlinkStyle("Hyperlink");
startTime = System.currentTimeMillis();
AtomicInteger bookmarkId = odh.getNextBookmarkId();
BindingHandler bh = new BindingHandler(wordMLPackage);
bh.setStartingIdForNewBookmarks(bookmarkId);
bh.applyBindings(wordMLPackage.getMainDocumentPart());
endTime = System.currentTimeMillis();
timingSummary.append("\nBindingHandler.applyBindings: " + (endTime-startTime));
String bound = XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true);
System.out.println(
);
saver.save(filepathprefix + "_bound.docx");
System.out.println("Saved: " + filepathprefix + "_bound.docx");
// process altChunk
if (bound.contains("altChunk")) {
try {
// Use reflection, so docx4j can be built
// by users who don't have the MergeDocx utility
Class<?> documentBuilder = Class
.forName("com.plutext.merge.ProcessAltChunk");
// Method method = documentBuilder.getMethod("merge",
// wmlPkgList.getClass());
Method[] methods = documentBuilder.getMethods();
Method processMethod = null;
for (int j = 0; j < methods.length; j++) {
// log.debug(methods[j].getName());
if (methods[j].getName().equals("process")) {
processMethod = methods[j];
}
}
if (processMethod == null )
throw new NoSuchMethodException();
startTime = System.currentTimeMillis();
wordMLPackage = (WordprocessingMLPackage) processMethod.invoke(null,
wordMLPackage);
endTime = System.currentTimeMillis();
timingSummary.append("\nBindingHandler.applyBindings: " + (endTime-startTime));
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
);
saver.save(filepathprefix + "_altChunksMerged.docx");
System.out.println("Saved: " + filepathprefix + "_altChunksMerged.docx");
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (Exception e) {
throw new Docx4JException("Problem processing w:altChunk", e);
}
}
// Either demonstrate reverter, or stripping of controls;
// you can't do both. So comment out one or the other.
// reverter(inputfilepath, filepathprefix + "_bound.docx");
//
// Strip content controls
startTime = System.currentTimeMillis();
RemovalHandler rh = new RemovalHandler();
rh.removeSDTs(wordMLPackage, Quantifier.ALL);
endTime = System.currentTimeMillis();
timingSummary.append("\nRemovalHandler: " + (endTime-startTime));
saver.save(filepathprefix + "_stripped.docx");
System.out.println("Saved: " + filepathprefix + "_stripped.docx");
System.out.println(timingSummary);
}