Class SAXOutputter
Most ContentHandler callbacks are supported. BOTH
ignorableWhitespace()
and skippedEntity()
have not
been implemented. The
class returned by
JDOMLocator
exposes the current node being operated
upon.
getLocator()
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.
- Author:
- Brett McLaughlin, Jason Hunter, Fred Trimble, Bradley S. Huffman
-
Constructor Summary
ConstructorsConstructorDescriptionThis will create aSAXOutputter
without any registered handler.SAXOutputter
(SAXOutputProcessor processor, Format format, ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler) This will create aSAXOutputter
with the specified SAX2 handlers.SAXOutputter
(ContentHandler contentHandler) This will create aSAXOutputter
with the specifiedContentHandler
.SAXOutputter
(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver) This will create aSAXOutputter
with the specified SAX2 handlers.SAXOutputter
(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler) This will create aSAXOutputter
with the specified SAX2 handlers. -
Method Summary
Modifier and TypeMethodDescriptionReturns the registeredContentHandler
.Return the registeredDeclHandler
.Return the registeredDTDHandler
.Return the registeredEntityResolver
.Return the registeredErrorHandler
.boolean
getFeature
(String name) This will look up the value of a SAX feature.Get the currentFormat
being used for outputReturn the registeredLexicalHandler
.Deprecated.there is no way to get a meaningful document Locator outside of an active output process, and the contents of the locator are meaningless outside of an active output process anyway.getProperty
(String name) This will look up the value of a SAX property.boolean
Returns whether DTD events will be reported.boolean
Returns whether attribute namespace declarations shall be reported as "xmlns" attributes.Get the currentSAXOutputProcessor
being used for output.void
This will output a list of JDOM nodes as a document, firing off the SAX events that have been registered.void
This will output theJDOM Document
, firing off the SAX events that have been registered.void
This will output a single JDOM element as a document, firing off the SAX events that have been registered.void
outputFragment
(List<? extends Content> nodes) This will output a list of JDOM nodes as a fragment of an XML document, firing off the SAX events that have been registered.void
outputFragment
(Content node) This will output a single JDOM nodes as a fragment of an XML document, firing off the SAX events that have been registered.void
setContentHandler
(ContentHandler contentHandler) This will set theContentHandler
.void
setDeclHandler
(DeclHandler declHandler) This will set theDeclHandler
.void
setDTDHandler
(DTDHandler dtdHandler) This will set theDTDHandler
.void
setEntityResolver
(EntityResolver entityResolver) This will set theEntityResolver
.void
setErrorHandler
(ErrorHandler errorHandler) This will set theErrorHandler
.void
setFeature
(String name, boolean value) This will set the state of a SAX feature.void
Set the currentFormat
to be used for output.void
setLexicalHandler
(LexicalHandler lexicalHandler) This will set theLexicalHandler
.void
setProperty
(String name, Object value) This will set the value of a SAX property.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.void
setReportNamespaceDeclarations
(boolean declareNamespaces) This will define whether attribute namespace declarations shall be reported as "xmlns" attributes.void
setSAXOutputProcessor
(SAXOutputProcessor processor) Set the currentSAXOutputProcessor
to be used for output.
-
Constructor Details
-
SAXOutputter
public SAXOutputter()This will create aSAXOutputter
without any registered handler. The application is then responsible for registering them using thesetXxxHandler()
methods. -
SAXOutputter
This will create aSAXOutputter
with the specifiedContentHandler
.- Parameters:
contentHandler
- containsContentHandler
callback methods
-
SAXOutputter
public SAXOutputter(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver) This will create aSAXOutputter
with the specified SAX2 handlers. At this time, onlyContentHandler
andEntityResolver
are supported.- Parameters:
contentHandler
- containsContentHandler
callback methodserrorHandler
- containsErrorHandler
callback methodsdtdHandler
- containsDTDHandler
callback methodsentityResolver
- containsEntityResolver
callback methods
-
SAXOutputter
public SAXOutputter(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler) This will create aSAXOutputter
with the specified SAX2 handlers. At this time, onlyContentHandler
andEntityResolver
are supported.- Parameters:
contentHandler
- containsContentHandler
callback methodserrorHandler
- containsErrorHandler
callback methodsdtdHandler
- containsDTDHandler
callback methodsentityResolver
- containsEntityResolver
callback methodslexicalHandler
- containsLexicalHandler
callbacks.
-
SAXOutputter
public SAXOutputter(SAXOutputProcessor processor, Format format, ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler) This will create aSAXOutputter
with the specified SAX2 handlers. At this time, onlyContentHandler
andEntityResolver
are supported.- Parameters:
processor
- theSAXOutputProcessor
to use for output.format
- theFormat
to use for output.contentHandler
- containsContentHandler
callback methodserrorHandler
- containsErrorHandler
callback methodsdtdHandler
- containsDTDHandler
callback methodsentityResolver
- containsEntityResolver
callback methodslexicalHandler
- containsLexicalHandler
callbacks.
-
-
Method Details
-
setContentHandler
This will set theContentHandler
.- Parameters:
contentHandler
- containsContentHandler
callback methods.
-
getContentHandler
Returns the registeredContentHandler
.- Returns:
- the current
ContentHandler
ornull
if none was registered.
-
setErrorHandler
This will set theErrorHandler
.- Parameters:
errorHandler
- containsErrorHandler
callback methods.
-
getErrorHandler
Return the registeredErrorHandler
.- Returns:
- the current
ErrorHandler
ornull
if none was registered.
-
setDTDHandler
This will set theDTDHandler
.- Parameters:
dtdHandler
- containsDTDHandler
callback methods.
-
getDTDHandler
Return the registeredDTDHandler
.- Returns:
- the current
DTDHandler
ornull
if none was registered.
-
setEntityResolver
This will set theEntityResolver
.- Parameters:
entityResolver
- contains EntityResolver callback methods.
-
getEntityResolver
Return the registeredEntityResolver
.- Returns:
- the current
EntityResolver
ornull
if none was registered.
-
setLexicalHandler
This will set theLexicalHandler
.- Parameters:
lexicalHandler
- contains lexical callback methods.
-
getLexicalHandler
Return the registeredLexicalHandler
.- Returns:
- the current
LexicalHandler
ornull
if none was registered.
-
setDeclHandler
This will set theDeclHandler
.- Parameters:
declHandler
- contains declaration callback methods.
-
getDeclHandler
Return the registeredDeclHandler
.- Returns:
- the current
DeclHandler
ornull
if none was registered.
-
getReportNamespaceDeclarations
public boolean getReportNamespaceDeclarations()Returns whether attribute namespace declarations shall be reported as "xmlns" attributes.- Returns:
- whether attribute namespace declarations shall be reported as "xmlns" attributes.
-
setReportNamespaceDeclarations
public void setReportNamespaceDeclarations(boolean declareNamespaces) This will define whether attribute namespace declarations shall be reported as "xmlns" attributes. This flag defaults tofalse
and behaves as the "namespace-prefixes" SAX core feature.- Parameters:
declareNamespaces
- whether attribute namespace declarations shall be reported as "xmlns" attributes.
-
getReportDTDEvents
public boolean getReportDTDEvents()Returns whether DTD events will be reported.- Returns:
- whether DTD events will be reported
-
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.- Parameters:
reportDtdEvents
- whether to notify DTD events.
-
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
indicates namespace URIs and unprefixed local names for element and attribute names will be available - access: read/write, but always
true
! http://xml.org/sax/features/namespace-prefixes
- description:
true
indicates XML 1.0 names (with prefixes) and attributes (including xmlns* attributes) will be available - access: read/write
http://xml.org/sax/features/validation
- description: controls whether SAXOutputter is
reporting DTD-related events; if
true
, the DocType internal subset will be parsed to fire DTD events - access: read/write, defaults to
true
- Parameters:
name
-String
the feature name, which is a fully-qualified URI.value
-boolean
the requested state of the feature (true or false).- Throws:
SAXNotRecognizedException
- when SAXOutputter does not recognize the feature name.SAXNotSupportedException
- when SAXOutputter recognizes the feature name but cannot set the requested value.
-
getFeature
This will look up the value of a SAX feature.- Parameters:
name
-String
the feature name, which is a fully-qualified URI.- Returns:
boolean
the current state of the feature (true or false).- Throws:
SAXNotRecognizedException
- when SAXOutputter does not recognize the feature name.SAXNotSupportedException
- when SAXOutputter recognizes the feature name but determine its value at this time.
-
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: An optional extension handler for lexical events like comments.
- access: read/write
http://xml.org/sax/properties/declaration-handler
- data type:
org.xml.sax.ext.DeclHandler
- description: An optional extension handler for DTD-related events other than notations and unparsed entities.
- access: read/write
- Parameters:
name
-String
the property name, which is a fully-qualified URI.value
-Object
the requested value for the property.- Throws:
SAXNotRecognizedException
- when SAXOutputter does not recognize the property name.SAXNotSupportedException
- when SAXOutputter recognizes the property name but cannot set the requested value.
-
getProperty
This will look up the value of a SAX property.- Parameters:
name
-String
the property name, which is a fully-qualified URI.- Returns:
Object
the current value of the property.- Throws:
SAXNotRecognizedException
- when SAXOutputter does not recognize the property name.SAXNotSupportedException
- when SAXOutputter recognizes the property name but cannot determine its value at this time.
-
getSAXOutputProcessor
Get the currentSAXOutputProcessor
being used for output.- Returns:
- The current SAXOutputProcessor
-
setSAXOutputProcessor
Set the currentSAXOutputProcessor
to be used for output.- Parameters:
processor
- the new SAXOutputProcessor
-
getFormat
Get the currentFormat
being used for output- Returns:
- the current Format
-
setFormat
Set the currentFormat
to be used for output.- Parameters:
format
- the new Format
-
output
This will output theJDOM Document
, firing off the SAX events that have been registered.- Parameters:
document
-JDOM Document
to output.- Throws:
JDOMException
- if any error occurred.
-
output
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).
- Parameters:
nodes
-List
of JDOM nodes to output.- Throws:
JDOMException
- if any error occurred.- See Also:
-
output
This will output a single JDOM element as a document, firing off the SAX events that have been registered.- Parameters:
node
- theElement
node to output.- Throws:
JDOMException
- if any error occurred.
-
outputFragment
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(org.xml.sax.Locator)
,ContentHandler.startDocument()
andContentHandler.endDocument()
callbacks on theContentHandler
. The user shall invoke these methods directly prior/after outputting the document fragments.- Parameters:
nodes
-List
of JDOM nodes to output.- Throws:
JDOMException
- if any error occurred.- See Also:
-
outputFragment
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(org.xml.sax.Locator)
,ContentHandler.startDocument()
andContentHandler.endDocument()
callbacks on theContentHandler
. The user shall invoke these methods directly prior/after outputting the document fragments.- Parameters:
node
- theContent
node to output.- Throws:
JDOMException
- if any error occurred.- See Also:
-
getLocator
Deprecated.there is no way to get a meaningful document Locator outside of an active output process, and the contents of the locator are meaningless outside of an active output process anyway.Returns null.- Returns:
- null
-