org.dom4j.io

Class SAXModifier

public class SAXModifier extends Object

The SAXModifier reads, modifies and writes XML documents using SAX.

Registered ElementModifierobjects can provide modifications to (part of) the xml tree, while the document is still being processed. This makes it possible to change large xml documents without having them in memory.

The modified document is written when the XMLWriteris specified.

Author: Wonne Keysers (Realsoftware.be)

See Also: SAXReader XMLWriter

Constructor Summary
SAXModifier()
Creates a new modifier.
SAXModifier(boolean pruneElements)
Creates a new modifier.
SAXModifier(XMLReader xmlReader)
Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.
SAXModifier(XMLReader xmlReader, boolean pruneElements)
Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.
Method Summary
voidaddModifier(String path, ElementModifier modifier)
Adds the ElementModifierto be called when the specified element path is encounted while parsing the source.
DocumentFactorygetDocumentFactory()
Get the DocumentFactoryused to create the DOM4J document structure
XMLWritergetXMLWriter()
Returns the current XMLWriter.
booleanisPruneElements()
Returns true when xml elements are not kept in memory while parsing.
Documentmodify(File source)
Reads a Document from the given java.io.Fileand writes it to the specified XMLWriterusing SAX.
Documentmodify(InputSource source)
Reads a Document from the given org.xml.sax.InputSourceand writes it to the specified XMLWriterusing SAX.
Documentmodify(InputStream source)
Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX.
Documentmodify(InputStream source, String systemId)
Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX.
Documentmodify(Reader source)
Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX.
Documentmodify(Reader source, String systemId)
Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX.
Documentmodify(URL source)
Reads a Document from the given java.net.URLand writes it to the specified XMLWriterusing SAX.
Documentmodify(String source)
Reads a Document from the given URL or filename and writes it to the specified XMLWriterusing SAX.
voidremoveModifier(String path)
Removes the ElementModifierfrom the event based processor, for the specified element path.
voidresetModifiers()
Removes all registered ElementModifierinstances from the event based processor.
voidsetDocumentFactory(DocumentFactory factory)
Sets the DocumentFactoryused to create the DOM4J document tree.
voidsetXMLWriter(XMLWriter writer)
Sets the XMLWriterused to write the modified document.

Constructor Detail

SAXModifier

public SAXModifier()
Creates a new modifier.
The XMLReader to parse the source will be created via the org.xml.sax.driver system property or JAXP if the system property is not set.

SAXModifier

public SAXModifier(boolean pruneElements)
Creates a new modifier.
The XMLReader to parse the source will be created via the org.xml.sax.driver system property or JAXP if the system property is not set.

Parameters: pruneElements Set to true when the modified document must NOT be kept in memory.

SAXModifier

public SAXModifier(XMLReader xmlReader)
Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

Parameters: xmlReader The XMLReader to use

SAXModifier

public SAXModifier(XMLReader xmlReader, boolean pruneElements)
Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

Parameters: xmlReader The XMLReader to use pruneElements Set to true when the modified document must NOT be kept in memory.

Method Detail

addModifier

public void addModifier(String path, ElementModifier modifier)
Adds the ElementModifierto be called when the specified element path is encounted while parsing the source.

Parameters: path The element path to be handled modifier The ElementModifierto be called by the event based processor.

getDocumentFactory

public DocumentFactory getDocumentFactory()
Get the DocumentFactoryused to create the DOM4J document structure

Returns: DocumentFactory that will be used

getXMLWriter

public XMLWriter getXMLWriter()
Returns the current XMLWriter.

Returns: XMLWriter

isPruneElements

public boolean isPruneElements()
Returns true when xml elements are not kept in memory while parsing. The Documentreturned by the modify methods will be null.

Returns: Returns the pruneElements.

modify

public Document modify(File source)
Reads a Document from the given java.io.Fileand writes it to the specified XMLWriterusing SAX. Registered {@linkElementModifier } objects are invoked on the fly.

Parameters: source is the File to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(InputSource source)
Reads a Document from the given org.xml.sax.InputSourceand writes it to the specified XMLWriterusing SAX. Registered ElementModifierobjects are invoked on the fly.

Parameters: source is the org.xml.sax.InputSource to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(InputStream source)
Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters: source is the java.io.InputStream to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(InputStream source, String systemId)
Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters: source is the java.io.InputStream to read from. systemId DOCUMENT ME!

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(Reader source)
Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters: source is the java.io.Reader to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(Reader source, String systemId)
Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters: source is the java.io.Reader to read from. systemId DOCUMENT ME!

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(URL source)
Reads a Document from the given java.net.URLand writes it to the specified XMLWriterusing SAX. Registered {@linkElementModifier } objects are invoked on the fly.

Parameters: source is the java.net.URL to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

modify

public Document modify(String source)
Reads a Document from the given URL or filename and writes it to the specified XMLWriterusing SAX. Registered {@linkElementModifier } objects are invoked on the fly.

Parameters: source is the URL or filename to read from.

Returns: the newly created Document instance

Throws: DocumentException DocumentException org.dom4j.DocumentException} if an error occurs during parsing.

removeModifier

public void removeModifier(String path)
Removes the ElementModifierfrom the event based processor, for the specified element path.

Parameters: path The path to remove the ElementModifierfor.

resetModifiers

public void resetModifiers()
Removes all registered ElementModifierinstances from the event based processor.

setDocumentFactory

public void setDocumentFactory(DocumentFactory factory)
Sets the DocumentFactoryused to create the DOM4J document tree.

Parameters: factory DocumentFactory to be used

setXMLWriter

public void setXMLWriter(XMLWriter writer)
Sets the XMLWriterused to write the modified document.

Parameters: writer The writer to use.

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

SourceForge