Outputs a JDOM document as a stream of SAX2 events.
Most ContentHandler callbacks are supported. Both
ignorableWhitespace()
and
skippedEntity()
have not
been implemented. The
JDOMLocator
class returned by
getLocator()
exposes the current node being operated
upon.
At this time, it is not possible to access notations and unparsed entity
references in a DTD from JDOM. Therefore,
DTDHandler
callbacks
have not been implemented yet.
The
ErrorHandler
callbacks have not been implemented, since
these are supposed to be invoked when the document is parsed and at this
point the document exists in memory and is known to have no errors.
SAXOutputter
public SAXOutputter()
This will create a SAXOutputter
without any
registered handler. The application is then responsible for
registering them using the setXxxHandler()
methods.
SAXOutputter
public SAXOutputter(ContentHandler contentHandler)
This will create a SAXOutputter
with the
specified ContentHandler
.
contentHandler
- contains ContentHandler
callback methods
SAXOutputter
public SAXOutputter(ContentHandler contentHandler,
ErrorHandler errorHandler,
DTDHandler dtdHandler,
EntityResolver entityResolver)
This will create a SAXOutputter
with the
specified SAX2 handlers. At this time, only ContentHandler
and EntityResolver
are supported.
contentHandler
- contains ContentHandler
callback methodserrorHandler
- contains ErrorHandler
callback methodsdtdHandler
- contains DTDHandler
callback methodsentityResolver
- contains EntityResolver
callback methods
SAXOutputter
public SAXOutputter(ContentHandler contentHandler,
ErrorHandler errorHandler,
DTDHandler dtdHandler,
EntityResolver entityResolver,
LexicalHandler lexicalHandler)
This will create a SAXOutputter
with the
specified SAX2 handlers. At this time, only ContentHandler
and EntityResolver
are supported.
contentHandler
- contains ContentHandler
callback methodserrorHandler
- contains ErrorHandler
callback methodsdtdHandler
- contains DTDHandler
callback methodsentityResolver
- contains EntityResolver
callback methodslexicalHandler
- contains LexicalHandler
callbacks.
createParser
protected XMLReader createParser()
throws Exception
Creates a SAX XMLReader.
getContentHandler
public ContentHandler getContentHandler()
Returns the registered ContentHandler
.
- the current
ContentHandler
or
null
if none was registered.
getDTDHandler
public DTDHandler getDTDHandler()
Return the registered DTDHandler
.
- the current
DTDHandler
or
null
if none was registered.
getDeclHandler
public DeclHandler getDeclHandler()
Return the registered DeclHandler
.
- the current
DeclHandler
or
null
if none was registered.
getEntityResolver
public EntityResolver getEntityResolver()
Return the registered EntityResolver
.
- the current
EntityResolver
or
null
if none was registered.
getErrorHandler
public ErrorHandler getErrorHandler()
Return the registered ErrorHandler
.
- the current
ErrorHandler
or
null
if none was registered.
getFeature
public boolean getFeature(String name)
throws SAXNotRecognizedException,
SAXNotSupportedException
This will look up the value of a SAX feature.
name
- String
the feature name, which is a
fully-qualified URI.
boolean
the current state of the feature
(true or false).
getLexicalHandler
public LexicalHandler getLexicalHandler()
Return the registered LexicalHandler
.
- the current
LexicalHandler
or
null
if none was registered.
getLocator
public JDOMLocator getLocator()
Returns a JDOMLocator object referencing the node currently
being processed by this outputter. The returned object is a
snapshot of the location information and can thus safely be
memorized for later use.
This method allows direct access to the location information
maintained by SAXOutputter without requiring to implement
XMLFilter
. (In SAX, locators are only available
though the
ContentHandler
interface).
Note that location information is only available while
SAXOutputter is outputting nodes. Hence this method should
only be used by objects taking part in the output processing
such as
ErrorHandler
s.
- a JDOMLocator object referencing the node currently
being processed or
null
if no output
operation is being performed.
getProperty
public Object getProperty(String name)
throws SAXNotRecognizedException,
SAXNotSupportedException
This will look up the value of a SAX property.
name
- String
the property name, which is a
fully-qualified URI.
Object
the current value of the property.
getReportDTDEvents
public boolean getReportDTDEvents()
Returns whether DTD events will be reported.
- whether DTD events will be reported
getReportNamespaceDeclarations
public boolean getReportNamespaceDeclarations()
Returns whether attribute namespace declarations shall be reported as
"xmlns" attributes.
- whether attribute namespace declarations shall be reported as
"xmlns" attributes.
output
public void output(List nodes)
throws JDOMException
This will output a list of JDOM nodes as a document, firing
off the SAX events that have been registered.
Warning: This method may output ill-formed XML
documents if the list contains top-level objects that are not
legal at the document level (e.g. Text or CDATA nodes, multiple
Element nodes, etc.). Thus, it should only be used to output
document portions towards ContentHandlers capable of accepting
such ill-formed documents (such as XSLT processors).
nodes
- List
of JDOM nodes to output.
output
public void output(Document document)
throws JDOMException
This will output the JDOM Document
, firing off the
SAX events that have been registered.
document
- JDOM Document
to output.
output
public void output(Element node)
throws JDOMException
This will output a single JDOM element as a document, firing
off the SAX events that have been registered.
node
- the Element
node to output.
outputFragment
public void outputFragment(List nodes)
throws JDOMException
This will output a list of JDOM nodes as a fragment of an XML
document, firing off the SAX events that have been registered.
Warning: This method does not call the
ContentHandler.setDocumentLocator
,
ContentHandler.startDocument
and
ContentHandler.endDocument
callbacks on the
ContentHandler
. The user shall
invoke these methods directly prior/after outputting the
document fragments.
nodes
- List
of JDOM nodes to output.
outputFragment
public void outputFragment(Content node)
throws JDOMException
This will output a single JDOM nodes as a fragment of an XML
document, firing off the SAX events that have been registered.
Warning: This method does not call the
ContentHandler.setDocumentLocator
,
ContentHandler.startDocument
and
ContentHandler.endDocument
callbacks on the
ContentHandler
. The user shall
invoke these methods directly prior/after outputting the
document fragments.
node
- the Content
node to output.
outputFragment(java.util.List)
setContentHandler
public void setContentHandler(ContentHandler contentHandler)
This will set the ContentHandler
.
contentHandler
- contains ContentHandler
callback methods.
setDTDHandler
public void setDTDHandler(DTDHandler dtdHandler)
This will set the DTDHandler
.
dtdHandler
- contains DTDHandler
callback methods.
setDeclHandler
public void setDeclHandler(DeclHandler declHandler)
This will set the DeclHandler
.
declHandler
- contains declaration callback methods.
setEntityResolver
public void setEntityResolver(EntityResolver entityResolver)
This will set the EntityResolver
.
entityResolver
- contains EntityResolver callback methods.
setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
This will set the ErrorHandler
.
errorHandler
- contains ErrorHandler
callback methods.
setFeature
public void setFeature(String name,
boolean value)
throws SAXNotRecognizedException,
SAXNotSupportedException
This will set the state of a SAX feature.
All XMLReaders are required to support setting to true and to false.
SAXOutputter currently supports the following SAX core features:
http://xml.org/sax/features/namespaces
- description:
true
- access:
true
http://xml.org/sax/features/namespace-prefixes
- description:
true
- access:
http://xml.org/sax/features/validation
- description:
true
- access:
true
name
- String
the feature name, which is a
fully-qualified URI.value
- boolean
the requested state of the
feature (true or false).
setLexicalHandler
public void setLexicalHandler(LexicalHandler lexicalHandler)
This will set the LexicalHandler
.
lexicalHandler
- contains lexical callback methods.
setProperty
public void setProperty(String name,
Object value)
throws SAXNotRecognizedException,
SAXNotSupportedException
This will set the value of a SAX property.
This method is also the standard mechanism for setting extended
handlers.
SAXOutputter currently supports the following SAX properties:
http://xml.org/sax/properties/lexical-handler
- data type:
org.xml.sax.ext.LexicalHandler
- description:
- access:
http://xml.org/sax/properties/declaration-handler
- data type:
org.xml.sax.ext.DeclHandler
- description:
- access:
name
- String
the property name, which is a
fully-qualified URI.value
- Object
the requested value for the property.
setReportDTDEvents
public void setReportDTDEvents(boolean reportDtdEvents)
This will define whether to report DTD events to SAX DeclHandlers
and LexicalHandlers if these handlers are registered and the
document to output includes a DocType declaration.
reportDtdEvents
- whether to notify DTD events.
setReportNamespaceDeclarations
public void setReportNamespaceDeclarations(boolean declareNamespaces)
This will define whether attribute namespace declarations shall be
reported as "xmlns" attributes. This flag defaults to false
and behaves as the "namespace-prefixes" SAX core feature.
declareNamespaces
- whether attribute namespace declarations
shall be reported as "xmlns" attributes.