Class SAXOutputter
- java.lang.Object
-
- org.jdom2.output.SAXOutputter
-
public class SAXOutputter extends java.lang.ObjectOutputs a JDOM document as a stream of SAX2 events.Most ContentHandler callbacks are supported. BOTH
ignorableWhitespace()andskippedEntity()have not been implemented. Theclass returned byJDOMLocatorexposes 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,
DTDHandlercallbacks have not been implemented yet.The
ErrorHandlercallbacks 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
Constructors Constructor Description SAXOutputter()This will create aSAXOutputterwithout any registered handler.SAXOutputter(SAXOutputProcessor processor, Format format, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ext.LexicalHandler lexicalHandler)This will create aSAXOutputterwith the specified SAX2 handlers.SAXOutputter(org.xml.sax.ContentHandler contentHandler)This will create aSAXOutputterwith the specifiedContentHandler.SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver)This will create aSAXOutputterwith the specified SAX2 handlers.SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ext.LexicalHandler lexicalHandler)This will create aSAXOutputterwith the specified SAX2 handlers.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.xml.sax.ContentHandlergetContentHandler()Returns the registeredContentHandler.org.xml.sax.ext.DeclHandlergetDeclHandler()Return the registeredDeclHandler.org.xml.sax.DTDHandlergetDTDHandler()Return the registeredDTDHandler.org.xml.sax.EntityResolvergetEntityResolver()Return the registeredEntityResolver.org.xml.sax.ErrorHandlergetErrorHandler()Return the registeredErrorHandler.booleangetFeature(java.lang.String name)This will look up the value of a SAX feature.FormatgetFormat()Get the currentFormatbeing used for outputorg.xml.sax.ext.LexicalHandlergetLexicalHandler()Return the registeredLexicalHandler.JDOMLocatorgetLocator()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.java.lang.ObjectgetProperty(java.lang.String name)This will look up the value of a SAX property.booleangetReportDTDEvents()Returns whether DTD events will be reported.booleangetReportNamespaceDeclarations()Returns whether attribute namespace declarations shall be reported as "xmlns" attributes.SAXOutputProcessorgetSAXOutputProcessor()Get the currentSAXOutputProcessorbeing used for output.voidoutput(java.util.List<? extends Content> nodes)This will output a list of JDOM nodes as a document, firing off the SAX events that have been registered.voidoutput(Document document)This will output theJDOM Document, firing off the SAX events that have been registered.voidoutput(Element node)This will output a single JDOM element as a document, firing off the SAX events that have been registered.voidoutputFragment(java.util.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.voidoutputFragment(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.voidsetContentHandler(org.xml.sax.ContentHandler contentHandler)This will set theContentHandler.voidsetDeclHandler(org.xml.sax.ext.DeclHandler declHandler)This will set theDeclHandler.voidsetDTDHandler(org.xml.sax.DTDHandler dtdHandler)This will set theDTDHandler.voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)This will set theEntityResolver.voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)This will set theErrorHandler.voidsetFeature(java.lang.String name, boolean value)This will set the state of a SAX feature.voidsetFormat(Format format)Set the currentFormatto be used for output.voidsetLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)This will set theLexicalHandler.voidsetProperty(java.lang.String name, java.lang.Object value)This will set the value of a SAX property.voidsetReportDTDEvents(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.voidsetReportNamespaceDeclarations(boolean declareNamespaces)This will define whether attribute namespace declarations shall be reported as "xmlns" attributes.voidsetSAXOutputProcessor(SAXOutputProcessor processor)Set the currentSAXOutputProcessorto be used for output.
-
-
-
Constructor Detail
-
SAXOutputter
public SAXOutputter()
This will create aSAXOutputterwithout any registered handler. The application is then responsible for registering them using thesetXxxHandler()methods.
-
SAXOutputter
public SAXOutputter(org.xml.sax.ContentHandler contentHandler)
This will create aSAXOutputterwith the specifiedContentHandler.- Parameters:
contentHandler- containsContentHandlercallback methods
-
SAXOutputter
public SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver)This will create aSAXOutputterwith the specified SAX2 handlers. At this time, onlyContentHandlerandEntityResolverare supported.- Parameters:
contentHandler- containsContentHandlercallback methodserrorHandler- containsErrorHandlercallback methodsdtdHandler- containsDTDHandlercallback methodsentityResolver- containsEntityResolvercallback methods
-
SAXOutputter
public SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ext.LexicalHandler lexicalHandler)This will create aSAXOutputterwith the specified SAX2 handlers. At this time, onlyContentHandlerandEntityResolverare supported.- Parameters:
contentHandler- containsContentHandlercallback methodserrorHandler- containsErrorHandlercallback methodsdtdHandler- containsDTDHandlercallback methodsentityResolver- containsEntityResolvercallback methodslexicalHandler- containsLexicalHandlercallbacks.
-
SAXOutputter
public SAXOutputter(SAXOutputProcessor processor, Format format, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver, org.xml.sax.ext.LexicalHandler lexicalHandler)
This will create aSAXOutputterwith the specified SAX2 handlers. At this time, onlyContentHandlerandEntityResolverare supported.- Parameters:
processor- theSAXOutputProcessorto use for output.format- theFormatto use for output.contentHandler- containsContentHandlercallback methodserrorHandler- containsErrorHandlercallback methodsdtdHandler- containsDTDHandlercallback methodsentityResolver- containsEntityResolvercallback methodslexicalHandler- containsLexicalHandlercallbacks.
-
-
Method Detail
-
setContentHandler
public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
This will set theContentHandler.- Parameters:
contentHandler- containsContentHandlercallback methods.
-
getContentHandler
public org.xml.sax.ContentHandler getContentHandler()
Returns the registeredContentHandler.- Returns:
- the current
ContentHandlerornullif none was registered.
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
This will set theErrorHandler.- Parameters:
errorHandler- containsErrorHandlercallback methods.
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
Return the registeredErrorHandler.- Returns:
- the current
ErrorHandlerornullif none was registered.
-
setDTDHandler
public void setDTDHandler(org.xml.sax.DTDHandler dtdHandler)
This will set theDTDHandler.- Parameters:
dtdHandler- containsDTDHandlercallback methods.
-
getDTDHandler
public org.xml.sax.DTDHandler getDTDHandler()
Return the registeredDTDHandler.- Returns:
- the current
DTDHandlerornullif none was registered.
-
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
This will set theEntityResolver.- Parameters:
entityResolver- contains EntityResolver callback methods.
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
Return the registeredEntityResolver.- Returns:
- the current
EntityResolverornullif none was registered.
-
setLexicalHandler
public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
This will set theLexicalHandler.- Parameters:
lexicalHandler- contains lexical callback methods.
-
getLexicalHandler
public org.xml.sax.ext.LexicalHandler getLexicalHandler()
Return the registeredLexicalHandler.- Returns:
- the current
LexicalHandlerornullif none was registered.
-
setDeclHandler
public void setDeclHandler(org.xml.sax.ext.DeclHandler declHandler)
This will set theDeclHandler.- Parameters:
declHandler- contains declaration callback methods.
-
getDeclHandler
public org.xml.sax.ext.DeclHandler getDeclHandler()
Return the registeredDeclHandler.- Returns:
- the current
DeclHandlerornullif 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 tofalseand 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(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionThis 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:
trueindicates 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:
trueindicates 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-Stringthe feature name, which is a fully-qualified URI.value-booleanthe requested state of the feature (true or false).- Throws:
org.xml.sax.SAXNotRecognizedException- when SAXOutputter does not recognize the feature name.org.xml.sax.SAXNotSupportedException- when SAXOutputter recognizes the feature name but cannot set the requested value.
-
getFeature
public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionThis will look up the value of a SAX feature.- Parameters:
name-Stringthe feature name, which is a fully-qualified URI.- Returns:
booleanthe current state of the feature (true or false).- Throws:
org.xml.sax.SAXNotRecognizedException- when SAXOutputter does not recognize the feature name.org.xml.sax.SAXNotSupportedException- when SAXOutputter recognizes the feature name but determine its value at this time.
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionThis 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-Stringthe property name, which is a fully-qualified URI.value-Objectthe requested value for the property.- Throws:
org.xml.sax.SAXNotRecognizedException- when SAXOutputter does not recognize the property name.org.xml.sax.SAXNotSupportedException- when SAXOutputter recognizes the property name but cannot set the requested value.
-
getProperty
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedExceptionThis will look up the value of a SAX property.- Parameters:
name-Stringthe property name, which is a fully-qualified URI.- Returns:
Objectthe current value of the property.- Throws:
org.xml.sax.SAXNotRecognizedException- when SAXOutputter does not recognize the property name.org.xml.sax.SAXNotSupportedException- when SAXOutputter recognizes the property name but cannot determine its value at this time.
-
getSAXOutputProcessor
public SAXOutputProcessor getSAXOutputProcessor()
Get the currentSAXOutputProcessorbeing used for output.- Returns:
- The current SAXOutputProcessor
-
setSAXOutputProcessor
public void setSAXOutputProcessor(SAXOutputProcessor processor)
Set the currentSAXOutputProcessorto be used for output.- Parameters:
processor- the new SAXOutputProcessor
-
getFormat
public Format getFormat()
Get the currentFormatbeing used for output- Returns:
- the current Format
-
setFormat
public void setFormat(Format format)
Set the currentFormatto be used for output.- Parameters:
format- the new Format
-
output
public void output(Document document) throws JDOMException
This will output theJDOM Document, firing off the SAX events that have been registered.- Parameters:
document-JDOM Documentto output.- Throws:
JDOMException- if any error occurred.
-
output
public void output(java.util.List<? extends Content> 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).
- Parameters:
nodes-Listof JDOM nodes to output.- Throws:
JDOMException- if any error occurred.- See Also:
output(org.jdom2.Document)
-
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.- Parameters:
node- theElementnode to output.- Throws:
JDOMException- if any error occurred.
-
outputFragment
public void outputFragment(java.util.List<? extends Content> 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(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-Listof JDOM nodes to output.- Throws:
JDOMException- if any error occurred.- See Also:
outputFragment(org.jdom2.Content)
-
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(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- theContentnode to output.- Throws:
JDOMException- if any error occurred.- See Also:
outputFragment(java.util.List)
-
getLocator
@Deprecated public JDOMLocator 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
-
-