org.apache.xml.serializer

Class ToHTMLSAXHandler

Implemented Interfaces:
ContentHandler, DeclHandler, DOM2DTM.CharacterNodeHandler, DOMSerializer, ErrorHandler, ExtendedContentHandler, ExtendedLexicalHandler, LexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes

public class ToHTMLSAXHandler
extends ToSAXHandler

This class accepts SAX-like calls, then sends true SAX calls to a wrapped SAX handler. There is optimization done knowing that the ultimate output is HTML.

Authors:
Santiago Pericas-Geertsen
G. Todd Miller

Fields inherited from interface org.apache.xml.serializer.ExtendedContentHandler

HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS

Fields inherited from interface org.apache.xml.serializer.SerializerConstants

BEGCDATA, CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, CNTCDATA, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENDCDATA, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XMLNS_PREFIX, XMLNS_URI, XML_PREFIX

Constructor Summary

ToHTMLSAXHandler(ContentHandler handler, String encoding)
A constructor
ToHTMLSAXHandler(ContentHandler handler, LexicalHandler lex, String encoding)
A constructor.

Method Summary

void
attributeDecl(String eName, String aName, String type, String valueDefault, String value)
Does nothing.
void
characters(String chars)
Receive notification of character data.
void
characters(char[] ch, int off, int len)
Receive notification of character data.
void
close()
Do nothing.
void
comment(char[] ch, int start, int length)
Receive notification of a comment anywhere in the document.
void
elementDecl(String name, String model)
Does nothing.
void
endCDATA()
Does nothing.
void
endDTD()
Does nothing.
void
endDocument()
Receive notification of the end of a document.
void
endElement(String elementName)
Receive notification of the end of an element.
void
endElement(String uri, String localName, String qName)
Receive notification of the end of an element.
void
endPrefixMapping(String prefix)
Does nothing.
void
externalEntityDecl(String arg0, String arg1, String arg2)
void
flushPending()
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.
Properties
getOutputFormat()
Returns null.
OutputStream
getOutputStream()
Reurns null
Writer
getWriter()
Returns null
void
ignorableWhitespace(char[] ch, int start, int length)
Does nothing.
void
indent(int n)
Does nothing.
void
internalEntityDecl(String name, String value)
Does nothing.
void
namespaceAfterStartElement(String prefix, String uri)
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement().
void
processingInstruction(String arg0, String arg1)
Receive notification of a processing instruction.
boolean
reset()
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).
void
serialize(Node node)
Does nothing.
void
setDocumentLocator(Locator arg0)
Does nothing.
boolean
setEscaping(boolean escape)
Turns special character escaping on/off.
void
setIndent(boolean indent)
Does nothing
void
setOutputFormat(Properties format)
Does nothing.
void
setOutputStream(OutputStream output)
Does nothing.
void
setWriter(Writer writer)
Does nothing.
void
skippedEntity(String arg0)
Does nothing.
void
startCDATA()
Does nothing.
void
startElement(String elementName)
An element starts, but attributes are not fully known yet.
void
startElement(String elementNamespaceURI, String elementLocalName, String elementName)
An element starts, but attributes are not fully known yet.
void
startElement(String namespaceURI, String localName, String qName, Attributes atts)
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.
void
startEntity(String arg0)
Does nothing.
void
startPrefixMapping(String prefix, String uri)
Begin the scope of a prefix-URI Namespace mapping just before another element is about to start.
boolean
startPrefixMapping(String prefix, String uri, boolean shouldFlush)
Handle a prefix/uri mapping, which is associated with a startElement() that is soon to follow.

Methods inherited from class org.apache.xml.serializer.ToSAXHandler

addUniqueAttribute, characters, characters, comment, error, fatalError, flushPending, processingInstruction, reset, setCdataSectionElements, setContentHandler, setLexHandler, setShouldOutputNSAttr, setTransformState, startDTD, startElement, startElement, startElement, warning

Methods inherited from class org.apache.xml.serializer.SerializerBase

addAttribute, addAttribute, addAttributeAlways, addAttributes, asContentHandler, asDOMSerializer, characters, close, comment, endEntity, entityReference, error, fatalError, fireEndEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getPrefix, getStandalone, getTransformer, getVersion, namespaceAfterStartElement, reset, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setSourceLocator, setStandalone, setTransformer, setVersion, startDocument, warning

Constructor Details

ToHTMLSAXHandler

public ToHTMLSAXHandler(ContentHandler handler,
                        String encoding)
A constructor

Parameters:
handler - the wrapped SAX content handler
encoding - the encoding of the output HTML document


ToHTMLSAXHandler

public ToHTMLSAXHandler(ContentHandler handler,
                        LexicalHandler lex,
                        String encoding)
A constructor.

Parameters:
handler - the wrapped SAX content handler
lex - the wrapped lexical handler
encoding - the encoding of the output HTML document

Method Details

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String valueDefault,
                          String value)
            throws SAXException
Does nothing.
Specified by:
attributeDecl in interface DeclHandler

Parameters:
eName - this parameter is ignored
aName - this parameter is ignored
type - this parameter is ignored
valueDefault - this parameter is ignored
value - this parameter is ignored

See Also:
DeclHandler.attributeDecl(String,String,String,String,String)


characters

public void characters(String chars)
            throws SAXException
Receive notification of character data.
Specified by:
characters in interface ExtendedContentHandler
Overrides:
characters in interface ToSAXHandler

Parameters:
chars - The string of characters to process.

Throws:
SAXException -

See Also:
ExtendedContentHandler.characters(String)


characters

public void characters(char[] ch,
                       int off,
                       int len)
            throws SAXException
Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

Parameters:
ch - The characters from the XML document.
off - The start position in the array.
len - The number of characters to read from the array.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ignorableWhitespace(char[],int,int), Locator, org.xml.sax.ContentHandler.characters(char[], int, int)


close

public void close()
Do nothing.
Specified by:
close in interface SerializationHandler
Overrides:
close in interface SerializerBase

See Also:
SerializationHandler.close()


comment

public void comment(char[] ch,
                    int start,
                    int length)
            throws SAXException
Receive notification of a comment anywhere in the document. This callback will be used for comments inside or outside the document element.

Parameters:
ch - An array holding the characters in the comment.
start - The starting position in the array.
length - The number of characters to use from the array.

Throws:
SAXException - The application may raise an exception.

See Also:
org.xml.sax.ext.LexicalHandler.comment(char[], int, int)


elementDecl

public void elementDecl(String name,
                        String model)
            throws SAXException
Does nothing.
Specified by:
elementDecl in interface DeclHandler

See Also:
DeclHandler.elementDecl(String,String)


endCDATA

public void endCDATA()
            throws SAXException
Does nothing.
Specified by:
endCDATA in interface LexicalHandler

See Also:
LexicalHandler.endCDATA()


endDTD

public void endDTD()
            throws SAXException
Does nothing.
Specified by:
endDTD in interface LexicalHandler

See Also:
LexicalHandler.endDTD()


endDocument

public void endDocument()
            throws SAXException
Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

Specified by:
endDocument in interface ContentHandler

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -


endElement

public void endElement(String elementName)
            throws SAXException
Receive notification of the end of an element.
Specified by:
endElement in interface ExtendedContentHandler

Parameters:
elementName - The element type name

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

See Also:
ExtendedContentHandler.endElement(String)


endElement

public void endElement(String uri,
                       String localName,
                       String qName)
            throws SAXException
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement() event for every endElement() event (even when the element is empty).

If the element name has a namespace prefix, the prefix will still be attached to the name.

Specified by:
endElement in interface ContentHandler

Parameters:
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

See Also:
ContentHandler.endElement(String,String,String)


endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Does nothing.
Specified by:
endPrefixMapping in interface ContentHandler


externalEntityDecl

public void externalEntityDecl(String arg0,
                               String arg1,
                               String arg2)
            throws SAXException
Specified by:
externalEntityDecl in interface DeclHandler

See Also:
DeclHandler.externalEntityDecl(String,String,String)


flushPending

public void flushPending()
            throws SAXException
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.
Specified by:
flushPending in interface SerializationHandler
Overrides:
flushPending in interface ToSAXHandler


getOutputFormat

public Properties getOutputFormat()
Returns null.
Specified by:
getOutputFormat in interface Serializer

Returns:
null

See Also:
Serializer.getOutputFormat()


getOutputStream

public OutputStream getOutputStream()
Reurns null
Specified by:
getOutputStream in interface Serializer

Returns:
null

See Also:
Serializer.getOutputStream()


getWriter

public Writer getWriter()
Returns null
Specified by:
getWriter in interface Serializer

Returns:
null

See Also:
Serializer.getWriter()


ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
            throws SAXException
Does nothing.

See Also:
org.xml.sax.ContentHandler.ignorableWhitespace(char[], int, int)


indent

public void indent(int n)
            throws SAXException
Does nothing.


internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
            throws SAXException
Does nothing.
Specified by:
internalEntityDecl in interface DeclHandler

See Also:
DTDHandler.unparsedEntityDecl(String,String,String,String)


namespaceAfterStartElement

public void namespaceAfterStartElement(String prefix,
                                       String uri)
            throws SAXException
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.
Specified by:
namespaceAfterStartElement in interface ExtendedContentHandler
Overrides:
namespaceAfterStartElement in interface SerializerBase

Parameters:
prefix - the prefix associated with the given URI.
uri - the URI of the namespace

See Also:
ExtendedContentHandler.namespaceAfterStartElement(String,String)


processingInstruction

public void processingInstruction(String arg0,
                                  String arg1)
            throws SAXException
Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in interface ToSAXHandler

Parameters:

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.processingInstruction(String,String)


reset

public boolean reset()
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).
Specified by:
reset in interface Serializer
Overrides:
reset in interface ToSAXHandler

Returns:
true if the class was successfuly reset.

See Also:
Serializer.reset()


serialize

public void serialize(Node node)
            throws IOException
Does nothing.
Specified by:
serialize in interface SerializationHandler
serialize in interface DOMSerializer

See Also:
DOMSerializer.serialize(Node)


setDocumentLocator

public void setDocumentLocator(Locator arg0)
Does nothing.
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in interface SerializerBase

See Also:
ContentHandler.setDocumentLocator(Locator)


setEscaping

public boolean setEscaping(boolean escape)
            throws SAXException
Turns special character escaping on/off.
Specified by:
setEscaping in interface SerializationHandler

Parameters:

See Also:
SerializationHandler.setEscaping(boolean)


setIndent

public void setIndent(boolean indent)
Does nothing
Specified by:
setIndent in interface XSLOutputAttributes
Overrides:
setIndent in interface SerializerBase

Parameters:
indent - the number of spaces to indent per indentation level (ignored)

See Also:
org.apache.xml.serializer.SerializationHandler.setIndent(boolean)


setOutputFormat

public void setOutputFormat(Properties format)
Does nothing.
Specified by:
setOutputFormat in interface Serializer

Parameters:
format - this parameter is not used

See Also:
Serializer.setOutputFormat(Properties)


setOutputStream

public void setOutputStream(OutputStream output)
Does nothing.
Specified by:
setOutputStream in interface Serializer

Parameters:
output - this parameter is ignored

See Also:
Serializer.setOutputStream(OutputStream)


setWriter

public void setWriter(Writer writer)
Does nothing.
Specified by:
setWriter in interface Serializer

Parameters:
writer - this parameter is ignored.

See Also:
Serializer.setWriter(Writer)


skippedEntity

public void skippedEntity(String arg0)
            throws SAXException
Does nothing.
Specified by:
skippedEntity in interface ContentHandler

See Also:
ContentHandler.skippedEntity(String)


startCDATA

public void startCDATA()
            throws SAXException
Does nothing.
Specified by:
startCDATA in interface LexicalHandler

See Also:
LexicalHandler.startCDATA()


startElement

public void startElement(String elementName)
            throws SAXException
An element starts, but attributes are not fully known yet.
Specified by:
startElement in interface ExtendedContentHandler
Overrides:
startElement in interface ToSAXHandler

Parameters:
elementName - the element name, with prefix, if any

See Also:
ExtendedContentHandler.startElement(String)


startElement

public void startElement(String elementNamespaceURI,
                         String elementLocalName,
                         String elementName)
            throws SAXException
An element starts, but attributes are not fully known yet.
Specified by:
startElement in interface ExtendedContentHandler
Overrides:
startElement in interface ToSAXHandler

Parameters:
elementNamespaceURI - the URI of the namespace of the element (optional)
elementLocalName - the element name, but without prefix (optional)
elementName - the element name, with prefix, if any (required)

See Also:
ExtendedContentHandler.startElement(String)


startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
            throws SAXException
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in interface ToSAXHandler

Parameters:
namespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The elements name.
atts - The attributes attached to the element, if any.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.startElement(String,String,String,Attributes), ContentHandler.endElement(String,String,String), AttributeList, ContentHandler.startElement(String,String,String,Attributes)


startEntity

public void startEntity(String arg0)
            throws SAXException
Does nothing.
Specified by:
startEntity in interface LexicalHandler

See Also:
LexicalHandler.startEntity(String)


startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Begin the scope of a prefix-URI Namespace mapping just before another element is about to start. This call will close any open tags so that the prefix mapping will not apply to the current element, but the up comming child.
Specified by:
startPrefixMapping in interface ContentHandler

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.

Throws:
SAXException - The client may throw an exception during processing.

See Also:
ContentHandler.startPrefixMapping(String,String)


startPrefixMapping

public boolean startPrefixMapping(String prefix,
                                  String uri,
                                  boolean shouldFlush)
            throws SAXException
Handle a prefix/uri mapping, which is associated with a startElement() that is soon to follow. Need to close any open start tag to make sure than any name space attributes due to this event are associated wih the up comming element, not the current one.
Specified by:
startPrefixMapping in interface ExtendedContentHandler

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
shouldFlush - true if any open tags need to be closed first, this will impact which element the mapping applies to (open parent, or its up comming child)

Returns:
returns true if the call made a change to the current namespace information, false if it did not change anything, e.g. if the prefix/namespace mapping was already in scope from before.

Throws:
SAXException - The client may throw an exception during processing.

See Also:
ExtendedContentHandler.startPrefixMapping(String,String,boolean)


Copyright B) 2004 Apache XML Project. All Rights Reserved.