org.apache.xalan.serialize
Class SerializerToHTML

java.lang.Object
  extended byorg.apache.xalan.serialize.SerializerToXML
      extended byorg.apache.xalan.serialize.SerializerToHTML
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ext.DeclHandler, DOMSerializer, org.xml.sax.ext.LexicalHandler, Serializer

public class SerializerToHTML
extends SerializerToXML

SerializerToHTML formats SAX-style events into XML.


Field Summary
private  String m_currentElementName
          The name of the current element.
private static ElemDesc m_dummy
          Dummy element for elements not found.
(package private) static Trie m_elementFlags
          A digital search trie for fast, case insensitive lookup of ElemDesc objects.
protected static CharInfo m_htmlcharInfo
          Map that tells which XML characters should have special treatment, and it provides character to entity name lookup.
private  boolean m_inBlockElem
          True if the current element is a block element.
protected  BoolStack m_isRawStack
          State stack to keep track of if the current element has output escaping disabled.
private  boolean m_omitMetaTag
          True if the META tag should be omitted.
private  boolean m_specialEscapeURLs
          True if URLs should be specially escaped with the %xx form.
 
Fields inherited from class org.apache.xalan.serialize.SerializerToXML
javaEncodingIsISO, level, m_canConvertMeth, m_cdataSectionNames, m_cdataSectionStates, m_charInfo, m_charToByteConverter, m_currentIndent, m_disableOutputEscapingStates, m_doctypePublic, m_doctypeSystem, m_doIndent, m_elemStack, m_encoding, m_format, m_inCData, m_indentAmount, m_inEntityRef, m_ispreserve, m_isprevtext, m_isUTF8, m_lineSep, m_lineSepLen, m_maxCharacter, m_mediatype, m_needToOutputDocTypeDecl, m_pos, m_preserves, m_shouldFlush, m_shouldNotWriteXMLHeader, m_spaceBeforeClose, m_standalone, m_standaloneWasSpecified, m_startNewLine, m_triedToGetConverter, m_version, m_writer, m_xmlcharInfo
 
Constructor Summary
SerializerToHTML()
          Default constructor.
 
Method Summary
 void cdata(char[] ch, int start, int length)
          Receive notification of cdata.
 void characters(char[] chars, int start, int length)
          Receive notification of character data.
private  int copyEntityIntoBuf(String s, int pos)
          Copy an entity into the accumulation buffer.
 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.
(package private)  ElemDesc getElemDesc(String name)
          Get a description of the given element.
 boolean getOmitMetaTag()
          Tells if the formatter should omit the META tag.
 boolean getSpecialEscapeURLs()
          Tells if the formatter should use special URL escaping.
private  boolean isASCIIDigit(char c)
          Tell if a character is an ASCII digit.
private  boolean isHHSign(String str)
          Dmitri Ilyin: Makes sure if the String is HH encoded sign.
private  String makeHHString(int i)
          Make an integer into an HH hex value.
protected  void processAttribute(String name, ElemDesc elemDesc, String value)
          Process an attribute.
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
 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 startDocument()
          Receive notification of the beginning of a document.
 void startElement(String namespaceURI, String localName, String name, org.xml.sax.Attributes atts)
          Receive notification of the beginning of an element.
 void writeAttrString(String string, String encoding)
          Writes the specified string after substituting specials, and UTF-16 surrogates for character references &#xnn.
 void writeAttrURI(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.xalan.serialize.SerializerToXML
accum, accum, accum, accumDefaultEntity, accumDefaultEscape, asContentHandler, asDOMSerializer, attributeDecl, canConvert, charactersRaw, childNodesWereAdded, comment, CopyFrom, elementDecl, endCDATA, endDocument, endDTD, endEntity, endNonEscaping, endPrefixMapping, endPreserving, externalEntityDecl, flushWriter, getOutputFormat, getOutputStream, getURF16SurrogateValue, getWriter, ignorableWhitespace, indent, init, init, internalEntityDecl, isCDataSection, isEscapingDisabled, isUTF16Surrogate, openElementForChildren, outputDocTypeDecl, outputEntityDecl, outputLineSep, printSpace, processAttribute, pushState, reset, serialize, setDocumentLocator, setOutputStream, setWriter, shouldIndent, skippedEntity, startCDATA, startDTD, startEntity, startNonEscaping, startPrefixMapping, startPreserving, subPartMatch, writeNormalizedChars, writeParentTagEnd, writeUTF16Surrogate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_isRawStack

protected BoolStack m_isRawStack
State stack to keep track of if the current element has output escaping disabled.


m_inBlockElem

private boolean m_inBlockElem
True if the current element is a block element. (seems like this needs to be a stack. -sb).


m_htmlcharInfo

protected static CharInfo m_htmlcharInfo
Map that tells which XML characters should have special treatment, and it provides character to entity name lookup.


m_elementFlags

static Trie m_elementFlags
A digital search trie for fast, case insensitive lookup of ElemDesc objects.


m_dummy

private static ElemDesc m_dummy
Dummy element for elements not found.


m_specialEscapeURLs

private boolean m_specialEscapeURLs
True if URLs should be specially escaped with the %xx form.


m_omitMetaTag

private boolean m_omitMetaTag
True if the META tag should be omitted.


m_currentElementName

private String m_currentElementName
The name of the current element.

Constructor Detail

SerializerToHTML

public SerializerToHTML()
Default constructor.

Method Detail

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.

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 class SerializerToXML
Parameters:
format - The output format to use

getSpecialEscapeURLs

public boolean getSpecialEscapeURLs()
Tells if the formatter should use special URL escaping.

Returns:
True if URLs should be specially escaped with the %xx form.

getOmitMetaTag

public boolean getOmitMetaTag()
Tells if the formatter should omit the META tag.

Returns:
True if the META tag should be omitted.

getElemDesc

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.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class SerializerToXML
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String name,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class SerializerToXML
Parameters:
namespaceURI -
localName -
name - The element type name.
atts - The attributes attached to the element, if any.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(java.lang.String, java.lang.String, java.lang.String), AttributeList

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String name)
                throws org.xml.sax.SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class SerializerToXML
Parameters:
namespaceURI -
localName -
name - The element type name
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

processAttribute

protected void processAttribute(String name,
                                ElemDesc elemDesc,
                                String value)
                         throws org.xml.sax.SAXException
Process an attribute.

Parameters:
name - The name of the attribute.
elemDesc - non-null reference to the owning element description.
value - The value of the attribute.
Throws:
org.xml.sax.SAXException

isASCIIDigit

private boolean isASCIIDigit(char c)
Tell if a character is an ASCII digit.


makeHHString

private String makeHHString(int i)
Make an integer into an HH hex value. Does no checking on the size of the input, since this is only meant to be used locally by writeAttrURI.

Parameters:
i - must be a value less than 255.
Returns:
should be a two character string.

isHHSign

private boolean isHHSign(String str)
Dmitri Ilyin: Makes sure if the String is HH encoded sign.

Parameters:
str - must be 2 characters long
Returns:
true or false

writeAttrURI

public void writeAttrURI(String string,
                         boolean doURLEscaping)
                  throws org.xml.sax.SAXException
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.
Throws:
org.xml.sax.SAXException - if a bad surrogate pair is detected.

writeAttrString

public void writeAttrString(String string,
                            String encoding)
                     throws org.xml.sax.SAXException
Writes the specified string after substituting specials, and UTF-16 surrogates for character references &#xnn.

Overrides:
writeAttrString in class SerializerToXML
Parameters:
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.
Throws:
org.xml.sax.SAXException

copyEntityIntoBuf

private int copyEntityIntoBuf(String s,
                              int pos)
                       throws org.xml.sax.SAXException
Copy an entity into the accumulation buffer.

Parameters:
s - The name of the entity.
pos - unused.
Returns:
The pos argument.
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] chars,
                       int start,
                       int length)
                throws org.xml.sax.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).

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class SerializerToXML
Parameters:
chars - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException
See Also:
SerializerToXML.ignorableWhitespace(char[], int, int), Locator

cdata

public void cdata(char[] ch,
                  int start,
                  int length)
           throws org.xml.sax.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).

Overrides:
cdata in class SerializerToXML
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException
See Also:
SerializerToXML.ignorableWhitespace(char[], int, int), Locator

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws org.xml.sax.SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class SerializerToXML
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException

entityReference

public void entityReference(String name)
                     throws org.xml.sax.SAXException
Receive notivication of a entityReference.

Overrides:
entityReference in class SerializerToXML
Parameters:
name - non-null reference to entity name string.
Throws:
org.xml.sax.SAXException