Top Description Inners Fields Constructors Methods
org.dom4j.jaxb

public Class JAXBModifier

extends JAXBSupport
Class Inheritance
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .InputStreamReader, .OutputStream, .Reader, .Writer, java.net.URL, java.nio.charset.Charset, java.util.HashMap, .Iterator, .Map, org.dom4j.Document, .DocumentException, org.dom4j.io.ElementModifier, .OutputFormat, .SAXModifier, .XMLWriter, org.xml.sax.InputSource

Reads an XML document using SAX and writes its content to the provided org.dom4j.io.XMLWriter. Modifications must be provided by org.dom4j.jaxb.JAXBObjectModifier objects, which are called prior to writing the XML fragment they are registered for.
Author
Wonne Keysers (Realsoftware.be)
See Also
org.dom4j.io.SAXModifier

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private SAXModifier
private HashMap<String, JAXBObjectModifier>
private OutputFormat
private boolean
private XMLWriter

Constructor Summary

AccessConstructor and Description
public
JAXBModifier(String
JAXB context path to be used
contextPath
)

Creates a new JAXBModifier for the given JAXB context path.

public
JAXBModifier(String
JAXB context path to be used
contextPath
,
ClassLoader
the classloader to use
classloader
)

Creates a new JAXBModifier for the given JAXB context path, using the given java.lang.ClassLoader.

public
JAXBModifier(String
JAXB context path to be used
contextPath
,
OutputFormat
the DOM4J org.dom4j.io.OutputFormatto be used
outputFormat
)

Creates a new JAXBModifier for the given JAXB context path.

public
JAXBModifier(String
JAXB context path to be used
contextPath
,
ClassLoader
the class loader to be used to load JAXB
classloader
,
OutputFormat
the DOM4J org.dom4j.io.OutputFormatto be used
outputFormat
)

Creates a new JAXBModifier for the given JAXB context path, using the specified java.lang.ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addObjectModifier(String
the element path to listen for
path
,
JAXBObjectModifier
the modifier to register
mod
)

Adds the JAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.

private XMLWriter
private SAXModifier
private XMLWriter
private SAXModifier
public boolean

Returns:

Returns true if elements are pruned.
isPruneElements
()

Returns true when the modified org.dom4j.Documentis not kept in memory.

public Document

Returns:

the resulting DOM4J document
modify
(File
the file to parse
source
)

Parses the specified java.io.Filewith SAX

public Document

Returns:

the resulting DOM4J document
modify
(File
the file to parse
source
,
Charset
the character set to use
charset
)

Parses the specified java.io.Filewith SAX, using the given java.nio.charset.Charset.

public Document

Returns:

the resulting DOM4J document
modify
(InputSource
the input source to parse
source
)

Parses the specified org.xml.sax.InputSourcewith SAX.

public Document

Returns:

the resulting DOM4J document
modify
(InputStream
the inputstream to parse
source
)

Parses the specified java.io.InputStreamwith SAX.

public Document

Returns:

the resulting DOM4J document
modify
(InputStream
the inputstream to parse
source
,
String
the URI of the given inputstream
systemId
)

Parses the specified java.io.InputStreamwith SAX.

public Document

Returns:

the resulting DOM4J document
modify
(Reader
the reader to use for parsing
r
)

Parses the specified java.io.Readerwith SAX.

public Document

Returns:

the resulting DOM4J document
modify
(Reader
the reader to parse
source
,
String
the URI of the given reader
systemId
)

Parses the specified java.io.Readerwith SAX.

public Document

Returns:

the resulting DOM4J document
modify
(String
the URL or filename to parse
url
)

Parses the the given URL or filename.

public Document

Returns:

the resulting DOM4J document
modify
(URL
the URL to parse
source
)

Parses the the given URL.

public void
removeObjectModifier(String
the xml path to remove the modifier for
path
)

Removes the JAXBObjectModifierfrom the event based processor, for the specified element path.

public void
resetObjectModifiers()

Removes all registered JAXBObjectModifierinstances from the event based processor.

public void
setOutput(File
the java.io.Fileto write to
file
)

Sets the Output to write the (modified) xml document to.

public void
setOutput(OutputStream
the java.io.OutputStreamto write to
outputStream
)

Sets the Output to write the (modified) xml document to.

public void
setOutput(Writer
the java.io.Writerto write to
writer
)

Sets the Output to write the (modified) xml document to.

public void
setPruneElements(boolean
When true, elements will not be kept in memory
pruneElements
)

Define whether the modified org.dom4j.Documentmust only be written to the output and pruned from the DOM4J tree.

Inherited from org.dom4j.jaxb.JAXBSupport:
marshalunmarshal

Field Detail

modifierback to summary
private SAXModifier modifier
modifiersback to summary
private HashMap<String, JAXBObjectModifier> modifiers
outputFormatback to summary
private OutputFormat outputFormat
pruneElementsback to summary
private boolean pruneElements
xmlWriterback to summary
private XMLWriter xmlWriter

Constructor Detail

JAXBModifierback to summary
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:String

JAXB context path to be used

See Also
javax.xml.bind.JAXBContext
JAXBModifierback to summary
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:String

JAXB context path to be used

classloader:ClassLoader

the classloader to use

See Also
javax.xml.bind.JAXBContext
JAXBModifierback to summary
public JAXBModifier(String contextPath, OutputFormat outputFormat)

Creates a new JAXBModifier for the given JAXB context path. The specified org.dom4j.io.OutputFormatwill be used while writing the XML stream.

Parameters
contextPath:String

JAXB context path to be used

outputFormat:OutputFormat

the DOM4J org.dom4j.io.OutputFormatto be used

See Also
javax.xml.bind.JAXBContext
JAXBModifierback to summary
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 org.dom4j.io.OutputFormat will be used while writing the XML stream.

Parameters
contextPath:String

JAXB context path to be used

classloader:ClassLoader

the class loader to be used to load JAXB

outputFormat:OutputFormat

the DOM4J org.dom4j.io.OutputFormatto be used

See Also
javax.xml.bind.JAXBContext

Method Detail

addObjectModifierback to summary
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:String

the element path to listen for

mod:JAXBObjectModifier

the modifier to register

createXMLWriterback to summary
private XMLWriter createXMLWriter() throws IOException
getModifierback to summary
private SAXModifier getModifier()
getXMLWriterback to summary
private XMLWriter getXMLWriter()
installModifierback to summary
private SAXModifier installModifier() throws IOException
isPruneElementsback to summary
public boolean isPruneElements()

Returns true when the modified org.dom4j.Documentis not kept in memory.

Returns:boolean

Returns true if elements are pruned.

modifyback to summary
public Document modify(File source) throws DocumentException, IOException

Parses the specified java.io.Filewith SAX

Parameters
source:File

the file to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(File source, Charset charset) throws DocumentException, IOException

Parses the specified java.io.Filewith SAX, using the given java.nio.charset.Charset.

Parameters
source:File

the file to parse

charset:Charset

the character set to use

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(InputSource source) throws DocumentException, IOException

Parses the specified org.xml.sax.InputSourcewith SAX.

Parameters
source:InputSource

the input source to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(InputStream source) throws DocumentException, IOException

Parses the specified java.io.InputStreamwith SAX.

Parameters
source:InputStream

the inputstream to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(InputStream source, String systemId) throws DocumentException, IOException

Parses the specified java.io.InputStreamwith SAX.

Parameters
source:InputStream

the inputstream to parse

systemId:String

the URI of the given inputstream

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(Reader r) throws DocumentException, IOException

Parses the specified java.io.Readerwith SAX.

Parameters
r:Reader

the reader to use for parsing

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(Reader source, String systemId) throws DocumentException, IOException

Parses the specified java.io.Readerwith SAX.

Parameters
source:Reader

the reader to parse

systemId:String

the URI of the given reader

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(String url) throws DocumentException, IOException

Parses the the given URL or filename.

Parameters
url:String

the URL or filename to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
modifyback to summary
public Document modify(URL source) throws DocumentException, IOException

Parses the the given URL.

Parameters
source:URL

the URL to parse

Returns:Document

the resulting DOM4J document

Exceptions
DocumentException:
when an error occurs while parsing
IOException:
when an error occurs while writing to the org.dom4j.io.XMLWriter
removeObjectModifierback to summary
public void removeObjectModifier(String path)

Removes the JAXBObjectModifierfrom the event based processor, for the specified element path.

Parameters
path:String

the xml path to remove the modifier for

resetObjectModifiersback to summary
public void resetObjectModifiers()

Removes all registered JAXBObjectModifierinstances from the event based processor.

setOutputback to summary
public void setOutput(File file) throws IOException

Sets the Output to write the (modified) xml document to.

Parameters
file:File

the java.io.Fileto write to

Exceptions
IOException:
when the file cannot be found or when the outputformat
setOutputback to summary
public void setOutput(OutputStream outputStream) throws IOException

Sets the Output to write the (modified) xml document to.

Parameters
outputStream:OutputStream

the java.io.OutputStreamto write to

Exceptions
IOException:
when an error occurs
setOutputback to summary
public void setOutput(Writer writer) throws IOException

Sets the Output to write the (modified) xml document to.

Parameters
writer:Writer

the java.io.Writerto write to

Exceptions
IOException:
when an error occurs
setPruneElementsback to summary
public void setPruneElements(boolean pruneElements)

Define whether the modified org.dom4j.Documentmust only be written to the output and pruned from the DOM4J tree.

Parameters
pruneElements:boolean

When true, elements will not be kept in memory

org.dom4j.jaxb back to summary

private Class JAXBModifier.JAXBElementModifier

extends Object
implements ElementModifier
Class Inheritance
All Implemented Interfaces
org.dom4j.io.ElementModifier

Field Summary

Modifier and TypeField and Description
private JAXBModifier
private JAXBObjectModifier

Constructor Summary

AccessConstructor and Description
public
JAXBElementModifier(JAXBModifier jaxbModifier, JAXBObjectModifier objectModifier)

Method Summary

Modifier and TypeMethod and Description
public Element
modifyElement(Element
org.dom4j.Elementto be parsed
element
)

Implements org.dom4j.io.ElementModifier.modifyElement.

Called by an event based processor when an elements closing tag is encountered.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

jaxbModifierback to summary
private JAXBModifier jaxbModifier
objectModifierback to summary
private JAXBObjectModifier objectModifier

Constructor Detail

JAXBElementModifierback to summary
public JAXBElementModifier(JAXBModifier jaxbModifier, JAXBObjectModifier objectModifier)

Method Detail

modifyElementback to summary
public Element modifyElement(Element element) throws Exception

Implements org.dom4j.io.ElementModifier.modifyElement.

Doc from org.dom4j.io.ElementModifier.modifyElement.

Called by an event based processor when an elements closing tag is encountered. This method must return the modified version of the provided org.dom4j.Elementor null if it has to be removed from the document.
The incoming org.dom4j.Elementis disconnected from the DOM4J tree. This means that navigation to the elements parent org.dom4j.Element and org.dom4j.Documentare not available. Only the element itself can be modified!

Parameters
element:Element

org.dom4j.Elementto be parsed

Returns:Element

the modified org.dom4j.Element

Exceptions
Exception:
of any kind