/**
* Bind the content controls of the passed document to the xml.
*/
public static void bind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags) throws Docx4JException {
OpenDoPEHandler openDoPEHandler = null;
CustomXmlDataStoragePart customXmlDataStoragePart = null;
RemovalHandler removalHandler = null;
//String xpathStorageItemId = null;
AtomicInteger bookmarkId = null;
if (flags == FLAG_NONE) {
//do everything
flags = (FLAG_BIND_INSERT_XML |
FLAG_BIND_BIND_XML |
FLAG_BIND_REMOVE_SDT |
FLAG_BIND_REMOVE_XML);
}
customXmlDataStoragePart
= CustomXmlDataStoragePartSelector.getCustomXmlDataStoragePart(wmlPackage);
if (customXmlDataStoragePart==null) {
throw new Docx4JException("Couldn't find CustomXmlDataStoragePart! exiting..");
}
if ((flags & FLAG_BIND_INSERT_XML) == FLAG_BIND_INSERT_XML) {
StartEvent startEvent = new StartEvent( WellKnownJobTypes.BIND, wmlPackage, WellKnownProcessSteps.BIND_INSERT_XML );
startEvent.publish();
insertXMLData(customXmlDataStoragePart, xmlDocument);
new EventFinished(startEvent).publish();
}
if ((flags & FLAG_BIND_BIND_XML) == FLAG_BIND_BIND_XML) {
StartEvent startEvent = new StartEvent( WellKnownJobTypes.BIND, wmlPackage, WellKnownProcessSteps.BIND_BIND_XML );
startEvent.publish();
if (wmlPackage.getMainDocumentPart().getXPathsPart()!=null) {
openDoPEHandler = new OpenDoPEHandler(wmlPackage);
openDoPEHandler.preprocess();
bookmarkId = openDoPEHandler.getNextBookmarkId();
}
BindingHandler bh = new BindingHandler(wmlPackage);
bh.setStartingIdForNewBookmarks(bookmarkId);
bh.applyBindings();