Package org.dom4j.io
Class SAXWriter
- java.lang.Object
-
- org.dom4j.io.SAXWriter
-
- All Implemented Interfaces:
org.xml.sax.XMLReader
public class SAXWriter extends java.lang.Object implements org.xml.sax.XMLReaderSAXWriterwrites a DOM4J tree to a SAX ContentHandler.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringFEATURE_NAMESPACE_PREFIXESprotected static java.lang.StringFEATURE_NAMESPACESprotected static java.lang.String[]LEXICAL_HANDLER_NAMES
-
Constructor Summary
Constructors Constructor Description SAXWriter()SAXWriter(org.xml.sax.ContentHandler contentHandler)SAXWriter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler)SAXWriter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler, org.xml.sax.EntityResolver entityResolver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.xml.sax.helpers.AttributesImpladdNamespaceAttribute(org.xml.sax.helpers.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 org.xml.sax.AttributescreateAttributes(Element element, org.xml.sax.Attributes namespaceAttributes)protected voiddocumentLocator(Document document)TheLocatoris 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 scopeprotected voidentityResolver(Document document)org.xml.sax.ContentHandlergetContentHandler()DOCUMENT ME!org.xml.sax.DTDHandlergetDTDHandler()DOCUMENT ME!org.xml.sax.EntityResolvergetEntityResolver()DOCUMENT ME!org.xml.sax.ErrorHandlergetErrorHandler()DOCUMENT ME!booleangetFeature(java.lang.String name)Looks up the value of a feature.org.xml.sax.ext.LexicalHandlergetLexicalHandler()DOCUMENT ME!java.lang.ObjectgetProperty(java.lang.String name)Gets the given SAX propertyprotected voidcheckForNullHandlers()Ensures non-null content handlers?booleanisDeclareNamespaceAttributes()Should namespace declarations be converted to "xmlns" attributes.protected booleanisIgnoreableNamespace(Namespace namespace, NamespaceStack namespaceStack)DOCUMENT ME!voidparse(java.lang.String systemId)This method is not supported.voidparse(org.xml.sax.InputSource input)Parses an XML document.voidsetContentHandler(org.xml.sax.ContentHandler contentHandler)Sets theContentHandlercalled when SAX events are raisedvoidsetDeclareNamespaceAttributes(boolean declareNamespaceAttrs)Sets whether namespace declarations should be exported as "xmlns" attributes or not.voidsetDTDHandler(org.xml.sax.DTDHandler handler)Sets theDTDHandler.voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)Sets theEntityResolver.voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)Sets theErrorHandler.voidsetFeature(java.lang.String name, boolean value)This implementation does actually use any features but just stores them for later retrievalvoidsetLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)Sets theLexicalHandler.voidsetProperty(java.lang.String name, java.lang.Object value)Sets the given SAX propertyvoidsetXMLReader(org.xml.sax.XMLReader xmlReader)Sets theXMLReaderused to write SAX events toprotected voidstartDocument()protected voidstartElement(Element element, org.xml.sax.helpers.AttributesImpl namespaceAttributes)protected org.xml.sax.helpers.AttributesImplstartPrefixMapping(Element element, NamespaceStack namespaceStack)Fires a SAX startPrefixMapping event for all the namespaceStack which have just come into scopevoidwrite(java.lang.String text)Generates SAX events for the given textvoidwrite(CDATA cdata)Generates SAX events for the given CDATAvoidwrite(Comment comment)Generates SAX events for the given Commentvoidwrite(Document document)Generates SAX events for the given Document and all its contentvoidwrite(Element element)Generates SAX events for the given Element and all its contentprotected voidwrite(Element element, NamespaceStack namespaceStack)voidwrite(Entity entity)Generates SAX events for the given Entityvoidwrite(Node node)A polymorphic method to write any Node to this SAX streamvoidwrite(ProcessingInstruction pi)Generates SAX events for the given ProcessingInstructionvoidwriteClose(Element element)Writes the closing tag of anElementprotected voidwriteContent(Branch branch, NamespaceStack namespaceStack)voidwriteOpen(Element element)
-
-
-
Field Detail
-
LEXICAL_HANDLER_NAMES
protected static final java.lang.String[] LEXICAL_HANDLER_NAMES
-
FEATURE_NAMESPACE_PREFIXES
protected static final java.lang.String FEATURE_NAMESPACE_PREFIXES
- See Also:
- Constant Field Values
-
FEATURE_NAMESPACES
protected static final java.lang.String FEATURE_NAMESPACES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SAXWriter
public SAXWriter()
-
SAXWriter
public SAXWriter(org.xml.sax.ContentHandler contentHandler)
-
SAXWriter
public SAXWriter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler)
-
SAXWriter
public SAXWriter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler, org.xml.sax.EntityResolver entityResolver)
-
-
Method Detail
-
write
public void write(Node node) throws org.xml.sax.SAXException
A polymorphic method to write any Node to this SAX stream- Parameters:
node- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
write
public void write(Document document) throws org.xml.sax.SAXException
Generates SAX events for the given Document and all its content- Parameters:
document- is the Document to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
write
public void write(Element element) throws org.xml.sax.SAXException
Generates SAX events for the given Element and all its content- Parameters:
element- is the Element to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
writeOpen
public void writeOpen(Element element) throws org.xml.sax.SAXException
- Parameters:
element-Elementto output.- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
writeClose
public void writeClose(Element element) throws org.xml.sax.SAXException
Writes the closing tag of an
Element- Parameters:
element-Elementto output.- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
write
public void write(java.lang.String text) throws org.xml.sax.SAXExceptionGenerates SAX events for the given text- Parameters:
text- is the text to send to the SAX ContentHandler- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
write
public void write(CDATA cdata) throws org.xml.sax.SAXException
Generates SAX events for the given CDATA- Parameters:
cdata- is the CDATA to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
write
public void write(Comment comment) throws org.xml.sax.SAXException
Generates SAX events for the given Comment- Parameters:
comment- is the Comment to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
write
public void write(Entity entity) throws org.xml.sax.SAXException
Generates SAX events for the given Entity- Parameters:
entity- is the Entity to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
write
public void write(ProcessingInstruction pi) throws org.xml.sax.SAXException
Generates SAX events for the given ProcessingInstruction- Parameters:
pi- is the ProcessingInstruction to parse- Throws:
org.xml.sax.SAXException- if there is a SAX error processing the events
-
isDeclareNamespaceAttributes
public boolean isDeclareNamespaceAttributes()
Should namespace declarations be converted to "xmlns" attributes. This property defaults tofalseas per the SAX specification. This property is set via the SAX feature "http://xml.org/sax/features/namespace-prefixes"- Returns:
- DOCUMENT ME!
-
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!
-
getContentHandler
public org.xml.sax.ContentHandler getContentHandler()
DOCUMENT ME!- Specified by:
getContentHandlerin interfaceorg.xml.sax.XMLReader- Returns:
- the
ContentHandlercalled when SAX events are raised
-
setContentHandler
public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
Sets theContentHandlercalled when SAX events are raised- Specified by:
setContentHandlerin interfaceorg.xml.sax.XMLReader- Parameters:
contentHandler- is theContentHandlercalled when SAX events are raised
-
getDTDHandler
public org.xml.sax.DTDHandler getDTDHandler()
DOCUMENT ME!- Specified by:
getDTDHandlerin interfaceorg.xml.sax.XMLReader- Returns:
- the
DTDHandler
-
setDTDHandler
public void setDTDHandler(org.xml.sax.DTDHandler handler)
Sets theDTDHandler.- Specified by:
setDTDHandlerin interfaceorg.xml.sax.XMLReader- Parameters:
handler- DOCUMENT ME!
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
DOCUMENT ME!- Specified by:
getErrorHandlerin interfaceorg.xml.sax.XMLReader- Returns:
- the
ErrorHandler
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Sets theErrorHandler.- Specified by:
setErrorHandlerin interfaceorg.xml.sax.XMLReader- Parameters:
errorHandler- DOCUMENT ME!
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
DOCUMENT ME!- Specified by:
getEntityResolverin interfaceorg.xml.sax.XMLReader- Returns:
- the
EntityResolverused when a Document contains a DTD
-
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Sets theEntityResolver.- Specified by:
setEntityResolverin interfaceorg.xml.sax.XMLReader- Parameters:
entityResolver- is theEntityResolver
-
getLexicalHandler
public org.xml.sax.ext.LexicalHandler getLexicalHandler()
DOCUMENT ME!- Returns:
- the
LexicalHandlerused when a Document contains a DTD
-
setLexicalHandler
public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
Sets theLexicalHandler.- Parameters:
lexicalHandler- is theLexicalHandler
-
setXMLReader
public void setXMLReader(org.xml.sax.XMLReader xmlReader)
Sets theXMLReaderused to write SAX events to- Parameters:
xmlReader- is theXMLReader
-
getFeature
public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionLooks up the value of a feature.- Specified by:
getFeaturein interfaceorg.xml.sax.XMLReader- Parameters:
name- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
org.xml.sax.SAXNotRecognizedException- DOCUMENT ME!org.xml.sax.SAXNotSupportedException- DOCUMENT ME!
-
setFeature
public void setFeature(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionThis implementation does actually use any features but just stores them for later retrieval- Specified by:
setFeaturein interfaceorg.xml.sax.XMLReader- Parameters:
name- DOCUMENT ME!value- DOCUMENT ME!- Throws:
org.xml.sax.SAXNotRecognizedException- DOCUMENT ME!org.xml.sax.SAXNotSupportedException- DOCUMENT ME!
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value)Sets the given SAX property- Specified by:
setPropertyin interfaceorg.xml.sax.XMLReader- Parameters:
name- DOCUMENT ME!value- DOCUMENT ME!
-
getProperty
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionGets the given SAX property- Specified by:
getPropertyin interfaceorg.xml.sax.XMLReader- Parameters:
name- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
org.xml.sax.SAXNotRecognizedException- DOCUMENT ME!org.xml.sax.SAXNotSupportedException- DOCUMENT ME!
-
parse
public void parse(java.lang.String systemId) throws org.xml.sax.SAXNotSupportedExceptionThis method is not supported.- Specified by:
parsein interfaceorg.xml.sax.XMLReader- Parameters:
systemId- DOCUMENT ME!- Throws:
org.xml.sax.SAXNotSupportedException- DOCUMENT ME!
-
parse
public void parse(org.xml.sax.InputSource input) throws org.xml.sax.SAXExceptionParses an XML document. This method can only accept DocumentInputSource inputs otherwise aSAXNotSupportedExceptionexception is thrown.- Specified by:
parsein interfaceorg.xml.sax.XMLReader- Parameters:
input- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!org.xml.sax.SAXNotSupportedException- if the input source is not wrapping a dom4j document
-
writeContent
protected void writeContent(Branch branch, NamespaceStack namespaceStack) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
documentLocator
protected void documentLocator(Document document) throws org.xml.sax.SAXException
TheLocatoris 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:
org.xml.sax.SAXException- DOCUMENT ME!
-
entityResolver
protected void entityResolver(Document document) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
dtdHandler
protected void dtdHandler(Document document) throws org.xml.sax.SAXException
We do not yet support DTD or XML Schemas so this method does nothing right now.- Parameters:
document- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
startDocument
protected void startDocument() throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
endDocument
protected void endDocument() throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
write
protected void write(Element element, NamespaceStack namespaceStack) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
protected org.xml.sax.helpers.AttributesImpl startPrefixMapping(Element element, NamespaceStack namespaceStack) throws org.xml.sax.SAXException
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:
org.xml.sax.SAXException- DOCUMENT ME!
-
endPrefixMapping
protected void endPrefixMapping(NamespaceStack stack, int stackSize) throws org.xml.sax.SAXException
Fires a SAX endPrefixMapping event for all the namespaceStack which have gone out of scope- Parameters:
stack- DOCUMENT ME!stackSize- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
startElement
protected void startElement(Element element, org.xml.sax.helpers.AttributesImpl namespaceAttributes) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
endElement
protected void endElement(Element element) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
createAttributes
protected org.xml.sax.Attributes createAttributes(Element element, org.xml.sax.Attributes namespaceAttributes) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
addNamespaceAttribute
protected org.xml.sax.helpers.AttributesImpl addNamespaceAttribute(org.xml.sax.helpers.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!
-
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
-
checkForNullHandlers
protected void checkForNullHandlers()
Ensures non-null content handlers?
-
-