Class JaxbCustomXmlDataStoragePart<E>
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.parts.Part
org.docx4j.openpackaging.parts.JaxbXmlPart<E>
org.docx4j.openpackaging.parts.opendope.JaxbCustomXmlDataStoragePart<E>
- All Implemented Interfaces:
CustomXmlPart
- Direct Known Subclasses:
BibliographyPart,ComponentsPart,ConditionsPart,DocPropsCoverPagePart,QuestionsPart,StandardisedAnswersPart,XPathsPart
public abstract class JaxbCustomXmlDataStoragePart<E> extends JaxbXmlPart<E> implements CustomXmlPart
-
Field Summary
Fields Modifier and Type Field Description protected org.w3c.dom.DocumentdocThis part's XML contents.Fields inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
jaxbElement, jc, log, MAX_BYTES_Unmarshal_Error -
Constructor Summary
Constructors Constructor Description JaxbCustomXmlDataStoragePart(PartName partName)JaxbCustomXmlDataStoragePart(PartName partName, javax.xml.bind.JAXBContext jc) -
Method Summary
Modifier and Type Method Description java.lang.StringcachedXPathGetString(java.lang.String xpath, java.lang.String prefixMappings)Use org.apache.xpath.CachedXPathAPI, since this is much quicker than default javax.xml.xpath.XPath implementations (Apache's anyway) for large XML files.voiddiscardCacheXPathObject()Use this to null out the org.apache.xpath.CachedXPathAPI object, which you should do if you've changed your source document, or want to reclaim memory.java.lang.StringgetItemId()voidinit()voidreadyXPath()XPaths are evaluated against a DOM document representation of the JAXBElement.voidremove()Remove this part from the pkg.booleansetNodeValueAtXPath(java.lang.String xpath, java.lang.String value, java.lang.String prefixMappings)voidsetXML(org.w3c.dom.Document xmlDocument)Set the XML datavoidupdateJaxbElementFromDocument()java.util.List<org.w3c.dom.Node>xpathGetNodes(java.lang.String xpathString, java.lang.String prefixMappings)java.lang.StringxpathGetString(java.lang.String xpathString, java.lang.String prefixMappings)Methods inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
addMcChoiceNamespace, getContents, getJAXBContext, getJaxbElement, getMcChoiceNamespaces, getMceIgnorable, getXML, isContentEqual, isUnmarshalled, marshal, marshal, marshal, marshal, pipe, pipe, pipe, setContents, setJAXBContext, setJaxbElement, setJaxbElement, setMceIgnorable, transform, unmarshal, unmarshal, variableReplaceMethods inherited from class org.docx4j.openpackaging.parts.Part
getContentLengthAsLoaded, getOwningRelationshipPart, getPackage, getRelationshipType, getSourceRelationship, getSourceRelationships, getVersion, rename, setContentLengthAsLoaded, setOwningRelationshipPart, setPackage, setPartShortcut, setRelationshipType, setSourceRelationship, setVersionMethods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
-
Field Details
-
doc
protected org.w3c.dom.Document docThis part's XML contents. Not guaranteed to be up to date. Whether it is or not will depend on how the class which extends Part chooses to treat it. It may be that the class uses some other internal representation for its data.
-
-
Constructor Details
-
JaxbCustomXmlDataStoragePart
- Throws:
InvalidFormatException
-
JaxbCustomXmlDataStoragePart
public JaxbCustomXmlDataStoragePart(PartName partName, javax.xml.bind.JAXBContext jc) throws InvalidFormatException- Throws:
InvalidFormatException
-
-
Method Details
-
init
public void init() -
readyXPath
public void readyXPath()XPaths are evaluated against a DOM document representation of the JAXBElement. These aren't kept in sync, so you can use this method to update the DOM document from the JAXBElement. -
updateJaxbElementFromDocument
public void updateJaxbElementFromDocument() -
xpathGetString
public java.lang.String xpathGetString(java.lang.String xpathString, java.lang.String prefixMappings) throws Docx4JException- Specified by:
xpathGetStringin interfaceCustomXmlPart- Throws:
Docx4JException
-
cachedXPathGetString
public java.lang.String cachedXPathGetString(java.lang.String xpath, java.lang.String prefixMappings) throws Docx4JExceptionDescription copied from interface:CustomXmlPartUse org.apache.xpath.CachedXPathAPI, since this is much quicker than default javax.xml.xpath.XPath implementations (Apache's anyway) for large XML files. This is because Apache's old XPathAPI class instantiated a new XPathContext (and thus building a new DTMManager, and new DTMs) each time it was called. XPathAPIObject instead retains its context as long as the object persists, reusing the DTMs. There was the question of whether to declare it here or just implement it in CustomXmlDataStoragePart (since this is mostly of value in binding the user's XML data file). It is here since otherwise BindingHandler would fail on DocPropsCoverPagePart and StandardisedAnswersPart (both of which extend JaxbCustomXmlDataStoragePart).- Specified by:
cachedXPathGetStringin interfaceCustomXmlPart- Returns:
- Throws:
Docx4JException- See Also:
CustomXmlPart.discardCacheXPathObject()
-
discardCacheXPathObject
public void discardCacheXPathObject()Description copied from interface:CustomXmlPartUse this to null out the org.apache.xpath.CachedXPathAPI object, which you should do if you've changed your source document, or want to reclaim memory.- Specified by:
discardCacheXPathObjectin interfaceCustomXmlPart
-
xpathGetNodes
public java.util.List<org.w3c.dom.Node> xpathGetNodes(java.lang.String xpathString, java.lang.String prefixMappings) throws Docx4JException- Specified by:
xpathGetNodesin interfaceCustomXmlPart- Throws:
Docx4JException
-
setNodeValueAtXPath
public boolean setNodeValueAtXPath(java.lang.String xpath, java.lang.String value, java.lang.String prefixMappings) throws Docx4JException- Specified by:
setNodeValueAtXPathin interfaceCustomXmlPart- Throws:
Docx4JException
-
getItemId
public java.lang.String getItemId()- Specified by:
getItemIdin interfaceCustomXmlPart- Since:
- 3.0.2
-
remove
public void remove()Remove this part from the pkg. Beware: it is up to you to make sure your content doesn't rely on this part being present! A symptom of that would be that Office now reports your file to be corrupt or in need of repair. -
setXML
Description copied from interface:CustomXmlPartSet the XML data- Specified by:
setXMLin interfaceCustomXmlPart- Throws:
Docx4JException
-