APIdia Launch Partner
Top Fields Constructors Methods
com.sun.org.apache.xalan.internal.xsltc.compiler

public Class Parser

extends Object
implements Constants, ContentHandler
Class Inheritance
All Implemented Interfaces
org.xml.sax.ContentHandler, com.sun.org.apache.xalan.internal.xsltc.compiler.Constants
Imports
com.sun.java_cup.internal.runtime.Symbol, com.sun.org.apache.xalan.internal.utils.ObjectFactory, com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg, .MethodType, .Type, .TypeCheckError, com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver, java.io.File, .IOException, .StringReader, java.util.ArrayList, .HashMap, .Iterator, .List, .Map, .Properties, .Stack, .StringTokenizer, javax.xml.XMLConstants, javax.xml.catalog.CatalogFeatures, jdk.xml.internal.ErrorHandlerProxy, .JdkConstants, .JdkXmlFeatures, .JdkXmlUtils, .SecuritySupport, .XMLSecurityManager, org.xml.sax.Attributes, .ContentHandler, .InputSource, .Locator, .SAXException, .XMLReader, org.xml.sax.helpers.AttributesImpl

Authors
Jacek Ambroziak, Santiago Pericas-Geertsen, G. Todd Miller, Morten Jorgensen, Erwin Bolwidt

Field Summary

Modifier and TypeField and Description
private int
private Stylesheet
private ArrayList<ErrorMsg>
private QName
private QName
private boolean
private Map<String, String[]>
private Map<String, String>
private Locator
private Map<String, Map<String, QName>>
private Output
private boolean
private Stack<SyntaxTreeNode>
_parentStack

SAX2 ContentHandler INTERFACE

private String
private String
private String
private Map<String, String>
private Map<String, QName>
private SyntaxTreeNode
private boolean
private SymbolTable
private String
private Template
private int
private QName
private Map<String, Object>
private ArrayList<ErrorMsg>
private XPathParser
private XSLTC
private static final String
private boolean
versionIsOne

Creates a new node in the abstract syntax tree.

private static final String

Constructor Summary

AccessConstructor and Description
public
Parser(XSLTC xsltc, boolean useOverrideDefaultParser, boolean hasUserErrListener)

Method Summary

Modifier and TypeMethod and Description
public void
public void
private void
public void
characters(char[] ch, int start, int length)

Implements org.xml.sax.ContentHandler.characters.

SAX2: Receive notification of character data.

private void
checkForSuperfluousAttributes(SyntaxTreeNode node, Attributes attrs)

checks the list of attributes against a list of allowed attributes for a particular element node.

public void
createAST(Stylesheet stylesheet)

Instanciates a SAX2 parser and generate the AST from the input.

public boolean
elementSupported(String namespace, String localName)

public void
endDocument()

Implements org.xml.sax.ContentHandler.endDocument.

SAX2: Receive notification of the end of a document.

public void
endElement(String uri, String localname, String qname)

Implements org.xml.sax.ContentHandler.endElement.

SAX2: Receive notification of the end of an element.

public void
endPrefixMapping(String prefix)

Implements org.xml.sax.ContentHandler.endPrefixMapping.

SAX2: End the scope of a prefix-URI Namespace mapping.

public boolean
errorsFound()

Returns true if there were any errors during compilation

private SyntaxTreeNode
findStylesheet(SyntaxTreeNode root, String href)

Find a Stylesheet element with a specific ID attribute value.

public boolean
public int
public Stylesheet
public SyntaxTreeNode
public ArrayList<ErrorMsg>
public QName
public QName
private int
getLineNumber()

Get the line number, or zero if there is no _locator.

public int
public Output
public Properties
public QName
getQName(final String stringRep)

public QName
getQName(final String stringRep, boolean reportError)

private QName
getQName(final String stringRep, boolean reportError, boolean ignoreDefaultNs)

public QName
getQName(String namespace, String prefix, String localname)

public QName
getQName(String scope, String name)

public QName
getQName(QName scope, QName name)

public QName
public QName
getQNameSafe(final String stringRep)

private SyntaxTreeNode
getStylesheet(SyntaxTreeNode root)

Extracts the DOM for the stylesheet.

public SymbolTable
public Template
public int
private String
public Stylesheet
public QName
public ArrayList<ErrorMsg>
public XSLTC
public void
ignorableWhitespace(char[] ch, int start, int length)

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

IGNORED - all ignorable whitespace is ignored

public void
init()

private void
initAttrTable(String elementName, String[] attrs)

private void
initExtClass(String elementName, String className)

private void
initExtClass(String namespace, String elementName, String className)

private void
private void
private void
initStdClass(String elementName, String className)

private void
initStdClasses()

Initialize the _instructionClasses map, which maps XSL element names to Java classes in this package.

private void
initSymbolTable()

Add primops and base functions to the symbol table.

private SyntaxTreeNode
loadExternalStylesheet(String location)

For embedded stylesheets: Load an external file with stylesheet

public VariableBase
public SyntaxTreeNode
makeInstance(String uri, String prefix, String local, Attributes attributes)

public Stylesheet
makeStylesheet(SyntaxTreeNode element)

Create an instance of the Stylesheet class, and then parse, typecheck and compile the instance.

public SyntaxTreeNode

Returns:

The root of the abstract syntax tree
parse
(XMLReader
A SAX2 SAXReader (parser)
reader
,
InputSource
A SAX2 InputSource can be passed to a SAX reader
input
)

Parses a stylesheet and builds the internal abstract syntax tree

public SyntaxTreeNode

Returns:

The root of the abstract syntax tree
parse
(InputSource
A SAX2 InputSource can be passed to a SAX reader
input
)

Parses a stylesheet and builds the internal abstract syntax tree

public Expression
parseExpression(SyntaxTreeNode
- XSL element where the expression occured
parent
,
String
- textual representation of the expression
exp
)

Parse an XPath expression:

public Expression
parseExpression(SyntaxTreeNode
- XSL element where the expression occured
parent
,
String
- name of this element's attribute to get expression from
attr
,
String
- default expression (if the attribute was not found)
def
)

Parse an XPath expression:

public Pattern
parsePattern(SyntaxTreeNode
- XSL element where the pattern occured
parent
,
String
- textual representation of the pattern
pattern
)

Parse an XPath pattern:

public Pattern
parsePattern(SyntaxTreeNode
- XSL element where the pattern occured
parent
,
String
- name of this element's attribute to get pattern from
attr
,
String
- default pattern (if the attribute was not found)
def
)

Parse an XPath pattern:

private SyntaxTreeNode
parseTopLevel(SyntaxTreeNode parent, String text, String expression)

Parse an XPath expression or pattern using the generated XPathParser The method will return a Dummy node if the XPath parser fails.

public void
printErrors()

Prints all compile-time errors

public void
printWarnings()

Prints all compile-time warnings

public void
processingInstruction(String name, String value)

Implements org.xml.sax.ContentHandler.processingInstruction.

SAX2: Receive notification of a processing instruction.

public void
public void
reportError(final int category, final ErrorMsg error)

Common error/warning message handler

public void
public void
setDocumentLocator(Locator locator)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Store the document locator to later retrieve line numbers of all elements from the stylesheet

public void
setOutput(Output output)

protected void
setPIParameters(String
The media attribute to be matched. May be null, in which case the prefered templates will be used (i.e. alternate = no).
media
,
String
The value of the title attribute to match. May be null.
title
,
String
The value of the charset attribute to match. May be null.
charset
)

Set the parameters to use to locate the correct <?xml-stylesheet ...?

public void
public void
setXSLTC(XSLTC xsltc)

public void
skippedEntity(String name)

Implements org.xml.sax.ContentHandler.skippedEntity.

IGNORED - we do not have to do anything with skipped entities

public void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

SAX2: Receive notification of the beginning of a document.

public void
startElement(String uri, String localname, String qname, Attributes attributes)

Implements org.xml.sax.ContentHandler.startElement.

SAX2: Receive notification of the beginning of an element.

public void
startPrefixMapping(String prefix, String uri)

Implements org.xml.sax.ContentHandler.startPrefixMapping.

SAX2: Begin the scope of a prefix-URI Namespace mapping.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_currentImportPrecedenceback to summary
private int _currentImportPrecedence
_currentStylesheetback to summary
private Stylesheet _currentStylesheet
_errorsback to summary
private ArrayList<ErrorMsg> _errors
_excludeResultPrefixesback to summary
private QName _excludeResultPrefixes
_extensionElementPrefixesback to summary
private QName _extensionElementPrefixes
_hasUserErrListenerback to summary
private boolean _hasUserErrListener
_instructionAttrsback to summary
private Map<String, String[]> _instructionAttrs
_instructionClassesback to summary
private Map<String, String> _instructionClasses
_locatorback to summary
private Locator _locator
_namespacesback to summary
private Map<String, Map<String, QName>> _namespaces
_outputback to summary
private Output _output
_overrideDefaultParserback to summary
private boolean _overrideDefaultParser
_parentStackback to summary
private Stack<SyntaxTreeNode> _parentStack

SAX2 ContentHandler INTERFACE

_PIcharsetback to summary
private String _PIcharset
_PImediaback to summary
private String _PImedia
_PItitleback to summary
private String _PItitle
_prefixMappingback to summary
private Map<String, String> _prefixMapping
_qNamesback to summary
private Map<String, QName> _qNames
_rootback to summary
private SyntaxTreeNode _root
_rootNamespaceDefback to summary
private boolean _rootNamespaceDef
_symbolTableback to summary
private SymbolTable _symbolTable
_targetback to summary
private String _target
_templateback to summary
private Template _template
_templateIndexback to summary
private int _templateIndex
_useAttributeSetsback to summary
private QName _useAttributeSets
_variableScopeback to summary
private Map<String, Object> _variableScope
_warningsback to summary
private ArrayList<ErrorMsg> _warnings
_xpathParserback to summary
private XPathParser _xpathParser
_xsltcback to summary
private XSLTC _xsltc
TRANSLETback to summary
private static final String TRANSLET
versionIsOneback to summary
private boolean versionIsOne

Creates a new node in the abstract syntax tree. This node can be o) a supported XSLT 1.0 element o) an unsupported XSLT element (post 1.0) o) a supported XSLT extension o) an unsupported XSLT extension o) a literal result element (not an XSLT element and not an extension) Unsupported elements do not directly generate an error. We have to wait until we have received all child elements of an unsupported element to see if any <xsl:fallback> elements exist.

XSLback to summary
private static final String XSL

Constructor Detail

Parserback to summary
public Parser(XSLTC xsltc, boolean useOverrideDefaultParser, boolean hasUserErrListener)

Method Detail

addParameterback to summary
public void addParameter(Param param)
addVariableback to summary
public void addVariable(Variable var)
addVariableOrParamback to summary
private void addVariableOrParam(VariableBase var)
charactersback to summary
public void characters(char[] ch, int start, int length)

Implements org.xml.sax.ContentHandler.characters.

SAX2: Receive notification of character data.

checkForSuperfluousAttributesback to summary
private void checkForSuperfluousAttributes(SyntaxTreeNode node, Attributes attrs)

checks the list of attributes against a list of allowed attributes for a particular element node.

createASTback to summary
public void createAST(Stylesheet stylesheet)

Instanciates a SAX2 parser and generate the AST from the input.

elementSupportedback to summary
public boolean elementSupported(String namespace, String localName)
endDocumentback to summary
public void endDocument()

Implements org.xml.sax.ContentHandler.endDocument.

SAX2: Receive notification of the end of a document.

endElementback to summary
public void endElement(String uri, String localname, String qname)

Implements org.xml.sax.ContentHandler.endElement.

SAX2: Receive notification of the end of an element.

endPrefixMappingback to summary
public void endPrefixMapping(String prefix)

Implements org.xml.sax.ContentHandler.endPrefixMapping.

SAX2: End the scope of a prefix-URI Namespace mapping. This has to be passed on to the symbol table!

errorsFoundback to summary
public boolean errorsFound()

Returns true if there were any errors during compilation

findStylesheetback to summary
private SyntaxTreeNode findStylesheet(SyntaxTreeNode root, String href)

Find a Stylesheet element with a specific ID attribute value. This method is used to find a Stylesheet node that is referred in a <?xml-stylesheet ... ?> processing instruction.

functionSupportedback to summary
public boolean functionSupported(String fname)
getCurrentImportPrecedenceback to summary
public int getCurrentImportPrecedence()
getCurrentStylesheetback to summary
public Stylesheet getCurrentStylesheet()
getDocumentRootback to summary
public SyntaxTreeNode getDocumentRoot()
getErrorsback to summary
public ArrayList<ErrorMsg> getErrors()
getExcludeResultPrefixesback to summary
public QName getExcludeResultPrefixes()
getExtensionElementPrefixesback to summary
public QName getExtensionElementPrefixes()
getLineNumberback to summary
private int getLineNumber()

Get the line number, or zero if there is no _locator.

getNextImportPrecedenceback to summary
public int getNextImportPrecedence()
getOutputback to summary
public Output getOutput()
getOutputPropertiesback to summary
public Properties getOutputProperties()
getQNameback to summary
public QName getQName(final String stringRep)
getQNameback to summary
public QName getQName(final String stringRep, boolean reportError)
getQNameback to summary
private QName getQName(final String stringRep, boolean reportError, boolean ignoreDefaultNs)
getQNameback to summary
public QName getQName(String namespace, String prefix, String localname)
getQNameback to summary
public QName getQName(String scope, String name)
getQNameback to summary
public QName getQName(QName scope, QName name)
getQNameIgnoreDefaultNsback to summary
public QName getQNameIgnoreDefaultNs(final String stringRep)
getQNameSafeback to summary
public QName getQNameSafe(final String stringRep)
getStylesheetback to summary
private SyntaxTreeNode getStylesheet(SyntaxTreeNode root) throws CompilerException

Extracts the DOM for the stylesheet. In the case of an embedded stylesheet, it extracts the DOM subtree corresponding to the embedded stylesheet that has an 'id' attribute whose value is the same as the value declared in the <?xml-stylesheet...?> processing instruction (P.I.). In the xml-stylesheet P.I. the value is labeled as the 'href' data of the P.I. The extracted DOM representing the stylesheet is returned as an Element object.

getSymbolTableback to summary
public SymbolTable getSymbolTable()
getTemplateback to summary
public Template getTemplate()
getTemplateIndexback to summary
public int getTemplateIndex()
getTokenValueback to summary
private String getTokenValue(String token)
getTopLevelStylesheetback to summary
public Stylesheet getTopLevelStylesheet()
getUseAttributeSetsback to summary
public QName getUseAttributeSets()
getWarningsback to summary
public ArrayList<ErrorMsg> getWarnings()
getXSLTCback to summary
public XSLTC getXSLTC()
ignorableWhitespaceback to summary
public void ignorableWhitespace(char[] ch, int start, int length)

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

IGNORED - all ignorable whitespace is ignored

initback to summary
public void init()
initAttrTableback to summary
private void initAttrTable(String elementName, String[] attrs)
initExtClassback to summary
private void initExtClass(String elementName, String className)
initExtClassback to summary
private void initExtClass(String namespace, String elementName, String className)
initExtClassesback to summary
private void initExtClasses()
initInstructionAttrsback to summary
private void initInstructionAttrs()
initStdClassback to summary
private void initStdClass(String elementName, String className)
initStdClassesback to summary
private void initStdClasses()

Initialize the _instructionClasses map, which maps XSL element names to Java classes in this package.

initSymbolTableback to summary
private void initSymbolTable()

Add primops and base functions to the symbol table.

Annotations
@SuppressWarnings:unused
loadExternalStylesheetback to summary
private SyntaxTreeNode loadExternalStylesheet(String location) throws CompilerException

For embedded stylesheets: Load an external file with stylesheet

lookupVariableback to summary
public VariableBase lookupVariable(QName name)
makeInstanceback to summary
public SyntaxTreeNode makeInstance(String uri, String prefix, String local, Attributes attributes)
makeStylesheetback to summary
public Stylesheet makeStylesheet(SyntaxTreeNode element) throws CompilerException

Create an instance of the Stylesheet class, and then parse, typecheck and compile the instance. Must be called after parse().

parseback to summary
public SyntaxTreeNode parse(XMLReader reader, InputSource input)

Parses a stylesheet and builds the internal abstract syntax tree

Parameters
reader:XMLReader

A SAX2 SAXReader (parser)

input:InputSource

A SAX2 InputSource can be passed to a SAX reader

Returns:SyntaxTreeNode

The root of the abstract syntax tree

parseback to summary
public SyntaxTreeNode parse(InputSource input)

Parses a stylesheet and builds the internal abstract syntax tree

Parameters
input:InputSource

A SAX2 InputSource can be passed to a SAX reader

Returns:SyntaxTreeNode

The root of the abstract syntax tree

parseExpressionback to summary
public Expression parseExpression(SyntaxTreeNode parent, String exp)

Parse an XPath expression:

Parameters
parent:SyntaxTreeNode

- XSL element where the expression occured

exp:String

- textual representation of the expression

parseExpressionback to summary
public Expression parseExpression(SyntaxTreeNode parent, String attr, String def)

Parse an XPath expression:

Parameters
parent:SyntaxTreeNode

- XSL element where the expression occured

attr:String

- name of this element's attribute to get expression from

def:String

- default expression (if the attribute was not found)

parsePatternback to summary
public Pattern parsePattern(SyntaxTreeNode parent, String pattern)

Parse an XPath pattern:

Parameters
parent:SyntaxTreeNode

- XSL element where the pattern occured

pattern:String

- textual representation of the pattern

parsePatternback to summary
public Pattern parsePattern(SyntaxTreeNode parent, String attr, String def)

Parse an XPath pattern:

Parameters
parent:SyntaxTreeNode

- XSL element where the pattern occured

attr:String

- name of this element's attribute to get pattern from

def:String

- default pattern (if the attribute was not found)

parseTopLevelback to summary
private SyntaxTreeNode parseTopLevel(SyntaxTreeNode parent, String text, String expression)

Parse an XPath expression or pattern using the generated XPathParser The method will return a Dummy node if the XPath parser fails.

printErrorsback to summary
public void printErrors()

Prints all compile-time errors

printWarningsback to summary
public void printWarnings()

Prints all compile-time warnings

processingInstructionback to summary
public void processingInstruction(String name, String value)

Implements org.xml.sax.ContentHandler.processingInstruction.

SAX2: Receive notification of a processing instruction. These require special handling for stylesheet PIs.

removeVariableback to summary
public void removeVariable(QName name)
reportErrorback to summary
public void reportError(final int category, final ErrorMsg error)

Common error/warning message handler

setCurrentStylesheetback to summary
public void setCurrentStylesheet(Stylesheet stylesheet)
setDocumentLocatorback to summary
public void setDocumentLocator(Locator locator)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Store the document locator to later retrieve line numbers of all elements from the stylesheet

setOutputback to summary
public void setOutput(Output output)
setPIParametersback to summary
protected void setPIParameters(String media, String title, String charset)

Set the parameters to use to locate the correct <?xml-stylesheet ...?> processing instruction in the case where the input document is an XML document with one or more references to a stylesheet.

Parameters
media:String

The media attribute to be matched. May be null, in which case the prefered templates will be used (i.e. alternate = no).

title:String

The value of the title attribute to match. May be null.

charset:String

The value of the charset attribute to match. May be null.

setTemplateback to summary
public void setTemplate(Template template)
setXSLTCback to summary
public void setXSLTC(XSLTC xsltc)
skippedEntityback to summary
public void skippedEntity(String name)

Implements org.xml.sax.ContentHandler.skippedEntity.

IGNORED - we do not have to do anything with skipped entities

startDocumentback to summary
public void startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

SAX2: Receive notification of the beginning of a document.

startElementback to summary
public void startElement(String uri, String localname, String qname, Attributes attributes) throws SAXException

Implements org.xml.sax.ContentHandler.startElement.

SAX2: Receive notification of the beginning of an element. The parser may re-use the attribute list that we're passed so we clone the attributes in our own Attributes implementation

Exceptions
SAXException:

Doc from org.xml.sax.ContentHandler.startElement.

any SAX exception, possibly wrapping another exception

startPrefixMappingback to summary
public void startPrefixMapping(String prefix, String uri)

Implements org.xml.sax.ContentHandler.startPrefixMapping.

SAX2: Begin the scope of a prefix-URI Namespace mapping. This has to be passed on to the symbol table!