public class SAXWriter extends Object implements XMLReader
SAXWriter
writes a DOM4J tree to a SAX ContentHandler.
Modifier and Type | Field and Description |
---|---|
private AttributesImpl |
attributes
code>AttributesImpl used when generating the Attributes
|
private ContentHandler |
contentHandler
ContentHandler to which SAX events are raised |
private boolean |
declareNamespaceAttributes
Whether namespace declarations are exported as attributes or not
|
private DTDHandler |
dtdHandler
code>DTDHandler fired when a document has a DTD
|
private EntityResolver |
entityResolver
code>EntityResolver fired when a document has a DTD
|
private ErrorHandler |
errorHandler |
protected static String |
FEATURE_NAMESPACE_PREFIXES |
protected static String |
FEATURE_NAMESPACES |
private Map |
features
Stores the features
|
protected static String[] |
LEXICAL_HANDLER_NAMES |
private LexicalHandler |
lexicalHandler
code>LexicalHandler fired on Entity and CDATA sections
|
private Map |
properties
Stores the properties
|
Constructor and Description |
---|
SAXWriter() |
SAXWriter(ContentHandler contentHandler) |
SAXWriter(ContentHandler contentHandler,
EntityResolver entityResolver,
LexicalHandler lexicalHandler) |
Modifier and Type | Method and Description |
---|---|
protected AttributesImpl |
addNamespaceAttribute(AttributesImpl namespaceAttributes,
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 void |
checkForNullHandlers()
Ensures non-null content handlers?
|
protected Attributes |
createAttributes(Element element,
Attributes namespaceAttributes) |
protected void |
documentLocator(Document document)
The
Locator is only really useful when parsing a textual
document as its main purpose is to identify the line and column number. |
protected void |
dtdHandler(Document document)
We do not yet support DTD or XML Schemas so this method does nothing
right now.
|
protected void |
endDocument() |
protected void |
endElement(Element element) |
protected void |
endPrefixMapping(NamespaceStack namespaceStack,
int stackSize)
Fires a SAX endPrefixMapping event for all the namespaceStack which
have gone out of scope
|
protected void |
entityResolver(Document document) |
ContentHandler |
getContentHandler()
Return the current content handler.
|
DTDHandler |
getDTDHandler()
Return the current DTD handler.
|
EntityResolver |
getEntityResolver()
Return the current entity resolver.
|
ErrorHandler |
getErrorHandler()
Return the current error handler.
|
boolean |
getFeature(String name)
Looks up the value of a feature.
|
LexicalHandler |
getLexicalHandler() |
Object |
getProperty(String name)
Gets the given SAX property
|
boolean |
isDeclareNamespaceAttributes()
Should namespace declarations be converted to "xmlns" attributes.
|
protected boolean |
isIgnoreableNamespace(Namespace namespace,
NamespaceStack namespaceStack) |
void |
parse(InputSource input)
Parses an XML document.
|
void |
parse(String systemId)
This method is not supported.
|
void |
setContentHandler(ContentHandler contentHandler)
Sets the
ContentHandler called when SAX events
are raised |
void |
setDeclareNamespaceAttributes(boolean declareNamespaceAttributes)
Sets whether namespace declarations should be exported as "xmlns" attributes or not.
|
void |
setDTDHandler(DTDHandler dtdHandler)
Sets the
DTDHandler . |
void |
setEntityResolver(EntityResolver entityResolver)
Sets the
EntityResolver . |
void |
setErrorHandler(ErrorHandler errorHandler)
Sets the
ErrorHandler . |
void |
setFeature(String name,
boolean value)
This implementation does actually use any features but just
stores them for later retrieval
|
void |
setLexicalHandler(LexicalHandler lexicalHandler)
Sets the
LexicalHandler . |
void |
setProperty(String name,
Object value)
Sets the given SAX property
|
void |
setXMLReader(XMLReader xmlReader)
Sets the
XMLReader used to write SAX events to |
protected void |
startDocument() |
protected void |
startElement(Element element,
AttributesImpl namespaceAttributes) |
protected AttributesImpl |
startPrefixMapping(Element element,
NamespaceStack namespaceStack)
Fires a SAX startPrefixMapping event for all the namespaceStack
which have just come into scope
|
void |
write(CDATA cdata)
Generates SAX events for the given CDATA
|
void |
write(Comment comment)
Generates SAX events for the given Comment
|
void |
write(Document document)
Generates SAX events for the given Document and all its content
|
void |
write(Element element)
Generates SAX events for the given Element and all its content
|
protected void |
write(Element element,
NamespaceStack namespaceStack) |
void |
write(Entity entity)
Generates SAX events for the given Entity
|
void |
write(ProcessingInstruction pi)
Generates SAX events for the given ProcessingInstruction
|
void |
write(String text)
Generates SAX events for the given text
|
protected void |
writeContent(Branch branch,
NamespaceStack namespaceStack) |
protected static final String[] LEXICAL_HANDLER_NAMES
protected static String FEATURE_NAMESPACE_PREFIXES
protected static String FEATURE_NAMESPACES
private ContentHandler contentHandler
ContentHandler
to which SAX events are raisedprivate DTDHandler dtdHandler
private EntityResolver entityResolver
private ErrorHandler errorHandler
private LexicalHandler lexicalHandler
private AttributesImpl attributes
private Map properties
private boolean declareNamespaceAttributes
public SAXWriter()
public SAXWriter(ContentHandler contentHandler)
public SAXWriter(ContentHandler contentHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler)
public void write(Document document) throws SAXException
document
- is the Document to parseSAXException
public void write(Element element) throws SAXException
element
- is the Element to parseSAXException
public void write(String text) throws SAXException
text
- is the text to send to the SAX ContentHandlerSAXException
public void write(CDATA cdata) throws SAXException
cdata
- is the CDATA to parseSAXException
public void write(Comment comment) throws SAXException
comment
- is the Comment to parseSAXException
public void write(Entity entity) throws SAXException
e
- is the Entity to parseSAXException
public void write(ProcessingInstruction pi) throws SAXException
pi
- is the ProcessingInstruction to parseSAXException
public boolean isDeclareNamespaceAttributes()
false
as per the SAX specification.
This property is set via the SAX feature "http://xml.org/sax/features/namespace-prefixes"public void setDeclareNamespaceAttributes(boolean declareNamespaceAttributes)
public ContentHandler getContentHandler()
XMLReader
getContentHandler
in interface XMLReader
ContentHandler
called when SAX events
are raisedXMLReader.setContentHandler(org.xml.sax.ContentHandler)
public void setContentHandler(ContentHandler contentHandler)
ContentHandler
called when SAX events
are raisedsetContentHandler
in interface XMLReader
contentHandler
- is the ContentHandler
called when SAX events
are raisedXMLReader.getContentHandler()
public DTDHandler getDTDHandler()
XMLReader
getDTDHandler
in interface XMLReader
DTDHandler
XMLReader.setDTDHandler(org.xml.sax.DTDHandler)
public void setDTDHandler(DTDHandler dtdHandler)
DTDHandler
.setDTDHandler
in interface XMLReader
dtdHandler
- The DTD handler.XMLReader.getDTDHandler()
public ErrorHandler getErrorHandler()
XMLReader
getErrorHandler
in interface XMLReader
ErrorHandler
XMLReader.setErrorHandler(org.xml.sax.ErrorHandler)
public void setErrorHandler(ErrorHandler errorHandler)
ErrorHandler
.setErrorHandler
in interface XMLReader
errorHandler
- The error handler.XMLReader.getErrorHandler()
public EntityResolver getEntityResolver()
XMLReader
getEntityResolver
in interface XMLReader
EntityResolver
used when a Document contains
a DTDXMLReader.setEntityResolver(org.xml.sax.EntityResolver)
public void setEntityResolver(EntityResolver entityResolver)
EntityResolver
.setEntityResolver
in interface XMLReader
entityResolver
- is the EntityResolver
XMLReader.getEntityResolver()
public LexicalHandler getLexicalHandler()
LexicalHandler
used when a Document contains
a DTDpublic void setLexicalHandler(LexicalHandler lexicalHandler)
LexicalHandler
.entityResolver
- is the LexicalHandler
public void setXMLReader(XMLReader xmlReader)
XMLReader
used to write SAX events toxmlReader
- is the XMLReader
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException
getFeature
in interface XMLReader
name
- The feature name, which is a fully-qualified URI.SAXNotRecognizedException
- When the
XMLReader does not recognize the feature name.SAXNotSupportedException
- When the
XMLReader recognizes the feature name but
cannot determine its value at this time.XMLReader.setFeature(java.lang.String, boolean)
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
setFeature
in interface XMLReader
name
- The feature name, which is a fully-qualified URI.SAXNotRecognizedException
- When the
XMLReader does not recognize the feature name.SAXNotSupportedException
- When the
XMLReader recognizes the feature name but
cannot set the requested value.XMLReader.getFeature(java.lang.String)
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
setProperty
in interface XMLReader
name
- The property name, which is a fully-qualified URI.SAXNotRecognizedException
- When the
XMLReader does not recognize the property name.SAXNotSupportedException
- When the
XMLReader recognizes the property name but
cannot set the requested value.public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException
getProperty
in interface XMLReader
name
- The property name, which is a fully-qualified URI.SAXNotRecognizedException
- When the
XMLReader does not recognize the property name.SAXNotSupportedException
- When the
XMLReader recognizes the property name but
cannot determine its value at this time.XMLReader.setProperty(java.lang.String, java.lang.Object)
public void parse(String systemId) throws SAXNotSupportedException
parse
in interface XMLReader
systemId
- The system identifier (URI).SAXNotSupportedException
XMLReader.parse(org.xml.sax.InputSource)
public void parse(InputSource input) throws SAXException
SAXNotSupportedException
exception is thrown.parse
in interface XMLReader
SAXNotSupportedException
- if the input source is not wrapping a dom4j documentSAXException
- Any SAX exception, possibly
wrapping another exception.InputSource
,
XMLReader.parse(java.lang.String)
,
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)
,
XMLReader.setDTDHandler(org.xml.sax.DTDHandler)
,
XMLReader.setContentHandler(org.xml.sax.ContentHandler)
,
XMLReader.setErrorHandler(org.xml.sax.ErrorHandler)
protected void writeContent(Branch branch, NamespaceStack namespaceStack) throws SAXException
SAXException
protected void documentLocator(Document document) throws SAXException
Locator
is 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.SAXException
protected void entityResolver(Document document) throws SAXException
SAXException
protected void dtdHandler(Document document) throws SAXException
SAXException
protected void startDocument() throws SAXException
SAXException
protected void endDocument() throws SAXException
SAXException
protected void write(Element element, NamespaceStack namespaceStack) throws SAXException
SAXException
protected AttributesImpl startPrefixMapping(Element element, NamespaceStack namespaceStack) throws SAXException
SAXException
protected void endPrefixMapping(NamespaceStack namespaceStack, int stackSize) throws SAXException
SAXException
protected void startElement(Element element, AttributesImpl namespaceAttributes) throws SAXException
SAXException
protected void endElement(Element element) throws SAXException
SAXException
protected Attributes createAttributes(Element element, Attributes namespaceAttributes) throws SAXException
SAXException
protected AttributesImpl addNamespaceAttribute(AttributesImpl namespaceAttributes, Namespace namespace)
protected boolean isIgnoreableNamespace(Namespace namespace, NamespaceStack namespaceStack)
protected void checkForNullHandlers()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses