org.apache.xml.serializer
Class ToStream

java.lang.Object
  extended by org.apache.xml.serializer.SerializerBase
      extended by org.apache.xml.serializer.ToStream
All Implemented Interfaces:
DOMSerializer, ExtendedContentHandler, ExtendedLexicalHandler, SerializationHandler, Serializer, SerializerConstants, XSLOutputAttributes, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
ToHTMLStream, ToTextStream, ToXMLStream

public abstract class ToStream
extends SerializerBase

This abstract class is a base class for other stream serializers (xml, html, text ...) that write output to a stream.


Nested Class Summary
(package private) static class ToStream.BoolStack
          Simple stack for boolean values.
private static class ToStream.WritertoStringBuffer
          This inner class is used only to collect attribute values written by the method writeAttrString() into a string buffer.
 
Field Summary
private static java.lang.String COMMENT_BEGIN
           
private static java.lang.String COMMENT_END
           
protected  boolean m_cdataStartCalled
          remembers if we are in between the startCDATA() and endCDATA() callbacks
protected  CharInfo m_charInfo
          Map that tells which characters should have special treatment, and it provides character to entity name lookup.
protected  ToStream.BoolStack m_disableOutputEscapingStates
          Stack to keep track of disabling output escaping.
(package private)  EncodingInfo m_encodingInfo
          The encoding information associated with this serializer.
protected  boolean m_escaping
          Taken from XSLTC
private  boolean m_expandDTDEntities
          If this flag is true DTD entity references are not left as-is, which is exiting older behavior.
protected  boolean m_inDoctype
          Tells if we're in an internal document type subset.
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
          The system line separator for writing out line breaks.
protected  int m_lineSepLen
          The length of the line seperator, since the write is done one character at a time.
protected  boolean m_lineSepUse
          True if the the system line separator is to be used.
(package private)  java.io.OutputStream m_outputStream
           
protected  ToStream.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.
protected  boolean m_spaceBeforeClose
          Add space before '/>' for XHTML.
(package private)  boolean m_startNewLine
          Flag to signal that a newline should be added.
private  boolean m_writer_set_by_user
           
private static char[] s_systemLineSep
           
 
Fields inherited from class org.apache.xml.serializer.SerializerBase
m_attrBuff, m_attributes, m_CdataElems, m_cdataTagOpen, m_charsBuff, m_docIsEmpty, m_doctypePublic, m_doctypeSystem, m_doIndent, m_elemContext, m_indentAmount, m_inEntityRef, m_inExternalDTD, m_mediatype, m_needToCallStartDocument, m_needToOutputDocTypeDecl, m_prefixMap, m_shouldNotWriteXMLHeader, m_sourceLocator, m_standaloneWasSpecified, m_StringOfCDATASections, m_tracer, m_version, m_writer, 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, XML_PREFIX, XMLNS_PREFIX, XMLNS_URI, XMLVERSION10, XMLVERSION11
 
Constructor Summary
ToStream()
          Default constructor
 
Method Summary
(package private)  int accumDefaultEntity(java.io.Writer writer, char ch, int i, char[] chars, int len, boolean fromTextNode, boolean escLF)
          Handle one of the default entities, return false if it is not a default entity.
private  int accumDefaultEscape(java.io.Writer writer, char ch, int i, char[] chars, int len, boolean fromTextNode, boolean escLF)
          Escape and writer.write a character.
 boolean addAttributeAlways(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean xslAttribute)
          Adds the given attribute to the set of attributes, even if there is no currently open element.
private  void addCdataSectionElement(java.lang.String URI_and_localName, java.util.Vector v)
          Adds a URI/LocalName pair of strings to the list.
 void addCdataSectionElements(java.lang.String URI_and_localNames)
          Remembers the cdata sections specified in the cdata-section-elements by appending the given cdata section elements to the list.
 void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
          Report an attribute type declaration.
protected  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 characters(java.lang.String s)
          Receive notification of character data.
protected  void charactersRaw(char[] ch, int start, int length)
          If available, when the disable-output-escaping attribute is used, output raw text without escaping.
protected  void closeCDATA()
          This helper method to writes out "]]>" when closing a CDATA section.
protected  void closeStartTag()
          For the enclosing elements starting tag write out out any attributes followed by ">"
 void comment(char[] ch, int start, int length)
          Receive notification of an XML comment anywhere in the document.
private  void DTDprolog()
          A private helper method to output the
 void elementDecl(java.lang.String name, java.lang.String model)
          Report an element type declaration.
 void endCDATA()
          Report the end of a CDATA section.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(java.lang.String name)
          Receive notification of the end of an element.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String name)
          Receive notification of the end of an element.
 void endNonEscaping()
          Ends an un-escaping section.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI Namespace mapping.
protected  java.lang.String ensureAttributesNamespaceIsDeclared(java.lang.String ns, java.lang.String localName, java.lang.String rawName)
          Makes sure that the namespace URI for the given qualified attribute name is declared.
(package private)  void ensurePrefixIsDeclared(java.lang.String ns, java.lang.String rawName)
           
protected  boolean escapingNotNeeded(char ch)
          Tell if this character can be written without escaping.
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report a parsed external entity declaration.
protected  void firePseudoAttributes()
          To fire off the pseudo characters of attributes, as they currently exist.
 void flushPending()
          This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.
protected  void flushWriter()
          Flush the formatter's result stream.
 int getIndentAmount()
          Returns the m_indentAmount.
 java.util.Properties getOutputFormat()
          Returns the output format for this serializer.
 java.io.OutputStream getOutputStream()
          Get the output stream where the events will be serialized to.
 java.io.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.
protected  void indent()
          Indent at the current element nesting depth.
protected  void indent(int depth)
          Might print a newline character and the indentation amount of the given depth.
 void internalEntityDecl(java.lang.String name, java.lang.String value)
          Report an internal entity declaration.
private static boolean isCharacterInC0orC1Range(char ch)
          This method checks if a given character is between C0 or C1 range of Control characters.
private  boolean isEscapingDisabled()
          Tell if the character escaping should be disabled for the current state.
private static boolean isNELorLSEPCharacter(char ch)
          This method checks if a given character either NEL (0x85) or LSEP (0x2028) These are new end of line charcters added in XML 1.1.
 void notationDecl(java.lang.String name, java.lang.String pubID, java.lang.String sysID)
          If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.
(package private)  void outputDocTypeDecl(java.lang.String name, boolean closeDecl)
          Output the doc type declaration.
(package private)  void outputEntityDecl(java.lang.String name, java.lang.String value)
          Output the doc type declaration.
protected  void outputLineSep()
          Output a system-dependent line break.
private  void printSpace(int n)
          Prints n spaces.
 void processAttributes(java.io.Writer writer, int nAttrs)
          Process the attributes, which means to write out the currently collected attributes to the writer.
private  int processDirty(char[] chars, int end, int i, char ch, int lastDirty, boolean fromTextNode)
          Process a dirty character and any preeceding clean characters that were not yet processed.
private  int processLineFeed(char[] chars, int i, int lastProcessed, java.io.Writer writer)
           
 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).
private  void resetToStream()
          Reset all of the fields owned by ToStream class
 void serialize(org.w3c.dom.Node node)
          Serializes the DOM node.
private  void setCdataSectionElements(java.lang.String key, java.util.Properties props)
          Searches for the list of qname properties with the specified key in the property list.
 void setCdataSectionElements(java.util.Vector URI_and_localNames)
          Remembers the cdata sections specified in the cdata-section-elements.
 void setContentHandler(org.xml.sax.ContentHandler ch)
          Set the SAX Content handler that the serializer sends its output to.
 void setDTDEntityExpansion(boolean expand)
          If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true;
 void setEncoding(java.lang.String encoding)
          Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 boolean setEscaping(boolean escape)
          Turns special character escaping on/off.
 void setIndentAmount(int m_indentAmount)
          Sets the m_indentAmount.
 boolean setLineSepUse(boolean use_sytem_line_break)
          Set if the operating systems end-of-line line separator should be used when serializing.
 void setNewLine(char[] eolChars)
          Sets the end of line characters to be used during serialization
 void setOutputFormat(java.util.Properties format)
          Specifies an output format for this serializer.
 void setOutputStream(java.io.OutputStream output)
          Specifies an output stream to which the document should be serialized.
private  void setOutputStreamInternal(java.io.OutputStream output, boolean setByUser)
           
(package private)  void setProp(java.lang.String name, java.lang.String val, boolean defaultVal)
           
 void setTransformer(javax.xml.transform.Transformer transformer)
          Sets the transformer associated with this serializer
 void setWriter(java.io.Writer writer)
          Specifies a writer to which the document should be serialized.
private  void setWriterInternal(java.io.Writer writer, boolean setByUser)
           
protected  boolean shouldIndent()
          Tell if, based on space preservation constraints and the doIndent property, if an indent should occur.
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report the start of DTD declarations, if any.
 void startElement(java.lang.String elementName)
          This method is used to notify of the start of an element
 void startElement(java.lang.String elementNamespaceURI, java.lang.String elementLocalName, java.lang.String elementName)
          Receive notification of the beginning of an element, additional namespace or attribute information can occur before or after this call, that is associated with this element.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes atts)
          Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.
 void startEntity(java.lang.String name)
          Report the beginning of an entity.
 void startNonEscaping()
          Starts an un-escaping section.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Begin the scope of a prefix-URI Namespace mapping just before another element is about to start.
 boolean startPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush)
          Handle a prefix/uri mapping, which is associated with a startElement() that is soon to follow.
 void unparsedEntityDecl(java.lang.String name, java.lang.String pubID, java.lang.String sysID, java.lang.String notationName)
          If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.
 void writeAttrString(java.io.Writer writer, java.lang.String string, java.lang.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, boolean useSystemLineSeparator)
          Normalize the characters, but don't escape.
private  void writeOutCleanChars(char[] chars, int i, int lastProcessed)
           
protected  int writeUTF16Surrogate(char c, char[] ch, int i, int end)
          Once a surrogate has been detected, write out the pair of characters if it is in the encoding, or if there is no encoding, otherwise write out an entity reference of the value of the unicode code point of the character represented by the high/low surrogate pair.
 
Methods inherited from class org.apache.xml.serializer.SerializerBase
addAttribute, addAttribute, addAttribute, addAttributes, addXSLAttribute, asContentHandler, asDOM3Serializer, asDOMSerializer, characters, close, comment, documentIsEmpty, endEntity, entityReference, error, fatalError, fireCDATAEvent, fireCharEvent, fireCommentEvent, fireEndDoc, fireEndElem, fireEndEntity, fireEntityReference, fireEscapingEvent, fireStartDoc, fireStartElem, fireStartEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getFirstCharLocName, getIndent, getLocalName, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputPropDefaultKeys, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getOutputPropKeys, getPrefix, getPrefixPart, getStandalone, getTransformer, getVersion, initCDATA, initCdataElems, inTemporaryOutputState, isCdataSection, namespaceAfterStartElement, patchName, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setIndent, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setStandaloneInternal, setVersion, startDocument, startDocumentInternal, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xml.serializer.ExtendedContentHandler
addUniqueAttribute
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, processingInstruction
 

Field Detail

COMMENT_BEGIN

private static final java.lang.String COMMENT_BEGIN
See Also:
Constant Field Values

COMMENT_END

private static final java.lang.String COMMENT_END
See Also:
Constant Field Values

m_disableOutputEscapingStates

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


m_encodingInfo

EncodingInfo m_encodingInfo
The encoding information associated with this serializer. Although initially there is no encoding, there is a dummy EncodingInfo object that will say that every character is in the encoding. This is useful for a serializer that is in temporary output state and has no associated encoding. A serializer in final output state will have an encoding, and will worry about whether single chars or surrogate pairs of high/low chars form characters in the output encoding.


m_preserves

protected ToStream.BoolStack m_preserves
Stack to keep track of whether or not we need to preserve whitespace. Used to push/pop values used for the field m_ispreserve, but m_ispreserve is only relevant if m_doIndent is true. If m_doIndent is false this field has no impact.


m_ispreserve

protected boolean m_ispreserve
State flag to tell if preservation of whitespace is important. Used only in shouldIndent() but only if m_doIndent is true. If m_doIndent is false this flag has no impact.


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. Used in endDocument() and shouldIndent() but only if m_doIndent is true. If m_doIndent is false this flag has no impact.


s_systemLineSep

private static final char[] s_systemLineSep

m_lineSep

protected char[] m_lineSep
The system line separator for writing out line breaks. The default value is from the system property, but this value can be set through the xsl:output extension attribute xalan:line-separator.


m_lineSepUse

protected boolean m_lineSepUse
True if the the system line separator is to be used.


m_lineSepLen

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


m_charInfo

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


m_shouldFlush

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


m_spaceBeforeClose

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


m_startNewLine

boolean m_startNewLine
Flag to signal that a newline should be added. Used only in indent() which is called only if m_doIndent is true. If m_doIndent is false this flag has no impact.


m_inDoctype

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


m_isUTF8

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


m_cdataStartCalled

protected boolean m_cdataStartCalled
remembers if we are in between the startCDATA() and endCDATA() callbacks


m_expandDTDEntities

private boolean m_expandDTDEntities
If this flag is true DTD entity references are not left as-is, which is exiting older behavior.


m_escaping

protected boolean m_escaping
Taken from XSLTC


m_outputStream

java.io.OutputStream m_outputStream

m_writer_set_by_user

private boolean m_writer_set_by_user
Constructor Detail

ToStream

public ToStream()
Default constructor

Method Detail

closeCDATA

protected void closeCDATA()
                   throws org.xml.sax.SAXException
This helper method to writes out "]]>" when closing a CDATA section.

Throws:
org.xml.sax.SAXException

serialize

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

Parameters:
node - Node to serialize.
Throws:
java.io.IOException - An I/O exception occured while serializing

flushWriter

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

Throws:
org.xml.sax.SAXException

getOutputStream

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

Returns:
reference to the result stream, or null of only a writer was set.

elementDecl

public void elementDecl(java.lang.String name,
                        java.lang.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.

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.

internalEntityDecl

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

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

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)

outputEntityDecl

void outputEntityDecl(java.lang.String name,
                      java.lang.String value)
                throws java.io.IOException
Output the doc type declaration.

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

outputLineSep

protected final void outputLineSep()
                            throws java.io.IOException
Output a system-dependent line break.

Throws:
org.xml.sax.SAXException
java.io.IOException

setProp

void setProp(java.lang.String name,
             java.lang.String val,
             boolean defaultVal)
Overrides:
setProp in class SerializerBase
Parameters:
name - The name of the property, e.g. "{http://myprop}indent-tabs" or "indent".
val - The value of the property, e.g. "4"
defaultVal - true if this is a default value being set for the property as opposed to a user define on, set say explicitly in the stylesheet or via JAXP

setOutputFormat

public void setOutputFormat(java.util.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.

Parameters:
format - The output format to use

getOutputFormat

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

Returns:
The output format in use

setWriter

public void setWriter(java.io.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.

Parameters:
writer - The output writer stream

setWriterInternal

private void setWriterInternal(java.io.Writer writer,
                               boolean setByUser)

setLineSepUse

public boolean setLineSepUse(boolean use_sytem_line_break)
Set if the operating systems end-of-line line separator should be used when serializing. If set false NL character (decimal 10) is left alone, otherwise the new-line will be replaced on output with the systems line separator. For example on UNIX this is NL, while on Windows it is two characters, CR NL, where CR is the carriage-return (decimal 13).

Parameters:
use_sytem_line_break - True if an input NL is replaced with the operating systems end-of-line separator.
Returns:
The previously set value of the serializer.

setOutputStream

public void setOutputStream(java.io.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.

Parameters:
output - The output stream

setOutputStreamInternal

private void setOutputStreamInternal(java.io.OutputStream output,
                                     boolean setByUser)

setEscaping

public boolean setEscaping(boolean escape)
Description copied from interface: SerializationHandler
Turns special character escaping on/off. Note that characters will never, even if this option is set to 'true', be escaped within CDATA sections in output XML documents.

Parameters:
escape - true if escaping is to be set on.
See Also:
SerializationHandler.setEscaping(boolean)

indent

protected void indent(int depth)
               throws java.io.IOException
Might print a newline character and the indentation amount of the given depth.

Parameters:
depth - the indentation depth (element nesting depth)
Throws:
org.xml.sax.SAXException - if an error occurs during writing.
java.io.IOException

indent

protected void indent()
               throws java.io.IOException
Indent at the current element nesting depth.

Throws:
java.io.IOException

printSpace

private void printSpace(int n)
                 throws java.io.IOException
Prints n spaces.

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

attributeDecl

public void attributeDecl(java.lang.String eName,
                          java.lang.String aName,
                          java.lang.String type,
                          java.lang.String valueDefault,
                          java.lang.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.

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.

getWriter

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

Returns:
Reference to the result Writer, or null.

externalEntityDecl

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

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

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)

escapingNotNeeded

protected boolean escapingNotNeeded(char ch)
Tell if this character can be written without escaping.


writeUTF16Surrogate

protected int writeUTF16Surrogate(char c,
                                  char[] ch,
                                  int i,
                                  int end)
                           throws java.io.IOException
Once a surrogate has been detected, write out the pair of characters if it is in the encoding, or if there is no encoding, otherwise write out an entity reference of the value of the unicode code point of the character represented by the high/low surrogate pair.

An exception is thrown if there is no low surrogate in the pair, because the array ends unexpectely, or if the low char is there but its value is such that it is not a low surrogate.

Parameters:
c - the first (high) part of the surrogate, which must be confirmed before calling this method.
ch - Character array.
i - position Where the surrogate was detected.
end - The end index of the significant characters.
Returns:
0 if the pair of characters was written out as-is, the unicode code point of the character represented by the surrogate pair if an entity reference with that value was written out.
Throws:
java.io.IOException
org.xml.sax.SAXException - if invalid UTF-16 surrogate detected.

accumDefaultEntity

int accumDefaultEntity(java.io.Writer writer,
                       char ch,
                       int i,
                       char[] chars,
                       int len,
                       boolean fromTextNode,
                       boolean escLF)
                 throws java.io.IOException
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.
fromTextNode - true if the characters being processed are from a text node, false if they are from an attribute value
escLF - true if the linefeed should be escaped.
Returns:
i+1 if the character was written, else i.
Throws:
java.io.IOException

writeNormalizedChars

void writeNormalizedChars(char[] ch,
                          int start,
                          int length,
                          boolean isCData,
                          boolean useSystemLineSeparator)
                    throws java.io.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.
useSystemLineSeparator - true if the operating systems end-of-line separator should be output rather than a new-line character.
Throws:
java.io.IOException
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()

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

cdata

protected 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

isEscapingDisabled

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

Returns:
true if the character escaping should be disabled.

charactersRaw

protected 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

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

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

processLineFeed

private int processLineFeed(char[] chars,
                            int i,
                            int lastProcessed,
                            java.io.Writer writer)
                     throws java.io.IOException
Throws:
java.io.IOException

writeOutCleanChars

private void writeOutCleanChars(char[] chars,
                                int i,
                                int lastProcessed)
                         throws java.io.IOException
Throws:
java.io.IOException

isCharacterInC0orC1Range

private static boolean isCharacterInC0orC1Range(char ch)
This method checks if a given character is between C0 or C1 range of Control characters. This method is added to support Control Characters for XML 1.1 If a given character is TAB (0x09), LF (0x0A) or CR (0x0D), this method return false. Since they are whitespace characters, no special processing is needed.

Parameters:
ch -
Returns:
boolean

isNELorLSEPCharacter

private static boolean isNELorLSEPCharacter(char ch)
This method checks if a given character either NEL (0x85) or LSEP (0x2028) These are new end of line charcters added in XML 1.1. These characters must be written as Numeric Character References (NCR) in XML 1.1 output document.

Parameters:
ch -
Returns:
boolean

processDirty

private int processDirty(char[] chars,
                         int end,
                         int i,
                         char ch,
                         int lastDirty,
                         boolean fromTextNode)
                  throws java.io.IOException
Process a dirty character and any preeceding clean characters that were not yet processed.

Parameters:
chars - array of characters being processed
end - one (1) beyond the last character in chars to be processed
i - the index of the dirty character
ch - the character in chars[i]
lastDirty - the last dirty character previous to i
fromTextNode - true if the characters being processed are from a text node, false if they are from an attribute value.
Returns:
the index of the last character processed
Throws:
java.io.IOException

characters

public void characters(java.lang.String s)
                throws org.xml.sax.SAXException
Receive notification of character data.

Parameters:
s - The string of characters to process.
Throws:
org.xml.sax.SAXException

accumDefaultEscape

private int accumDefaultEscape(java.io.Writer writer,
                               char ch,
                               int i,
                               char[] chars,
                               int len,
                               boolean fromTextNode,
                               boolean escLF)
                        throws java.io.IOException
Escape and 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.
fromTextNode - true if the characters being processed are from a text node, false if the characters being processed are from an attribute value.
escLF - true if the linefeed should be escaped.
Returns:
i+1 if a character was written, i+2 if two characters were written out, else return i.
Throws:
org.xml.sax.SAXException
java.io.IOException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String name,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.

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

startElement

public void startElement(java.lang.String elementNamespaceURI,
                         java.lang.String elementLocalName,
                         java.lang.String elementName)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element, additional namespace or attribute information can occur before or after this call, that is associated with this element.

Parameters:
elementNamespaceURI - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
elementLocalName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
elementName - The element type name.
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

startElement

public void startElement(java.lang.String elementName)
                  throws org.xml.sax.SAXException
Description copied from interface: ExtendedContentHandler
This method is used to notify of the start of an element

Parameters:
elementName - the fully qualified name of the element
Throws:
org.xml.sax.SAXException

outputDocTypeDecl

void outputDocTypeDecl(java.lang.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:
java.io.IOException
org.xml.sax.SAXException

processAttributes

public void processAttributes(java.io.Writer writer,
                              int nAttrs)
                       throws java.io.IOException,
                              org.xml.sax.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
Throws:
java.io.IOException
org.xml.sax.SAXException

writeAttrString

public void writeAttrString(java.io.Writer writer,
                            java.lang.String string,
                            java.lang.String encoding)
                     throws java.io.IOException
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:
java.io.IOException

endElement

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

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

endElement

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

Parameters:
name - The element type name
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

startPrefixMapping

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

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)

startPrefixMapping

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

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
shouldFlush - true if any open tags need to be closed first, this will impact which element the mapping applies to (open parent, or its up comming child)
Returns:
returns true if the call made a change to the current namespace information, false if it did not change anything, e.g. if the prefix/namespace mapping was already in scope from before.
Throws:
org.xml.sax.SAXException - The client may throw an exception during processing.
See Also:
ExtendedContentHandler.startPrefixMapping(java.lang.String, java.lang.String, boolean)

comment

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

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.

endCDATA

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

Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
startCDATA()

endDTD

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

Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
startDTD(java.lang.String, java.lang.String, java.lang.String)

endPrefixMapping

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

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)

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.

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(java.lang.String name)
                   throws org.xml.sax.SAXException
Receive notification of a skipped entity.

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)

startCDATA

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

Throws:
org.xml.sax.SAXException - The application may raise an exception.
See Also:
endCDATA()

startEntity

public void startEntity(java.lang.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.

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:
SerializerBase.endEntity(java.lang.String), DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

closeStartTag

protected void closeStartTag()
                      throws org.xml.sax.SAXException
For the enclosing elements starting tag write out out any attributes followed by ">"

Throws:
org.xml.sax.SAXException

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.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.

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)

getIndentAmount

public int getIndentAmount()
Returns the m_indentAmount.

Specified by:
getIndentAmount in interface XSLOutputAttributes
Overrides:
getIndentAmount in class SerializerBase
Returns:
int

setIndentAmount

public void setIndentAmount(int m_indentAmount)
Sets the m_indentAmount.

Specified by:
setIndentAmount in interface SerializationHandler
Overrides:
setIndentAmount in class SerializerBase
Parameters:
m_indentAmount - The m_indentAmount to set

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.

setCdataSectionElements

private void setCdataSectionElements(java.lang.String key,
                                     java.util.Properties props)
Searches for the list of qname properties with the specified key in the property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

Parameters:
key - the property key.
props - the list of properties to search in. Sets the vector of local-name/URI pairs of the cdata section elements specified in the cdata-section-elements property. This method is essentially a copy of getQNameProperties() from OutputProperties. Eventually this method should go away and a call to setCdataSectionElements(Vector v) should be made directly.

addCdataSectionElement

private void addCdataSectionElement(java.lang.String URI_and_localName,
                                    java.util.Vector v)
Adds a URI/LocalName pair of strings to the list.

Parameters:
URI_and_localName - String of the form "{uri}local" or "local"

setCdataSectionElements

public void setCdataSectionElements(java.util.Vector URI_and_localNames)
Remembers the cdata sections specified in the cdata-section-elements. The "official way to set URI and localName pairs. This method should be used by both Xalan and XSLTC.

Parameters:
URI_and_localNames - a vector of pairs of Strings (URI/local)

ensureAttributesNamespaceIsDeclared

protected java.lang.String ensureAttributesNamespaceIsDeclared(java.lang.String ns,
                                                               java.lang.String localName,
                                                               java.lang.String rawName)
                                                        throws org.xml.sax.SAXException
Makes sure that the namespace URI for the given qualified attribute name is declared.

Parameters:
ns - the namespace URI
rawName - the qualified name
Returns:
returns null if no action is taken, otherwise it returns the prefix used in declaring the namespace.
Throws:
org.xml.sax.SAXException

ensurePrefixIsDeclared

void ensurePrefixIsDeclared(java.lang.String ns,
                            java.lang.String rawName)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

flushPending

public void flushPending()
                  throws org.xml.sax.SAXException
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.

Throws:
org.xml.sax.SAXException

setContentHandler

public void setContentHandler(org.xml.sax.ContentHandler ch)
Description copied from interface: SerializationHandler
Set the SAX Content handler that the serializer sends its output to. This method only applies to a ToSAXHandler, not to a ToStream serializer.

See Also:
Serializer.asContentHandler(), ToSAXHandler

addAttributeAlways

public boolean addAttributeAlways(java.lang.String uri,
                                  java.lang.String localName,
                                  java.lang.String rawName,
                                  java.lang.String type,
                                  java.lang.String value,
                                  boolean xslAttribute)
Adds the given attribute to the set of attributes, even if there is no currently open element. This is useful if a SAX startPrefixMapping() should need to add an attribute before the element name is seen. This method is a copy of its super classes method, except that some tracing of events is done. This is so the tracing is only done for stream serializers, not for SAX ones.

Overrides:
addAttributeAlways in class SerializerBase
Parameters:
uri - the URI of the attribute
localName - the local name of the attribute
rawName - the qualified name of the attribute
type - the type of the attribute (probably CDATA)
value - the value of the attribute
xslAttribute - true if this attribute is coming from an xsl:attribute element.
Returns:
true if the attribute value was added, false if the attribute already existed and the value was replaced with the new value.

firePseudoAttributes

protected void firePseudoAttributes()
To fire off the pseudo characters of attributes, as they currently exist. This method should be called everytime an attribute is added, or when an attribute value is changed, or an element is created.


setTransformer

public void setTransformer(javax.xml.transform.Transformer transformer)
Description copied from class: SerializerBase
Sets the transformer associated with this serializer

Specified by:
setTransformer in interface SerializationHandler
Overrides:
setTransformer in class SerializerBase
Parameters:
transformer - the transformer associated with this serializer.
See Also:
SerializationHandler.setTransformer(Transformer)

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 class SerializerBase
Returns:
true if the class was successfuly reset.

resetToStream

private void resetToStream()
Reset all of the fields owned by ToStream class


setEncoding

public void setEncoding(java.lang.String encoding)
Sets the character encoding coming from the xsl:output encoding stylesheet attribute.

Specified by:
setEncoding in interface XSLOutputAttributes
Overrides:
setEncoding in class SerializerBase
Parameters:
encoding - the character encoding

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String pubID,
                         java.lang.String sysID)
                  throws org.xml.sax.SAXException
If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.

Specified by:
notationDecl in interface org.xml.sax.DTDHandler
Overrides:
notationDecl in class SerializerBase
Throws:
org.xml.sax.SAXException
See Also:
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String pubID,
                               java.lang.String sysID,
                               java.lang.String notationName)
                        throws org.xml.sax.SAXException
If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.

Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Overrides:
unparsedEntityDecl in class SerializerBase
Throws:
org.xml.sax.SAXException
See Also:
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

DTDprolog

private void DTDprolog()
                throws org.xml.sax.SAXException,
                       java.io.IOException
A private helper method to output the

Throws:
org.xml.sax.SAXException
java.io.IOException

setDTDEntityExpansion

public void setDTDEntityExpansion(boolean expand)
If set to false the serializer does not expand DTD entities, but leaves them as is, the default value is true;

Specified by:
setDTDEntityExpansion in interface SerializationHandler
Overrides:
setDTDEntityExpansion in class SerializerBase
Parameters:
expand - true if DTD entities are to be expanded, false if they are to be left as DTD entity references.

setNewLine

public void setNewLine(char[] eolChars)
Sets the end of line characters to be used during serialization

Parameters:
eolChars - A character array corresponding to the characters to be used.

addCdataSectionElements

public void addCdataSectionElements(java.lang.String URI_and_localNames)
Remembers the cdata sections specified in the cdata-section-elements by appending the given cdata section elements to the list. This method can be called multiple times, but once an element is put in the list of cdata section elements it can not be removed. This method should be used by both Xalan and XSLTC.

Parameters:
URI_and_localNames - a whitespace separated list of element names, each element is a URI in curly braces (optional) and a local name. An example of such a parameter is: "{http://company.com}price {myURI2}book chapter"