java.lang.ObjectSAXOutputter
public class SAXOutputter
Outputs a JDOM document as a stream of SAX2 events.
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.
Field Summary | |
---|---|
private static java.lang.String[] | attrTypeToNameMap Array to map JDOM attribute type (as entry index) to SAX attribute type names. |
private org.xml.sax.ContentHandler | contentHandler registered ContentHandler |
private static java.lang.String | CVS_ID |
private static java.lang.String | DECL_HANDLER_ALT_PROPERTY Shortcut for SAX-ext. |
private static java.lang.String | DECL_HANDLER_SAX_PROPERTY Shortcut for SAX-ext. |
private boolean | declareNamespaces Whether to report attribute namespace declarations as xmlns attributes. |
private org.xml.sax.ext.DeclHandler | declHandler registered DeclHandler |
private org.xml.sax.DTDHandler | dtdHandler registered DTDHandler |
private org.xml.sax.EntityResolver | entityResolver registered EntityResolver |
private org.xml.sax.ErrorHandler | errorHandler registered ErrorHandler |
private static java.lang.String | LEXICAL_HANDLER_ALT_PROPERTY Shortcut for SAX-ext. |
private static java.lang.String | LEXICAL_HANDLER_SAX_PROPERTY Shortcut for SAX-ext. |
private org.xml.sax.ext.LexicalHandler | lexicalHandler registered LexicalHandler |
private JDOMLocator | locator A SAX Locator that points at the JDOM node currently being outputted. |
private static java.lang.String | NAMESPACES_SAX_FEATURE Shortcut for SAX namespaces core feature |
private static java.lang.String | NS_PREFIXES_SAX_FEATURE Shortcut for SAX namespace-prefixes core feature |
private boolean | reportDtdEvents Whether to report DTD events to DeclHandlers and LexicalHandlers. |
private static java.lang.String | VALIDATION_SAX_FEATURE Shortcut for SAX validation core feature |
Constructor Summary | |
---|---|
SAXOutputter() This will create a SAXOutputter without any registered handler. | |
SAXOutputter(org.xml.sax.ContentHandler contentHandler) This will create a SAXOutputter with the specified ContentHandler . | |
SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver) This will create a SAXOutputter with 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 a SAXOutputter with the specified SAX2 handlers. |
Method Summary | |
---|---|
private org.xml.sax.helpers.AttributesImpl | addNsAttribute(org.xml.sax.helpers.AttributesImpl atts, Namespace ns) Appends a namespace declaration in the form of a xmlns attribute to an attribute list, crerating this latter if needed. |
private void | cdata(java.lang.String cdataText) This will be called for each chunk of CDATA section encountered. |
private void | characters(java.lang.String elementText) This will be called for each chunk of character data encountered. |
private void | comment(java.lang.String commentText) This will be called for each chunk of comment data encontered. |
private org.xml.sax.XMLReader | createDTDParser() This will create a SAX XMLReader capable of parsing a DTD and configure it so that the DTD parsing events are routed to the handlers registered onto this SAXOutputter. |
protected org.xml.sax.XMLReader | createParser() Creates a SAX XMLReader. |
private void | documentLocator(Document document) This method tells you the line of the XML file being parsed. |
private void | dtdEvents(Document document) This parses a DTD declaration to fire the related events towards the registered handlers. |
private void | element(Element element, NamespaceStack namespaces) This will recursively invoke all of the callbacks for a particular element. |
private void | elementContent(Content node, NamespaceStack namespaces) This will invoke the callbacks for the content of an element. |
private void | elementContent(java.util.List content, NamespaceStack namespaces) This will invoke the callbacks for the content of an element. |
private void | endDocument() Always the last method of all callbacks in all handlers to be invoked. |
private void | endElement(Element element) This will invoke the endElement callback in the ContentHandler . |
private void | endPrefixMapping(NamespaceStack namespaces, int previouslyDeclaredNamespaces) This will invoke the endPrefixMapping callback in the ContentHandler when a namespace is goes out of scope in the Document . |
private void | entityRef(EntityRef entity) This will invoke the ContentHandler.skippedEntity callback when an entity reference is encountered. |
private static java.lang.String | getAttributeTypeName(int type) Returns the SAX 2.0 attribute type string from the type of a JDOM Attribute. |
org.xml.sax.ContentHandler | getContentHandler() Returns the registered ContentHandler . |
org.xml.sax.ext.DeclHandler | getDeclHandler() Return the registered DeclHandler . |
org.xml.sax.DTDHandler | getDTDHandler() Return the registered DTDHandler . |
org.xml.sax.EntityResolver | getEntityResolver() Return the registered EntityResolver . |
org.xml.sax.ErrorHandler | getErrorHandler() Return the registered ErrorHandler . |
boolean | getFeature(java.lang.String name) This will look up the value of a SAX feature. |
org.xml.sax.ext.LexicalHandler | getLexicalHandler() Return the registered LexicalHandler . |
JDOMLocator | getLocator() Returns a JDOMLocator object referencing the node currently being processed by this outputter. |
java.lang.Object | getProperty(java.lang.String name) This will look up the value of a SAX property. |
boolean | getReportDTDEvents() Returns whether DTD events will be reported. |
boolean | getReportNamespaceDeclarations() Returns whether attribute namespace declarations shall be reported as "xmlns" attributes. |
private void | handleError(JDOMException exception) Notifies the registered SAX error handler (if any) of an input processing error. |
void | output(Document document) This will output the JDOM Document , firing off the SAX events that have been registered. |
void | output(Element node) This will output a single JDOM element as a document, firing off the SAX events that have been registered. |
void | output(java.util.List nodes) This will output a list of JDOM nodes as a 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 | outputFragment(java.util.List 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. |
private void | processingInstruction(ProcessingInstruction pi) This will invoke the ContentHandler.processingInstruction callback when a processing instruction is encountered. |
void | setContentHandler(org.xml.sax.ContentHandler contentHandler) This will set the ContentHandler . |
void | setDeclHandler(org.xml.sax.ext.DeclHandler declHandler) This will set the DeclHandler . |
void | setDTDHandler(org.xml.sax.DTDHandler dtdHandler) This will set the DTDHandler . |
void | setEntityResolver(org.xml.sax.EntityResolver entityResolver) This will set the EntityResolver . |
void | setErrorHandler(org.xml.sax.ErrorHandler errorHandler) This will set the ErrorHandler . |
void | setFeature(java.lang.String name, boolean value) This will set the state of a SAX feature. |
void | setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler) This will set the LexicalHandler . |
void | setProperty(java.lang.String name, java.lang.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. |
private void | startDocument() This method is always the second method of all callbacks in all handlers to be invoked (setDocumentLocator is always first). |
private void | startElement(Element element, org.xml.sax.Attributes nsAtts) This will invoke the startElement callback in the ContentHandler . |
private org.xml.sax.Attributes | startPrefixMapping(Element element, NamespaceStack namespaces) This will invoke the ContentHandler.startPrefixMapping callback when a new namespace is encountered in the Document . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String CVS_ID
private static final java.lang.String NAMESPACES_SAX_FEATURE
private static final java.lang.String NS_PREFIXES_SAX_FEATURE
private static final java.lang.String VALIDATION_SAX_FEATURE
private static final java.lang.String LEXICAL_HANDLER_SAX_PROPERTY
private static final java.lang.String DECL_HANDLER_SAX_PROPERTY
private static final java.lang.String LEXICAL_HANDLER_ALT_PROPERTY
private static final java.lang.String DECL_HANDLER_ALT_PROPERTY
private static final java.lang.String[] attrTypeToNameMap
private org.xml.sax.ContentHandler contentHandler
ContentHandler
private org.xml.sax.ErrorHandler errorHandler
ErrorHandler
private org.xml.sax.DTDHandler dtdHandler
DTDHandler
private org.xml.sax.EntityResolver entityResolver
EntityResolver
private org.xml.sax.ext.LexicalHandler lexicalHandler
LexicalHandler
private org.xml.sax.ext.DeclHandler declHandler
DeclHandler
private boolean declareNamespaces
false
as per SAX specifications. private boolean reportDtdEvents
true
. private JDOMLocator locator
Constructor Detail |
---|
public SAXOutputter()
SAXOutputter
without any registered handler. The application is then responsible for registering them using the setXxxHandler()
methods. public SAXOutputter(org.xml.sax.ContentHandler contentHandler)
SAXOutputter
with the specified ContentHandler
. contentHandler
- contains ContentHandler
callback methodspublic SAXOutputter(org.xml.sax.ContentHandler contentHandler, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.DTDHandler dtdHandler, org.xml.sax.EntityResolver entityResolver)
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 methodspublic 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)
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.Method Detail |
---|
public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
ContentHandler
. contentHandler
- contains ContentHandler
callback methods.public org.xml.sax.ContentHandler getContentHandler()
ContentHandler
. ContentHandler
or null
if none was registered.public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
ErrorHandler
. errorHandler
- contains ErrorHandler
callback methods.public org.xml.sax.ErrorHandler getErrorHandler()
ErrorHandler
. ErrorHandler
or null
if none was registered.public void setDTDHandler(org.xml.sax.DTDHandler dtdHandler)
DTDHandler
. dtdHandler
- contains DTDHandler
callback methods.public org.xml.sax.DTDHandler getDTDHandler()
DTDHandler
. DTDHandler
or null
if none was registered.public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
EntityResolver
. entityResolver
- contains EntityResolver callback methods.public org.xml.sax.EntityResolver getEntityResolver()
EntityResolver
. EntityResolver
or null
if none was registered.public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
LexicalHandler
. lexicalHandler
- contains lexical callback methods.public org.xml.sax.ext.LexicalHandler getLexicalHandler()
LexicalHandler
. LexicalHandler
or null
if none was registered.public void setDeclHandler(org.xml.sax.ext.DeclHandler declHandler)
DeclHandler
. declHandler
- contains declaration callback methods.public org.xml.sax.ext.DeclHandler getDeclHandler()
DeclHandler
. DeclHandler
or null
if none was registered.public boolean getReportNamespaceDeclarations()
public void setReportNamespaceDeclarations(boolean declareNamespaces)
false
and behaves as the "namespace-prefixes" SAX core feature. declareNamespaces
- whether attribute namespace declarations shall be reported as "xmlns" attributes.public boolean getReportDTDEvents()
public void setReportDTDEvents(boolean reportDtdEvents)
reportDtdEvents
- whether to notify DTD events.public void setFeature(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
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
true
indicates namespace URIs and unprefixed local names for element and attribute names will be availabletrue
!http://xml.org/sax/features/namespace-prefixes
true
indicates XML 1.0 names (with prefixes) and attributes (including xmlns* attributes) will be availablehttp://xml.org/sax/features/validation
true
, the DocType internal subset will be parsed to fire DTD eventstrue
name
- String
the feature name, which is a fully-qualified URI.value
- boolean
the requested state of the feature (true or false). 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.public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
name
- String
the feature name, which is a fully-qualified URI. boolean
the current state of the feature (true or false). 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.public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
SAXOutputter currently supports the following SAX properties:
http://xml.org/sax/properties/lexical-handler
org.xml.sax.ext.LexicalHandler
http://xml.org/sax/properties/declaration-handler
org.xml.sax.ext.DeclHandler
name
- String
the property name, which is a fully-qualified URI.value
- Object
the requested value for the property. 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.public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
name
- String
the property name, which is a fully-qualified URI. Object
the current value of the property. 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.public void output(Document document) throws JDOMException
JDOM Document
, firing off the SAX events that have been registered. document
- JDOM Document
to output. JDOMException
- if any error occurred.public void output(java.util.List nodes) throws JDOMException
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. JDOMException
- if any error occurred.output(Document)
public void output(Element node) throws JDOMException
node
- the Element
node to output. JDOMException
- if any error occurred.public void outputFragment(java.util.List nodes) throws JDOMException
Warning: This method does not call the ContentHandler.setDocumentLocator(org.xml.sax.Locator)
, 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. JDOMException
- if any error occurred.outputFragment(Content)
public void outputFragment(Content node) throws JDOMException
Warning: This method does not call the ContentHandler.setDocumentLocator(org.xml.sax.Locator)
, 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. JDOMException
- if any error occurred.outputFragment(java.util.List)
private void dtdEvents(Document document) throws JDOMException
document
- JDOM Document
the DocType is to process. JDOMException
private void documentLocator(Document document)
This method tells you the line of the XML file being parsed. For an in-memory document, it's meaningless. The location is only valid for the current parsing lifecycle, but the document has already been parsed. Therefore, it returns -1 for both line and column numbers.
document
- JDOM Document
.private void startDocument() throws JDOMException
This method is always the second method of all callbacks in all handlers to be invoked (setDocumentLocator is always first).
JDOMException
private void endDocument() throws JDOMException
Always the last method of all callbacks in all handlers to be invoked.
JDOMException
private void processingInstruction(ProcessingInstruction pi) throws JDOMException
This will invoke the ContentHandler.processingInstruction
callback when a processing instruction is encountered.
pi
- ProcessingInstruction
containing target and data. JDOMException
private void element(Element element, NamespaceStack namespaces) throws JDOMException
This will recursively invoke all of the callbacks for a particular element.
element
- Element
used in callbacks.namespaces
- List
stack of Namespaces in scope. JDOMException
private org.xml.sax.Attributes startPrefixMapping(Element element, NamespaceStack namespaces) throws JDOMException
This will invoke the ContentHandler.startPrefixMapping
callback when a new namespace is encountered in the Document
.
element
- Element
used in callbacks.namespaces
- List
stack of Namespaces in scope. Attributes
declaring the namespaces local to element
or null
. JDOMException
private void endPrefixMapping(NamespaceStack namespaces, int previouslyDeclaredNamespaces) throws JDOMException
This will invoke the endPrefixMapping
callback in the ContentHandler
when a namespace is goes out of scope in the Document
.
namespaces
- List
stack of Namespaces in scope.previouslyDeclaredNamespaces
- number of previously declared namespaces JDOMException
private void startElement(Element element, org.xml.sax.Attributes nsAtts) throws JDOMException
This will invoke the startElement
callback in the ContentHandler
.
element
- Element
used in callbacks.nsAtts
- List
of namespaces to declare with the element or null
. JDOMException
private void endElement(Element element) throws JDOMException
This will invoke the endElement
callback in the ContentHandler
.
element
- Element
used in callbacks. JDOMException
private void elementContent(java.util.List content, NamespaceStack namespaces) throws JDOMException
This will invoke the callbacks for the content of an element.
content
- element content as a List
of nodes.namespaces
- List
stack of Namespaces in scope. JDOMException
private void elementContent(Content node, NamespaceStack namespaces) throws JDOMException
This will invoke the callbacks for the content of an element.
node
- a Content
node.namespaces
- List
stack of Namespaces in scope. JDOMException
private void cdata(java.lang.String cdataText) throws JDOMException
This will be called for each chunk of CDATA section encountered.
cdataText
- all text in the CDATA section, including whitespace. JDOMException
private void characters(java.lang.String elementText) throws JDOMException
This will be called for each chunk of character data encountered.
elementText
- all text in an element, including whitespace. JDOMException
private void comment(java.lang.String commentText) throws JDOMException
This will be called for each chunk of comment data encontered.
commentText
- all text in a comment, including whitespace. JDOMException
private void entityRef(EntityRef entity) throws JDOMException
This will invoke the ContentHandler.skippedEntity
callback when an entity reference is encountered.
entity
- EntityRef
. JDOMException
private org.xml.sax.helpers.AttributesImpl addNsAttribute(org.xml.sax.helpers.AttributesImpl atts, Namespace ns)
Appends a namespace declaration in the form of a xmlns attribute to an attribute list, crerating this latter if needed.
atts
- AttributeImpl
where to add the attribute.ns
- Namespace
the namespace to declare. AttributeImpl
the updated attribute list.private static java.lang.String getAttributeTypeName(int type)
Returns the SAX 2.0 attribute type string from the type of a JDOM Attribute.
type
- int
the type of the JDOM attribute. String
the SAX 2.0 attribute type string.Attribute.getAttributeType()
, Attributes.getType(int)
private void handleError(JDOMException exception) throws JDOMException
Notifies the registered SAX error handler
(if any) of an input processing error. The error handler can choose to absorb the error and let the processing continue.
exception
- JDOMException
containing the error information; will be wrapped in a SAXParseException
when reported to the SAX error handler. JDOMException
- if no error handler has been registered or if the error handler fired a SAXException
.protected org.xml.sax.XMLReader createParser() throws java.lang.Exception
Creates a SAX XMLReader.
XMLReader
a SAX2 parser. java.lang.Exception
- if no parser can be created.private org.xml.sax.XMLReader createDTDParser() throws JDOMException
This will create a SAX XMLReader capable of parsing a DTD and configure it so that the DTD parsing events are routed to the handlers registered onto this SAXOutputter.
XMLReader
a SAX2 parser. JDOMException
- if no parser can be created.public JDOMLocator getLocator()
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.
null
if no output operation is being performed.