org.dom4j.io

Class SAXWriter

public class SAXWriter extends Object implements XMLReader

SAXWriter writes a DOM4J tree to a SAX ContentHandler.

Version: $Revision: 1.24 $

Author: James Strachan

Field Summary
protected static StringFEATURE_NAMESPACES
protected static StringFEATURE_NAMESPACE_PREFIXES
protected static String[]LEXICAL_HANDLER_NAMES
Constructor Summary
SAXWriter()
SAXWriter(ContentHandler contentHandler)
SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler)
SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler, EntityResolver entityResolver)
Method Summary
protected AttributesImpladdNamespaceAttribute(AttributesImpl attrs, Namespace namespace)
If isDelcareNamespaceAttributes() is enabled then this method will add the given namespace declaration to the supplied attributes object, creating one if it does not exist.
protected voidcheckForNullHandlers()
Ensures non-null content handlers?
protected AttributescreateAttributes(Element element, Attributes namespaceAttributes)
protected voiddocumentLocator(Document document)
The org.xml.sax.Locatoris only really useful when parsing a textual document as its main purpose is to identify the line and column number.
protected voiddtdHandler(Document document)
We do not yet support DTD or XML Schemas so this method does nothing right now.
protected voidendDocument()
protected voidendElement(Element element)
protected voidendPrefixMapping(NamespaceStack stack, int stackSize)
Fires a SAX endPrefixMapping event for all the namespaceStack which have gone out of scope
protected voidentityResolver(Document document)
ContentHandlergetContentHandler()
DOCUMENT ME!
DTDHandlergetDTDHandler()
DOCUMENT ME!
EntityResolvergetEntityResolver()
DOCUMENT ME!
ErrorHandlergetErrorHandler()
DOCUMENT ME!
booleangetFeature(String name)
Looks up the value of a feature.
LexicalHandlergetLexicalHandler()
DOCUMENT ME!
ObjectgetProperty(String name)
Gets the given SAX property
booleanisDeclareNamespaceAttributes()
Should namespace declarations be converted to "xmlns" attributes.
protected booleanisIgnoreableNamespace(Namespace namespace, NamespaceStack namespaceStack)
DOCUMENT ME!
voidparse(String systemId)
This method is not supported.
voidparse(InputSource input)
Parses an XML document.
voidsetContentHandler(ContentHandler contentHandler)
Sets the ContentHandler called when SAX events are raised
voidsetDeclareNamespaceAttributes(boolean declareNamespaceAttrs)
Sets whether namespace declarations should be exported as "xmlns" attributes or not.
voidsetDTDHandler(DTDHandler handler)
Sets the DTDHandler.
voidsetEntityResolver(EntityResolver entityResolver)
Sets the EntityResolver.
voidsetErrorHandler(ErrorHandler errorHandler)
Sets the ErrorHandler.
voidsetFeature(String name, boolean value)
This implementation does actually use any features but just stores them for later retrieval
voidsetLexicalHandler(LexicalHandler lexicalHandler)
Sets the LexicalHandler.
voidsetProperty(String name, Object value)
Sets the given SAX property
voidsetXMLReader(XMLReader xmlReader)
Sets the XMLReader used to write SAX events to
protected voidstartDocument()
protected voidstartElement(Element element, AttributesImpl namespaceAttributes)
protected AttributesImplstartPrefixMapping(Element element, NamespaceStack namespaceStack)
Fires a SAX startPrefixMapping event for all the namespaceStack which have just come into scope
voidwrite(Node node)
A polymorphic method to write any Node to this SAX stream
voidwrite(Document document)
Generates SAX events for the given Document and all its content
voidwrite(Element element)
Generates SAX events for the given Element and all its content
voidwrite(String text)
Generates SAX events for the given text
voidwrite(CDATA cdata)
Generates SAX events for the given CDATA
voidwrite(Comment comment)
Generates SAX events for the given Comment
voidwrite(Entity entity)
Generates SAX events for the given Entity
voidwrite(ProcessingInstruction pi)
Generates SAX events for the given ProcessingInstruction
protected voidwrite(Element element, NamespaceStack namespaceStack)
voidwriteClose(Element element)

Writes the closing tag of an Element

protected voidwriteContent(Branch branch, NamespaceStack namespaceStack)
voidwriteOpen(Element element)

Writes the opening tag of an Element, including its Attributes but without its content.

Field Detail

FEATURE_NAMESPACES

protected static final String FEATURE_NAMESPACES

FEATURE_NAMESPACE_PREFIXES

protected static final String FEATURE_NAMESPACE_PREFIXES

LEXICAL_HANDLER_NAMES

protected static final String[] LEXICAL_HANDLER_NAMES

Constructor Detail

SAXWriter

public SAXWriter()

SAXWriter

public SAXWriter(ContentHandler contentHandler)

SAXWriter

public SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler)

SAXWriter

public SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler, EntityResolver entityResolver)

Method Detail

addNamespaceAttribute

protected AttributesImpl addNamespaceAttribute(AttributesImpl attrs, Namespace namespace)
If isDelcareNamespaceAttributes() is enabled then this method will add the given namespace declaration to the supplied attributes object, creating one if it does not exist.

Parameters: attrs DOCUMENT ME! namespace DOCUMENT ME!

Returns: DOCUMENT ME!

checkForNullHandlers

protected void checkForNullHandlers()
Ensures non-null content handlers?

createAttributes

protected Attributes createAttributes(Element element, Attributes namespaceAttributes)

documentLocator

protected void documentLocator(Document document)
The org.xml.sax.Locatoris only really useful when parsing a textual document as its main purpose is to identify the line and column number. Since we are processing an in memory tree which will probably have its line number information removed, we'll just use -1 for the line and column numbers.

Parameters: document DOCUMENT ME!

Throws: SAXException DOCUMENT ME!

dtdHandler

protected void dtdHandler(Document document)
We do not yet support DTD or XML Schemas so this method does nothing right now.

Parameters: document DOCUMENT ME!

Throws: SAXException DOCUMENT ME!

endDocument

protected void endDocument()

endElement

protected void endElement(Element element)

endPrefixMapping

protected void endPrefixMapping(NamespaceStack stack, int stackSize)
Fires a SAX endPrefixMapping event for all the namespaceStack which have gone out of scope

Parameters: stack DOCUMENT ME! stackSize DOCUMENT ME!

Throws: SAXException DOCUMENT ME!

entityResolver

protected void entityResolver(Document document)

getContentHandler

public ContentHandler getContentHandler()
DOCUMENT ME!

Returns: the ContentHandler called when SAX events are raised

getDTDHandler

public DTDHandler getDTDHandler()
DOCUMENT ME!

Returns: the DTDHandler

getEntityResolver

public EntityResolver getEntityResolver()
DOCUMENT ME!

Returns: the EntityResolver used when a Document contains a DTD

getErrorHandler

public ErrorHandler getErrorHandler()
DOCUMENT ME!

Returns: the ErrorHandler

getFeature

public boolean getFeature(String name)
Looks up the value of a feature.

Parameters: name DOCUMENT ME!

Returns: DOCUMENT ME!

Throws: SAXNotRecognizedException DOCUMENT ME! SAXNotSupportedException DOCUMENT ME!

getLexicalHandler

public LexicalHandler getLexicalHandler()
DOCUMENT ME!

Returns: the LexicalHandler used when a Document contains a DTD

getProperty

public Object getProperty(String name)
Gets the given SAX property

Parameters: name DOCUMENT ME!

Returns: DOCUMENT ME!

Throws: SAXNotRecognizedException DOCUMENT ME! SAXNotSupportedException DOCUMENT ME!

isDeclareNamespaceAttributes

public boolean isDeclareNamespaceAttributes()
Should namespace declarations be converted to "xmlns" attributes. This property defaults to false as per the SAX specification. This property is set via the SAX feature "http://xml.org/sax/features/namespace-prefixes"

Returns: DOCUMENT ME!

isIgnoreableNamespace

protected boolean isIgnoreableNamespace(Namespace namespace, NamespaceStack namespaceStack)
DOCUMENT ME!

Parameters: namespace DOCUMENT ME! namespaceStack DOCUMENT ME!

Returns: true if the given namespace is an ignorable namespace (such as Namespace.NO_NAMESPACE or Namespace.XML_NAMESPACE) or if the namespace has already been declared in the current scope

parse

public void parse(String systemId)
This method is not supported.

Parameters: systemId DOCUMENT ME!

Throws: SAXNotSupportedException DOCUMENT ME!

parse

public void parse(InputSource input)
Parses an XML document. This method can only accept DocumentInputSource inputs otherwise a SAXNotSupportedExceptionexception is thrown.

Parameters: input DOCUMENT ME!

Throws: SAXException DOCUMENT ME! SAXNotSupportedException if the input source is not wrapping a dom4j document

setContentHandler

public void setContentHandler(ContentHandler contentHandler)
Sets the ContentHandler called when SAX events are raised

Parameters: contentHandler is the ContentHandler called when SAX events are raised

setDeclareNamespaceAttributes

public void setDeclareNamespaceAttributes(boolean declareNamespaceAttrs)
Sets whether namespace declarations should be exported as "xmlns" attributes or not. This property is set from the SAX feature "http://xml.org/sax/features/namespace-prefixes"

Parameters: declareNamespaceAttrs DOCUMENT ME!

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Sets the DTDHandler.

Parameters: handler DOCUMENT ME!

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Sets the EntityResolver.

Parameters: entityResolver is the EntityResolver

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Sets the ErrorHandler.

Parameters: errorHandler DOCUMENT ME!

setFeature

public void setFeature(String name, boolean value)
This implementation does actually use any features but just stores them for later retrieval

Parameters: name DOCUMENT ME! value DOCUMENT ME!

Throws: SAXNotRecognizedException DOCUMENT ME! SAXNotSupportedException DOCUMENT ME!

setLexicalHandler

public void setLexicalHandler(LexicalHandler lexicalHandler)
Sets the LexicalHandler.

Parameters: lexicalHandler is the LexicalHandler

setProperty

public void setProperty(String name, Object value)
Sets the given SAX property

Parameters: name DOCUMENT ME! value DOCUMENT ME!

setXMLReader

public void setXMLReader(XMLReader xmlReader)
Sets the XMLReader used to write SAX events to

Parameters: xmlReader is the XMLReader

startDocument

protected void startDocument()

startElement

protected void startElement(Element element, AttributesImpl namespaceAttributes)

startPrefixMapping

protected AttributesImpl startPrefixMapping(Element element, NamespaceStack namespaceStack)
Fires a SAX startPrefixMapping event for all the namespaceStack which have just come into scope

Parameters: element DOCUMENT ME! namespaceStack DOCUMENT ME!

Returns: DOCUMENT ME!

Throws: SAXException DOCUMENT ME!

write

public void write(Node node)
A polymorphic method to write any Node to this SAX stream

Parameters: node DOCUMENT ME!

Throws: SAXException DOCUMENT ME!

write

public void write(Document document)
Generates SAX events for the given Document and all its content

Parameters: document is the Document to parse

Throws: SAXException if there is a SAX error processing the events

write

public void write(Element element)
Generates SAX events for the given Element and all its content

Parameters: element is the Element to parse

Throws: SAXException if there is a SAX error processing the events

write

public void write(String text)
Generates SAX events for the given text

Parameters: text is the text to send to the SAX ContentHandler

Throws: SAXException if there is a SAX error processing the events

write

public void write(CDATA cdata)
Generates SAX events for the given CDATA

Parameters: cdata is the CDATA to parse

Throws: SAXException if there is a SAX error processing the events

write

public void write(Comment comment)
Generates SAX events for the given Comment

Parameters: comment is the Comment to parse

Throws: SAXException if there is a SAX error processing the events

write

public void write(Entity entity)
Generates SAX events for the given Entity

Parameters: entity is the Entity to parse

Throws: SAXException if there is a SAX error processing the events

write

public void write(ProcessingInstruction pi)
Generates SAX events for the given ProcessingInstruction

Parameters: pi is the ProcessingInstruction to parse

Throws: SAXException if there is a SAX error processing the events

write

protected void write(Element element, NamespaceStack namespaceStack)

writeClose

public void writeClose(Element element)

Writes the closing tag of an Element

Parameters: element Element to output.

Throws: SAXException DOCUMENT ME!

writeContent

protected void writeContent(Branch branch, NamespaceStack namespaceStack)

writeOpen

public void writeOpen(Element element)

Writes the opening tag of an Element, including its Attributes but without its content.

Parameters: element Element to output.

Throws: SAXException DOCUMENT ME!

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

SourceForge