org.apache.xalan.stree
Class SourceTreeHandler

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--org.apache.xalan.stree.SourceTreeHandler

public class SourceTreeHandler
extends DefaultHandler
implements TransformerHandler, DeclHandler, DTDHandler

This class handles SAX2 parse events to create a source tree for transformation.


Constructor Summary
SourceTreeHandler()
          Create a SourceTreeHandler.
SourceTreeHandler(TransformerImpl transformer)
          Create a SourceTreeHandler that will start a transformation as soon as a startDocument occurs.
SourceTreeHandler(TransformerImpl transformer, boolean doFragment)
          Create a SourceTreeHandler that will start a transformation as soon as a startDocument occurs.
 
Method Summary
 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.
 void characters(char[] ch, int start, int length)
          Implement the characters event.
 void charactersRaw(char[] ch, int start, int length)
          Implement the characters event.
 void comment(char[] ch, int start, int length)
          Report an XML comment anywhere in the document.
 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 endDocument()
          Implement the endDocument event.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(java.lang.String ns, java.lang.String localName, java.lang.String name)
          Implement the endElement event.
 void endEntity(java.lang.String name)
          Report the end of an entity.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI mapping.
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report a parsed external entity declaration.
 Source getInputSource()
          Get Source Document.
 Node getRoot()
          Get the root document of tree that is being or will be created.
 java.lang.String getSystemId()
          Get the base ID (URI or system ID) from where relative URLs will be resolved.
 Transformer getTransformer()
          Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.
 boolean getUseMultiThreading()
          Tell whether or not the tree being built should handle transformation while the parse is still going on.
 void ignorableWhitespace(char[] ch, int start, int length)
          Implement the ignorableWhitespace event.
 void internalEntityDecl(java.lang.String name, java.lang.String value)
          Report an internal entity declaration.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Receive notification of a notation declaration event.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Implement the processingInstruction event.
 void setDocumentLocator(Locator locator)
          Implement the setDocumentLocator event.
 void setExceptionThrown(java.lang.Exception e)
          If an exception was thrown, keep track of it
 void setInputSource(Source source)
          Set the Source document
 void setResult(Result result)
          Method setResult allows the user of the TransformerHandler to set the result of the transform.
 void setRoot(DocImpl root)
          Set the root document of tree will be created.
 void setShouldTransformAtEnd(boolean b)
           
 void setSystemId(java.lang.String baseID)
          Set the base ID (URL or system ID) from where relative URLs will be resolved.
 void setUseMultiThreading(boolean b)
          Set whether or not the tree being built should handle transformation while the parse is still going on.
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDocument()
          Implement the startDocument event.
 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 ns, java.lang.String localName, java.lang.String name, Attributes atts)
          Implement the startElement event.
 void startEntity(java.lang.String name)
          Report the beginning of an entity.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          Receive notification of an unparsed entity declaration event.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, resolveEntity, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceTreeHandler

public SourceTreeHandler(TransformerImpl transformer)
Create a SourceTreeHandler that will start a transformation as soon as a startDocument occurs.
Parameters:
transformer - The transformer this will use to transform a source tree into a result tree.

SourceTreeHandler

public SourceTreeHandler(TransformerImpl transformer,
                         boolean doFragment)
Create a SourceTreeHandler that will start a transformation as soon as a startDocument occurs.
Parameters:
transformer - The transformer this will use to transform a source tree into a result tree.

SourceTreeHandler

public SourceTreeHandler()
Create a SourceTreeHandler.
Method Detail

setShouldTransformAtEnd

public void setShouldTransformAtEnd(boolean b)

getRoot

public Node getRoot()
Get the root document of tree that is being or will be created.
Returns:
Root document

setRoot

public void setRoot(DocImpl root)
Set the root document of tree will be created.
Parameters:
root - root document of tree that will be created

setExceptionThrown

public void setExceptionThrown(java.lang.Exception e)
If an exception was thrown, keep track of it
Parameters:
e - Exception that was thrown

setInputSource

public void setInputSource(Source source)
Set the Source document
Parameters:
source - source document

getInputSource

public Source getInputSource()
Get Source Document.
Returns:
source document

setDocumentLocator

public void setDocumentLocator(Locator locator)
Implement the setDocumentLocator event.
Parameters:
locator - Document locator
Overrides:
setDocumentLocator in class DefaultHandler

setUseMultiThreading

public void setUseMultiThreading(boolean b)
Set whether or not the tree being built should handle transformation while the parse is still going on.
Parameters:
b - Flag to indicate whether to use multiple threads

getUseMultiThreading

public boolean getUseMultiThreading()
Tell whether or not the tree being built should handle transformation while the parse is still going on.
Returns:
Flag to indicate whether to use multiple threads

startDocument

public void startDocument()
                   throws SAXException
Implement the startDocument event.
Throws:
SAXException -  
Overrides:
startDocument in class DefaultHandler

endDocument

public void endDocument()
                 throws SAXException
Implement the endDocument event.
Throws:
SAXException -  
Overrides:
endDocument in class DefaultHandler

startElement

public void startElement(java.lang.String ns,
                         java.lang.String localName,
                         java.lang.String name,
                         Attributes atts)
                  throws SAXException
Implement the startElement event.
Parameters:
ns - Namespace of the element
localName - Local part of the qualified name of the element
name - Name of the element
atts - List of attributes associated with the element
Throws:
SAXException -  
Overrides:
startElement in class DefaultHandler

endElement

public void endElement(java.lang.String ns,
                       java.lang.String localName,
                       java.lang.String name)
                throws SAXException
Implement the endElement event.
Parameters:
ns - Namespace of the element
localName - Local part of the qualified name of the element
name - Name of the element
Throws:
SAXException -  
Overrides:
endElement in class DefaultHandler

startCDATA

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

The contents of the CDATA section will be reported through the regular characters event.

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

endCDATA

public void endCDATA()
              throws SAXException
Report the end of a CDATA section.
Throws:
SAXException - The application may raise an exception.
See Also:
startCDATA()

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Implement the characters event.
Parameters:
ch - Character array from the characters event
start - Start index of characters to process in the array
length - Number of characters to process in the array
Throws:
SAXException -  
Overrides:
characters in class DefaultHandler

charactersRaw

public void charactersRaw(char[] ch,
                          int start,
                          int length)
                   throws SAXException
Implement the characters event.
Parameters:
ch - Character array from the characters event
start - Start index of characters to process in the array
length - Number of characters to process in the array
Throws:
SAXException -  

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Implement the ignorableWhitespace event.
Parameters:
ch - Character array from the characters event
start - Start index of characters to process in the array
length - Number of characters to process in the array
Throws:
SAXException -  
Overrides:
ignorableWhitespace in class DefaultHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
Implement the processingInstruction event.
Parameters:
target - Target of PI node
data - Content of PI node
Throws:
SAXException -  
Overrides:
processingInstruction in class DefaultHandler

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Report 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:
SAXException - The application may raise an exception.

startEntity

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

Note that skipped entities will be reported through the skippedEntity event, which is part of the ContentHandler interface.

Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException - The application may raise an exception.
See Also:
endEntity(java.lang.String), DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

endEntity

public void endEntity(java.lang.String name)
               throws SAXException
Report the end of an entity.
Parameters:
name - The name of the entity that is ending.
Throws:
SAXException - The application may raise an exception.
See Also:
startEntity(java.lang.String)

startDTD

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

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:
SAXException - The application may raise an exception.
See Also:
endDTD(), startEntity(java.lang.String)

endDTD

public void endDTD()
            throws SAXException
Report the end of DTD declarations.
Throws:
SAXException - The application may raise an exception.
See Also:
startDTD(java.lang.String, java.lang.String, java.lang.String)

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.

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
Throws:
SAXException -  
Overrides:
startPrefixMapping in class DefaultHandler
See Also:
endPrefixMapping(java.lang.String), startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

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.

Parameters:
prefix - The prefix that was being mapping.
Throws:
SAXException -  
Overrides:
endPrefixMapping in class DefaultHandler
See Also:
startPrefixMapping(java.lang.String, java.lang.String), endElement(java.lang.String, java.lang.String, java.lang.String)

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.

Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException -  
Overrides:
skippedEntity in class DefaultHandler

setResult

public void setResult(Result result)
               throws java.lang.IllegalArgumentException
Method setResult allows the user of the TransformerHandler to set the result of the transform.
Specified by:
setResult in interface TransformerHandler
Parameters:
result - A Result instance, should not be null.
Throws:
java.lang.IllegalArgumentException - if result is invalid for some reason.

setSystemId

public void setSystemId(java.lang.String baseID)
Set the base ID (URL or system ID) from where relative URLs will be resolved.
Specified by:
setSystemId in interface TransformerHandler
Parameters:
baseID - Base URL for the source tree.

getSystemId

public java.lang.String getSystemId()
Get the base ID (URI or system ID) from where relative URLs will be resolved.
Specified by:
getSystemId in interface TransformerHandler
Returns:
The systemID that was set with setSystemId(java.lang.String).

getTransformer

public Transformer getTransformer()
Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.
Specified by:
getTransformer in interface TransformerHandler

elementDecl

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

Specified by:
elementDecl in interface DeclHandler
Parameters:
name - The element type name.
model - The content model as a normalized string.
Throws:
SAXException - The application may raise an exception.

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

Specified by:
attributeDecl in interface DeclHandler
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:
SAXException - The application may raise an exception.

internalEntityDecl

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

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

Specified by:
internalEntityDecl in interface DeclHandler
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:
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)

externalEntityDecl

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

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

Specified by:
externalEntityDecl in interface DeclHandler
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:
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)

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws SAXException
Receive notification of a notation declaration event.

It is up to the application to record the notation for later reference, if necessary.

At least one of publicId and systemId must be non-null. If a system identifier is present, and it is a URL, the SAX parser must resolve it fully before passing it to the application through this event.

There is no guarantee that the notation declaration will be reported before any unparsed entities that use it.

Specified by:
notationDecl in interface DTDHandler
Parameters:
name - The notation name.
publicId - The notation's public identifier, or null if none was given.
systemId - The notation's system identifier, or null if none was given.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
Overrides:
notationDecl in class DefaultHandler
See Also:
unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String), AttributeList

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws SAXException
Receive notification of an unparsed entity declaration event.

Note that the notation name corresponds to a notation reported by the notationDecl event. It is up to the application to record the entity for later reference, if necessary.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application.

Specified by:
unparsedEntityDecl in interface DTDHandler
Parameters:
name - The unparsed entity's name.
publicId - The entity's public identifier, or null if none was given.
systemId - The entity's system identifier.
notation - name The name of the associated notation.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
Overrides:
unparsedEntityDecl in class DefaultHandler
See Also:
notationDecl(java.lang.String, java.lang.String, java.lang.String), AttributeList


Copyright � 2000 Apache XML Project. All Rights Reserved.