com.novell.xsl.result
Class XMLSerializer

java.lang.Object
  extended bycom.novell.xsl.result.SerializerImpl
      extended bycom.novell.xsl.result.XMLSerializer
All Implemented Interfaces:
ResultHandler, Serializer
Direct Known Subclasses:
HTMLSerializer

public class XMLSerializer
extends SerializerImpl
implements ResultHandler, Serializer

Class to output the XSLT result tree as a sequence of bytes representing the result tree as serialized XML This implements the


Field Summary
protected  List attributeNames
           
protected  List attributeValues
           
protected  boolean cdataOutput
           
protected  boolean children
           
protected  NamespaceStack currentNamespaces
           
protected  int elementCount
           
protected  String elementName
           
protected  boolean forceDTD
           
protected  int indentLevel
           
protected  int nodeType
           
protected  boolean noEscape
           
protected  boolean startTagOpen
           
protected  Stack stateStack
           
protected static int XML_SPACE_DEFAULT
           
protected static int XML_SPACE_PRESERVE
           
protected  int xmlSpace
           
protected static Integer xmlSpaceDefault
           
protected static Integer xmlSpacePreserve
           
 
Fields inherited from class com.novell.xsl.result.SerializerImpl
actualEncoding, options, stream, writer
 
Constructor Summary
XMLSerializer()
          Construct a default XML serializer
XMLSerializer(OutputStream stream)
          Construct an XML serializer that will output to the passed stream
 
Method Summary
 void attribute(String name, String value)
          Receive notification of an attribute.
 void characters(String data)
          Receive notification of character data.
protected  void closeStartTag()
          Close any open element start tag
 void comment(String value)
          Receive notification of a comment.
protected  void doIndent(int level)
          Indent up to indent level This is provided so HTMLSerializer can override it
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String name)
          Receive notification of the end of an element.
protected  ExpandedQName getExpandedName(String qName, boolean isAttribute)
          Get the expanded name for a node QName using the currently in-scope namespace nodes.
protected  void initState()
          Initialize the state at the start of a document
protected  void injectWhitespace(int nodeType, int lastNodeType)
          Optionally inject whitespace into the output to "pretty print" the serialized XML
 void namespace(String name, NamespaceName value)
          Receive notification of a namespace node.
 void noTextEscaping(boolean noEscape)
          Tell Serializer to do no text escaping
protected  void outputXMLAttribute(ExpandedQName name, String value)
          Serialize an XML attribute name
protected  void popState()
          Restore the last element state
 void processingInstruction(String target, String value)
          Receive notification of a processing instruction.
protected  void pushState()
          Save the current element state
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String name, String namespaceURI)
          Receive notification of the beginning of an element.
protected  boolean useCdataOutput(String name)
          Return whether or not CDATA section output should be used for text children of the passed element name
protected  void writeDTD(String name)
          Write a DTD declaration.
 
Methods inherited from class com.novell.xsl.result.SerializerImpl
getOptions, getStream, initWriter, setOptions, setStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.novell.xsl.result.Serializer
getOptions, getStream, setOptions, setStream
 

Field Detail

elementCount

protected int elementCount

startTagOpen

protected boolean startTagOpen

noEscape

protected boolean noEscape

forceDTD

protected boolean forceDTD

indentLevel

protected int indentLevel

nodeType

protected int nodeType

attributeNames

protected List attributeNames

attributeValues

protected List attributeValues

children

protected boolean children

elementName

protected String elementName

currentNamespaces

protected NamespaceStack currentNamespaces

cdataOutput

protected boolean cdataOutput

stateStack

protected Stack stateStack

XML_SPACE_DEFAULT

protected static final int XML_SPACE_DEFAULT
See Also:
Constant Field Values

XML_SPACE_PRESERVE

protected static final int XML_SPACE_PRESERVE
See Also:
Constant Field Values

xmlSpaceDefault

protected static final Integer xmlSpaceDefault

xmlSpacePreserve

protected static final Integer xmlSpacePreserve

xmlSpace

protected int xmlSpace
Constructor Detail

XMLSerializer

public XMLSerializer()
Construct a default XML serializer


XMLSerializer

public XMLSerializer(OutputStream stream)
Construct an XML serializer that will output to the passed stream

Method Detail

startDocument

public void startDocument()
                   throws ResultException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ResultHandler
Throws:
ResultException - if an implementation-dependent error occurs

endDocument

public void endDocument()
                 throws ResultException
Receive notification of the end of a document.

Specified by:
endDocument in interface ResultHandler
Throws:
ResultException - if an implementation-dependent error occurs

startElement

public void startElement(String name,
                         String namespaceURI)
                  throws IllegalNameException,
                         IllegalNodeException,
                         ResultException
Receive notification of the beginning of an element.

Specified by:
startElement in interface ResultHandler
Parameters:
name - the element's name
namespaceURI - the element's namespace uri
Throws:
IllegalNameException - if the specified element name is illegal
IllegalNodeException - if the current node cannot contain elements
ResultException - if an implementation-dependent error occurs

endElement

public void endElement(String name)
                throws ResultException
Receive notification of the end of an element.

Specified by:
endElement in interface ResultHandler
Throws:
ResultException - if an implementation-dependent error occurs

attribute

public void attribute(String name,
                      String value)
               throws AttributeAfterChildException,
                      IllegalNameException,
                      IllegalNodeException,
                      ResultException
Receive notification of an attribute.

Specified by:
attribute in interface ResultHandler
Parameters:
name - the attribute's name
value - the attribute's value
Throws:
AttributeAfterChildException - if the current node is an element with children (attributes cannot be added to an element after children have been added to it)
IllegalNameException - if the specified attribute name is illegal
IllegalNodeException - if the current node is not an element
ResultException - if an implementation-dependent error occurs

characters

public void characters(String data)
                throws IllegalNodeException,
                       ResultException
Receive notification of character data.

Specified by:
characters in interface ResultHandler
Parameters:
data - the character data
Throws:
IllegalNodeException - if the current node cannot contain character data
ResultException - if an implementation-dependent error occurs

processingInstruction

public void processingInstruction(String target,
                                  String value)
                           throws IllegalNameException,
                                  IllegalNodeException,
                                  ResultException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface ResultHandler
Parameters:
target - the processing instruction's target
value - the processing instruction's value, or null if there is no value
Throws:
IllegalNameException - if the specified target name is illegal
IllegalNodeException - if the current node cannot contain processing instructions
ResultException - if an implementation-dependent error occurs

comment

public void comment(String value)
             throws IllegalNodeException,
                    ResultException
Receive notification of a comment.

Specified by:
comment in interface ResultHandler
Parameters:
value - the comment's value
Throws:
IllegalNodeException - if the current node cannot contain comments
ResultException - if an implementation-dependent error occurs

namespace

public void namespace(String name,
                      NamespaceName value)
               throws IllegalNodeException,
                      ResultException
Receive notification of a namespace node. An implementation should keep track of what namespace attributes are in scope in the xml representation to avoid placing redundant attributes on elements.

Specified by:
namespace in interface ResultHandler
Parameters:
name - the namespace prefix
value - the namespace name (URI)
Throws:
IllegalNodeException - if the current node cannot contain namespaces
ResultException - if an implementation-dependent error occurs

noTextEscaping

public void noTextEscaping(boolean noEscape)
Tell Serializer to do no text escaping

Specified by:
noTextEscaping in interface Serializer
Overrides:
noTextEscaping in class SerializerImpl
Parameters:
noEscape - True if no escaping should be performed, false if escaping should be performed

writeDTD

protected void writeDTD(String name)
                 throws IOException
Write a DTD declaration. The declaration will only be written if doctypeSystem is not null and non-empty. If doctypePublic is also non-null and non-empty, it will be used instead of doctypeSystem as the PUBLIC id. The name of the DTD will come from the DocumentType node, if there is one, otherwise will be set to the local name of the first element.

Parameters:
name - The name for the DTD
Throws:
IOException

closeStartTag

protected void closeStartTag()
                      throws IOException,
                             ResultException
Close any open element start tag

Throws:
IOException
ResultException

injectWhitespace

protected void injectWhitespace(int nodeType,
                                int lastNodeType)
                         throws IOException
Optionally inject whitespace into the output to "pretty print" the serialized XML

Parameters:
nodeType - The type of the current node (the node before which whitespace will be injected.
lastNodeType - The type of the node that preceded the current node.
Throws:
IOException

doIndent

protected void doIndent(int level)
                 throws IOException
Indent up to indent level This is provided so HTMLSerializer can override it

Parameters:
level - Number of tabs to output
Throws:
IOException

useCdataOutput

protected boolean useCdataOutput(String name)
                          throws IllegalNameException
Return whether or not CDATA section output should be used for text children of the passed element name

Parameters:
name - The element name to check
Throws:
IllegalNameException

initState

protected void initState()
Initialize the state at the start of a document


pushState

protected void pushState()
Save the current element state


popState

protected void popState()
Restore the last element state


getExpandedName

protected ExpandedQName getExpandedName(String qName,
                                        boolean isAttribute)
                                 throws IllegalNameException
Get the expanded name for a node QName using the currently in-scope namespace nodes.

Parameters:
qName - The QName to expand
isAttribute - True if the name is for an attribute node
Returns:
The expanded name of the passed QName
Throws:
IllegalNameException

outputXMLAttribute

protected void outputXMLAttribute(ExpandedQName name,
                                  String value)
                           throws IOException
Serialize an XML attribute name

Parameters:
name - The expanded name of the attribute.
value - The value of the attribute
Throws:
IOException