Save This Page
Home » openjdk-7 » com.sun.org.apache.xml.internal » serializer » [javadoc | source]
com.sun.org.apache.xml.internal.serializer
abstract public class: ToStream [javadoc | source]
java.lang.Object
   com.sun.org.apache.xml.internal.serializer.SerializerBase
      com.sun.org.apache.xml.internal.serializer.ToStream

All Implemented Interfaces:
    SerializationHandler, SerializerConstants

Direct Known Subclasses:
    ToXMLStream, ToTextStream, ToHTMLStream

This abstract class is a base class for other stream serializers (xml, html, text ...) that write output to a stream.
Nested Class Summary:
static final class  ToStream.BoolStack  Simple stack for boolean values. This class is a copy of the one in com.sun.org.apache.xml.internal.utils. It exists to cut the serializers dependancy on that package. A minor changes from that package are: doesn't implement Clonable 
Field Summary
protected  ToStream.BoolStack m_disableOutputEscapingStates    Stack to keep track of disabling output escaping. 
 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. 
 Method m_canConvertMeth    Method reference to the sun.io.CharToByteConverter#canConvert method for this encoding. Invalid if m_charToByteConverter is null. 
 boolean m_triedToGetConverter    Boolean that tells if we already tried to get the converter. 
 Object m_charToByteConverter    Opaque reference to the sun.io.CharToByteConverter for this encoding. 
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. 
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. 
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. 
protected  int m_maxCharacter    The maximum character size before we have to resort to escaping. 
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. 
protected  boolean m_lineSepUse    True if the the system line separator is to be used. 
protected  int m_lineSepLen    The length of the line seperator, since the write is done one character at a time. 
protected  CharInfo m_charInfo    Map that tells which characters should have special treatment, and it provides character to entity name lookup. 
 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. 
 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. 
protected  boolean m_inDoctype    Tells if we're in an internal document type subset. 
 boolean m_isUTF8    Flag to quickly tell if the encoding is UTF8. 
protected  Properties m_format    The xsl:output properties. 
protected  boolean m_cdataStartCalled    remembers if we are in between the startCDATA() and endCDATA() callbacks 
Fields inherited from com.sun.org.apache.xml.internal.serializer.SerializerBase:
m_needToCallStartDocument,  m_cdataTagOpen,  m_attributes,  m_inEntityRef,  m_inExternalDTD,  m_needToOutputDocTypeDecl,  m_standaloneWasSpecified,  m_doIndent,  m_indentAmount,  m_cdataSectionElements,  m_prefixMap,  m_tracer,  m_sourceLocator,  m_writer,  m_elemContext,  m_charsBuff,  m_attrBuff,  m_needToCallSetDocumentInfo
Constructor:
 public ToStream() 
Method from com.sun.org.apache.xml.internal.serializer.ToStream Summary:
accumDefaultEntity,   accumDefaultEscape,   addAttributeAlways,   attributeDecl,   cdata,   characters,   characters,   charactersRaw,   closeCDATA,   closeStartTag,   comment,   elementDecl,   endCDATA,   endDTD,   endElement,   endElement,   endNonEscaping,   endPrefixMapping,   ensureAttributesNamespaceIsDeclared,   ensurePrefixIsDeclared,   escapingNotNeeded,   externalEntityDecl,   firePseudoAttributes,   flushPending,   flushWriter,   getIndentAmount,   getOutputFormat,   getOutputStream,   getWriter,   ignorableWhitespace,   indent,   indent,   init,   internalEntityDecl,   isUTF16Surrogate,   notationDecl,   outputDocTypeDecl,   outputEntityDecl,   outputLineSep,   processAttributes,   reset,   serialize,   setCdataSectionElements,   setContentHandler,   setDTDEntityExpansion,   setEncoding,   setEscaping,   setIndentAmount,   setLineSepUse,   setOutputFormat,   setOutputStream,   setTransformer,   setWriter,   shouldIndent,   skippedEntity,   startCDATA,   startDTD,   startElement,   startElement,   startElement,   startEntity,   startNonEscaping,   startPrefixMapping,   startPrefixMapping,   unparsedEntityDecl,   writeAttrString,   writeNormalizedChars,   writeUTF16Surrogate
Methods from com.sun.org.apache.xml.internal.serializer.SerializerBase:
addAttribute,   addAttribute,   addAttribute,   addAttributeAlways,   addAttributes,   addXSLAttribute,   asContentHandler,   asDOMSerializer,   characters,   close,   comment,   endEntity,   entityReference,   error,   fatalError,   fireCDATAEvent,   fireCharEvent,   fireCommentEvent,   fireEndDoc,   fireEndElem,   fireEndEntity,   fireEntityReference,   fireEscapingEvent,   fireStartDoc,   fireStartElem,   fireStartEntity,   getDoctypePublic,   getDoctypeSystem,   getEncoding,   getIndent,   getIndentAmount,   getLocalName,   getMediaType,   getNamespaceMappings,   getNamespaceURI,   getNamespaceURIFromPrefix,   getOmitXMLDeclaration,   getPrefix,   getPrefixPart,   getStandalone,   getTransformer,   getVersion,   inTemporaryOutputState,   initCDATA,   isCdataSection,   namespaceAfterStartElement,   notationDecl,   patchName,   reset,   setDTDEntityExpansion,   setDoctype,   setDoctypePublic,   setDoctypeSystem,   setDocumentInfo,   setDocumentLocator,   setEncoding,   setIndent,   setIndentAmount,   setMediaType,   setNamespaceMappings,   setOmitXMLDeclaration,   setSourceLocator,   setStandalone,   setStandaloneInternal,   setTransformer,   setVersion,   startDocument,   startDocumentInternal,   unparsedEntityDecl,   warning
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.org.apache.xml.internal.serializer.ToStream Detail:
 protected int accumDefaultEntity(Writer writer,
    char ch,
    int i,
    char[] chars,
    int len,
    boolean fromTextNode,
    boolean escLF) throws IOException 
    Handle one of the default entities, return false if it is not a default entity.
 protected int accumDefaultEscape(Writer writer,
    char ch,
    int i,
    char[] chars,
    int len,
    boolean fromTextNode,
    boolean escLF) throws IOException 
    Escape and writer.write a character.
 public boolean addAttributeAlways(String uri,
    String localName,
    String rawName,
    String type,
    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.
 public  void attributeDecl(String eName,
    String aName,
    String type,
    String valueDefault,
    String value) throws 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.

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

    The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

    The application must not attempt to read from the array outside of the specified range.

    Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

 public  void characters(String s) throws SAXException 
    Receive notification of character data.
 public  void characters(char[] chars,
    int start,
    int length) throws SAXException 
    Receive notification of character data.

    The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

    The application must not attempt to read from the array outside of the specified range.

    Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

 protected  void charactersRaw(char[] ch,
    int start,
    int length) throws SAXException 
    If available, when the disable-output-escaping attribute is used, output raw text without escaping.
 protected  void closeCDATA() throws SAXException 
    This helper method to writes out "]]>" when closing a CDATA section.
 protected  void closeStartTag() throws SAXException 
    For the enclosing elements starting tag write out out any attributes followed by ">"
 public  void comment(char[] ch,
    int start,
    int length) throws SAXException 
    Receive notification of an XML comment anywhere in the document. This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).
 public  void elementDecl(String name,
    String model) throws 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.

 public  void endCDATA() throws SAXException 
    Report the end of a CDATA section.
 public  void endDTD() throws SAXException 
    Report the end of DTD declarations.
 public  void endElement(String name) throws SAXException 
    Receive notification of the end of an element.
 public  void endElement(String namespaceURI,
    String localName,
    String name) throws SAXException 
    Receive notification of the end of an element.
 public  void endNonEscaping() throws SAXException 
    Ends an un-escaping section.
 public  void endPrefixMapping(String prefix) throws SAXException 
    End the scope of a prefix-URI Namespace mapping.
 protected String ensureAttributesNamespaceIsDeclared(String ns,
    String localName,
    String rawName) throws SAXException 
    Makes sure that the namespace URI for the given qualified attribute name is declared.
  void ensurePrefixIsDeclared(String ns,
    String rawName) throws SAXException 
 protected boolean escapingNotNeeded(char ch) 
    Tell if this character can be written without escaping.
 public  void externalEntityDecl(String name,
    String publicId,
    String systemId) throws SAXException 
    Report a parsed external entity declaration.

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

 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.
 public  void flushPending() throws SAXException 
    This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.
 protected final  void flushWriter() throws SAXException 
    Flush the formatter's result stream.
 public int getIndentAmount() 
    Returns the m_indentAmount.
 public Properties getOutputFormat() 
    Returns the output format for this serializer.
 public OutputStream getOutputStream() 
    Get the output stream where the events will be serialized to.
 public Writer getWriter() 
    Get the character stream where the events will be serialized to.
 public  void ignorableWhitespace(char[] ch,
    int start,
    int length) throws SAXException 
    Receive notification of ignorable whitespace in element content. Not sure how to get this invoked quite yet.
 protected  void indent() throws IOException 
    Indent at the current element nesting depth.
 protected  void indent(int depth) throws IOException 
    Might print a newline character and the indentation amount of the given depth.
 protected synchronized  void init(OutputStream output,
    Properties format,
    boolean defaultProperties) throws UnsupportedEncodingException 
    Initialize the serializer with the specified output stream and output format. Must be called before calling any of the serialize methods.
 public  void internalEntityDecl(String name,
    String value) throws SAXException 
    Report an internal entity declaration.

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

 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
 public  void notationDecl(String name,
    String pubID,
    String sysID) throws SAXException 
    If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.
  void outputDocTypeDecl(String name,
    boolean closeDecl) throws SAXException 
    Output the doc type declaration.
  void outputEntityDecl(String name,
    String value) throws IOException 
    Output the doc type declaration.
 protected final  void outputLineSep() throws IOException 
    Output a system-dependent line break.
 public  void processAttributes(Writer writer,
    int nAttrs) throws IOException, SAXException 
    Process the attributes, which means to write out the currently collected attributes to the writer. The attributes are not cleared by this method
 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).
 public  void serialize(Node node) throws IOException 
    Serializes the DOM node. Throws an exception only if an I/O exception occured while serializing.
 public  void setCdataSectionElements(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.
 public  void setContentHandler(ContentHandler ch) 
 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;
 public  void setEncoding(String encoding) 
    Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 public boolean setEscaping(boolean escape) 
 public  void setIndentAmount(int m_indentAmount) 
    Sets the m_indentAmount.
 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).
 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.
 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.

 public  void setTransformer(Transformer transformer) 
 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.
 protected boolean shouldIndent() 
    Tell if, based on space preservation constraints and the doIndent property, if an indent should occur.
 public  void skippedEntity(String name) throws SAXException 
    Receive notification of a skipped entity.
 public  void startCDATA() throws SAXException 
    Report the start of a CDATA section.
 public  void startDTD(String name,
    String publicId,
    String systemId) throws SAXException 
    Report the start of DTD declarations, if any. Any declarations are assumed to be in the internal subset unless otherwise indicated.
 public  void startElement(String elementName) throws SAXException 
 public  void startElement(String elementNamespaceURI,
    String elementLocalName,
    String elementName) throws 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.
 public  void startElement(String namespaceURI,
    String localName,
    String name,
    Attributes atts) throws 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.
 public  void startEntity(String name) throws 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.
 public  void startNonEscaping() throws 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.

 public  void startPrefixMapping(String prefix,
    String uri) throws 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.
 public boolean startPrefixMapping(String prefix,
    String uri,
    boolean shouldFlush) throws 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.
 public  void unparsedEntityDecl(String name,
    String pubID,
    String sysID,
    String notationName) throws SAXException 
    If this method is called, the serializer is used as a DTDHandler, which changes behavior how the serializer handles document entities.
 public  void writeAttrString(Writer writer,
    String string,
    String encoding) throws IOException 
    Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
  void writeNormalizedChars(char[] ch,
    int start,
    int length,
    boolean isCData,
    boolean useSystemLineSeparator) throws IOException, SAXException 
    Normalize the characters, but don't escape.
 protected int writeUTF16Surrogate(char c,
    char[] ch,
    int i,
    int end) throws 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.