org.apache.xalan.transformer
Class ResultTreeHandler

java.lang.Object
  |
  +--org.apache.xalan.transformer.QueuedEvents
        |
        +--org.apache.xalan.transformer.ResultTreeHandler

public class ResultTreeHandler
extends org.apache.xalan.transformer.QueuedEvents
implements ContentHandler, SerializerHandler, org.xml.sax.ext.LexicalHandler

This class is a layer between the direct calls to the result tree content handler, and the transformer. For one thing, we have to delay the call to getContentHandler().startElement(name, atts) because of the xsl:attribute and xsl:copy calls. In other words, the attributes have to be fully collected before you can call startElement.


Constructor Summary
ResultTreeHandler()
          Null constructor for object pooling.
ResultTreeHandler(TransformerImpl transformer, ContentHandler realHandler)
          Create a new result tree handler.
 
Method Summary
 void addAttribute(Attr attr)
          Copy an DOM attribute to the created output element, executing attribute templates as need be, and processing the xsl:use attribute.
 void addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value)
          Add an attribute to the end of the list.
 void addAttributes(Node src)
          Copy DOM attributes to the result element.
 void characters(char[] ch, int start, int length)
          Bottleneck the characters event.
 void cloneToResultTree(Node node, boolean shouldCloneAttributes)
          Clone an element with or without children.
 void comment(char[] ch, int start, int length)
          Bottleneck the comment event.
 void comment(java.lang.String data)
          Bottleneck the comment event.
 void endCDATA()
          End the CDATA characters.
 void endDocument()
          Bottleneck the endDocument event.
 void endDTD()
          End the DTD.
 void endElement(java.lang.String ns, java.lang.String localName, java.lang.String name)
          Bottleneck the endElement event.
 void endEntity(java.lang.String name)
          End an entity.
 void endNonEscaping()
          Ends an un-escaping section.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI mapping.
 void endPreserving()
          Ends a whitespace preserving section.
 void entityReference(java.lang.String name)
          Bottleneck the comment event.
 void flushPending()
          Flush the pending element.
 void flushPending(int type)
          Flush the pending element.
 ContentHandler getContentHandler()
          Return the current content handler.
 NamespaceSupport getNamespaceSupport()
          Get the NamespaceSupport object.
 java.lang.String getNewUniqueNSPrefix()
          Get new unique namespace prefix.
 MutableAttrListImpl getPendingAttributes()
          Get the pending attributes.
 java.lang.String getPrefix(java.lang.String namespace)
          Given a namespace, try and find a prefix.
 int getUniqueNSValue()
          Get a unique namespace value.
 java.lang.String getURI(java.lang.String prefix)
          Given a prefix, return the namespace,
 void ignorableWhitespace(char[] ch, int start, int length)
          Bottleneck the ignorableWhitespace event.
 void init(TransformerImpl transformer, ContentHandler realHandler)
          Initializer method.
 boolean isDefinedNSDecl(Attr attr)
           
 boolean isElementPending()
          Tell if an element is pending, to be output to the result tree.
 void outputResultTreeFragment(XObject obj, XPathContext support)
          Given a result tree fragment, walk the tree and output it to the result stream.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Bottleneck the processingInstruction event.
 void processNSDecls(Node src)
          Copy xmlns: attributes in if not already in scope.
 void setContentHandler(ContentHandler ch)
          Set the current content handler.
 void setDocumentLocator(Locator locator)
          To fullfill the FormatterListener interface...
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Start the CDATACharacters.
 void startDocument()
          Bottleneck the startDocument event.
 void startDTD(java.lang.String s1, java.lang.String s2, java.lang.String s3)
          Start the DTD.
 void startElement(java.lang.String ns, java.lang.String localName, java.lang.String name)
          Bottleneck the startElement event.
 void startElement(java.lang.String ns, java.lang.String localName, java.lang.String name, Attributes atts)
          Bottleneck the startElement event.
 void startEntity(java.lang.String name)
          Start 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.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush)
           
 void startPreserving()
          Starts a whitespace preserving section.
 
Methods inherited from class org.apache.xalan.transformer.QueuedEvents
reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultTreeHandler

public ResultTreeHandler()
Null constructor for object pooling.

ResultTreeHandler

public ResultTreeHandler(TransformerImpl transformer,
                         ContentHandler realHandler)
Create a new result tree handler. The real content handler will be the ContentHandler passed as an argument.
Method Detail

init

public void init(TransformerImpl transformer,
                 ContentHandler realHandler)
Initializer method.

startDocument

public void startDocument()
                   throws SAXException
Bottleneck the startDocument event.
Specified by:
startDocument in interface ContentHandler

endDocument

public void endDocument()
                 throws SAXException
Bottleneck the endDocument event. This may be called more than once in order to make sure the pending start document is called.
Specified by:
endDocument in interface ContentHandler

startElement

public void startElement(java.lang.String ns,
                         java.lang.String localName,
                         java.lang.String name)
                  throws SAXException
Bottleneck the startElement event. This is used to "pend" an element, so that attributes can still be added to it before the real "startElement" is called on the result tree listener.

startElement

public void startElement(java.lang.String ns,
                         java.lang.String localName,
                         java.lang.String name,
                         Attributes atts)
                  throws SAXException
Bottleneck the startElement event. This is used to "pend" an element, so that attributes can still be added to it before the real "startElement" is called on the result tree listener.
Specified by:
startElement in interface ContentHandler

endElement

public void endElement(java.lang.String ns,
                       java.lang.String localName,
                       java.lang.String name)
                throws SAXException
Bottleneck the endElement event.
Specified by:
endElement in interface ContentHandler

startPrefixMapping

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

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each-other: all startPrefixMapping events will occur before the corresponding startElement event, and all endPrefixMapping events will occur after the corresponding endElement event, but their order is not guaranteed.

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

startPrefixMapping

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

endPrefixMapping

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

See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

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

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Bottleneck the characters event.
Specified by:
characters in interface ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Bottleneck the ignorableWhitespace event.
Specified by:
ignorableWhitespace in interface ContentHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
Bottleneck the processingInstruction event.
Specified by:
processingInstruction in interface ContentHandler

comment

public void comment(java.lang.String data)
             throws SAXException
Bottleneck the comment event.

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Bottleneck the comment event.
Specified by:
comment in interface org.xml.sax.ext.LexicalHandler

entityReference

public void entityReference(java.lang.String name)
                     throws SAXException
Bottleneck the comment event.

startEntity

public void startEntity(java.lang.String name)
                 throws SAXException
Start an entity.
Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

endEntity

public void endEntity(java.lang.String name)
               throws SAXException
End an entity.
Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

startDTD

public void startDTD(java.lang.String s1,
                     java.lang.String s2,
                     java.lang.String s3)
              throws SAXException
Start the DTD.
Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
            throws SAXException
End the DTD.
Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

startNonEscaping

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.

Specified by:
startNonEscaping in interface SerializerHandler

endNonEscaping

public void endNonEscaping()
                    throws SAXException
Ends an un-escaping section.
Specified by:
endNonEscaping in interface SerializerHandler
See Also:
startNonEscaping()

startPreserving

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

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

Specified by:
startPreserving in interface SerializerHandler

endPreserving

public void endPreserving()
                   throws SAXException
Ends a whitespace preserving section.
Specified by:
endPreserving in interface SerializerHandler
See Also:
startPreserving()

startCDATA

public void startCDATA()
                throws SAXException
Start the CDATACharacters.
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
              throws SAXException
End the CDATA characters.
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws SAXException
Receive notification of a skipped entity.

The Parser will invoke this method once for each entity skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

Specified by:
skippedEntity in interface ContentHandler
Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

flushPending

public void flushPending()
                  throws SAXException
Flush the pending element.

flushPending

public void flushPending(int type)
                  throws SAXException
Flush the pending element.

outputResultTreeFragment

public void outputResultTreeFragment(XObject obj,
                                     XPathContext support)
                              throws SAXException
Given a result tree fragment, walk the tree and output it to the result stream.

cloneToResultTree

public void cloneToResultTree(Node node,
                              boolean shouldCloneAttributes)
                       throws SAXException
Clone an element with or without children.

setDocumentLocator

public void setDocumentLocator(Locator locator)
To fullfill the FormatterListener interface... no action for the moment.
Specified by:
setDocumentLocator in interface ContentHandler

processNSDecls

public void processNSDecls(Node src)
                    throws SAXException
Copy xmlns: attributes in if not already in scope.

getURI

public java.lang.String getURI(java.lang.String prefix)
Given a prefix, return the namespace,

getPrefix

public java.lang.String getPrefix(java.lang.String namespace)
Given a namespace, try and find a prefix.

getNamespaceSupport

public NamespaceSupport getNamespaceSupport()
Get the NamespaceSupport object.

getContentHandler

public ContentHandler getContentHandler()
Return the current content handler.
Returns:
The current content handler, or null if none has been registered.
See Also:
setContentHandler(org.xml.sax.ContentHandler)

setContentHandler

public void setContentHandler(ContentHandler ch)
Set the current content handler.
Returns:
The current content handler, or null if none has been registered.
See Also:
getContentHandler()

getUniqueNSValue

public int getUniqueNSValue()
Get a unique namespace value.

getNewUniqueNSPrefix

public java.lang.String getNewUniqueNSPrefix()
Get new unique namespace prefix.

getPendingAttributes

public MutableAttrListImpl getPendingAttributes()
Get the pending attributes. We have to delay the call to m_flistener.startElement(name, atts) because of the xsl:attribute and xsl:copy calls. In other words, the attributes have to be fully collected before you can call startElement.

addAttribute

public void addAttribute(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         java.lang.String type,
                         java.lang.String value)
                  throws SAXException
Add an attribute to the end of the list.

Do not pass in xmlns decls to this function!

For the sake of speed, this method does no checking to see if the attribute is already in the list: that is the responsibility of the application.

Parameters:
uri - The Namespace URI, or the empty string if none is available or Namespace processing is not being performed.
localName - The local name, or the empty string if Namespace processing is not being performed.
rawName - The raw XML 1.0 name, or the empty string if raw names are not available.
type - The attribute type as a string.
value - The attribute value.

isDefinedNSDecl

public boolean isDefinedNSDecl(Attr attr)

addAttribute

public void addAttribute(Attr attr)
                  throws SAXException
Copy an DOM attribute to the created output element, executing attribute templates as need be, and processing the xsl:use attribute.

addAttributes

public void addAttributes(Node src)
                   throws SAXException
Copy DOM attributes to the result element.

isElementPending

public boolean isElementPending()
Tell if an element is pending, to be output to the result tree.


Copyright © 2000 Apache XML Project. All Rights Reserved.