org.apache.xalan.processor
Class StylesheetHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.xalan.processor.StylesheetHandler
All Implemented Interfaces:
javax.xml.transform.sax.TemplatesHandler, NodeConsumer, PrefixResolver, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class StylesheetHandler
extends org.xml.sax.helpers.DefaultHandler
implements javax.xml.transform.sax.TemplatesHandler, PrefixResolver, NodeConsumer

Initializes and processes a stylesheet via SAX events. This class acts as essentially a state machine, maintaining a ContentHandler stack, and pushing appropriate content handlers as parse events occur.


Field Summary
(package private)  java.util.Stack m_baseIdentifiers
          This will act as a stack to keep track of the current include base.
private  int m_docOrderCount
          An increasing number that is used to indicate the order in which this element was encountered during the parse of the XSLT tree.
private  int m_elementID
          Keep track of the elementID, so we can tell when is has completed.
private  java.util.Stack m_elems
          The stack of elements, pushed and popped as events occur.
private  int m_fragmentID
          The ID of the fragment that has been found (warning: I worry that this should be in a stack).
private  java.lang.String m_fragmentIDString
          If we have a URL to a XML fragment, the value is stored in this string, and the m_shouldProcess flag is set to false until we match an ID with this string.
private  FunctionTable m_funcTable
          The function table of XPath and XSLT;
private  java.util.Stack m_importSourceStack
          A stack of Source objects obtained from a URIResolver, for each element in this stack there is a 1-1 correspondence with an element in the m_importStack.
private  java.util.Stack m_importStack
          A stack of URL hrefs for imported stylesheets.
private  boolean m_incremental
          The flag for the setting of the incremental feature;
(package private)  Stylesheet m_lastPoppedStylesheet
          The last stylesheet that was popped off the stylesheets stack.
(package private)  java.util.Stack m_nsSupportStack
          Stack of NamespaceSupport objects.
private  boolean m_optimize
          The flag for the setting of the optimize feature;
private  org.w3c.dom.Node m_originatingNode
          The originating node if the current stylesheet is being created from a DOM.
private  boolean m_parsingComplete
          m_parsingComplete becomes true when the top-level stylesheet and all its included/imported stylesheets have been been fully parsed, as an indication that composition/optimization/compilation can begin.
private  java.util.Vector m_prefixMappings
           
private  java.util.Stack m_processors
          The stack of current processors.
private  XSLTSchema m_schema
          The root of the XSLT Schema, which tells us how to transition content handlers, create elements, etc.
private  boolean m_shouldProcess
          If we have a URL to a XML fragment, this is set to false until the ID is found.
private  boolean m_source_location
          The flag for the setting of the source_location feature;
private  BoolStack m_spacePreserveStack
          Stack of booleans that are pushed and popped in start/endElement depending on the value of xml:space=default/preserve.
private  int m_stylesheetLevel
          The level of the stylesheet we are at.
private  java.util.Stack m_stylesheetLocatorStack
          The top of this stack should contain the currently processed stylesheet SAX locator object.
private  TransformerFactoryImpl m_stylesheetProcessor
          The XSLT TransformerFactory for needed services.
(package private)  StylesheetRoot m_stylesheetRoot
          The root stylesheet of the stylesheets tree.
private  java.util.Stack m_stylesheets
          The stack of stylesheets being processed.
private  int m_stylesheetType
          The current stylesheet type.
static int STYPE_IMPORT
          If getStylesheetType returns this value, the current stylesheet is an imported stylesheet.
static int STYPE_INCLUDE
          If getStylesheetType returns this value, the current stylesheet is an included stylesheet.
static int STYPE_ROOT
          If getStylesheetType returns this value, the current stylesheet is a root stylesheet.
private  boolean warnedAboutOldXSLTNamespace
          If this is set to true, we've already warned about using the older XSLT namespace URL.
 
Constructor Summary
StylesheetHandler(TransformerFactoryImpl processor)
          Create a StylesheetHandler object, creating a root stylesheet as the target.
 
Method Summary
private  void assertion(boolean condition, java.lang.String msg)
          Assert that a condition is true.
 void characters(char[] ch, int start, int length)
          Receive notification of character data inside an element.
private  void checkForFragmentID(org.xml.sax.Attributes attributes)
          Check to see if an ID attribute matched the #id, called from startElement.
(package private)  XPath createMatchPatternXPath(java.lang.String str, ElemTemplateElement owningTemplate)
          Process an expression string into an XPath.
 XPath createXPath(java.lang.String str, ElemTemplateElement owningTemplate)
          Process an expression string into an XPath.
 void endDocument()
          Receive notification of the end of the document.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName)
          Receive notification of the end of an element.
 void endPrefixMapping(java.lang.String prefix)
          Receive notification of the end of a Namespace mapping.
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable XSLT processing error.
protected  void error(java.lang.String msg, java.lang.Exception e)
          Tell the user of an error, and probably throw an exception.
protected  void error(java.lang.String msg, java.lang.Object[] args, java.lang.Exception e)
          Tell the user of an error, and probably throw an exception.
 void fatalError(org.xml.sax.SAXParseException e)
          Report a fatal XSLT processing error.
private  void flushCharacters()
          Flush the characters buffer.
 java.lang.String getBaseIdentifier()
          Return the base identifier.
(package private)  XSLTElementProcessor getCurrentProcessor()
          Get the current XSLTElementProcessor at the top of the stack.
(package private)  ElemTemplateElement getElemTemplateElement()
          Get the current ElemTemplateElement at the top of the stack.
private  double getElemVersion()
           
 boolean getIncremental()
           
(package private)  Stylesheet getLastPoppedStylesheet()
          Return the last stylesheet that was popped off the stylesheets stack.
 SAXSourceLocator getLocator()
          Get the current stylesheet Locator object.
 java.lang.String getNamespaceForPrefix(java.lang.String prefix)
          Given a namespace, get the corrisponding prefix from the current namespace support context.
 java.lang.String getNamespaceForPrefix(java.lang.String prefix, org.w3c.dom.Node context)
          Given a namespace, get the corrisponding prefix.
(package private)  org.xml.sax.helpers.NamespaceSupport getNamespaceSupport()
          Get the current NamespaceSupport object.
 boolean getOptimize()
           
 org.w3c.dom.Node getOriginatingNode()
          Set the node that is originating the SAX event.
(package private)  XSLTElementProcessor getProcessorFor(java.lang.String uri, java.lang.String localName, java.lang.String rawName)
          Given a namespace URI, and a local name or a node type, get the processor for the element, or return null if not allowed.
 XSLTSchema getSchema()
          Get the root of the XSLT Schema, which tells us how to transition content handlers, create elements, etc.
 boolean getSource_location()
           
(package private)  Stylesheet getStylesheet()
          Return the stylesheet that this handler is constructing.
 TransformerFactoryImpl getStylesheetProcessor()
          Get the XSLT TransformerFactoryImpl for needed services.
 StylesheetRoot getStylesheetRoot()
          Return the stylesheet root that this handler is constructing.
(package private)  int getStylesheetType()
          Get the type of stylesheet that should be built or is being processed.
 java.lang.String getSystemId()
          Get the base ID (URI or system ID) from where relative URLs will be resolved.
 javax.xml.transform.Templates getTemplates()
          When this object is used as a ContentHandler or ContentHandler, it will create a Templates object, which the caller can get once the SAX events have been completed.
 boolean handlesNullPrefixes()
           
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
(package private)  boolean importStackContains(java.lang.String hrefUrl)
          See if the imported stylesheet stack already contains the given URL.
(package private)  void init(TransformerFactoryImpl processor)
          Do common initialization.
(package private)  boolean isSpacePreserve()
          Return boolean value from the spacePreserve stack depending on the value of xml:space=default/preserve.
 boolean isStylesheetParsingComplete()
          Test whether the _last_ endDocument() has been processed.
(package private)  int nextUid()
          Returns the next m_docOrderCount number and increments the number for future use.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Receive notification of a notation declaration.
(package private)  java.lang.String peekImportURL()
           
(package private)  javax.xml.transform.Source peekSourceFromURIResolver()
           
(package private)  java.lang.String popBaseIndentifier()
          Pop a base URI from the stack.
(package private)  ElemTemplateElement popElemTemplateElement()
          Get the current XSLTElementProcessor from the top of the stack.
(package private)  javax.xml.transform.Source popImportSource()
          Pop a Source from a user provided URIResolver, corresponding to the URL popped from the m_importStack.
(package private)  java.lang.String popImportURL()
          Pop an import href from the stylesheet stack.
(package private)  void popNamespaceSupport()
          Pop the current NamespaceSupport object.
(package private)  XSLTElementProcessor popProcessor()
          Pop the current XSLTElementProcessor from the top of the stack.
(package private)  void popSpaceHandling()
          Pop boolean value from the spacePreserve stack.
(package private)  Stylesheet popStylesheet()
          Pop the last stylesheet pushed, and return the stylesheet that this handler is constructing, and set the last popped stylesheet member.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
(package private)  void pushBaseIndentifier(java.lang.String baseID)
          Push a base identifier onto the base URI stack.
(package private)  void pushElemTemplateElement(ElemTemplateElement elem)
          Push the current XSLTElementProcessor to the top of the stack.
(package private)  void pushImportSource(javax.xml.transform.Source sourceFromURIResolver)
          Push the Source of an import href onto the stylesheet stack, obtained from a URIResolver, null if there is no URIResolver, or if that resolver returned null.
(package private)  void pushImportURL(java.lang.String hrefUrl)
          Push an import href onto the stylesheet stack.
(package private)  void pushNewNamespaceSupport()
          Push a new NamespaceSupport instance.
(package private)  void pushProcessor(XSLTElementProcessor processor)
          Push the current XSLTElementProcessor onto the top of the stack.
(package private)  void pushSpaceHandling(org.xml.sax.Attributes attrs)
          Push boolean value on to the spacePreserve stack depending on the value of xml:space=default/preserve.
(package private)  void pushSpaceHandling(boolean b)
          Push boolean value on to the spacePreserve stack.
 void pushStylesheet(Stylesheet s)
          Push the current stylesheet being constructed.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Resolve an external entity.
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive a Locator object for document events.
 void setOriginatingNode(org.w3c.dom.Node n)
          Set the node that is originating the SAX event.
(package private)  void setStylesheetType(int type)
          Set the type of stylesheet that should be built or is being processed.
 void setSystemId(java.lang.String baseID)
          Set the base ID (URL or system ID) for the stylesheet created by this builder.
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
private  boolean stackContains(java.util.Stack stack, java.lang.String url)
          Utility function to see if the stack contains the given URL.
 void startDocument()
          Receive notification of the beginning of the document.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName, org.xml.sax.Attributes attributes)
          Receive notification of the start of an element.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Receive notification of the start of a 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.
 void warn(java.lang.String msg, java.lang.Object[] args)
          Warn the user of an problem.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a XSLT processing warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_funcTable

private FunctionTable m_funcTable
The function table of XPath and XSLT;


m_optimize

private boolean m_optimize
The flag for the setting of the optimize feature;


m_incremental

private boolean m_incremental
The flag for the setting of the incremental feature;


m_source_location

private boolean m_source_location
The flag for the setting of the source_location feature;


m_stylesheetLevel

private int m_stylesheetLevel
The level of the stylesheet we are at.


m_parsingComplete

private boolean m_parsingComplete
m_parsingComplete becomes true when the top-level stylesheet and all its included/imported stylesheets have been been fully parsed, as an indication that composition/optimization/compilation can begin.

See Also:
isStylesheetParsingComplete

m_prefixMappings

private java.util.Vector m_prefixMappings

m_shouldProcess

private boolean m_shouldProcess
If we have a URL to a XML fragment, this is set to false until the ID is found. (warning: I worry that this should be in a stack).


m_fragmentIDString

private java.lang.String m_fragmentIDString
If we have a URL to a XML fragment, the value is stored in this string, and the m_shouldProcess flag is set to false until we match an ID with this string. (warning: I worry that this should be in a stack).


m_elementID

private int m_elementID
Keep track of the elementID, so we can tell when is has completed. This isn't a real ID, but rather a nesting level. However, it's good enough for our purposes. (warning: I worry that this should be in a stack).


m_fragmentID

private int m_fragmentID
The ID of the fragment that has been found (warning: I worry that this should be in a stack).


m_stylesheetProcessor

private TransformerFactoryImpl m_stylesheetProcessor
The XSLT TransformerFactory for needed services.


STYPE_ROOT

public static final int STYPE_ROOT
If getStylesheetType returns this value, the current stylesheet is a root stylesheet.

See Also:
Constant Field Values

STYPE_INCLUDE

public static final int STYPE_INCLUDE
If getStylesheetType returns this value, the current stylesheet is an included stylesheet.

See Also:
Constant Field Values

STYPE_IMPORT

public static final int STYPE_IMPORT
If getStylesheetType returns this value, the current stylesheet is an imported stylesheet.

See Also:
Constant Field Values

m_stylesheetType

private int m_stylesheetType
The current stylesheet type.


m_stylesheets

private java.util.Stack m_stylesheets
The stack of stylesheets being processed.


m_stylesheetRoot

StylesheetRoot m_stylesheetRoot
The root stylesheet of the stylesheets tree.


m_lastPoppedStylesheet

Stylesheet m_lastPoppedStylesheet
The last stylesheet that was popped off the stylesheets stack.


m_processors

private java.util.Stack m_processors
The stack of current processors.


m_schema

private XSLTSchema m_schema
The root of the XSLT Schema, which tells us how to transition content handlers, create elements, etc. For the moment at least, this can't be static, since the processors store state.


m_elems

private java.util.Stack m_elems
The stack of elements, pushed and popped as events occur.


m_docOrderCount

private int m_docOrderCount
An increasing number that is used to indicate the order in which this element was encountered during the parse of the XSLT tree.


m_baseIdentifiers

java.util.Stack m_baseIdentifiers
This will act as a stack to keep track of the current include base.


m_stylesheetLocatorStack

private java.util.Stack m_stylesheetLocatorStack
The top of this stack should contain the currently processed stylesheet SAX locator object.


m_importStack

private java.util.Stack m_importStack
A stack of URL hrefs for imported stylesheets. This is used to diagnose circular imports.


m_importSourceStack

private java.util.Stack m_importSourceStack
A stack of Source objects obtained from a URIResolver, for each element in this stack there is a 1-1 correspondence with an element in the m_importStack.


warnedAboutOldXSLTNamespace

private boolean warnedAboutOldXSLTNamespace
If this is set to true, we've already warned about using the older XSLT namespace URL.


m_nsSupportStack

java.util.Stack m_nsSupportStack
Stack of NamespaceSupport objects.


m_originatingNode

private org.w3c.dom.Node m_originatingNode
The originating node if the current stylesheet is being created from a DOM.

See Also:
NodeConsumer

m_spacePreserveStack

private BoolStack m_spacePreserveStack
Stack of booleans that are pushed and popped in start/endElement depending on the value of xml:space=default/preserve.

Constructor Detail

StylesheetHandler

public StylesheetHandler(TransformerFactoryImpl processor)
                  throws javax.xml.transform.TransformerConfigurationException
Create a StylesheetHandler object, creating a root stylesheet as the target.

Parameters:
processor - non-null reference to the transformer factory that owns this handler.
Throws:
javax.xml.transform.TransformerConfigurationException - if a StylesheetRoot can not be constructed for some reason.
Method Detail

init

void init(TransformerFactoryImpl processor)
Do common initialization.

Parameters:
processor - non-null reference to the transformer factory that owns this handler.

createXPath

public XPath createXPath(java.lang.String str,
                         ElemTemplateElement owningTemplate)
                  throws javax.xml.transform.TransformerException
Process an expression string into an XPath. Must be public for access by the AVT class.

Parameters:
str - A non-null reference to a valid or invalid XPath expression string.
Returns:
A non-null reference to an XPath object that represents the string argument.
Throws:
javax.xml.transform.TransformerException - if the expression can not be processed.
See Also:
Section 4 Expressions in XSLT Specification

createMatchPatternXPath

XPath createMatchPatternXPath(java.lang.String str,
                              ElemTemplateElement owningTemplate)
                        throws javax.xml.transform.TransformerException
Process an expression string into an XPath.

Parameters:
str - A non-null reference to a valid or invalid match pattern string.
Returns:
A non-null reference to an XPath object that represents the string argument.
Throws:
javax.xml.transform.TransformerException - if the pattern can not be processed.
See Also:
Section 5.2 Patterns in XSLT Specification

getNamespaceForPrefix

public java.lang.String getNamespaceForPrefix(java.lang.String prefix)
Given a namespace, get the corrisponding prefix from the current namespace support context.

Specified by:
getNamespaceForPrefix in interface PrefixResolver
Parameters:
prefix - The prefix to look up, which may be an empty string ("") for the default Namespace.
Returns:
The associated Namespace URI, or null if the prefix is undeclared in this context.

getNamespaceForPrefix

public java.lang.String getNamespaceForPrefix(java.lang.String prefix,
                                              org.w3c.dom.Node context)
Given a namespace, get the corrisponding prefix. This is here only to support the PrefixResolver interface, and will throw an error if invoked on this object.

Specified by:
getNamespaceForPrefix in interface PrefixResolver
Parameters:
prefix - The prefix to look up, which may be an empty string ("") for the default Namespace.
context - The node context from which to look up the URI.
Returns:
The associated Namespace URI, or null if the prefix is undeclared in this context.

stackContains

private boolean stackContains(java.util.Stack stack,
                              java.lang.String url)
Utility function to see if the stack contains the given URL.

Parameters:
stack - non-null reference to a Stack.
url - URL string on which an equality test will be performed.
Returns:
true if the stack contains the url argument.

getTemplates

public javax.xml.transform.Templates getTemplates()
When this object is used as a ContentHandler or ContentHandler, it will create a Templates object, which the caller can get once the SAX events have been completed.

Specified by:
getTemplates in interface javax.xml.transform.sax.TemplatesHandler
Returns:
The stylesheet object that was created during the SAX event process, or null if no stylesheet has been created. Author Scott Boag

setSystemId

public void setSystemId(java.lang.String baseID)
Set the base ID (URL or system ID) for the stylesheet created by this builder. This must be set in order to resolve relative URLs in the stylesheet.

Specified by:
setSystemId in interface javax.xml.transform.sax.TemplatesHandler
Parameters:
baseID - Base URL for this stylesheet.

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 javax.xml.transform.sax.TemplatesHandler
Returns:
The systemID that was set with setSystemId(java.lang.String).

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException
Resolve an external entity.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
Parameters:
publicId - The public identifer, or null if none is available.
systemId - The system identifier provided in the XML document.
Returns:
The new input source, or null to require the default behaviour.
Throws:
org.xml.sax.SAXException - if the entity can not be resolved.

notationDecl

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

By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.

Specified by:
notationDecl in interface org.xml.sax.DTDHandler
Overrides:
notationDecl in class org.xml.sax.helpers.DefaultHandler
Parameters:
name - The notation name.
publicId - The notation public identifier, or null if not available.
systemId - The notation system identifier.
See Also:
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)

unparsedEntityDecl

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

Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler
Overrides:
unparsedEntityDecl in class org.xml.sax.helpers.DefaultHandler
Parameters:
name - The entity name.
publicId - The entity public identifier, or null if not available.
systemId - The entity system identifier.
notationName - The name of the associated notation.
See Also:
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

getProcessorFor

XSLTElementProcessor getProcessorFor(java.lang.String uri,
                                     java.lang.String localName,
                                     java.lang.String rawName)
                               throws org.xml.sax.SAXException
Given a namespace URI, and a local name or a node type, get the processor for the element, or return null if not allowed.

Parameters:
uri - The Namespace URI, or an empty string.
localName - The local name (without prefix), or empty string if not namespace processing.
rawName - The qualified name (with prefix).
Returns:
A non-null reference to a element processor.
Throws:
org.xml.sax.SAXException - if the element is not allowed in the found position in the stylesheet.

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Receive a Locator object for document events. This is called by the parser to push a locator for the stylesheet being parsed. The stack needs to be popped after the stylesheet has been parsed. We pop in popStylesheet.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
Parameters:
locator - A locator for all SAX document events.
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator), Locator

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification of the beginning of the document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

isStylesheetParsingComplete

public boolean isStylesheetParsingComplete()
Test whether the _last_ endDocument() has been processed. This is needed as guidance for stylesheet optimization and compilation engines, which generally don't want to start until all included and imported stylesheets have been fully parsed.

Returns:
true iff the complete stylesheet tree has been built.

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receive notification of the end of the document.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endDocument()

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Receive notification of the start of a Namespace mapping.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI mapped to the prefix.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Receive notification of the end of a Namespace mapping.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
endPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Parameters:
prefix - The Namespace prefix being declared.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endPrefixMapping(java.lang.String)

flushCharacters

private void flushCharacters()
                      throws org.xml.sax.SAXException
Flush the characters buffer.

Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Receive notification of the start of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The Namespace URI, or an empty string.
localName - The local name (without prefix), or empty string if not namespace processing.
rawName - The qualified name (with prefix).
attributes - The specified or defaulted attributes.
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String rawName)
                throws org.xml.sax.SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri - The Namespace URI, or an empty string.
localName - The local name (without prefix), or empty string if not namespace processing.
rawName - The qualified name (with prefix).
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data inside an element.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters.
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.characters(char[], int, int)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The whitespace characters.
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.ignorableWhitespace(char[], int, int)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class org.xml.sax.helpers.DefaultHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)

skippedEntity

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

By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Overrides:
skippedEntity in class org.xml.sax.helpers.DefaultHandler
Parameters:
name - The name of the skipped entity.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)

warn

public void warn(java.lang.String msg,
                 java.lang.Object[] args)
          throws org.xml.sax.SAXException
Warn the user of an problem.

Parameters:
msg - An key into the XSLTErrorResources table, that is one of the WG_ prefixed definitions.
args - An array of arguments for the given warning.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.warning(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

assertion

private void assertion(boolean condition,
                       java.lang.String msg)
                throws java.lang.RuntimeException
Assert that a condition is true. If it is not true, throw an error.

Parameters:
condition - false if an error should not be thrown, otherwise true.
msg - Error message to be passed to the RuntimeException as an argument.
Throws:
java.lang.RuntimeException - if the condition is not true.

error

protected void error(java.lang.String msg,
                     java.lang.Exception e)
              throws org.xml.sax.SAXException
Tell the user of an error, and probably throw an exception.

Parameters:
msg - An error message.
e - An error which the SAXException should wrap.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.error(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

error

protected void error(java.lang.String msg,
                     java.lang.Object[] args,
                     java.lang.Exception e)
              throws org.xml.sax.SAXException
Tell the user of an error, and probably throw an exception.

Parameters:
msg - A key into the XSLTErrorResources table, that is one of the WG_ prefixed definitions.
args - An array of arguments for the given warning.
e - An error which the SAXException should wrap.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.error(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Receive notification of a XSLT processing warning.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The warning information encoded as an exception.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.warning(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Receive notification of a recoverable XSLT processing error.

Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The error information encoded as an exception.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.error(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Report a fatal XSLT processing error.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - The error information encoded as an exception.
Throws:
org.xml.sax.SAXException - that wraps a TransformerException if the current ErrorListener.fatalError(javax.xml.transform.TransformerException) method chooses to flag this condition as an error.

checkForFragmentID

private void checkForFragmentID(org.xml.sax.Attributes attributes)
Check to see if an ID attribute matched the #id, called from startElement.

Parameters:
attributes - The specified or defaulted attributes.

getStylesheetProcessor

public TransformerFactoryImpl getStylesheetProcessor()
Get the XSLT TransformerFactoryImpl for needed services. TODO: This method should be renamed.

Returns:
The TransformerFactoryImpl that owns this handler.

getStylesheetType

int getStylesheetType()
Get the type of stylesheet that should be built or is being processed.

Returns:
one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT.

setStylesheetType

void setStylesheetType(int type)
Set the type of stylesheet that should be built or is being processed.

Parameters:
type - Must be one of STYPE_ROOT, STYPE_INCLUDE, or STYPE_IMPORT.

getStylesheet

Stylesheet getStylesheet()
Return the stylesheet that this handler is constructing.

Returns:
The current stylesheet that is on top of the stylesheets stack, or null if no stylesheet is on the stylesheets stack.

getLastPoppedStylesheet

Stylesheet getLastPoppedStylesheet()
Return the last stylesheet that was popped off the stylesheets stack.

Returns:
The last popped stylesheet, or null.

getStylesheetRoot

public StylesheetRoot getStylesheetRoot()
Return the stylesheet root that this handler is constructing.

Returns:
The root stylesheet of the stylesheets tree.

pushStylesheet

public void pushStylesheet(Stylesheet s)
Push the current stylesheet being constructed. If no other stylesheets have been pushed onto the stack, assume the argument is a stylesheet root, and also set the stylesheet root member.

Parameters:
s - non-null reference to a stylesheet.

popStylesheet

Stylesheet popStylesheet()
Pop the last stylesheet pushed, and return the stylesheet that this handler is constructing, and set the last popped stylesheet member. Also pop the stylesheet locator stack.

Returns:
The stylesheet popped off the stack, or the last popped stylesheet.

getCurrentProcessor

XSLTElementProcessor getCurrentProcessor()
Get the current XSLTElementProcessor at the top of the stack.

Returns:
Valid XSLTElementProcessor, which should never be null.

pushProcessor

void pushProcessor(XSLTElementProcessor processor)
Push the current XSLTElementProcessor onto the top of the stack.

Parameters:
processor - non-null reference to the current element processor.

popProcessor

XSLTElementProcessor popProcessor()
Pop the current XSLTElementProcessor from the top of the stack.

Returns:
the XSLTElementProcessor which was popped.

getSchema

public XSLTSchema getSchema()
Get the root of the XSLT Schema, which tells us how to transition content handlers, create elements, etc.

Returns:
The root XSLT Schema, which should never be null.

getElemTemplateElement

ElemTemplateElement getElemTemplateElement()
Get the current ElemTemplateElement at the top of the stack.

Returns:
Valid ElemTemplateElement, which may be null.

nextUid

int nextUid()
Returns the next m_docOrderCount number and increments the number for future use.


pushElemTemplateElement

void pushElemTemplateElement(ElemTemplateElement elem)
Push the current XSLTElementProcessor to the top of the stack. As a side-effect, set the document order index (simply because this is a convenient place to set it).

Parameters:
elem - Should be a non-null reference to the intended current template element.

popElemTemplateElement

ElemTemplateElement popElemTemplateElement()
Get the current XSLTElementProcessor from the top of the stack.

Returns:
the ElemTemplateElement which was popped.

pushBaseIndentifier

void pushBaseIndentifier(java.lang.String baseID)
Push a base identifier onto the base URI stack.

Parameters:
baseID - The current base identifier for this position in the stylesheet, which may be a fragment identifier, or which may be null.
See Also:
Section 3.2 Base URI of XSLT specification.

popBaseIndentifier

java.lang.String popBaseIndentifier()
Pop a base URI from the stack.

Returns:
baseIdentifier.

getBaseIdentifier

public java.lang.String getBaseIdentifier()
Return the base identifier.

Specified by:
getBaseIdentifier in interface PrefixResolver
Returns:
The base identifier of the current stylesheet.

getLocator

public SAXSourceLocator getLocator()
Get the current stylesheet Locator object.

Returns:
non-null reference to the current locator object.

pushImportURL

void pushImportURL(java.lang.String hrefUrl)
Push an import href onto the stylesheet stack.

Parameters:
hrefUrl - non-null reference to the URL for the current imported stylesheet.

pushImportSource

void pushImportSource(javax.xml.transform.Source sourceFromURIResolver)
Push the Source of an import href onto the stylesheet stack, obtained from a URIResolver, null if there is no URIResolver, or if that resolver returned null.


importStackContains

boolean importStackContains(java.lang.String hrefUrl)
See if the imported stylesheet stack already contains the given URL. Used to test for recursive imports.

Parameters:
hrefUrl - non-null reference to a URL string.
Returns:
true if the URL is on the import stack.

popImportURL

java.lang.String popImportURL()
Pop an import href from the stylesheet stack.

Returns:
non-null reference to the import URL that was popped.

peekImportURL

java.lang.String peekImportURL()

peekSourceFromURIResolver

javax.xml.transform.Source peekSourceFromURIResolver()

popImportSource

javax.xml.transform.Source popImportSource()
Pop a Source from a user provided URIResolver, corresponding to the URL popped from the m_importStack.


pushNewNamespaceSupport

void pushNewNamespaceSupport()
Push a new NamespaceSupport instance.


popNamespaceSupport

void popNamespaceSupport()
Pop the current NamespaceSupport object.


getNamespaceSupport

org.xml.sax.helpers.NamespaceSupport getNamespaceSupport()
Get the current NamespaceSupport object.

Returns:
a non-null reference to the current NamespaceSupport object, which is the top of the namespace support stack.

setOriginatingNode

public void setOriginatingNode(org.w3c.dom.Node n)
Set the node that is originating the SAX event.

Specified by:
setOriginatingNode in interface NodeConsumer
Parameters:
n - Reference to node that originated the current event.
See Also:
NodeConsumer

getOriginatingNode

public org.w3c.dom.Node getOriginatingNode()
Set the node that is originating the SAX event.

Returns:
Reference to node that originated the current event.
See Also:
NodeConsumer

isSpacePreserve

boolean isSpacePreserve()
Return boolean value from the spacePreserve stack depending on the value of xml:space=default/preserve.

Returns:
true if space should be preserved, false otherwise.

popSpaceHandling

void popSpaceHandling()
Pop boolean value from the spacePreserve stack.


pushSpaceHandling

void pushSpaceHandling(boolean b)
                 throws org.xml.sax.SAXParseException
Push boolean value on to the spacePreserve stack.

Parameters:
b - true if space should be preserved, false otherwise.
Throws:
org.xml.sax.SAXParseException

pushSpaceHandling

void pushSpaceHandling(org.xml.sax.Attributes attrs)
                 throws org.xml.sax.SAXParseException
Push boolean value on to the spacePreserve stack depending on the value of xml:space=default/preserve.

Parameters:
attrs - list of attributes that were passed to startElement.
Throws:
org.xml.sax.SAXParseException

getElemVersion

private double getElemVersion()

handlesNullPrefixes

public boolean handlesNullPrefixes()
Specified by:
handlesNullPrefixes in interface PrefixResolver
See Also:
PrefixResolver.handlesNullPrefixes()

getOptimize

public boolean getOptimize()
Returns:
Optimization flag

getIncremental

public boolean getIncremental()
Returns:
Incremental flag

getSource_location

public boolean getSource_location()
Returns:
Source Location flag