Class StylesheetHandler
- All Implemented Interfaces:
TemplatesHandler,NodeConsumer,PrefixResolver,ContentHandler,DTDHandler,EntityResolver,ErrorHandler
public class StylesheetHandler extends DefaultHandler implements TemplatesHandler, PrefixResolver, NodeConsumer
-
Field Summary
Fields Modifier and Type Field Description static intSTYPE_IMPORTIf getStylesheetType returns this value, the current stylesheet is an imported stylesheet.static intSTYPE_INCLUDEIf getStylesheetType returns this value, the current stylesheet is an included stylesheet.static intSTYPE_ROOTIf getStylesheetType returns this value, the current stylesheet is a root stylesheet. -
Constructor Summary
Constructors Constructor Description StylesheetHandler(TransformerFactoryImpl processor)Create a StylesheetHandler object, creating a root stylesheet as the target. -
Method Summary
Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)Receive notification of character data inside an element.XPathcreateXPath(String str, ElemTemplateElement owningTemplate)Process an expression string into an XPath.voidendDocument()Receive notification of the end of the document.voidendElement(String uri, String localName, String rawName)Receive notification of the end of an element.voidendPrefixMapping(String prefix)Receive notification of the end of a Namespace mapping.protected voiderror(String msg, Exception e)Tell the user of an error, and probably throw an exception.protected voiderror(String msg, Object[] args, Exception e)Tell the user of an error, and probably throw an exception.voiderror(SAXParseException e)Receive notification of a recoverable XSLT processing error.voidfatalError(SAXParseException e)Report a fatal XSLT processing error.StringgetBaseIdentifier()Return the base identifier.booleangetIncremental()SAXSourceLocatorgetLocator()Get the current stylesheet Locator object.StringgetNamespaceForPrefix(String prefix)Given a namespace, get the corrisponding prefix from the current namespace support context.StringgetNamespaceForPrefix(String prefix, Node context)Given a namespace, get the corrisponding prefix.booleangetOptimize()NodegetOriginatingNode()Set the node that is originating the SAX event.XSLTSchemagetSchema()Get the root of the XSLT Schema, which tells us how to transition content handlers, create elements, etc.booleangetSource_location()TransformerFactoryImplgetStylesheetProcessor()Get the XSLT TransformerFactoryImpl for needed services.StylesheetRootgetStylesheetRoot()Return the stylesheet root that this handler is constructing.StringgetSystemId()Get the base ID (URI or system ID) from where relative URLs will be resolved.TemplatesgetTemplates()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.booleanhandlesNullPrefixes()voidignorableWhitespace(char[] ch, int start, int length)Receive notification of ignorable whitespace in element content.booleanisStylesheetParsingComplete()Test whether the _last_ endDocument() has been processed.voidnotationDecl(String name, String publicId, String systemId)Receive notification of a notation declaration.voidprocessingInstruction(String target, String data)Receive notification of a processing instruction.voidpushStylesheet(Stylesheet s)Push the current stylesheet being constructed.InputSourceresolveEntity(String publicId, String systemId)Resolve an external entity.voidsetDocumentLocator(Locator locator)Receive a Locator object for document events.voidsetOriginatingNode(Node n)Set the node that is originating the SAX event.voidsetSystemId(String baseID)Set the base ID (URL or system ID) for the stylesheet created by this builder.voidskippedEntity(String name)Receive notification of a skipped entity.voidstartDocument()Receive notification of the beginning of the document.voidstartElement(String uri, String localName, String rawName, Attributes attributes)Receive notification of the start of an element.voidstartPrefixMapping(String prefix, String uri)Receive notification of the start of a Namespace mapping.voidunparsedEntityDecl(String name, String publicId, String systemId, String notationName)Receive notification of an unparsed entity declaration.voidwarn(String msg, Object[] args)Warn the user of an problem.voidwarning(SAXParseException e)Receive notification of a XSLT processing warning.
-
Field Details
-
STYPE_ROOT
public static final int STYPE_ROOTIf getStylesheetType returns this value, the current stylesheet is a root stylesheet.- See Also:
- Constant Field Values
-
STYPE_INCLUDE
public static final int STYPE_INCLUDEIf getStylesheetType returns this value, the current stylesheet is an included stylesheet.- See Also:
- Constant Field Values
-
STYPE_IMPORT
public static final int STYPE_IMPORTIf getStylesheetType returns this value, the current stylesheet is an imported stylesheet.- See Also:
- Constant Field Values
-
-
Constructor Details
-
StylesheetHandler
public StylesheetHandler(TransformerFactoryImpl processor) throws TransformerConfigurationExceptionCreate a StylesheetHandler object, creating a root stylesheet as the target.- Parameters:
processor- non-null reference to the transformer factory that owns this handler.- Throws:
TransformerConfigurationException- if a StylesheetRoot can not be constructed for some reason.
-
-
Method Details
-
createXPath
public XPath createXPath(String str, ElemTemplateElement owningTemplate) throws TransformerExceptionProcess 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:
TransformerException- if the expression can not be processed.- See Also:
- Section 4 Expressions in XSLT Specification
-
getNamespaceForPrefix
Given a namespace, get the corrisponding prefix from the current namespace support context.- Specified by:
getNamespaceForPrefixin interfacePrefixResolver- 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
Given a namespace, get the corrisponding prefix. This is here only to support thePrefixResolverinterface, and will throw an error if invoked on this object.- Specified by:
getNamespaceForPrefixin interfacePrefixResolver- 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.
-
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:
getTemplatesin interfaceTemplatesHandler- Returns:
- The stylesheet object that was created during the SAX event process, or null if no stylesheet has been created. Author Scott Boag
-
setSystemId
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:
setSystemIdin interfaceTemplatesHandler- Parameters:
baseID- Base URL for this stylesheet.
-
getSystemId
Get the base ID (URI or system ID) from where relative URLs will be resolved.- Specified by:
getSystemIdin interfaceTemplatesHandler- Returns:
- The systemID that was set with
setSystemId(java.lang.String).
-
resolveEntity
Resolve an external entity.- Specified by:
resolveEntityin interfaceEntityResolver- Overrides:
resolveEntityin classDefaultHandler- 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:
SAXException- if the entity can not be resolved.- See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)
-
notationDecl
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:
notationDeclin interfaceDTDHandler- Overrides:
notationDeclin classDefaultHandler- 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
Receive notification of an unparsed entity declaration.- Specified by:
unparsedEntityDeclin interfaceDTDHandler- Overrides:
unparsedEntityDeclin classDefaultHandler- 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)
-
setDocumentLocator
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:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler- Parameters:
locator- A locator for all SAX document events.- See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator),Locator
-
startDocument
Receive notification of the beginning of the document.- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
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
Receive notification of the end of the document.- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.endDocument()
-
startPrefixMapping
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:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Parameters:
prefix- The Namespace prefix being declared.uri- The Namespace URI mapped to the prefix.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
-
endPrefixMapping
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:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Parameters:
prefix- The Namespace prefix being declared.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.endPrefixMapping(java.lang.String)
-
startElement
public void startElement(String uri, String localName, String rawName, Attributes attributes) throws SAXExceptionReceive notification of the start of an element.- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- 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:
SAXException- See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-
endElement
Receive notification of the end of an element.- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- 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:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
-
characters
Receive notification of character data inside an element.- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Parameters:
ch- The characters.start- The start position in the character array.length- The number of characters to use from the character array.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.characters(char[], int, int)
-
ignorableWhitespace
Receive notification of ignorable whitespace in element content.- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- 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:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.ignorableWhitespace(char[], int, int)
-
processingInstruction
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:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classDefaultHandler- Parameters:
target- The processing instruction target.data- The processing instruction data, or null if none is supplied.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)
-
skippedEntity
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:
skippedEntityin interfaceContentHandler- Overrides:
skippedEntityin classDefaultHandler- Parameters:
name- The name of the skipped entity.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)
-
warn
Warn the user of an problem.- Parameters:
msg- An key into theXSLTErrorResourcestable, that is one of the WG_ prefixed definitions.args- An array of arguments for the given warning.- Throws:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.warning(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.
-
error
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:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.error(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.
-
error
Tell the user of an error, and probably throw an exception.- Parameters:
msg- A key into theXSLTErrorResourcestable, 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:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.error(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.
-
warning
Receive notification of a XSLT processing warning.- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin classDefaultHandler- Parameters:
e- The warning information encoded as an exception.- Throws:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.warning(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.- See Also:
ErrorHandler.warning(org.xml.sax.SAXParseException),SAXParseException
-
error
Receive notification of a recoverable XSLT processing error.- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classDefaultHandler- Parameters:
e- The error information encoded as an exception.- Throws:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.error(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.- See Also:
ErrorHandler.warning(org.xml.sax.SAXParseException),SAXParseException
-
fatalError
Report a fatal XSLT processing error.- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classDefaultHandler- Parameters:
e- The error information encoded as an exception.- Throws:
SAXException- that wraps aTransformerExceptionif the currentErrorListener.fatalError(javax.xml.transform.TransformerException)method chooses to flag this condition as an error.- See Also:
ErrorHandler.fatalError(org.xml.sax.SAXParseException),SAXParseException
-
getStylesheetProcessor
Get the XSLT TransformerFactoryImpl for needed services. TODO: This method should be renamed.- Returns:
- The TransformerFactoryImpl that owns this handler.
-
getStylesheetRoot
Return the stylesheet root that this handler is constructing.- Returns:
- The root stylesheet of the stylesheets tree.
-
pushStylesheet
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.
-
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.
-
getBaseIdentifier
Return the base identifier.- Specified by:
getBaseIdentifierin interfacePrefixResolver- Returns:
- The base identifier of the current stylesheet.
-
getLocator
Get the current stylesheet Locator object.- Returns:
- non-null reference to the current locator object.
-
setOriginatingNode
Set the node that is originating the SAX event.- Specified by:
setOriginatingNodein interfaceNodeConsumer- Parameters:
n- Reference to node that originated the current event.- See Also:
NodeConsumer
-
getOriginatingNode
Set the node that is originating the SAX event.- Returns:
- Reference to node that originated the current event.
- See Also:
NodeConsumer
-
handlesNullPrefixes
public boolean handlesNullPrefixes()- Specified by:
handlesNullPrefixesin interfacePrefixResolver- 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
-