org.apache.xalan.serialize
Class SerializerToXML

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

public class SerializerToXML
extends Object
implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.ext.DeclHandler, Serializer, DOMSerializer

SerializerToXML formats SAX-style events into XML.


Field Summary
private static boolean DEBUG
          Indicate whether running in Debug mode
(package private) static boolean javaEncodingIsISO
          Assume java encoding names are the same as the ISO encoding names if this is true.
protected  int level
          Current level of indent.
(package private)  Method m_canConvertMeth
          Method reference to the sun.io.CharToByteConverter#canConvert method for this encoding.
protected  Vector m_cdataSectionNames
          List of QNames obtained from the xsl:output properties.
protected  BoolStack m_cdataSectionStates
          True will be pushed, if characters should be in CDATA section blocks.
protected  CharInfo m_charInfo
          Map that tells which characters should have special treatment, and it provides character to entity name lookup.
private static Hashtable m_charInfos
          Table of user-specified char infos.
(package private)  Object m_charToByteConverter
          Opaque reference to the sun.io.CharToByteConverter for this encoding.
protected  int m_currentIndent
          Flag to keep track of the indent amount.
protected  BoolStack m_disableOutputEscapingStates
          Stack to keep track of disabling output escaping.
(package private)  String m_doctypePublic
          The public ID for the doc type.
(package private)  String m_doctypeSystem
          The System ID for the doc type.
protected  boolean m_doIndent
          Flag to tell if indenting (pretty-printing) is on.
private  String m_elemName
          NEEDSDOC Field m_elemName
protected  BoolStack m_elemStack
          A stack of Boolean objects that tell if the given element has children.
protected  String m_encoding
          The character encoding.
protected  Properties m_format
          The xsl:output properties.
protected  boolean m_inCData
          True if the current characters should be in CDATA blocks.
 int m_indentAmount
          Amount to indent.
private  boolean m_inDoctype
          Tells if we're in an internal document type subset.
protected  boolean m_inEntityRef
          Tells if we're in an EntityRef event.
private  boolean m_inExternalDTD
          This flag is set while receiving events from the external DTD
protected  boolean m_ispreserve
          State flag to tell if preservation of whitespace is important.
protected  boolean m_isprevtext
          State flag that tells if the previous node processed was text, so we can tell if we should preserve whitespace.
(package private)  boolean m_isUTF8
          Flag to quickly tell if the encoding is UTF8.
protected  char[] m_lineSep
          Use the system line seperator to write line breaks.
protected  int m_lineSepLen
          The length of the line seperator, since the write is done one character at a time.
protected  int m_maxCharacter
          The maximum character size before we have to resort to escaping.
(package private)  String m_mediatype
          The mediatype.
(package private)  boolean m_needToOutputDocTypeDecl
          Flag to tell that we need to add the doctype decl, which we can't do until the first element is encountered.
protected  int m_pos
          The current position in the m_charBuf or m_byteBuf.
protected  BoolStack m_preserves
          Stack to keep track of whether or not we need to preserve whitespace.
(package private)  boolean m_shouldFlush
          True if we control the buffer, and we should flush the output on endDocument.
 boolean m_shouldNotWriteXMLHeader
          Tells if we should write the XML declaration.
 boolean m_spaceBeforeClose
          Add space before '/>' for XHTML.
(package private)  boolean m_standalone
          The standalone value for the doctype.
(package private)  boolean m_standaloneWasSpecified
          True if standalone was specified.
(package private)  boolean m_startNewLine
          Flag to signal that a newline should be added.
(package private)  boolean m_triedToGetConverter
          Boolean that tells if we already tried to get the converter.
 String m_version
          Tells the XML version, for writing out to the XML decl.
protected  Writer m_writer
          The writer where the XML will be written.
protected static CharInfo m_xmlcharInfo
          Map that tells which XML characters should have special treatment, and it provides character to entity name lookup.
 
Constructor Summary
SerializerToXML()
          Default constructor.
 
Method Summary
protected  void accum(char b)
          Append a character to the buffer.
protected  void accum(char[] chars, int start, int length)
          Append a character to the buffer.
protected  void accum(String s)
          Append a character to the buffer.
protected  int accumDefaultEntity(char ch, int i, char[] chars, int len, boolean escLF)
          Handle one of the default entities, return false if it is not a default entity.
protected  int accumDefaultEscape(char ch, int i, char[] chars, int len, boolean escLF)
          Escape and m_writer.write a character.
 org.xml.sax.ContentHandler asContentHandler()
          Return a ContentHandler interface into this serializer.
 DOMSerializer asDOMSerializer()
          Return a DOMSerializer interface into this serializer.
 void attributeDecl(String eName, String aName, String type, String valueDefault, String value)
          Report an attribute type declaration.
 boolean canConvert(char ch)
          Tell if this character can be written without escaping.
 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.
 void charactersRaw(char[] ch, int start, int length)
          If available, when the disable-output-escaping attribute is used, output raw text without escaping.
protected  boolean childNodesWereAdded()
          Tell if child nodes have been added to the current element.
 void comment(char[] ch, int start, int length)
          Report an XML comment anywhere in the document.
 void CopyFrom(SerializerToXML xmlListener)
          Copy properties from another SerializerToXML.
 void elementDecl(String name, String model)
          Report an element type declaration.
 void endCDATA()
          Report the end of a CDATA section.
 void endDocument()
          Receive notification of the end of a document.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(String namespaceURI, String localName, String name)
          Receive notification of the end of an element.
 void endEntity(String name)
          Report the end of an entity.
 void endNonEscaping()
          Ends an un-escaping section.
 void endPrefixMapping(String prefix)
          End the scope of a prefix-URI Namespace mapping.
 void endPreserving()
          Ends a whitespace preserving section.
 void entityReference(String name)
          Receive notivication of a entityReference.
 void externalEntityDecl(String name, String publicId, String systemId)
          Report a parsed external entity declaration.
 void flushWriter()
          Flush the formatter's result stream.
 Properties getOutputFormat()
          Returns the output format for this serializer.
 OutputStream getOutputStream()
          Get the output stream where the events will be serialized to.
(package private)  int getURF16SurrogateValue(char c, char[] ch, int i, int end)
          Once a surrogate has been detected, get the pair as a single integer value.
 Writer getWriter()
          Get the character stream where the events will be serialized to.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
 void indent(int n)
          Prints a newline character and n spaces.
 void init(OutputStream output, Properties format)
          Initialize the serializer with the specified output stream and output format.
 void init(Writer writer, Properties format)
          Initialize the serializer with the specified writer and output format.
private  void init(Writer writer, Properties format, boolean shouldFlush)
          Initialize the serializer with the specified writer and output format.
 void internalEntityDecl(String name, String value)
          Report an internal entity declaration.
protected  boolean isCDataSection()
          Tell if the characters in the current state should be put in cdata section blocks.
protected  boolean isEscapingDisabled()
          Tell if the character escaping should be disabled for the current state.
(package private) static boolean isUTF16Surrogate(char c)
          Return true if the character is the high member of a surrogate pair.
protected  void openElementForChildren()
          Flag the current element as not yet having any children.
(package private)  void outputDocTypeDecl(String name, boolean closeDecl)
          Output the doc type declaration.
(package private)  void outputEntityDecl(String name, String value)
          Output the doc type declaration.
protected  void outputLineSep()
          Output a system-dependent line break.
 void printSpace(int n)
          Prints n spaces.
protected  void processAttribute(String name, String value)
          Process an attribute.
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
protected  void pushState(String namespaceURI, String localName, Vector qnames, BoolStack state)
          Push a boolean state based on if the name of the element is found in the list of qnames.
 boolean reset()
          Resets the serializer.
 void serialize(org.w3c.dom.Node node)
          Serializes the DOM node.
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive an object for locating the origin of SAX document events.
 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 setWriter(Writer writer)
          Specifies a writer to which the document should be serialized.
protected  boolean shouldIndent()
          Tell if, based on space preservation constraints and the doIndent property, if an indent should occur.
 void skippedEntity(String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDocument()
          Receive notification of the beginning of a document.
 void startDTD(String name, String publicId, String systemId)
          Report the start of DTD declarations, if any.
 void startElement(String namespaceURI, String localName, String name, org.xml.sax.Attributes atts)
          Receive notification of the beginning of an element.
 void startEntity(String name)
          Report the beginning of an entity.
 void startNonEscaping()
          Starts an un-escaping section.
 void startPrefixMapping(String prefix, String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 void startPreserving()
          Starts a whitespace preserving section.
protected static boolean subPartMatch(String p, String t)
          Tell if two strings are equal, without worry if the first string is null.
 void writeAttrString(String string, String encoding)
          Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
(package private)  void writeNormalizedChars(char[] ch, int start, int length, boolean isCData)
          Normalize the characters, but don't escape.
protected  void writeParentTagEnd()
          Check to see if a parent's ">" has been written, and, if it has not, write it.
protected  int writeUTF16Surrogate(char c, char[] ch, int i, int end)
          Once a surrogate has been detected, write the pair as a single character reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_writer

protected Writer m_writer
The writer where the XML will be written.


m_shouldFlush

boolean m_shouldFlush
True if we control the buffer, and we should flush the output on endDocument.


m_encoding

protected String m_encoding
The character encoding. Must match the encoding used for the printWriter.


javaEncodingIsISO

static boolean javaEncodingIsISO
Assume java encoding names are the same as the ISO encoding names if this is true.


m_shouldNotWriteXMLHeader

public boolean m_shouldNotWriteXMLHeader
Tells if we should write the XML declaration.


m_version

public String m_version
Tells the XML version, for writing out to the XML decl.


m_elemStack

protected BoolStack m_elemStack
A stack of Boolean objects that tell if the given element has children.


m_disableOutputEscapingStates

protected BoolStack m_disableOutputEscapingStates
Stack to keep track of disabling output escaping.


m_cdataSectionStates

protected BoolStack m_cdataSectionStates
True will be pushed, if characters should be in CDATA section blocks.


m_cdataSectionNames

protected Vector m_cdataSectionNames
List of QNames obtained from the xsl:output properties.


m_inCData

protected boolean m_inCData
True if the current characters should be in CDATA blocks.


m_lineSep

protected final char[] m_lineSep
Use the system line seperator to write line breaks.


m_lineSepLen

protected final int m_lineSepLen
The length of the line seperator, since the write is done one character at a time.


m_ispreserve

protected boolean m_ispreserve
State flag to tell if preservation of whitespace is important.


m_preserves

protected BoolStack m_preserves
Stack to keep track of whether or not we need to preserve whitespace.


m_isprevtext

protected boolean m_isprevtext
State flag that tells if the previous node processed was text, so we can tell if we should preserve whitespace.


m_doIndent

protected boolean m_doIndent
Flag to tell if indenting (pretty-printing) is on.


m_currentIndent

protected int m_currentIndent
Flag to keep track of the indent amount.


m_indentAmount

public int m_indentAmount
Amount to indent.


level

protected int level
Current level of indent.


m_startNewLine

boolean m_startNewLine
Flag to signal that a newline should be added.


m_needToOutputDocTypeDecl

boolean m_needToOutputDocTypeDecl
Flag to tell that we need to add the doctype decl, which we can't do until the first element is encountered.


m_doctypeSystem

String m_doctypeSystem
The System ID for the doc type.


m_doctypePublic

String m_doctypePublic
The public ID for the doc type.


m_standalone

boolean m_standalone
The standalone value for the doctype.


m_standaloneWasSpecified

boolean m_standaloneWasSpecified
True if standalone was specified.


m_mediatype

String m_mediatype
The mediatype. Not used right now.


m_inEntityRef

protected boolean m_inEntityRef
Tells if we're in an EntityRef event.


m_inDoctype

private boolean m_inDoctype
Tells if we're in an internal document type subset.


m_xmlcharInfo

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


m_charInfo

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


m_charInfos

private static Hashtable m_charInfos
Table of user-specified char infos.


m_isUTF8

boolean m_isUTF8
Flag to quickly tell if the encoding is UTF8.


m_maxCharacter

protected int m_maxCharacter
The maximum character size before we have to resort to escaping.


m_spaceBeforeClose

public boolean m_spaceBeforeClose
Add space before '/>' for XHTML.


m_format

protected Properties m_format
The xsl:output properties.


DEBUG

private static final boolean DEBUG
Indicate whether running in Debug mode

See Also:
Constant Field Values

m_inExternalDTD

private boolean m_inExternalDTD
This flag is set while receiving events from the external DTD


m_pos

protected int m_pos
The current position in the m_charBuf or m_byteBuf.


m_elemName

private String m_elemName
NEEDSDOC Field m_elemName


m_charToByteConverter

Object m_charToByteConverter
Opaque reference to the sun.io.CharToByteConverter for this encoding.


m_canConvertMeth

Method m_canConvertMeth
Method reference to the sun.io.CharToByteConverter#canConvert method for this encoding. Invalid if m_charToByteConverter is null.


m_triedToGetConverter

boolean m_triedToGetConverter
Boolean that tells if we already tried to get the converter.

Constructor Detail

SerializerToXML

public SerializerToXML()
Default constructor.

Method Detail

isEscapingDisabled

protected boolean isEscapingDisabled()
Tell if the character escaping should be disabled for the current state.

Returns:
true if the character escaping should be disabled.

isCDataSection

protected boolean isCDataSection()
Tell if the characters in the current state should be put in cdata section blocks.

Returns:
true if the characters in the current state should be put in cdata section blocks.

outputLineSep

protected final void outputLineSep()
                            throws org.xml.sax.SAXException
Output a system-dependent line break.

Throws:
org.xml.sax.SAXException

CopyFrom

public void CopyFrom(SerializerToXML xmlListener)
Copy properties from another SerializerToXML.

Parameters:
xmlListener - non-null reference to a SerializerToXML object.

init

public void init(Writer writer,
                 Properties format)
Initialize the serializer with the specified writer and output format. Must be called before calling any of the serialize methods.

Parameters:
writer - The writer to use
format - The output format

init

private void init(Writer writer,
                  Properties format,
                  boolean shouldFlush)
Initialize the serializer with the specified writer and output format. Must be called before calling any of the serialize methods.

Parameters:
writer - The writer to use
format - The output format
shouldFlush - True if the writer should be flushed at EndDocument.

init

public void init(OutputStream output,
                 Properties format)
          throws UnsupportedEncodingException
Initialize the serializer with the specified output stream and output format. Must be called before calling any of the serialize methods.

Parameters:
output - The output stream to use
format - The output format
Throws:
UnsupportedEncodingException - The encoding specified in the output format is not supported

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Receive an object for locating the origin of SAX document events.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Parameters:
locator - An object that can return the location of any SAX document event.
See Also:
Locator

outputDocTypeDecl

void outputDocTypeDecl(String name,
                       boolean closeDecl)
                 throws org.xml.sax.SAXException
Output the doc type declaration.

Parameters:
name - non-null reference to document type name. NEEDSDOC @param closeDecl
Throws:
org.xml.sax.SAXException

outputEntityDecl

void outputEntityDecl(String name,
                      String value)
                throws org.xml.sax.SAXException
Output the doc type declaration.

Parameters:
name - non-null reference to document type name. NEEDSDOC @param value
Throws:
org.xml.sax.SAXException

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
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException

endDocument

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

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

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws org.xml.sax.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 org.xml.sax.ext.LexicalHandler
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:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
endDTD(), startEntity(java.lang.String)

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Report the end of DTD declarations.

Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
startDTD(java.lang.String, java.lang.String, java.lang.String)

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws org.xml.sax.SAXException
Begin the scope of a prefix-URI Namespace mapping.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.
See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws org.xml.sax.SAXException
End the scope of a prefix-URI Namespace mapping.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - The prefix that was being mapping.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.
See Also:
ContentHandler.endPrefixMapping(java.lang.String)

subPartMatch

protected static final boolean subPartMatch(String p,
                                            String t)
Tell if two strings are equal, without worry if the first string is null.

Parameters:
p - String reference, which may be null.
t - String reference, which may be null.
Returns:
true if strings are equal.

pushState

protected void pushState(String namespaceURI,
                         String localName,
                         Vector qnames,
                         BoolStack state)
Push a boolean state based on if the name of the element is found in the list of qnames. A state is always pushed, one way or the other.

Parameters:
namespaceURI - Should be a non-null reference to the namespace URL of the element that owns the state, or empty string.
localName - Should be a non-null reference to the local name of the element that owns the state.
qnames - Vector of qualified names of elements, or null.
state - The stack where the state should be pushed.

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
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.
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.
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes), ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), AttributeList

writeParentTagEnd

protected void writeParentTagEnd()
                          throws org.xml.sax.SAXException
Check to see if a parent's ">" has been written, and, if it has not, write it.

Throws:
org.xml.sax.SAXException

openElementForChildren

protected void openElementForChildren()
Flag the current element as not yet having any children.


childNodesWereAdded

protected boolean childNodesWereAdded()
Tell if child nodes have been added to the current element. Must be called in balance with openElementForChildren().

Returns:
true if child nodes were added.

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
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.
name - The element type name
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
org.xml.sax.SAXException

processAttribute

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

Parameters:
name - The name of the attribute.
value - The value of the attribute.
Throws:
org.xml.sax.SAXException

startNonEscaping

public void startNonEscaping()
                      throws org.xml.sax.SAXException
Starts an un-escaping section. All characters printed within an un-escaping section are printed as is, without escaping special characters into entity references. Only XML and HTML serializers need to support this method.

The contents of the un-escaping section will be delivered through the regular characters event.

Throws:
org.xml.sax.SAXException

endNonEscaping

public void endNonEscaping()
                    throws org.xml.sax.SAXException
Ends an un-escaping section.

Throws:
org.xml.sax.SAXException
See Also:
startNonEscaping()

startPreserving

public void startPreserving()
                     throws org.xml.sax.SAXException
Starts a whitespace preserving section. All characters printed within a preserving section are printed without indentation and without consolidating multiple spaces. This is equivalent to the xml:space="preserve" attribute. Only XML and HTML serializers need to support this method.

The contents of the whitespace preserving section will be delivered through the regular characters event.

Throws:
org.xml.sax.SAXException

endPreserving

public void endPreserving()
                   throws org.xml.sax.SAXException
Ends a whitespace preserving section.

Throws:
org.xml.sax.SAXException
See Also:
startPreserving()

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

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws org.xml.sax.SAXException
Report 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 org.xml.sax.ext.LexicalHandler
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:
org.xml.sax.SAXException - The application may raise an exception.

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Report the start of a CDATA section.

Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
endCDATA()

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Report the end of a CDATA section.

Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
startCDATA()

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

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:
ignorableWhitespace(char[], int, int), Locator

accum

protected final void accum(char b)
                    throws org.xml.sax.SAXException
Append a character to the buffer.

Parameters:
b - byte to be written to result stream.
Throws:
org.xml.sax.SAXException

accum

protected final void accum(char[] chars,
                           int start,
                           int length)
                    throws org.xml.sax.SAXException
Append a character to the buffer.

Parameters:
chars - non-null reference to character array.
start - Start of characters to be written.
length - Number of characters to be written.
Throws:
org.xml.sax.SAXException

accum

protected final void accum(String s)
                    throws org.xml.sax.SAXException
Append a character to the buffer.

Parameters:
s - non-null reference to string to be written to the character buffer.
Throws:
org.xml.sax.SAXException

flushWriter

public final void flushWriter()
                       throws org.xml.sax.SAXException
Flush the formatter's result stream.

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
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:
ignorableWhitespace(char[], int, int), Locator

charactersRaw

public void charactersRaw(char[] ch,
                          int start,
                          int length)
                   throws org.xml.sax.SAXException
If available, when the disable-output-escaping attribute is used, output raw text without escaping.

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

isUTF16Surrogate

static final boolean isUTF16Surrogate(char c)
Return true if the character is the high member of a surrogate pair. NEEDSDOC @param c NEEDSDOC ($objectName$) @return


getURF16SurrogateValue

int getURF16SurrogateValue(char c,
                           char[] ch,
                           int i,
                           int end)
                     throws org.xml.sax.SAXException
Once a surrogate has been detected, get the pair as a single integer value.

Parameters:
c - the first part of the surrogate.
ch - Character array.
i - position Where the surrogate was detected.
end - The end index of the significant characters.
Returns:
i+1.
Throws:
org.xml.sax.SAXException - if invalid UTF-16 surrogate detected.

writeUTF16Surrogate

protected int writeUTF16Surrogate(char c,
                                  char[] ch,
                                  int i,
                                  int end)
                           throws IOException,
                                  org.xml.sax.SAXException
Once a surrogate has been detected, write the pair as a single character reference.

Parameters:
c - the first part of the surrogate.
ch - Character array.
i - position Where the surrogate was detected.
end - The end index of the significant characters.
Returns:
i+1.
Throws:
IOException
org.xml.sax.SAXException - if invalid UTF-16 surrogate detected.

writeNormalizedChars

void writeNormalizedChars(char[] ch,
                          int start,
                          int length,
                          boolean isCData)
                    throws IOException,
                           org.xml.sax.SAXException
Normalize the characters, but don't escape.

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.
isCData - true if a CDATA block should be built around the characters.
Throws:
IOException
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content. Not sure how to get this invoked quite yet.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
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:
characters(char[], int, int)

skippedEntity

public void skippedEntity(String name)
                   throws org.xml.sax.SAXException
Receive notification of a skipped entity.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]".
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.skippedEntity(java.lang.String)

startEntity

public void startEntity(String name)
                 throws org.xml.sax.SAXException
Report the beginning of an entity. The start and end of the document entity are not reported. The start and end of the external DTD subset are reported using the pseudo-name "[dtd]". All other events must be properly nested within start/end entity events.

Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
endEntity(java.lang.String), DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

endEntity

public void endEntity(String name)
               throws org.xml.sax.SAXException
Report the end of an entity.

Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler
Parameters:
name - The name of the entity that is ending.
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
startEntity(java.lang.String)

entityReference

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

Parameters:
name - The name of the entity.
Throws:
org.xml.sax.SAXException

elementDecl

public void elementDecl(String name,
                        String model)
                 throws org.xml.sax.SAXException
Report an element type declaration.

The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all whitespace is removed,and will include the enclosing parentheses.

Specified by:
elementDecl in interface org.xml.sax.ext.DeclHandler
Parameters:
name - The element type name.
model - The content model as a normalized string.
Throws:
org.xml.sax.SAXException - The application may raise an exception.

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String valueDefault,
                          String value)
                   throws org.xml.sax.SAXException
Report an attribute type declaration.

Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION", or a parenthesized token group with the separator "|" and all whitespace removed.

Specified by:
attributeDecl in interface org.xml.sax.ext.DeclHandler
Parameters:
eName - The name of the associated element.
aName - The name of the attribute.
type - A string representing the attribute type.
valueDefault - A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
value - A string representing the attribute's default value, or null if there is none.
Throws:
org.xml.sax.SAXException - The application may raise an exception.

internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
                        throws org.xml.sax.SAXException
Report an internal entity declaration.

Only the effective (first) declaration for each entity will be reported.

Specified by:
internalEntityDecl in interface org.xml.sax.ext.DeclHandler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
value - The replacement text of the entity.
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
externalEntityDecl(java.lang.String, java.lang.String, java.lang.String), DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
                        throws org.xml.sax.SAXException
Report a parsed external entity declaration.

Only the effective (first) declaration for each entity will be reported.

Specified by:
externalEntityDecl in interface org.xml.sax.ext.DeclHandler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
publicId - The declared public identifier of the entity, or null if none was declared.
systemId - The declared system identifier of the entity.
Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
internalEntityDecl(java.lang.String, java.lang.String), DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

accumDefaultEntity

protected int accumDefaultEntity(char ch,
                                 int i,
                                 char[] chars,
                                 int len,
                                 boolean escLF)
                          throws org.xml.sax.SAXException
Handle one of the default entities, return false if it is not a default entity.

Parameters:
ch - character to be escaped.
i - index into character array.
chars - non-null reference to character array.
len - length of chars.
escLF - true if the linefeed should be escaped.
Returns:
i+1 if the character was written, else i.
Throws:
org.xml.sax.SAXException

accumDefaultEscape

protected int accumDefaultEscape(char ch,
                                 int i,
                                 char[] chars,
                                 int len,
                                 boolean escLF)
                          throws org.xml.sax.SAXException
Escape and m_writer.write a character.

Parameters:
ch - character to be escaped.
i - index into character array.
chars - non-null reference to character array.
len - length of chars.
escLF - true if the linefeed should be escaped.
Returns:
i+1 if the character was written, else i.
Throws:
org.xml.sax.SAXException

canConvert

public boolean canConvert(char ch)
Tell if this character can be written without escaping.


writeAttrString

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

Parameters:
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.
Throws:
org.xml.sax.SAXException

shouldIndent

protected boolean shouldIndent()
Tell if, based on space preservation constraints and the doIndent property, if an indent should occur.

Returns:
True if an indent should occur.

printSpace

public void printSpace(int n)
                throws org.xml.sax.SAXException
Prints n spaces.

Parameters:
n - Number of spaces to print.
Throws:
org.xml.sax.SAXException - if an error occurs when writing.

indent

public void indent(int n)
            throws org.xml.sax.SAXException
Prints a newline character and n spaces.

Parameters:
n - Number of spaces to print.
Throws:
org.xml.sax.SAXException - if an error occurs during writing.

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
Parameters:
output - The output stream

getOutputStream

public OutputStream getOutputStream()
Get the output stream where the events will be serialized to.

Specified by:
getOutputStream in interface Serializer
Returns:
reference to the result stream, or null of only a writer was set.

setWriter

public void setWriter(Writer writer)
Specifies a writer to which the document should be serialized. This method should not be called while the serializer is in the process of serializing a document.

Specified by:
setWriter in interface Serializer
Parameters:
writer - The output writer stream

getWriter

public Writer getWriter()
Get the character stream where the events will be serialized to.

Specified by:
getWriter in interface Serializer
Returns:
Reference to the result Writer, or null.

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

getOutputFormat

public Properties getOutputFormat()
Returns the output format for this serializer.

Specified by:
getOutputFormat in interface Serializer
Returns:
The output format in use

asContentHandler

public org.xml.sax.ContentHandler asContentHandler()
                                            throws IOException
Return a ContentHandler interface into this serializer. If the serializer does not support the ContentHandler interface, it should return null.

Specified by:
asContentHandler in interface Serializer
Returns:
A ContentHandler interface into this serializer, or null if the serializer is not SAX 2 capable
Throws:
IOException - An I/O exception occured

asDOMSerializer

public DOMSerializer asDOMSerializer()
                              throws IOException
Return a DOMSerializer interface into this serializer. If the serializer does not support the DOMSerializer interface, it should return null.

Specified by:
asDOMSerializer in interface Serializer
Returns:
A DOMSerializer interface into this serializer, or null if the serializer is not DOM capable
Throws:
IOException - An I/O exception occured

reset

public boolean reset()
Resets the serializer. If this method returns true, the serializer may be used for subsequent serialization of new documents. It is possible to change the output format and output stream prior to serializing, or to use the existing output format and output stream.

Specified by:
reset in interface Serializer
Returns:
True if serializer has been reset and can be reused

serialize

public void serialize(org.w3c.dom.Node node)
               throws IOException
Serializes the DOM node. Throws an exception only if an I/O exception occured while serializing.

Specified by:
serialize in interface DOMSerializer
Parameters:
node - Node to serialize.
Throws:
IOException - An I/O exception occured while serializing