Class JAXBModifier
java.lang.Object
org.dom4j.jaxb.JAXBSupport
org.dom4j.jaxb.JAXBModifier
Reads an XML document using SAX and writes its content to the provided
XMLWriter. Modifications must be provided by JAXBObjectModifier objects, which are called prior to writing
the XML fragment they are registered for.- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SAXModifierprivate HashMap<String, JAXBObjectModifier> private OutputFormatprivate booleanprivate XMLWriter -
Constructor Summary
ConstructorsConstructorDescriptionJAXBModifier(String contextPath) Creates a new JAXBModifier for the given JAXB context path.JAXBModifier(String contextPath, ClassLoader classloader) Creates a new JAXBModifier for the given JAXB context path, using the givenClassLoader.JAXBModifier(String contextPath, ClassLoader classloader, OutputFormat outputFormat) Creates a new JAXBModifier for the given JAXB context path, using the specifiedClassLoader.JAXBModifier(String contextPath, OutputFormat outputFormat) Creates a new JAXBModifier for the given JAXB context path. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObjectModifier(String path, JAXBObjectModifier mod) Adds theJAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.private XMLWriterprivate SAXModifierprivate XMLWriterprivate SAXModifierbooleanReturns true when the modifiedDocumentis not kept in memory.Parses the specifiedFilewith SAXmodify(InputStream source) Parses the specifiedInputStreamwith SAX.modify(InputStream source, String systemId) Parses the specifiedInputStreamwith SAX.Parses the specifiedReaderwith SAX.Parses the specifiedReaderwith SAX.Parses the the given URL or filename.Parses the the given URL.modify(InputSource source) Parses the specifiedInputSourcewith SAX.voidremoveObjectModifier(String path) Removes theJAXBObjectModifierfrom the event based processor, for the specified element path.voidRemoves all registeredJAXBObjectModifierinstances from the event based processor.voidSets the Output to write the (modified) xml document to.voidsetOutput(OutputStream outputStream) Sets the Output to write the (modified) xml document to.voidSets the Output to write the (modified) xml document to.voidsetPruneElements(boolean pruneElements) Define whether the modifiedDocumentmust only be written to the output and pruned from the DOM4J tree.Methods inherited from class JAXBSupport
marshal, unmarshal
-
Field Details
-
modifier
-
xmlWriter
-
pruneElements
private boolean pruneElements -
outputFormat
-
modifiers
-
-
Constructor Details
-
JAXBModifier
Creates a new JAXBModifier for the given JAXB context path. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!- Parameters:
contextPath- JAXB context path to be used- See Also:
-
JAXBModifier
Creates a new JAXBModifier for the given JAXB context path, using the givenClassLoader. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!- Parameters:
contextPath- JAXB context path to be usedclassloader- the classloader to use- See Also:
-
JAXBModifier
Creates a new JAXBModifier for the given JAXB context path. The specifiedOutputFormatwill be used while writing the XML stream.- Parameters:
contextPath- JAXB context path to be usedoutputFormat- the DOM4JOutputFormatto be used- See Also:
-
JAXBModifier
Creates a new JAXBModifier for the given JAXB context path, using the specifiedClassLoader. The specifiedOutputFormatwill be used while writing the XML stream.- Parameters:
contextPath- JAXB context path to be usedclassloader- the class loader to be used to load JAXBoutputFormat- the DOM4JOutputFormatto be used- See Also:
-
-
Method Details
-
modify
Parses the specifiedFilewith SAX- Parameters:
source- the file to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
- Parameters:
source- the file to parsecharset- the character set to use- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the specifiedInputSourcewith SAX.- Parameters:
source- the input source to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the specifiedInputStreamwith SAX.- Parameters:
source- the inputstream to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the specifiedInputStreamwith SAX.- Parameters:
source- the inputstream to parsesystemId- the URI of the given inputstream- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the specifiedReaderwith SAX.- Parameters:
r- the reader to use for parsing- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the specifiedReaderwith SAX.- Parameters:
source- the reader to parsesystemId- the URI of the given reader- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the the given URL or filename.- Parameters:
url- the URL or filename to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
modify
Parses the the given URL.- Parameters:
source- the URL to parse- Returns:
- the resulting DOM4J document
- Throws:
DocumentException- when an error occurs while parsingIOException- when an error occurs while writing to theXMLWriter
-
setOutput
Sets the Output to write the (modified) xml document to.- Parameters:
file- theFileto write to- Throws:
IOException- when the file cannot be found or when the outputformat
-
setOutput
Sets the Output to write the (modified) xml document to.- Parameters:
outputStream- theOutputStreamto write to- Throws:
IOException- when an error occurs
-
setOutput
Sets the Output to write the (modified) xml document to.- Parameters:
writer- theWriterto write to- Throws:
IOException- when an error occurs
-
addObjectModifier
Adds theJAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.- Parameters:
path- the element path to listen formod- the modifier to register
-
removeObjectModifier
Removes theJAXBObjectModifierfrom the event based processor, for the specified element path.- Parameters:
path- the xml path to remove the modifier for
-
resetObjectModifiers
public void resetObjectModifiers()Removes all registeredJAXBObjectModifierinstances from the event based processor. -
isPruneElements
public boolean isPruneElements()Returns true when the modifiedDocumentis not kept in memory.- Returns:
- Returns true if elements are pruned.
-
setPruneElements
public void setPruneElements(boolean pruneElements) Define whether the modifiedDocumentmust only be written to the output and pruned from the DOM4J tree.- Parameters:
pruneElements- When true, elements will not be kept in memory
-
installModifier
- Throws:
IOException
-
getModifier
-
getXMLWriter
-
createXMLWriter
- Throws:
IOException
-