Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jdom.output
Class SAXOutputter  view SAXOutputter download SAXOutputter.java

java.lang.Object
  extended byorg.jdom.output.SAXOutputter

public class SAXOutputter
extends java.lang.Object

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() 55 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.

Version:
$Revision: 1.37 $, $Date: 2004/09/03 06:11:00 $

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, org.jdom.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(org.jdom.Document document)
           This method tells you the line of the XML file being parsed.
private  void dtdEvents(org.jdom.Document document)
          This parses a DTD declaration to fire the related events towards the registered handlers.
private  void element(org.jdom.Element element, NamespaceStack namespaces)
           This will recursively invoke all of the callbacks for a particular element.
private  void elementContent(org.jdom.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(org.jdom.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(org.jdom.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(org.jdom.JDOMException exception)
           Notifies the registered SAX error handler (if any) of an input processing error.
 void output(org.jdom.Document document)
          This will output the JDOM Document, firing off the SAX events that have been registered.
 void output(org.jdom.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(org.jdom.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(org.jdom.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(org.jdom.Element element, org.xml.sax.Attributes nsAtts)
           This will invoke the startElement callback in the ContentHandler.
private  org.xml.sax.Attributes startPrefixMapping(org.jdom.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

CVS_ID

private static final java.lang.String CVS_ID
See Also:
Constant Field Values

NAMESPACES_SAX_FEATURE

private static final java.lang.String NAMESPACES_SAX_FEATURE
Shortcut for SAX namespaces core feature

See Also:
Constant Field Values

NS_PREFIXES_SAX_FEATURE

private static final java.lang.String NS_PREFIXES_SAX_FEATURE
Shortcut for SAX namespace-prefixes core feature

See Also:
Constant Field Values

VALIDATION_SAX_FEATURE

private static final java.lang.String VALIDATION_SAX_FEATURE
Shortcut for SAX validation core feature

See Also:
Constant Field Values

LEXICAL_HANDLER_SAX_PROPERTY

private static final java.lang.String LEXICAL_HANDLER_SAX_PROPERTY
Shortcut for SAX-ext. lexical handler property

See Also:
Constant Field Values

DECL_HANDLER_SAX_PROPERTY

private static final java.lang.String DECL_HANDLER_SAX_PROPERTY
Shortcut for SAX-ext. declaration handler property

See Also:
Constant Field Values

LEXICAL_HANDLER_ALT_PROPERTY

private static final java.lang.String LEXICAL_HANDLER_ALT_PROPERTY
Shortcut for SAX-ext. lexical handler alternate property. Although this property URI is not the one defined by the SAX "standard", some parsers use it instead of the official one.

See Also:
Constant Field Values

DECL_HANDLER_ALT_PROPERTY

private static final java.lang.String DECL_HANDLER_ALT_PROPERTY
Shortcut for SAX-ext. declaration handler alternate property

See Also:
Constant Field Values

attrTypeToNameMap

private static final java.lang.String[] attrTypeToNameMap
Array to map JDOM attribute type (as entry index) to SAX attribute type names.


contentHandler

private org.xml.sax.ContentHandler contentHandler
registered ContentHandler


errorHandler

private org.xml.sax.ErrorHandler errorHandler
registered ErrorHandler


dtdHandler

private org.xml.sax.DTDHandler dtdHandler
registered DTDHandler


entityResolver

private org.xml.sax.EntityResolver entityResolver
registered EntityResolver


lexicalHandler

private org.xml.sax.ext.LexicalHandler lexicalHandler
registered LexicalHandler


declHandler

private org.xml.sax.ext.DeclHandler declHandler
registered DeclHandler


declareNamespaces

private boolean declareNamespaces
Whether to report attribute namespace declarations as xmlns attributes. Defaults to false as per SAX specifications.

See Also:
SAX namespace specifications

reportDtdEvents

private boolean reportDtdEvents
Whether to report DTD events to DeclHandlers and LexicalHandlers. Defaults to true.


locator

private JDOMLocator locator
A SAX Locator that points at the JDOM node currently being outputted.

Constructor Detail

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(org.xml.sax.ContentHandler contentHandler)
This will create a SAXOutputter with the specified ContentHandler.


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 a SAXOutputter with the specified SAX2 handlers. At this time, only ContentHandler and EntityResolver are supported.


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 a SAXOutputter with the specified SAX2 handlers. At this time, only ContentHandler and EntityResolver are supported.

Method Detail

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
This will set the ContentHandler.


getContentHandler

public org.xml.sax.ContentHandler getContentHandler()
Returns the registered ContentHandler.


setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
This will set the ErrorHandler.


getErrorHandler

public org.xml.sax.ErrorHandler getErrorHandler()
Return the registered ErrorHandler.


setDTDHandler

public void setDTDHandler(org.xml.sax.DTDHandler dtdHandler)
This will set the DTDHandler.


getDTDHandler

public org.xml.sax.DTDHandler getDTDHandler()
Return the registered DTDHandler.


setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
This will set the EntityResolver.


getEntityResolver

public org.xml.sax.EntityResolver getEntityResolver()
Return the registered EntityResolver.


setLexicalHandler

public void setLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
This will set the LexicalHandler.


getLexicalHandler

public org.xml.sax.ext.LexicalHandler getLexicalHandler()
Return the registered LexicalHandler.


setDeclHandler

public void setDeclHandler(org.xml.sax.ext.DeclHandler declHandler)
This will set the DeclHandler.


getDeclHandler

public org.xml.sax.ext.DeclHandler getDeclHandler()
Return the registered DeclHandler.


getReportNamespaceDeclarations

public boolean getReportNamespaceDeclarations()
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 to false and behaves as the "namespace-prefixes" SAX core feature.


getReportDTDEvents

public boolean getReportDTDEvents()
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.


setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.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


getFeature

public boolean getFeature(java.lang.String name)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
This will look up the value of a SAX feature.


setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.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


getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
This will look up the value of a SAX property.


output

public void output(org.jdom.Document document)
            throws org.jdom.JDOMException
This will output the JDOM Document, firing off the SAX events that have been registered.


output

public void output(java.util.List nodes)
            throws org.jdom.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).


output

public void output(org.jdom.Element node)
            throws org.jdom.JDOMException
This will output a single JDOM element as a document, firing off the SAX events that have been registered.


outputFragment

public void outputFragment(java.util.List nodes)
                    throws org.jdom.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.setDocumentLocator(org.xml.sax.Locator) 55 , ContentHandler.startDocument()>ContentHandler.startDocument() 55 and ContentHandler.endDocument()>ContentHandler.endDocument() 55 callbacks on the ContentHandler 55 . The user shall invoke these methods directly prior/after outputting the document fragments.


outputFragment

public void outputFragment(org.jdom.Content node)
                    throws org.jdom.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.setDocumentLocator(org.xml.sax.Locator) 55 , ContentHandler.startDocument()>ContentHandler.startDocument() 55 and ContentHandler.endDocument()>ContentHandler.endDocument() 55 callbacks on the ContentHandler 55 . The user shall invoke these methods directly prior/after outputting the document fragments.


dtdEvents

private void dtdEvents(org.jdom.Document document)
                throws org.jdom.JDOMException
This parses a DTD declaration to fire the related events towards the registered handlers.


documentLocator

private void documentLocator(org.jdom.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.


startDocument

private void startDocument()
                    throws org.jdom.JDOMException

This method is always the second method of all callbacks in all handlers to be invoked (setDocumentLocator is always first).


endDocument

private void endDocument()
                  throws org.jdom.JDOMException

Always the last method of all callbacks in all handlers to be invoked.


processingInstruction

private void processingInstruction(org.jdom.ProcessingInstruction pi)
                            throws org.jdom.JDOMException

This will invoke the ContentHandler.processingInstruction callback when a processing instruction is encountered.


element

private void element(org.jdom.Element element,
                     NamespaceStack namespaces)
              throws org.jdom.JDOMException

This will recursively invoke all of the callbacks for a particular element.


startPrefixMapping

private org.xml.sax.Attributes startPrefixMapping(org.jdom.Element element,
                                                  NamespaceStack namespaces)
                                           throws org.jdom.JDOMException

This will invoke the ContentHandler.startPrefixMapping callback when a new namespace is encountered in the Document.


endPrefixMapping

private void endPrefixMapping(NamespaceStack namespaces,
                              int previouslyDeclaredNamespaces)
                       throws org.jdom.JDOMException

This will invoke the endPrefixMapping callback in the ContentHandler when a namespace is goes out of scope in the Document.


startElement

private void startElement(org.jdom.Element element,
                          org.xml.sax.Attributes nsAtts)
                   throws org.jdom.JDOMException

This will invoke the startElement callback in the ContentHandler.


endElement

private void endElement(org.jdom.Element element)
                 throws org.jdom.JDOMException

This will invoke the endElement callback in the ContentHandler.


elementContent

private void elementContent(java.util.List content,
                            NamespaceStack namespaces)
                     throws org.jdom.JDOMException

This will invoke the callbacks for the content of an element.


elementContent

private void elementContent(org.jdom.Content node,
                            NamespaceStack namespaces)
                     throws org.jdom.JDOMException

This will invoke the callbacks for the content of an element.


cdata

private void cdata(java.lang.String cdataText)
            throws org.jdom.JDOMException

This will be called for each chunk of CDATA section encountered.


characters

private void characters(java.lang.String elementText)
                 throws org.jdom.JDOMException

This will be called for each chunk of character data encountered.


comment

private void comment(java.lang.String commentText)
              throws org.jdom.JDOMException

This will be called for each chunk of comment data encontered.


entityRef

private void entityRef(org.jdom.EntityRef entity)
                throws org.jdom.JDOMException

This will invoke the ContentHandler.skippedEntity callback when an entity reference is encountered.


addNsAttribute

private org.xml.sax.helpers.AttributesImpl addNsAttribute(org.xml.sax.helpers.AttributesImpl atts,
                                                          org.jdom.Namespace ns)

Appends a namespace declaration in the form of a xmlns attribute to an attribute list, crerating this latter if needed.


getAttributeTypeName

private static java.lang.String getAttributeTypeName(int type)

Returns the SAX 2.0 attribute type string from the type of a JDOM Attribute.


handleError

private void handleError(org.jdom.JDOMException exception)
                  throws org.jdom.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.


createParser

protected org.xml.sax.XMLReader createParser()
                                      throws java.lang.Exception

Creates a SAX XMLReader.


createDTDParser

private org.xml.sax.XMLReader createDTDParser()
                                       throws org.jdom.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.


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 ErrorHandlers.