org.dom4j.jaxb

Class JAXBModifier

public class JAXBModifier extends JAXBSupport

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.

Author: Wonne Keysers (Realsoftware.be)

See Also: SAXModifier

Constructor Summary
JAXBModifier(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 given java.lang.ClassLoader.
JAXBModifier(String contextPath, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path.
JAXBModifier(String contextPath, ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path, using the specified java.lang.Classloader.
Method Summary
voidaddObjectModifier(String path, JAXBObjectModifier mod)
Adds the JAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.
booleanisPruneElements()
Returns true when the modified Documentis not kept in memory.
Documentmodify(File source)
Parses the specified java.io.Filewith SAX
Documentmodify(File source, Charset charset)
Parses the specified java.io.Filewith SAX, using the given java.nio.charset.Charset.
Documentmodify(InputSource source)
Parses the specified org.xml.sax.InputSourcewith SAX.
Documentmodify(InputStream source)
Parses the specified java.io.InputStreamwith SAX.
Documentmodify(InputStream source, String systemId)
Parses the specified java.io.InputStreamwith SAX.
Documentmodify(Reader r)
Parses the specified java.io.Readerwith SAX.
Documentmodify(Reader source, String systemId)
Parses the specified java.io.Readerwith SAX.
Documentmodify(String url)
Parses the the given URL or filename.
Documentmodify(URL source)
Parses the the given URL.
voidremoveObjectModifier(String path)
Removes the JAXBObjectModifierfrom the event based processor, for the specified element path.
voidresetObjectModifiers()
Removes all registered JAXBObjectModifierinstances from the event based processor.
voidsetOutput(File file)
Sets the Output to write the (modified) xml document to.
voidsetOutput(OutputStream outputStream)
Sets the Output to write the (modified) xml document to.
voidsetOutput(Writer writer)
Sets the Output to write the (modified) xml document to.
voidsetPruneElements(boolean pruneElements)
Define whether the modified Documentmust only be written to the output and pruned from the DOM4J tree.

Constructor Detail

JAXBModifier

public JAXBModifier(String contextPath)
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: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, ClassLoader classloader)
Creates a new JAXBModifier for the given JAXB context path, using the given java.lang.ClassLoader. 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 classloader the classloader to use

See Also: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path. The specified OutputFormatwill be used while writing the XML stream.

Parameters: contextPath JAXB context path to be used outputFormat the DOM4J OutputFormatto be used

See Also: javax.xml.bind.JAXBContext

JAXBModifier

public JAXBModifier(String contextPath, ClassLoader classloader, OutputFormat outputFormat)
Creates a new JAXBModifier for the given JAXB context path, using the specified java.lang.Classloader. The specified OutputFormat will be used while writing the XML stream.

Parameters: contextPath JAXB context path to be used classloader the class loader to be used to load JAXB outputFormat the DOM4J OutputFormatto be used

See Also: javax.xml.bind.JAXBContext

Method Detail

addObjectModifier

public void addObjectModifier(String path, JAXBObjectModifier mod)
Adds the JAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.

Parameters: path the element path to listen for mod the modifier to register

isPruneElements

public boolean isPruneElements()
Returns true when the modified Documentis not kept in memory.

Returns: Returns true if elements are pruned.

modify

public Document modify(File source)
Parses the specified java.io.Filewith SAX

Parameters: source the file to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(File source, Charset charset)
Parses the specified java.io.Filewith SAX, using the given java.nio.charset.Charset.

Parameters: source the file to parse charset the character set to use

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(InputSource source)
Parses the specified org.xml.sax.InputSourcewith SAX.

Parameters: source the input source to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(InputStream source)
Parses the specified java.io.InputStreamwith SAX.

Parameters: source the inputstream to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(InputStream source, String systemId)
Parses the specified java.io.InputStreamwith SAX.

Parameters: source the inputstream to parse systemId the URI of the given inputstream

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(Reader r)
Parses the specified java.io.Readerwith SAX.

Parameters: r the reader to use for parsing

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(Reader source, String systemId)
Parses the specified java.io.Readerwith SAX.

Parameters: source the reader to parse systemId the URI of the given reader

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(String url)
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 parsing IOException when an error occurs while writing to the XMLWriter

modify

public Document modify(URL source)
Parses the the given URL.

Parameters: source the URL to parse

Returns: the resulting DOM4J document

Throws: DocumentException when an error occurs while parsing IOException when an error occurs while writing to the XMLWriter

removeObjectModifier

public void removeObjectModifier(String path)
Removes the JAXBObjectModifierfrom 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 registered JAXBObjectModifierinstances from the event based processor.

setOutput

public void setOutput(File file)
Sets the Output to write the (modified) xml document to.

Parameters: file the java.io.Fileto write to

Throws: IOException when the file cannot be found or when the outputformat

setOutput

public void setOutput(OutputStream outputStream)
Sets the Output to write the (modified) xml document to.

Parameters: outputStream the java.io.OutputStreamto write to

Throws: IOException when an error occurs

setOutput

public void setOutput(Writer writer)
Sets the Output to write the (modified) xml document to.

Parameters: writer the java.io.Writerto write to

Throws: IOException when an error occurs

setPruneElements

public void setPruneElements(boolean pruneElements)
Define whether the modified Documentmust only be written to the output and pruned from the DOM4J tree.

Parameters: pruneElements When true, elements will not be kept in memory

Copyright B) 2005 MetaStuff Ltd. All Rights Reserved. Hosted by

SourceForge