org.apache.xml.serializer
Class ToUnknownStream

java.lang.Object
  |
  +--org.apache.xml.serializer.SerializerBase
        |
        +--org.apache.xml.serializer.ToUnknownStream

public final class ToUnknownStream
extends SerializerBase

This class wraps another SerializationHandler. The wrapped object will either handler XML or HTML, which is not known until a little later when the first XML tag is seen. If the first tag is then the wrapped object is an HTML handler, otherwise it is an XML handler. This class effectively caches the first few calls to it then passes them on to the wrapped handler (once it exists). After that subsequent calls a simply passed directly to the wrapped handler. The user of this class doesn't know if the output is ultimatley XML or HTML. This class is not a public API, it is public because it is used within Xalan.

Usage:
**For internal use only**

Constructor Summary
ToUnknownStream()
          Default constructor.
 
Method Summary
 void addAttribute(java.lang.String rawName, java.lang.String value)
          Adds an attribute to the currenly open tag
 void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean XSLAttribute)
          Adds an attribute to the currenly open tag
 void addAttributes(Attributes atts)
           
 void addUniqueAttribute(java.lang.String rawName, java.lang.String value, int flags)
          Adds a unique attribute to the currenly open tag
 ContentHandler asContentHandler()
           
 DOMSerializer asDOMSerializer()
           
 void attributeDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3, java.lang.String arg4)
          Pass the call on to the underlying handler
 void characters(char[] characters, int offset, int length)
          Pass the call on to the underlying handler
 void characters(java.lang.String chars)
          Converts the String to a character array and calls the SAX method characters(char[],int,int);
 void close()
           
 void comment(char[] ch, int start, int length)
          Pass the call on to the underlying handler
 void comment(java.lang.String comment)
          Pass the call on to the underlying handler
 void elementDecl(java.lang.String arg0, java.lang.String arg1)
          Pass the call on to the underlying handler
 void endCDATA()
          Pass the call on to the underlying handler
 void endDocument()
          Pass the call on to the underlying handler
 void endDTD()
          Pass the call on to the underlying handler
 void endElement(java.lang.String elementName)
          Pass the call on to the underlying handler
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          Pass the call on to the underlying handler
 void endEntity(java.lang.String name)
          Pass the call on to the underlying handler
 void endPrefixMapping(java.lang.String prefix)
          Pass the call on to the underlying handler
 void entityReference(java.lang.String entityName)
           
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Pass the call on to the underlying handler
 void flushPending()
           
 java.lang.String getDoctypePublic()
          Pass the call on to the underlying handler
 java.lang.String getDoctypeSystem()
          Pass the call on to the underlying handler
 java.lang.String getEncoding()
          Pass the call on to the underlying handler
 boolean getIndent()
          Pass the call on to the underlying handler
 int getIndentAmount()
          Pass the call on to the underlying handler
 java.lang.String getMediaType()
          Pass the call on to the underlying handler
 NamespaceMappings getNamespaceMappings()
          Get the current namespace mappings.
 java.lang.String getNamespaceURI(java.lang.String qname, boolean isElement)
           
 java.lang.String getNamespaceURIFromPrefix(java.lang.String prefix)
           
 boolean getOmitXMLDeclaration()
          Pass the call on to the underlying handler
 java.util.Properties getOutputFormat()
           
 java.io.OutputStream getOutputStream()
           
 java.lang.String getPrefix(java.lang.String namespaceURI)
           
 java.lang.String getStandalone()
          Pass the call on to the underlying handler
 Transformer getTransformer()
           
 java.lang.String getVersion()
          Pass the call on to the underlying handler
 java.io.Writer getWriter()
           
 void ignorableWhitespace(char[] ch, int start, int length)
          Pass the call on to the underlying handler
 void internalEntityDecl(java.lang.String arg0, java.lang.String arg1)
          Pass the call on to the underlying handler
 void namespaceAfterStartElement(java.lang.String prefix, java.lang.String uri)
          This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement().
 void processingInstruction(java.lang.String target, java.lang.String data)
          Pass the call on to the underlying handler
 boolean reset()
          passes the call on to the underlying HTML or XML handler
 void serialize(Node node)
          Converts the DOM node to output
 void setCdataSectionElements(java.util.Vector URI_and_localNames)
           
 void setContentHandler(ContentHandler ch)
           
 void setDoctype(java.lang.String system, java.lang.String pub)
           
 void setDoctypePublic(java.lang.String doctype)
          Set the doctype in the underlying XML handler.
 void setDoctypeSystem(java.lang.String doctype)
          Set the doctype in the underlying XML handler.
 void setDocumentLocator(Locator locator)
          Pass the call on to the underlying handler
 void setEncoding(java.lang.String encoding)
          Pass the call on to the underlying handler
 boolean setEscaping(boolean escape)
           
 void setIndent(boolean indent)
          Pass the call on to the underlying handler
 void setIndentAmount(int value)
          Pass the call on to the underlying handler
 void setMediaType(java.lang.String mediaType)
           
 void setOmitXMLDeclaration(boolean b)
          Pass the call on to the underlying handler
 void setOutputFormat(java.util.Properties format)
          Set the properties of the handler
 void setOutputStream(java.io.OutputStream output)
          Sets the output stream to write to
 void setSourceLocator(SourceLocator locator)
          This method is used to set the source locator, which might be used to generated an error message.
 void setStandalone(java.lang.String standalone)
          Pass the call on to the underlying handler
 void setTransformer(Transformer t)
           
 void setVersion(java.lang.String version)
          This method cannot be cached because default is different in HTML and XML (we need more than a boolean).
 void setWriter(java.io.Writer writer)
          Sets the writer to write to
 void skippedEntity(java.lang.String name)
          Pass the call on to the underlying handler
 void startCDATA()
          Pass the call on to the underlying handler
 void startDocument()
           
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Pass the call on to the underlying handler
 void startElement(java.lang.String qName)
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String elementName, Attributes atts)
           
 void startEntity(java.lang.String name)
          Pass the call on to the underlying handler
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 boolean startPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush)
           
 
Methods inherited from class org.apache.xml.serializer.SerializerBase
addAttribute, addAttributeAlways, addXSLAttribute, characters, error, fatalError, fireEndEntity, notationDecl, setDTDEntityExpansion, setNamespaceMappings, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToUnknownStream

public ToUnknownStream()
Default constructor. Initially this object wraps an XML Stream object, so _handler is never null. That may change later to an HTML Stream object.
Method Detail

asContentHandler

public ContentHandler asContentHandler()
                                throws java.io.IOException
Returns:
the wrapped XML or HTML handler
Overrides:
asContentHandler in class SerializerBase
See Also:
Serializer.asContentHandler()

close

public void close()
Overrides:
close in class SerializerBase
See Also:
SerializationHandler.close()

getOutputFormat

public java.util.Properties getOutputFormat()
Returns:
the properties of the underlying handler
See Also:
Serializer.getOutputFormat()

getOutputStream

public java.io.OutputStream getOutputStream()
Returns:
the OutputStream of the underlying XML or HTML handler
See Also:
Serializer.getOutputStream()

getWriter

public java.io.Writer getWriter()
Returns:
the Writer of the underlying XML or HTML handler
See Also:
Serializer.getWriter()

reset

public boolean reset()
passes the call on to the underlying HTML or XML handler
Returns:
???
Overrides:
reset in class SerializerBase
See Also:
Serializer.reset()

serialize

public void serialize(Node node)
               throws java.io.IOException
Converts the DOM node to output
Parameters:
node - the DOM node to transform to output
See Also:
DOMSerializer.serialize(Node)

setEscaping

public boolean setEscaping(boolean escape)
                    throws SAXException
See Also:
SerializationHandler.setEscaping(boolean)

setOutputFormat

public void setOutputFormat(java.util.Properties format)
Set the properties of the handler
Parameters:
format - the output properties to set
See Also:
Serializer.setOutputFormat(Properties)

setOutputStream

public void setOutputStream(java.io.OutputStream output)
Sets the output stream to write to
Parameters:
output - the OutputStream to write to
See Also:
Serializer.setOutputStream(OutputStream)

setWriter

public void setWriter(java.io.Writer writer)
Sets the writer to write to
Parameters:
writer - the writer to write to
See Also:
Serializer.setWriter(Writer)

addAttribute

public void addAttribute(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         java.lang.String type,
                         java.lang.String value,
                         boolean XSLAttribute)
                  throws SAXException
Adds an attribute to the currenly open tag
Parameters:
uri - the URI of a namespace
localName - the attribute name, without prefix
rawName - the attribute name, with prefix (if any)
type - the type of the attribute, typically "CDATA"
value - the value of the parameter
XSLAttribute - true if this attribute is coming from an xsl:attribute element
Overrides:
addAttribute in class SerializerBase
See Also:
ExtendedContentHandler.addAttribute(String, String, String, String, String)

addAttribute

public void addAttribute(java.lang.String rawName,
                         java.lang.String value)
Adds an attribute to the currenly open tag
Parameters:
rawName - the attribute name, with prefix (if any)
value - the value of the parameter
Overrides:
addAttribute in class SerializerBase
See Also:
ExtendedContentHandler.addAttribute(String, String)

addUniqueAttribute

public void addUniqueAttribute(java.lang.String rawName,
                               java.lang.String value,
                               int flags)
                        throws SAXException
Adds a unique attribute to the currenly open tag

characters

public void characters(java.lang.String chars)
                throws SAXException
Converts the String to a character array and calls the SAX method characters(char[],int,int);
See Also:
ExtendedContentHandler.characters(String)

endElement

public void endElement(java.lang.String elementName)
                throws SAXException
Pass the call on to the underlying handler
See Also:
ExtendedContentHandler.endElement(String)

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws SAXException
Parameters:
prefix - The prefix that maps to the URI
uri - The URI for the namespace
See Also:
ContentHandler.startPrefixMapping(String, String)

namespaceAfterStartElement

public void namespaceAfterStartElement(java.lang.String prefix,
                                       java.lang.String uri)
                                throws SAXException
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.
Parameters:
uri - the URI of the namespace
prefix - the prefix associated with the given URI.
Overrides:
namespaceAfterStartElement in class SerializerBase
See Also:
ExtendedContentHandler.namespaceAfterStartElement(String, String)

startPrefixMapping

public boolean startPrefixMapping(java.lang.String prefix,
                                  java.lang.String uri,
                                  boolean shouldFlush)
                           throws SAXException

setVersion

public void setVersion(java.lang.String version)
This method cannot be cached because default is different in HTML and XML (we need more than a boolean).
Overrides:
setVersion in class SerializerBase

startDocument

public void startDocument()
                   throws SAXException
Overrides:
startDocument in class SerializerBase
See Also:
ContentHandler.startDocument()

startElement

public void startElement(java.lang.String qName)
                  throws SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName)
                  throws SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String elementName,
                         Attributes atts)
                  throws SAXException

comment

public void comment(java.lang.String comment)
             throws SAXException
Pass the call on to the underlying handler
Overrides:
comment in class SerializerBase
See Also:
ExtendedLexicalHandler.comment(String)

getDoctypePublic

public java.lang.String getDoctypePublic()
Pass the call on to the underlying handler
Overrides:
getDoctypePublic in class SerializerBase
See Also:
XSLOutputAttributes.getDoctypePublic()

getDoctypeSystem

public java.lang.String getDoctypeSystem()
Pass the call on to the underlying handler
Overrides:
getDoctypeSystem in class SerializerBase
See Also:
XSLOutputAttributes.getDoctypeSystem()

getEncoding

public java.lang.String getEncoding()
Pass the call on to the underlying handler
Overrides:
getEncoding in class SerializerBase
See Also:
XSLOutputAttributes.getEncoding()

getIndent

public boolean getIndent()
Pass the call on to the underlying handler
Overrides:
getIndent in class SerializerBase
See Also:
XSLOutputAttributes.getIndent()

getIndentAmount

public int getIndentAmount()
Pass the call on to the underlying handler
Overrides:
getIndentAmount in class SerializerBase
See Also:
XSLOutputAttributes.getIndentAmount()

getMediaType

public java.lang.String getMediaType()
Pass the call on to the underlying handler
Overrides:
getMediaType in class SerializerBase
See Also:
XSLOutputAttributes.getMediaType()

getOmitXMLDeclaration

public boolean getOmitXMLDeclaration()
Pass the call on to the underlying handler
Overrides:
getOmitXMLDeclaration in class SerializerBase
See Also:
XSLOutputAttributes.getOmitXMLDeclaration()

getStandalone

public java.lang.String getStandalone()
Pass the call on to the underlying handler
Overrides:
getStandalone in class SerializerBase
See Also:
XSLOutputAttributes.getStandalone()

getVersion

public java.lang.String getVersion()
Pass the call on to the underlying handler
Overrides:
getVersion in class SerializerBase
See Also:
XSLOutputAttributes.getVersion()

setDoctype

public void setDoctype(java.lang.String system,
                       java.lang.String pub)
Overrides:
setDoctype in class SerializerBase
See Also:
XSLOutputAttributes.setDoctype(String, String)

setDoctypePublic

public void setDoctypePublic(java.lang.String doctype)
Set the doctype in the underlying XML handler. Remember that this method was called, just in case we need to transfer this doctype to an HTML handler
Parameters:
doctype - the public doctype to set
Overrides:
setDoctypePublic in class SerializerBase
See Also:
XSLOutputAttributes.setDoctypePublic(String)

setDoctypeSystem

public void setDoctypeSystem(java.lang.String doctype)
Set the doctype in the underlying XML handler. Remember that this method was called, just in case we need to transfer this doctype to an HTML handler
Parameters:
doctype - the system doctype to set
Overrides:
setDoctypeSystem in class SerializerBase
See Also:
XSLOutputAttributes.setDoctypeSystem(String)

setEncoding

public void setEncoding(java.lang.String encoding)
Pass the call on to the underlying handler
Overrides:
setEncoding in class SerializerBase
See Also:
XSLOutputAttributes.setEncoding(String)

setIndent

public void setIndent(boolean indent)
Pass the call on to the underlying handler
Overrides:
setIndent in class SerializerBase
See Also:
XSLOutputAttributes.setIndent(boolean)

setIndentAmount

public void setIndentAmount(int value)
Pass the call on to the underlying handler
Overrides:
setIndentAmount in class SerializerBase

setMediaType

public void setMediaType(java.lang.String mediaType)
Overrides:
setMediaType in class SerializerBase
See Also:
XSLOutputAttributes.setMediaType(String)

setOmitXMLDeclaration

public void setOmitXMLDeclaration(boolean b)
Pass the call on to the underlying handler
Overrides:
setOmitXMLDeclaration in class SerializerBase
See Also:
XSLOutputAttributes.setOmitXMLDeclaration(boolean)

setStandalone

public void setStandalone(java.lang.String standalone)
Pass the call on to the underlying handler
Overrides:
setStandalone in class SerializerBase
See Also:
XSLOutputAttributes.setStandalone(String)

attributeDecl

public void attributeDecl(java.lang.String arg0,
                          java.lang.String arg1,
                          java.lang.String arg2,
                          java.lang.String arg3,
                          java.lang.String arg4)
                   throws SAXException
Pass the call on to the underlying handler
See Also:
DeclHandler.attributeDecl(String, String, String, String, String)

elementDecl

public void elementDecl(java.lang.String arg0,
                        java.lang.String arg1)
                 throws SAXException
Pass the call on to the underlying handler
See Also:
DeclHandler.elementDecl(String, String)

externalEntityDecl

public void externalEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId)
                        throws SAXException
Pass the call on to the underlying handler
See Also:
DeclHandler.externalEntityDecl(String, String, String)

internalEntityDecl

public void internalEntityDecl(java.lang.String arg0,
                               java.lang.String arg1)
                        throws SAXException
Pass the call on to the underlying handler
See Also:
DeclHandler.internalEntityDecl(String, String)

characters

public void characters(char[] characters,
                       int offset,
                       int length)
                throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.characters(char[], int, int)

endDocument

public void endDocument()
                 throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.endDocument()

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.endElement(String, String, String)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.endPrefixMapping(String)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.ignorableWhitespace(char[], int, int)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.processingInstruction(String, String)

setDocumentLocator

public void setDocumentLocator(Locator locator)
Pass the call on to the underlying handler
Overrides:
setDocumentLocator in class SerializerBase
See Also:
ContentHandler.setDocumentLocator(Locator)

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws SAXException
Pass the call on to the underlying handler
See Also:
ContentHandler.skippedEntity(String)

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.comment(char[], int, int)

endCDATA

public void endCDATA()
              throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.endCDATA()

endDTD

public void endDTD()
            throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.endDTD()

endEntity

public void endEntity(java.lang.String name)
               throws SAXException
Pass the call on to the underlying handler
Overrides:
endEntity in class SerializerBase
See Also:
LexicalHandler.endEntity(String)

startCDATA

public void startCDATA()
                throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.startCDATA()

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.startDTD(String, String, String)

startEntity

public void startEntity(java.lang.String name)
                 throws SAXException
Pass the call on to the underlying handler
See Also:
LexicalHandler.startEntity(String)

asDOMSerializer

public DOMSerializer asDOMSerializer()
                              throws java.io.IOException
Overrides:
asDOMSerializer in class SerializerBase
See Also:
Serializer.asDOMSerializer()

setCdataSectionElements

public void setCdataSectionElements(java.util.Vector URI_and_localNames)
Parameters:
URI_and_localNames - Vector a list of pairs of URI/localName specified in the cdata-section-elements attribute.
See Also:
XSLOutputAttributes.setCdataSectionElements(java.util.Vector)

addAttributes

public void addAttributes(Attributes atts)
                   throws SAXException
Overrides:
addAttributes in class SerializerBase
See Also:
ExtendedContentHandler.addAttributes(org.xml.sax.Attributes)

getNamespaceMappings

public NamespaceMappings getNamespaceMappings()
Get the current namespace mappings. Simply returns the mappings of the wrapped handler.
Overrides:
getNamespaceMappings in class SerializerBase
See Also:
ExtendedContentHandler.getNamespaceMappings()

flushPending

public void flushPending()
                  throws SAXException
See Also:
SerializationHandler.flushPending()

getPrefix

public java.lang.String getPrefix(java.lang.String namespaceURI)
Overrides:
getPrefix in class SerializerBase
See Also:
ExtendedContentHandler.getPrefix(java.lang.String)

entityReference

public void entityReference(java.lang.String entityName)
                     throws SAXException
Overrides:
entityReference in class SerializerBase
See Also:
ExtendedContentHandler.entityReference(java.lang.String)

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String qname,
                                        boolean isElement)
Overrides:
getNamespaceURI in class SerializerBase
See Also:
ExtendedContentHandler.getNamespaceURI(java.lang.String, boolean)

getNamespaceURIFromPrefix

public java.lang.String getNamespaceURIFromPrefix(java.lang.String prefix)
Overrides:
getNamespaceURIFromPrefix in class SerializerBase

setTransformer

public void setTransformer(Transformer t)
Overrides:
setTransformer in class SerializerBase

getTransformer

public Transformer getTransformer()
Overrides:
getTransformer in class SerializerBase

setContentHandler

public void setContentHandler(ContentHandler ch)
See Also:
SerializationHandler.setContentHandler(org.xml.sax.ContentHandler)

setSourceLocator

public void setSourceLocator(SourceLocator locator)
This method is used to set the source locator, which might be used to generated an error message.
Parameters:
locator - the source locator
Overrides:
setSourceLocator in class SerializerBase
See Also:
ExtendedContentHandler.setSourceLocator(javax.xml.transform.SourceLocator)


Copyright © 2005 Apache XML Project. All Rights Reserved.