org.jdom.output

Class SAXOutputter


public class SAXOutputter
extends java.lang.Object

SAXOutputter takes a JDOM tree and fires SAX2 events. Most ContentHandler callbacks are supported. Both ignorableWhitespace and skippedEntity have not been implemented. The setDocumentLocator callback has been implemented, but the locator object always returns -1 for getColumnNumber and getLineNumber. The EntityResolver callback resolveEntity has been implemented for DTDs. At this time, it is not possible to access notations and unparsed entity references in a DTD from a JDOM tree. 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. However, the document has already been parsed in order to create the JDOM tree.
Version:
$Revision: 1.18 $, $Date: 2002/01/08 09:17:10 $
Authors:
Brett McLaughlin
Jason Hunter
Fred Trimble
Bradley S. Huffman

Constructor Summary

SAXOutputter()
This will create a SAXOutputter without any registered handler.
SAXOutputter(ContentHandler contentHandler)
This will create a SAXOutputter with the specified ContentHandler.
SAXOutputter(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver)
This will create a SAXOutputter with the specified SAX2 handlers.
SAXOutputter(ContentHandler contentHandler, ErrorHandler errorHandler, DTDHandler dtdHandler, EntityResolver entityResolver, LexicalHandler lexicalHandler)
This will create a SAXOutputter with the specified SAX2 handlers.

Method Summary

protected XMLReader
createParser()
Creates a SAX XMLReader.
ContentHandler
getContentHandler()
Returns the registered ContentHandler.
DTDHandler
getDTDHandler()
Return the registered DTDHandler.
DeclHandler
getDeclHandler()
Return the registered DeclHandler.
EntityResolver
getEntityResolver()
Return the registered EntityResolver.
ErrorHandler
getErrorHandler()
Return the registered ErrorHandler.
boolean
getFeature(String name)
This will look up the value of a SAX feature.
LexicalHandler
getLexicalHandler()
Return the registered LexicalHandler.
Object
getProperty(String name)
This will look up the value of a SAX property.
void
output(Document document)
This will output the JDOM Document, firing off the SAX events that have been registered.
void
setContentHandler(ContentHandler contentHandler)
This will set the ContentHandler.
void
setDTDHandler(DTDHandler dtdHandler)
This will set the DTDHandler.
void
setDeclHandler(DeclHandler declHandler)
This will set the DeclHandler.
void
setEntityResolver(EntityResolver entityResolver)
This will set the EntityResolver.
void
setErrorHandler(ErrorHandler errorHandler)
This will set the ErrorHandler.
void
setFeature(String name, boolean value)
This will set the state of a SAX feature.
void
setLexicalHandler(LexicalHandler lexicalHandler)
This will set the LexicalHandler.
void
setProperty(String name, Object value)
This will set the value of a SAX property.
void
setReportNamespaceDeclarations(boolean declareNamespaces)
This will define whether attribute namespace declarations shall be reported as "xmlns" attributes.

Constructor Details

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.
Parameters:
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.
Parameters:
contentHandler - contains ContentHandler callback methods
errorHandler - contains ErrorHandler callback methods
dtdHandler - contains DTDHandler callback methods
entityResolver - 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.
Parameters:
contentHandler - contains ContentHandler callback methods
errorHandler - contains ErrorHandler callback methods
dtdHandler - contains DTDHandler callback methods
entityResolver - contains EntityResolver callback methods
lexicalHandler - contains LexicalHandler callbacks.

Method Details

createParser

protected XMLReader createParser()
            throws Exception
Creates a SAX XMLReader.
Returns:
XMLReader a SAX2 parser.

getContentHandler

public ContentHandler getContentHandler()
Returns the registered ContentHandler.
Returns:
the current ContentHandler or null if none was registered.

getDTDHandler

public DTDHandler getDTDHandler()
Return the registered DTDHandler.
Returns:
the current DTDHandler or null if none was registered.

getDeclHandler

public DeclHandler getDeclHandler()
Return the registered DeclHandler.
Returns:
the current DeclHandler or null if none was registered.

getEntityResolver

public EntityResolver getEntityResolver()
Return the registered EntityResolver.
Returns:
the current EntityResolver or null if none was registered.

getErrorHandler

public ErrorHandler getErrorHandler()
Return the registered ErrorHandler.
Returns:
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.
Parameters:
name - String the feature name, which is a fully-qualified URI.
Returns:
boolean the current state of the feature (true or false).

getLexicalHandler

public LexicalHandler getLexicalHandler()
Return the registered LexicalHandler.
Returns:
the current LexicalHandler or null if none was registered.

getProperty

public Object getProperty(String name)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
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.

output

public void output(Document document)
            throws JDOMException
This will output the JDOM Document, firing off the SAX events that have been registered.
Parameters:
document - JDOM Document to output.

setContentHandler

public void setContentHandler(ContentHandler contentHandler)
This will set the ContentHandler.
Parameters:
contentHandler - contains ContentHandler callback methods.

setDTDHandler

public void setDTDHandler(DTDHandler dtdHandler)
This will set the DTDHandler.
Parameters:
dtdHandler - contains DTDHandler callback methods.

setDeclHandler

public void setDeclHandler(DeclHandler declHandler)
This will set the DeclHandler.
Parameters:
declHandler - contains declaration callback methods.

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
This will set the EntityResolver.
Parameters:
entityResolver - contains EntityResolver callback methods.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
This will set the ErrorHandler.
Parameters:
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:
access:true
http://xml.org/sax/features/namespace-prefixes
description:
access:
Parameters:
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.
Parameters:
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:
Parameters:
name - String the property name, which is a fully-qualified URI.
value - Object the requested value for the property.

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.
Parameters:

Copyright B) 2002 Jason Hunter, Brett McLaughlin. All Rights Reserved.