Top Description Fields Constructors Methods
org.dom4j.io

public Class SAXModifier

extends Object
Class Inheritance
Imports
java.io.File, .InputStream, .Reader, java.net.URL, java.util.HashMap, .Iterator, .Map, org.dom4j.Document, .DocumentException, .DocumentFactory, org.xml.sax.InputSource, .SAXException, .XMLReader

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
org.dom4j.io.SAXReader, org.dom4j.io.XMLWriter

Field Summary

Modifier and TypeField and Description
private HashMap<String, ElementModifier>
private SAXModifyReader
private boolean
private XMLReader
private XMLWriter

Constructor Summary

AccessConstructor and Description
public
SAXModifier()

Creates a new modifier.

public
SAXModifier(boolean
Set to true when the modified document must NOT be kept in memory.
pruneElements
)

Creates a new modifier.

public
SAXModifier(XMLReader
The XMLReader to use
xmlReader
)

Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

public
SAXModifier(XMLReader
The XMLReader to use
xmlReader
,
boolean
Set to true when the modified document must NOT be kept in memory.
pruneElements
)

Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

Method Summary

Modifier and TypeMethod and Description
public void
addModifier(String
The element path to be handled
path
,
ElementModifier
The ElementModifierto be called by the event based processor.
modifier
)

Adds the ElementModifierto be called when the specified element path is encounted while parsing the source.

public DocumentFactory

Returns:

DocumentFactory that will be used
getDocumentFactory
()

Get the org.dom4j.DocumentFactoryused to create the DOM4J document structure

private SAXModifyReader
private XMLReader
public XMLWriter

Returns:

XMLWriter
getXMLWriter
()

Returns the current XMLWriter.

private SAXReader
public boolean

Returns:

Returns the pruneElements.
isPruneElements
()

Returns true when xml elements are not kept in memory while parsing.

public Document

Returns:

the newly created Document instance
modify
(File
is the File to read from.
source
)

Reads a Document from the given java.io.Fileand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(InputSource
is the org.xml.sax.InputSource to read from.
source
)

Reads a Document from the given org.xml.sax.InputSourceand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(InputStream
is the java.io.InputStream to read from.
source
)

Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(InputStream
is the java.io.InputStream to read from.
source
,
String
DOCUMENT ME!
systemId
)

Reads a Document from the given java.io.InputStreamand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(Reader
is the java.io.Reader to read from.
source
)

Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(Reader
is the java.io.Reader to read from.
source
,
String
DOCUMENT ME!
systemId
)

Reads a Document from the given java.io.Readerand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(URL
is the java.net.URL to read from.
source
)

Reads a Document from the given java.net.URLand writes it to the specified XMLWriterusing SAX.

public Document

Returns:

the newly created Document instance
modify
(String
is the URL or filename to read from.
source
)

Reads a Document from the given URL or filename and writes it to the specified XMLWriterusing SAX.

public void
removeModifier(String
The path to remove the ElementModifierfor.
path
)

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

public void
resetModifiers()

Removes all registered ElementModifierinstances from the event based processor.

public void
setDocumentFactory(DocumentFactory
DocumentFactory to be used
factory
)

Sets the org.dom4j.DocumentFactoryused to create the DOM4J document tree.

public void
setXMLWriter(XMLWriter
The writer to use.
writer
)

Sets the XMLWriterused to write the modified document.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modifiersback to summary
private HashMap<String, ElementModifier> modifiers
modifyReaderback to summary
private SAXModifyReader modifyReader
pruneElementsback to summary
private boolean pruneElements
xmlReaderback to summary
private XMLReader xmlReader
xmlWriterback to summary
private XMLWriter xmlWriter

Constructor Detail

SAXModifierback to summary
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.

SAXModifierback to summary
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:boolean

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

SAXModifierback to summary
public SAXModifier(XMLReader xmlReader)

Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

Parameters
xmlReader:XMLReader

The XMLReader to use

SAXModifierback to summary
public SAXModifier(XMLReader xmlReader, boolean pruneElements)

Creates a new modifier that will the specified org.xml.sax.XMLReader to parse the source.

Parameters
xmlReader:XMLReader

The XMLReader to use

pruneElements:boolean

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

Method Detail

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

The element path to be handled

modifier:ElementModifier

The ElementModifierto be called by the event based processor.

getDocumentFactoryback to summary
public DocumentFactory getDocumentFactory()

Get the org.dom4j.DocumentFactoryused to create the DOM4J document structure

Returns:DocumentFactory

DocumentFactory that will be used

getSAXModifyReaderback to summary
private SAXModifyReader getSAXModifyReader()
getXMLReaderback to summary
private XMLReader getXMLReader() throws SAXException
getXMLWriterback to summary
public XMLWriter getXMLWriter()

Returns the current XMLWriter.

Returns:XMLWriter

XMLWriter

installModifyReaderback to summary
private SAXReader installModifyReader() throws DocumentException
isPruneElementsback to summary
public boolean isPruneElements()

Returns true when xml elements are not kept in memory while parsing. The org.dom4j.Documentreturned by the modify methods will be null.

Returns:boolean

Returns the pruneElements.

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

Reads a Document from the given java.io.Fileand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters
source:File

is the File to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(InputSource source) throws DocumentException

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:InputSource

is the org.xml.sax.InputSource to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(InputStream source) throws DocumentException

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:InputStream

is the java.io.InputStream to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(InputStream source, String systemId) throws DocumentException

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:InputStream

is the java.io.InputStream to read from.

systemId:String

DOCUMENT ME!

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(Reader source) throws DocumentException

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:Reader

is the java.io.Reader to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(Reader source, String systemId) throws DocumentException

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:Reader

is the java.io.Reader to read from.

systemId:String

DOCUMENT ME!

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(URL source) throws DocumentException

Reads a Document from the given java.net.URLand writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters
source:URL

is the java.net.URL to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
modifyback to summary
public Document modify(String source) throws DocumentException

Reads a Document from the given URL or filename and writes it to the specified XMLWriterusing SAX. Registered ElementModifier objects are invoked on the fly.

Parameters
source:String

is the URL or filename to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
removeModifierback to summary
public void removeModifier(String path)

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

Parameters
path:String

The path to remove the ElementModifierfor.

resetModifiersback to summary
public void resetModifiers()

Removes all registered ElementModifierinstances from the event based processor.

setDocumentFactoryback to summary
public void setDocumentFactory(DocumentFactory factory)

Sets the org.dom4j.DocumentFactoryused to create the DOM4J document tree.

Parameters
factory:DocumentFactory

DocumentFactory to be used

setXMLWriterback to summary
public void setXMLWriter(XMLWriter writer)

Sets the XMLWriterused to write the modified document.

Parameters
writer:XMLWriter

The writer to use.