org.apache.xml.serializer

Class ToHTMLStream

Implemented Interfaces:
org.xml.sax.ContentHandler, DeclHandler, org.xml.sax.DTDHandler, ErrorHandler, DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, org.xml.sax.ext.LexicalHandler, SerializationHandler, Serializer, org.apache.xml.serializer.SerializerConstants, org.apache.xml.serializer.XSLOutputAttributes

public class ToHTMLStream
extends ToStream

This serializer takes a series of SAX or SAX-like events and writes its output to the given stream. This class is not a public API, it is public because it is used from another package.

Field Summary

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

PKG_NAME, PKG_PATH

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

CDATA_CONTINUE, CDATA_DELIMITER_CLOSE, CDATA_DELIMITER_OPEN, DEFAULT_SAX_SERIALIZER, EMPTYSTRING, ENTITY_AMP, ENTITY_CRLF, ENTITY_GT, ENTITY_LT, ENTITY_QUOT, XMLNS_PREFIX, XMLNS_URI, XMLVERSION10, XMLVERSION11, 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
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, addCdataSectionElements, attributeDecl, characters, characters, comment, elementDecl, endCDATA, endDTD, endElement, endElement, endNonEscaping, endPrefixMapping, externalEntityDecl, flushPending, getIndentAmount, getOutputFormat, getOutputStream, getWriter, ignorableWhitespace, internalEntityDecl, notationDecl, processAttributes, reset, serialize, setCdataSectionElements, setContentHandler, setDTDEntityExpansion, setEncoding, setEscaping, setIndentAmount, setLineSepUse, setNewLine, setOutputFormat, setOutputStream, setTransformer, setWriter, skippedEntity, startCDATA, startDTD, startElement, startElement, startElement, startEntity, startNonEscaping, startPrefixMapping, startPrefixMapping, unparsedEntityDecl, writeAttrString

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

addAttribute, addAttribute, addAttribute, addAttributeAlways, addAttributes, addXSLAttribute, asContentHandler, asDOM3Serializer, asDOMSerializer, characters, close, comment, documentIsEmpty, endEntity, entityReference, error, fatalError, fireEndEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getIndentAmount, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getPrefix, getStandalone, getTransformer, getVersion, namespaceAfterStartElement, notationDecl, reset, setDTDEntityExpansion, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setEncoding, setIndent, setIndentAmount, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setTransformer, setVersion, startDocument, unparsedEntityDecl, 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.
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.
See Also:
ToHTMLStream, org.xml.sax.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.
See Also:
ToHTMLStream, org.xml.sax.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).
Overrides:
comment in interface ToStream
Parameters:
start - The starting position in the array.
length - The number of characters to use from the array.

elementDecl

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

endDTD

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

endDocument

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

endElement

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

endElement

public final void endElement(String namespaceURI,
                             String localName,
                             String name)
            throws SAXException
Receive notification of the end of an element.
Overrides:
endElement in interface ToStream
Parameters:
namespaceURI -
localName -
name - The element type name

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.

externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
            throws SAXException
This method does nothing.
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.
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

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
Parameters:
writer - the writer to write processed attributes to.
nAttrs - the number of attributes in m_attributes to be processed

processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Receive notification of a processing instruction.
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.

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. This method can be called multiple times before starting the serialization of a particular result-tree. In principle all serialization parameters can be changed, with the exception of method="html" (it must be method="html" otherwise we shouldn't even have a ToHTMLStream object here!)
Specified by:
setOutputFormat in interface Serializer
Overrides:
setOutputFormat in interface ToStream
Parameters:
format - The output format or serialzation parameters to use.

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

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String name,
                         Attributes atts)
            throws SAXException
Receive notification of the beginning of an element.
Overrides:
startElement in interface ToStream
Parameters:
namespaceURI -
localName -
name - The element type name.
atts - The attributes attached to the element, if any.
See Also:
endElement, org.xml.sax.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) 2006 Apache XML Project. All Rights Reserved.