org.apache.xml.serializer

Class ToHTMLStream

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

public class ToHTMLStream
extends ToStream

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

ToHTMLStream()
Default constructor.

Method Summary

void
addUniqueAttribute(String name, String value, int flags)
This method is used to add an attribute to the currently open element.
void
attributeDecl(String eName, String aName, String type, String valueDefault, String value)
This method does nothing.
void
cdata(ch[] , int start, int length)
Receive notification of cdata.
void
characters(chars[] , int start, int length)
Receive notification of character data.
void
comment(ch[] , int start, int length)
Receive notification of an XML comment anywhere in the document.
void
elementDecl(String name, String model)
This method does nothing.
void
endDTD()
Report the end of DTD declarations.
void
endDocument()
Receive notification of the end of a document.
void
endElement(String elemName)
void
endElement(String namespaceURI, String localName, String name)
Receive notification of the end of an element.
void
entityReference(String name)
Receive notivication of a entityReference.
void
externalEntityDecl(String name, String publicId, String systemId)
This method does nothing.
static ElemDesc
getElemDesc(String name)
Get a description of the given element.
void
internalEntityDecl(String name, String value)
This method 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
processAttributes(java.io.Writer writer, int nAttrs)
Process the attributes, which means to write out the currently collected attributes to the writer.
void
processingInstruction(String target, String data)
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
setOmitMetaTag(boolean bool)
Tells if the formatter should omit the META tag.
void
setOutputFormat(Properties format)
Specifies an output format for this serializer.
void
setOutputStream(OutputStream output)
Specifies an output stream to which the document should be serialized.
void
setSpecialEscapeURLs(boolean bool)
Tells if the formatter should use special URL escaping.
void
startDTD(String name, String publicId, String systemId)
Report the start of DTD declarations, if any.
void
startElement(String namespaceURI, String localName, String name, Attributes atts)
Receive notification of the beginning of an element.
void
writeAttrString(java.io.Writer writer, String string, String encoding)
Writes the specified string after substituting specials, and UTF-16 surrogates for character references &#xnn.
void
writeAttrURI(java.io.Writer writer, String string, boolean doURLEscaping)
Write the specified string after substituting non ASCII characters, with %HH, where HH is the hex of the byte value.

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

addAttributeAlways, attributeDecl, characters, characters, comment, elementDecl, endCDATA, endDTD, endElement, endElement, endNonEscaping, endPrefixMapping, externalEntityDecl, flushPending, getIndentAmount, getOutputFormat, getOutputStream, getWriter, ignorableWhitespace, internalEntityDecl, processAttributes, reset, serialize, setCdataSectionElements, setContentHandler, setEscaping, setIndentAmount, setLineSepUse, setOutputFormat, setOutputStream, setTransformer, setWriter, skippedEntity, startCDATA, startDTD, startElement, startElement, startElement, startEntity, startNonEscaping, startPrefixMapping, startPrefixMapping, writeAttrString

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

ToHTMLStream

public ToHTMLStream()
Default constructor.

Method Details

addUniqueAttribute

public void addUniqueAttribute(String name,
                               String value,
                               int flags)
            throws SAXException
This method is used to add an attribute to the currently open element. The caller has guaranted that this attribute is unique, which means that it not been seen before and will not be seen again.
Specified by:
addUniqueAttribute in interface ExtendedContentHandler

Parameters:
name - the qualified name of the attribute
value - the value of the attribute which can contain only ASCII printable characters characters in the range 32 to 127 inclusive.
flags - the bit values of this integer give optimization information.


attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String valueDefault,
                          String value)
            throws SAXException
This method does nothing.
Specified by:
attributeDecl in interface DeclHandler
Overrides:
attributeDecl in interface ToStream


cdata

public final void cdata(ch[] ,
                        int start,
                        int length)
            throws SAXException
Receive notification of cdata.

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:
start - The start position in the array.
length - The number of characters to read from the array.

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

See Also:
ToHTMLStream, Locator


characters

public final void characters(chars[] ,
                             int start,
                             int length)
            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).

Overrides:
characters in interface ToStream

Parameters:
start - The start position in the array.
length - The number of characters to read from the array.

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

See Also:
ToHTMLStream, Locator


comment

public void comment(ch[] ,
                    int start,
                    int length)
            throws SAXException
Receive notification of an XML comment anywhere in the document. This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).
Specified by:
comment in interface LexicalHandler
Overrides:
comment in interface ToStream

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


elementDecl

public void elementDecl(String name,
                        String model)
            throws SAXException
This method does nothing.
Specified by:
elementDecl in interface DeclHandler
Overrides:
elementDecl in interface ToStream


endDTD

public void endDTD()
            throws SAXException
Report the end of DTD declarations.
Specified by:
endDTD in interface LexicalHandler
Overrides:
endDTD in interface ToStream

Throws:
SAXException - The application may raise an exception.

See Also:
startDTD(String,String,String)


endDocument

public final void endDocument()
            throws SAXException
Receive notification of the end of a document.
Specified by:
endDocument in interface ContentHandler

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


endElement

public final void endElement(String elemName)
            throws SAXException
Specified by:
endElement in interface ExtendedContentHandler
Overrides:
endElement in interface ToStream

See Also:
ExtendedContentHandler.endElement(String)


endElement

public final void endElement(String namespaceURI,
                             String localName,
                             String name)
            throws SAXException
Receive notification of the end of an element.
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in interface ToStream

Parameters:
namespaceURI -
localName -
name - The element type name

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


entityReference

public final void entityReference(String name)
            throws SAXException
Receive notivication of a entityReference.
Specified by:
entityReference in interface ExtendedContentHandler
Overrides:
entityReference in interface SerializerBase

Parameters:
name - non-null reference to entity name string.

Throws:
SAXException -


externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
            throws SAXException
This method does nothing.
Specified by:
externalEntityDecl in interface DeclHandler
Overrides:
externalEntityDecl in interface ToStream


getElemDesc

public static final ElemDesc getElemDesc(String name)
Get a description of the given element.

Parameters:
name - non-null name of element, case insensitive.

Returns:
non-null reference to ElemDesc, which may be m_dummy if no element description matches the given name.


internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
            throws SAXException
This method does nothing.
Specified by:
internalEntityDecl in interface DeclHandler
Overrides:
internalEntityDecl in interface ToStream


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)


processAttributes

public void processAttributes(java.io.Writer writer,
                              int nAttrs)
            throws IOException,
                   SAXException
Process the attributes, which means to write out the currently collected attributes to the writer. The attributes are not cleared by this method
Overrides:
processAttributes in interface ToStream

Parameters:
writer - the writer to write processed attributes to.
nAttrs - the number of attributes in m_attributes to be processed

Throws:
SAXException -


processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Receive notification of a processing instruction.
Specified by:
processingInstruction in interface ContentHandler

Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.

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


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 ToStream

Returns:
true if the class was successfuly reset.


setOmitMetaTag

public void setOmitMetaTag(boolean bool)
Tells if the formatter should omit the META tag.

Parameters:
bool - True if the META tag should be omitted.


setOutputFormat

public void setOutputFormat(Properties format)
Specifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document.
Specified by:
setOutputFormat in interface Serializer
Overrides:
setOutputFormat in interface ToStream

Parameters:
format - The output format to use


setOutputStream

public void setOutputStream(OutputStream output)
Specifies an output stream to which the document should be serialized. This method should not be called while the serializer is in the process of serializing a document.

The encoding specified in the output properties is used, or if no encoding was specified, the default for the selected output method.

Specified by:
setOutputStream in interface Serializer
Overrides:
setOutputStream in interface ToStream

Parameters:
output - The output stream


setSpecialEscapeURLs

public void setSpecialEscapeURLs(boolean bool)
Tells if the formatter should use special URL escaping.

Parameters:
bool - True if URLs should be specially escaped with the %xx form.


startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
            throws SAXException
Report the start of DTD declarations, if any. Any declarations are assumed to be in the internal subset unless otherwise indicated.
Specified by:
startDTD in interface LexicalHandler
Overrides:
startDTD in interface ToStream

Parameters:
name - The document type name.
publicId - The declared public identifier for the external DTD subset, or null if none was declared.
systemId - The declared system identifier for the external DTD subset, or null if none was declared.

Throws:
SAXException - The application may raise an exception.

See Also:
ToStream.endDTD(), ToStream.startEntity(String)


startElement

public void startElement(String namespaceURI,
                         String localName,
                         String name,
                         Attributes atts)
            throws SAXException
Receive notification of the beginning of an element.
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in interface ToStream

Parameters:
namespaceURI -
localName -
name - The element type name.
atts - The attributes attached to the element, if any.

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

See Also:
endElement, AttributeList


writeAttrString

public void writeAttrString(java.io.Writer writer,
                            String string,
                            String encoding)
            throws IOException
Writes the specified string after substituting specials, and UTF-16 surrogates for character references &#xnn.

Parameters:
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.


writeAttrURI

public void writeAttrURI(java.io.Writer writer,
                         String string,
                         boolean doURLEscaping)
            throws IOException
Write the specified string after substituting non ASCII characters, with %HH, where HH is the hex of the byte value.

Parameters:
string - String to convert to XML format.
doURLEscaping - True if we should try to encode as per http://www.ietf.org/rfc/rfc2396.txt.


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