|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.novell.xsl.parser.StylesheetParser
This class parses XSLT stylesheets and stores the information in a
Stylesheet
object. It relies on a DOM input tree.
This class performs tree parse on the DOM objects to "compile" them into a tree of
XSLT-specific objects.
The same stylesheet parser instance must be used to parse everything associated with a given stylesheet and cannot be reused to parse a different stylesheet.
It is important to realize that this class deals with five different parsers: the XSLT stylesheet parser represented by this class, the XML parser that parses standard XML (for parsing imported and included stylesheets), the XPath expression parser, the XSLT pattern parser, and the attribute value template (AVT) parser.
The implementation of the individual parsers for different xsl:
elements is for the most
part in separate classes, accessed through a static parse()
method.
Exceptions to this include xsl:include
, xsl:import
, xsl:sort
,
xsl:fallback
, and xsl:stylesheet
/xsl:transform
.
Extension elements can be implemented by using a namespace of the form:
http://www.novell.com/nxsl/java/{fully-qualified-class-name}. If the namespace is declared
to be an extension element prefix and the namespace-qualified element appears where an XSLT
instruction element may appear a Class
object for the class name is retrieved and a method
of the form:
public static com.novell.xsl.process.Template parse(StylesheetParser stylesheetParser, Element element)
throws XSLTParserException;
is found and called through introspection.
If an element with a namespace of the above form is found as a top-level element a Class
object for the
class name is retrieved and a method of the form:
public static void parse(StylesheetParser stylesheetParser, Element element)
throws XSLTParserException;
is found and called through introspection. The top-level extension element can use the methods
setNamedObject()
, getNamedObject()
, and removeNamedObject()
for
storing state information.
Extension functions implemented in java can be used in XPath expressions by qualifying the function name with a namespace of the same sort used for extension elements. In this case, the class specified by the namespace is searched for a method matching the function name and signature specified by the function call. A constructor is specified by using the class name as the name of the function.
AttrDef
,
Stylesheet
Constructor Summary | |
StylesheetParser(Stylesheet stylesheet)
Constructs a new stylesheet parser that builds the specified Stylesheet object. |
|
StylesheetParser(Stylesheet stylesheet,
FunctionLibrary library)
Constructs a new stylesheet parser that builds the specified Stylesheet object.
|
|
StylesheetParser(Stylesheet stylesheet,
FunctionLibrary library,
boolean brokenMode)
Constructs a new stylesheet parser that builds the specified Stylesheet object.
|
Method Summary | |
void |
addFunction(Function function)
Add a function to the library |
StringBuffer |
buildErrorPrologue(StringBuffer prologue,
Node contextNode,
Node lineNumberContext)
Construct an error message prologue containing as much context information as possible. |
protected void |
checkVariables()
Check top-level variable references to ensure that they have all been defined. |
int |
getElementNumber()
Get the current ordering number of elements in the stylesheet tree. |
ExpandedQName |
getExpandedName(String qName)
Return the expanded name given the passed QName, given the current namespace context |
Function |
getFunction(ExpandedQName name)
Return an object of type Function given the function name. |
int |
getImportPrecedence()
Get the current import precedence number. |
Object |
getNamedObject(String name)
Retrieve an object previously set using setNamedObject() |
NamespaceName |
getNamespaceName(String prefix)
Return the currently in-scope namespace URI for the passed prefix. |
Parser |
getPatternParser()
Return the XSLT pattern parser being used by this StylesheetParser . |
Stylesheet |
getStylesheet()
Return the Stylesheet object for which the stylesheet parse is
being performed. |
ParserVariables |
getVariables()
Return the ParserVariables object used by this StylesheetParser . |
Parser |
getXPathParser()
Return the XPath expression parser being used by this StylesheetParser . |
protected Template |
handleElementFallback(Element element)
Handle any fallback information for an element. |
protected void |
includeStylesheet(Document xslDocument,
URL baseURI)
Includes the specified XSL document using the specified URI as the document's base URI. |
boolean |
isForwardsCompatibleMode()
Return true if stylesheet parser is currently in forwards-compatible
processing mode. |
boolean |
isFunctionAvailable(ExpressionContext context,
ExpandedQName name)
Return true if a function under a given name is available |
void |
parse(Document xsltDocument,
URL baseURI)
Parses the passed XSLT document. |
NamespaceName[] |
parseElementPrefixes(Node contextNode,
String prefixList)
Parse a whitespace separated list of prefixes. |
protected Template |
parseExtElement(Element element,
NamespaceName namespace)
Parse a non-xslt extension element template that appears as a descendant of an xsl:template element |
protected FallbackTemplate |
parseFallbackTemplate(Element element)
Parse a single xsl:fallback element |
protected FallbackTemplatesTemplate |
parseFallbackTemplates(Node node,
Node context)
Parse child xsl:fallback elements of a given extension element |
protected void |
parseImport(Element element)
Parses the specified xsl:import element. |
protected void |
parseInclude(Element element)
Parses the specified xsl:include element. |
protected Document |
parseIncludeOrImport(Element element,
URL[] uri)
Perform common parsing and processing for xsl:include and xsl:import elements. |
protected Template |
parseLiteralElement(Element element)
Parses the specified element as a literal result object. |
Collection |
parseQNames(Node contextNode,
String string)
Parse a whitespace separated list of QNames names and return a list of expanded names |
SortKey |
parseSortElement(Element element)
Parse an xsl:sort element, returning a SortKey object.
|
void |
parseStrippingList(Element contextNode,
String elementList,
boolean strip)
Parse the "elements" attribute of an xsl:strip-space or xsl:preserve space element. |
protected void |
parseStylesheet(Element element)
Parses the specified xsl:stylesheet element. |
Template[] |
parseTemplates(Node source,
boolean sortWasAllowed)
Parses the specified source node and its subsequent siblings as a template, and returns the result as an array of Template
objects. |
protected void |
parseTopLevelExtElement(Element element,
NamespaceName namespace)
Parse a non-xsl top-level element that appears as the child of an xsl:stylesheet of xsl:transform element.
|
Node |
popNSContext()
Remove the current namespace context, restoring the namespace context that was in effect before the current. |
void |
pushNSContext(Node newContext)
Change the namespace context to a new node. |
Object |
removeNamedObject(String name)
Remove an object previously set using setNamedObject() |
Expression |
reportAttributeExpressionError(Element contextNode,
String attrName,
XPathParserException e)
Report an XPath parser error for an attribute value. |
void |
reportError(Element topLevelContext,
Node contextNode,
String key)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(Element topLevelContext,
Node contextNode,
String key,
Object[] parms)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(Element topLevelContext,
Node contextNode,
String key,
String parm0)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(Node contextNode,
String key)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(Node contextNode,
String key,
Object[] parms)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(Node contextNode,
String key,
String parm0)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportError(String msg)
Report a parsing error by notifying the stylesheet's error handler. |
void |
reportInvalidAttributeValue(Element contextNode,
String attrName,
boolean isRequired,
String attrValue)
Report an invalid attribute value on an element. |
void |
reportWarning(Node contextNode,
String msg)
Reports a parsing warning by notifying the stylesheet's error handler. |
void |
setBuiltInDefinitions(Node namespaceContext)
Sets the built-in definitions for the stylesheet that this stylesheet parser is building. |
void |
setNamedObject(String name,
Object object)
Store an object with the StylesheetParser by a name. |
protected void |
simplifiedStylesheet(Element element,
RuleCollection ruleCollection)
Parse a simplified stylesheet that consists just a literal result element. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StylesheetParser(Stylesheet stylesheet)
Stylesheet
object.
stylesheet
- the stylesheet that this parser is buildingpublic StylesheetParser(Stylesheet stylesheet, FunctionLibrary library)
Stylesheet
object.
setBuiltInDefinitions()
must be called before further building the stylesheet.
stylesheet
- the stylesheet that this parser is buildinglibrary
- The FunctionLibrary
to use for this stylesheet.setBuiltInDefinitions(org.w3c.dom.Node)
public StylesheetParser(Stylesheet stylesheet, FunctionLibrary library, boolean brokenMode)
Stylesheet
object.
setBuiltInDefinitions()
must be called before further building the stylesheet.
stylesheet
- the stylesheet that this parser is buildinglibrary
- The FunctionLibrary
to use for this stylesheet.brokenMode
- if true then use old behavior that was broken but has since been fixed. This
is used solely for backward compatibility.setBuiltInDefinitions(org.w3c.dom.Node)
Method Detail |
public void setBuiltInDefinitions(Node namespaceContext) throws XSLTParserException
XSLTParserException
- if a fatal error occurs during parsingpublic void parse(Document xsltDocument, URL baseURI) throws XSLTParserException
null
. Note that a valid,
non-null
base URI is needed to properly resolve relative URIs in the XSLT
document.
xsltDocument
- the XSLT document to be imported
XSLTParserException
- if a fatal error occurs during parsingpublic boolean isForwardsCompatibleMode()
true
if stylesheet parser is currently in forwards-compatible
processing mode.
true
if stylesheet parser is currently in forwards-compatible
processing mode.public Stylesheet getStylesheet()
Stylesheet
object for which the stylesheet parse is
being performed.
Stylesheet
object for which the stylesheet parse is being performed.public Parser getXPathParser()
StylesheetParser
.
Parser
.public Parser getPatternParser()
StylesheetParser
.
Parser
.public int getImportPrecedence()
public int getElementNumber()
This is a relative measurement of element appearance in the stylesheet tree. This is used for the various XSLT rules that resolve conflicts based on relative position in the stylesheet (e.g., the template rule appearing last)
public ParserVariables getVariables()
ParserVariables
object used by this StylesheetParser
.
ParserVariables
object used by this StylesheetParser
.public void setNamedObject(String name, Object object)
name
- The name to associate with the passed Object
object
- The object to storegetNamedObject(java.lang.String)
public Object getNamedObject(String name)
setNamedObject()
name
- The name associated with the object when stored using setNamedObject()
Object
, or null if no Object
found by passed namesetNamedObject(java.lang.String, java.lang.Object)
public Object removeNamedObject(String name)
setNamedObject()
name
- The name associated with the object when stored using setNamedObject()
Object
, or null if no Object
found by passed namesetNamedObject(java.lang.String, java.lang.Object)
protected void checkVariables() throws XSLTParserException
XSLTParserException
- Thrown if the stylesheet ErrorHandler
throws an exception when and if the error is reported that a referenced
variable was never defined.protected void includeStylesheet(Document xslDocument, URL baseURI) throws XSLTParserException
xslDocument
- the XSLT document to be importedbaseURI
- the XSLT document's base URI, or null
if
the base URI is unknown
XSLTParserException
- if a fatal error occurs during parsingpublic Function getFunction(ExpandedQName name) throws XPathParserException
getFunction
in interface FunctionLibrary
name
- The name of the function
XPathParserException
public boolean isFunctionAvailable(ExpressionContext context, ExpandedQName name)
isFunctionAvailable
in interface FunctionLibrary
context
- the expression contextname
- name of the functionpublic void addFunction(Function function)
addFunction
in interface FunctionLibrary
function
- The function to bind.public NamespaceName getNamespaceName(String prefix)
getNamespaceName
in interface NamespaceContext
prefix
- The QName prefix of interest
public ExpandedQName getExpandedName(String qName)
getExpandedName
in interface NamespaceContext
qName
- The QName to expand
public void pushNSContext(Node newContext)
newContext
- The node that is the new namespace context.public Node popNSContext()
protected void parseStylesheet(Element element) throws XSLTParserException
xsl:stylesheet
element.
element
- the xsl:stylesheet
element to be parsed
XSLTParserException
- if a fatal error occurs during parsingprotected void simplifiedStylesheet(Element element, RuleCollection ruleCollection) throws XSLTParserException
element
- The literal result element that makes up the simplified
stylesheet.ruleCollection
- The stylesheet rule collection.
XSLTParserException
protected void parseImport(Element element) throws XSLTParserException
xsl:import
element.
element
- the xsl:import
element to be parsed
XSLTParserException
- if a fatal error occurs during parsingprotected void parseInclude(Element element) throws XSLTParserException
xsl:include
element.
element
- the xsl:include
element to be parsed
XSLTParserException
- if a fatal error occurs during parsingprotected Document parseIncludeOrImport(Element element, URL[] uri) throws XSLTParserException
element
- The xsl:include or xsl:import element.uri
- A 1-element URL array (pass by reference)
XSLTParserException
public void parseStrippingList(Element contextNode, String elementList, boolean strip) throws XSLTParserException
contextNode
- The context node for error reportingelementList
- The "elements" attribute value.strip
- True if from xsl:strip-space, false otherwise
XSLTParserException
- if a fatal error occurs during parsingpublic Template[] parseTemplates(Node source, boolean sortWasAllowed) throws XSLTParserException
Template
objects.
source
- the source node where parsing is to beginsortWasAllowed
- true
if xsl:sort
elements were allowed as siblings to the source
node, false
if not; used to
generate sensible error messages
Template
objects for
the parsed nodes
XSLTParserException
- if a fatal error occurs during parsingprotected Template parseLiteralElement(Element element) throws XSLTParserException
element
- the element to be parsed
LiteralElementTemplate
for the parsed
element
XSLTParserException
- if a fatal error occurs during parsingprotected Template parseExtElement(Element element, NamespaceName namespace) throws XSLTParserException
xsl:template
element
element
- The extension element.namespace
- The namespace name of the extension element
Template
object representing the extension element
XSLTParserException
protected void parseTopLevelExtElement(Element element, NamespaceName namespace) throws XSLTParserException
xsl:stylesheet
of xsl:transform
element.
XSLT doesn't specify any manner of qualifying a top-level extension element (indeed, extension elements are specified only to be those that appear in a template) so we use our magic extension prefix to recognize such elements.
element
- The extension element.namespace
- The namespace name of the extension element
XSLTParserException
protected Template handleElementFallback(Element element) throws XSLTParserException
FallbackTemplatesTemplate
object or a BadTemplate
object.
element
- The element for which to provide fallback behavior
XSLTParserException
FallbackTemplatesTemplate
,
BadTemplate
protected FallbackTemplatesTemplate parseFallbackTemplates(Node node, Node context) throws XSLTParserException
xsl:fallback
elements of a given extension element
node
- The child of the extension element at which to begin looking
for xsl:fallback
elementscontext
- The extension element node in the stylesheet
FallbackTemplatesTemplate
that, when instantiated, will instantiate
each xsl:fallback
template
XSLTParserException
FallbackTemplatesTemplate
protected FallbackTemplate parseFallbackTemplate(Element element) throws XSLTParserException
xsl:fallback
element
element
- The xsl:fallback
element node
FallbackTemplate
object that, when instantiated, will instantiate
the contents of the xsl:fallback
element
XSLTParserException
FallbackTemplate
public SortKey parseSortElement(Element element) throws XSLTParserException
xsl:sort
element, returning a SortKey
object.
One or more SortKey
objects is used to construct a SortCriteria
object.
element
- The xsl:sort
element to parse.
SortKey
object.
XSLTParserException
- if a fatal error occurs during parsingSortKey
,
SortCriteria
public NamespaceName[] parseElementPrefixes(Node contextNode, String prefixList) throws XSLTParserException
extension-element-prefixes
, namespace-alias
attributes, etc.
If the string "#default"
is encountered the default namespace is used.
contextNode
- The context node for error reportingprefixList
- A whitespace-separated list of namespace prefixes.
"#default"
is treated as indicating the default namespace.
XSLTParserException
public Collection parseQNames(Node contextNode, String string) throws XSLTParserException
contextNode
- The context node for error reportingstring
- The whitespace separated list of element names
XSLTParserException
public void reportError(String msg) throws XSLTParserException
msg
- the error message
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Element topLevelContext, Node contextNode, String key, Object[] parms) throws XSLTParserException
topLevelContext
- The Element
in which the contextNode appearscontextNode
- The node that is causing the error.key
- the error message key from XSLTParserExceptionparms
- the replacement parameters for the message (may be null)
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Element topLevelContext, Node contextNode, String key, String parm0) throws XSLTParserException
topLevelContext
- The Element
in which the contextNode appearscontextNode
- The node that is causing the error.key
- the error message key from XSLTParserExceptionparm0
- the replacement parameter for the message (may be null)
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Element topLevelContext, Node contextNode, String key) throws XSLTParserException
topLevelContext
- The Element
in which the contextNode appearscontextNode
- The node that is causing the error.key
- the error message key from XSLTParserException
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Node contextNode, String key, Object[] parms) throws XSLTParserException
contextNode
- The node that is causing the error.key
- the error message key from XSLTParserExceptionparms
- the replacement parameters for the message (may be null)
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Node contextNode, String key, String parm0) throws XSLTParserException
contextNode
- The node that is causing the error.key
- the error message key from XSLTParserExceptionparm0
- the replacement parameter for the message (may be null)
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportError(Node contextNode, String key) throws XSLTParserException
contextNode
- The node that is causing the error.key
- the error message key from XSLTParserException
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic void reportInvalidAttributeValue(Element contextNode, String attrName, boolean isRequired, String attrValue) throws XSLTParserException
contextNode
- The Element containing the bad attributeattrName
- The name of the attributeattrValue
- The bad attribute value
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itpublic Expression reportAttributeExpressionError(Element contextNode, String attrName, XPathParserException e) throws XSLTParserException
BadExpression
object is returned that
will report an error if it is ever evaluated.
contextNode
- The Element containing the bad attributeattrName
- The name of the attributee
- The XPathParserException
XSLTParserException
- if the error is fatal and the ErrorHandler
throws itBadExpression
public StringBuffer buildErrorPrologue(StringBuffer prologue, Node contextNode, Node lineNumberContext)
prologue
- A StringBuffer
in which to build the prologue. If this is
null a StringBuffer
will be allocated.contextNode
- The node in the stylesheet that supplies the context for
the error message.lineNumberContext
- if non-null
, get line number info from this node
StringBuffer
in which the prologue was built.public void reportWarning(Node contextNode, String msg)
contextNode
- The node in the stylesheet document closest to
the problem.msg
- the warning message
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |