santiagopg 2003/02/12 08:35:28
Modified: java/src/org/apache/xalan/xsltc/compiler Tag: xslt20
DecimalFormatting.java LiteralElement.java
Parser.java QName.java StaticContext.java
Stylesheet.java SyntaxTreeNode.java Whitespace.java
Added: java/src/org/apache/xalan/xsltc/compiler/util Tag: xslt20
ToDoException.java
Log:
Changes to the XSLT AST and static context to support XSLT 2.0 standard
attributes such as [xsl:]default-xpath-namespace. Also, a few minor
changes to the implementation of qname.
Revision Changes Path
No revision
No revision
1.9.2.1.2.5 +1 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DecimalFormatting.java
Index: DecimalFormatting.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DecimalFormatting.java,v
retrieving revision 1.9.2.1.2.4
retrieving revision 1.9.2.1.2.5
diff -u -r1.9.2.1.2.4 -r1.9.2.1.2.5
--- DecimalFormatting.java 30 Jan 2003 00:39:23 -0000 1.9.2.1.2.4
+++ DecimalFormatting.java 12 Feb 2003 16:35:18 -0000 1.9.2.1.2.5
@@ -75,7 +75,6 @@
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
-import org.apache.xalan.xsltc.runtime.AttributeList;
import org.apache.xalan.xsltc.compiler.*;
import org.apache.xalan.xsltc.compiler.util.*;
1.18.2.1.2.6 +3 -30
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
Index: LiteralElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
retrieving revision 1.18.2.1.2.5
retrieving revision 1.18.2.1.2.6
diff -u -r1.18.2.1.2.5 -r1.18.2.1.2.6
--- LiteralElement.java 30 Jan 2003 00:39:23 -0000 1.18.2.1.2.5
+++ LiteralElement.java 12 Feb 2003 16:35:18 -0000 1.18.2.1.2.6
@@ -81,10 +81,6 @@
private static final String XMLNS_STRING = "xmlns";
private static final QName USE_ATTRIBUTE_SETS =
new QName(XSLT_URI, "xsl", "use-attribute-sets");
- private static final QName EXCLUDE_RESULT_PREFIXES =
- new QName(XSLT_URI, "xsl", "exclude-result-prefixes");
- private static final QName EXTENSION_ELEMENT_PREFIXES =
- new QName(XSLT_URI, "xsl", "extension-element-prefixes");
private String _name;
private LiteralElement _literalElemParent;
@@ -170,7 +166,7 @@
StaticContext scontext = getStaticContext();
final String alternative = scontext.getPrefixAlias(prefix);
if (alternative != null) {
- scontext.setExcludePrefixes(prefix);
+ addExcludeResultURI(scontext.getNamespace(prefix));
prefix = alternative;
}
@@ -283,14 +279,6 @@
if (qname.equals(USE_ATTRIBUTE_SETS)) {
setFirstAttribute(new UseAttributeSets(val, parser));
}
- // Handle xsl:extension-element-prefixes
- else if (qname.equals(EXTENSION_ELEMENT_PREFIXES)) {
- scontext.setExcludePrefixes(val);
- }
- // Handle xsl:exclude-result-prefixes
- else if (qname.equals(EXCLUDE_RESULT_PREFIXES)) {
- scontext.setExcludePrefixes(val);
- }
else {
// Ignore special attributes (e.g. xmlns:prefix and xmlns)
final String prefix = qname.getPrefix();
@@ -317,28 +305,13 @@
final String prefix = (String)include.next();
if (!prefix.equals("xml")) {
final String uri = lookupNamespace(prefix);
- if (uri != null && !scontext.getExcludeUri(uri)) {
+ if (uri != null && !scontext.getExcludeResultURI(uri)) {
registerNamespace(prefix, uri, true);
}
}
}
parseContents(ccontext);
-
- // Process all attributes and register all namespaces they use
- for (int i = 0; i < count; i++) {
- final QName qname = parser.getQName(_attributes.getQName(i));
- final String val = _attributes.getValue(i);
-
- // Handle xsl:extension-element-prefixes
- if (qname.equals(EXTENSION_ELEMENT_PREFIXES)) {
- scontext.setUnexcludePrefixes(val);
- }
- // Handle xsl:exclude-result-prefixes
- else if (qname.equals(EXCLUDE_RESULT_PREFIXES)) {
- scontext.setUnexcludePrefixes(val);
- }
- }
}
protected boolean contextDependent() {
1.51.2.1.2.9 +108 -77
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.51.2.1.2.8
retrieving revision 1.51.2.1.2.9
diff -u -r1.51.2.1.2.8 -r1.51.2.1.2.9
--- Parser.java 30 Jan 2003 00:39:23 -0000 1.51.2.1.2.8
+++ Parser.java 12 Feb 2003 16:35:19 -0000 1.51.2.1.2.9
@@ -81,11 +81,10 @@
import org.w3c.dom.*;
import org.xml.sax.*;
+import org.xml.sax.helpers.AttributesImpl;
import java_cup.runtime.Symbol;
-
import org.apache.xalan.xsltc.compiler.util.*;
-import org.apache.xalan.xsltc.runtime.AttributeList;
public class Parser implements Constants, ContentHandler {
@@ -284,25 +283,32 @@
}
/**
- * Instantiates a SAX2 parser and generate the AST from the input.
+ * This method performs two passes on the AST. The first pass is used
+ * to parse attributes and XPath expression. The second pass is used
+ * to type check the tree.
*/
public void createAST(Stylesheet stylesheet) {
+ CompilerContext ccontext = CompilerContext.getInstance();
+
try {
if (stylesheet != null) {
- stylesheet.parse(CompilerContext.getInstance());
+ // Initiate parsing phase by calling parse()
+ stylesheet.parse(ccontext);
+
final int precedence = stylesheet.getImportPrecedence();
final Iterator elements = stylesheet.iterator();
while (elements.hasNext()) {
Object child = elements.next();
if (child instanceof Text) {
final int l = _locator.getLineNumber();
- ErrorMsg err =
- new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null);
+ ErrorMsg err = new ErrorMsg(
+ ErrorMsg.ILLEGAL_TEXT_NODE_ERR, l, null);
reportError(ERROR, err);
}
}
if (!errorsFound()) {
- stylesheet.typeCheck(CompilerContext.getInstance());
+ // Initiate type checking phase by calling typeCheck()
+ stylesheet.typeCheck(ccontext);
}
}
}
@@ -872,50 +878,50 @@
}
}
else {
- if (uri != null) {
- // Check if the element belongs in our namespace
- if (uri.equals(XSLT_URI)) {
- node = new UnsupportedElement(uri, prefix, local);
- UnsupportedElement element = (UnsupportedElement)node;
- ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_XSL_ERR,
- _locator.getLineNumber(),local);
- element.setErrorMessage(msg);
- }
- // Check if this is an XSLTC extension element
- else if (uri.equals(TRANSLET_URI)) {
- node = new UnsupportedElement(uri, prefix, local);
- UnsupportedElement element = (UnsupportedElement)node;
- ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
- _locator.getLineNumber(),local);
- element.setErrorMessage(msg);
- }
- // Check if this is an extension of some other XSLT processor
- else {
- Stylesheet sheet = _xsltc.getStylesheet();
- if ((sheet != null) && (sheet.isExtension(uri))) {
- if (sheet != (SyntaxTreeNode)_parentStack.peek()) {
- node = new UnsupportedElement(uri, prefix, local);
- UnsupportedElement elem = (UnsupportedElement)node;
- ErrorMsg msg =
- new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
- _locator.getLineNumber(),
- prefix+":"+local);
- elem.setErrorMessage(msg);
- }
- }
+ // Check if the element belongs in our namespace
+ if (uri.equals(XSLT_URI)) {
+ node = new UnsupportedElement(uri, prefix, local);
+ UnsupportedElement element = (UnsupportedElement)node;
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_XSL_ERR,
+ _locator.getLineNumber(),local);
+ element.setErrorMessage(msg);
+ }
+ // Check if this is an XSLTC extension element
+ else if (uri.equals(TRANSLET_URI)) {
+ node = new UnsupportedElement(uri, prefix, local);
+ UnsupportedElement element = (UnsupportedElement)node;
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
+ _locator.getLineNumber(),local);
+ element.setErrorMessage(msg);
+ }
+ // Check if this is an extension of some other XSLT processor
+ else {
+ // TODO: check if stack is empty
+ SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
+ StaticContext scontext = parent.getStaticContext();
+
+ // Check parent's static context for extension URI
+ if (scontext.getExtensionElementURI(uri)) {
+ // TODO
+ throw new ToDoException("do something with extension!");
}
}
- if (node == null) node = new LiteralElement();
- }
- if ((node != null) && (node instanceof LiteralElement)) {
- ((LiteralElement)node).setQName(qname);
+
+ // If unrecognized then assume literal
+ if (node == null) {
+ node = new LiteralElement();
+ ((LiteralElement) node).setQName(qname);
+ }
}
- return(node);
+
+ return node;
}
/**
* checks the list of attributes against a list of allowed attributes
* for a particular element node.
+ * TODO: change the implementation of this method to use the version
+ * stored in each SyntaxTreeNode.
*/
private void checkForSuperfluousAttributes(SyntaxTreeNode node,
Attributes attrs)
@@ -1165,7 +1171,15 @@
// -- SAX2 ContentHandler implementation -----------------------------
+ /**
+ * Stack of ancestors in reverse document order.
+ */
private Stack _parentStack = null;
+
+ /**
+ * Prefix mapping for each element node defined. This mapping is
+ * set by calling SyntaxTreeNode.setPrefixMapping().
+ */
private HashMap _prefixMapping = null;
/**
@@ -1181,7 +1195,8 @@
/**
* SAX2: Receive notification of the end of a document.
*/
- public void endDocument() { }
+ public void endDocument() {
+ }
/**
* SAX2: Begin the scope of a prefix-URI Namespace mapping.
@@ -1198,7 +1213,8 @@
* SAX2: End the scope of a prefix-URI Namespace mapping.
* This has to be passed on to the symbol table!
*/
- public void endPrefixMapping(String prefix) { }
+ public void endPrefixMapping(String prefix) {
+ }
/**
* SAX2: Receive notification of the beginning of an element.
@@ -1206,45 +1222,53 @@
* we clone the attributes in our own Attributes implementation
*/
public void startElement(String uri, String localname,
- String qname, Attributes attributes)
- throws SAXException {
+ String qname, Attributes attributes) throws SAXException
+ {
final int col = qname.lastIndexOf(':');
- final String prefix = (col == -1) ? null : qname.substring(0, col);
+ final String prefix = (col == -1) ? "" : qname.substring(0, col);
+ SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
+
+ // Unqualified names cannot be global
+ if (uri.length() == 0 && parent instanceof Stylesheet) {
+ ErrorMsg err = new ErrorMsg(ErrorMsg.ELEMENT_PARSE_ERR, qname);
+ throw new SAXException(err.toString());
+ }
- SyntaxTreeNode element = makeInstance(uri, prefix,
- localname, attributes);
+ // Create AST node based on element qname
+ SyntaxTreeNode element = makeInstance(uri, prefix, localname,
+ attributes);
if (element == null) {
- ErrorMsg err = new ErrorMsg(ErrorMsg.ELEMENT_PARSE_ERR,
- prefix+':'+localname);
+ ErrorMsg err = new ErrorMsg(ErrorMsg.ELEMENT_PARSE_ERR, qname);
throw new SAXException(err.toString());
}
- // If this is the root element of the XML document we need to make sure
- // that it contains a definition of the XSL namespace URI
+ // If this is the root element of the XML document we need to
+ // make sure that it contains a definition of the XSL namespace URI
if (_root == null) {
if (_prefixMapping == null ||
- _prefixMapping.containsValue(Constants.XSLT_URI) == false)
+ _prefixMapping.containsValue(Constants.XSLT_URI) == false) {
_rootNamespaceDef = false;
- else
+ }
+ else {
_rootNamespaceDef = true;
+ }
_root = element;
}
else {
- SyntaxTreeNode parent = (SyntaxTreeNode)_parentStack.peek();
parent.add(element);
element.setParent(parent);
}
- element.setAttributes((Attributes)new AttributeList(attributes));
- element.setPrefixMapping(_prefixMapping);
- if (element instanceof Stylesheet) {
- // Extension elements and excluded elements have to be
- // handled at this point in order to correctly generate
- // Fallback elements from <xsl:fallback>s.
- ((Stylesheet)element).excludeExtensionPrefixes(this);
- }
+ // Set NS declaration - must be set before attributes
+ element.setPrefixMapping(_prefixMapping);
+ // Set attributes (processes standard attributes too)
+ element.setAttributes(new AttributesImpl(attributes));
+
+ // Reset NS mapping
_prefixMapping = null;
+
+ // Push element to the parent's stack
_parentStack.push(element);
}
@@ -1272,6 +1296,7 @@
}
// Ignore text nodes that occur directly under <xsl:stylesheet>
+ // TODO: report error if this text node contains non-whitespace
if (parent instanceof Stylesheet) return;
// Get last element of parent
@@ -1303,8 +1328,7 @@
*/
public void processingInstruction(String name, String value) {
// We only handle the <?xml-stylesheet ...?> PI
- if ((_target == null) && (name.equals("xml-stylesheet"))) {
-
+ if (_target == null && name.equals("xml-stylesheet")) {
String href = null; // URI of stylesheet found
String media = null; // Media of stylesheet found
String title = null; // Title of stylesheet found
@@ -1314,21 +1338,26 @@
StringTokenizer tokens = new StringTokenizer(value);
while (tokens.hasMoreTokens()) {
String token = (String)tokens.nextToken();
- if (token.startsWith("href"))
+ if (token.startsWith("href")) {
href = getTokenValue(token);
- else if (token.startsWith("media"))
+ }
+ else if (token.startsWith("media")) {
media = getTokenValue(token);
- else if (token.startsWith("title"))
+ }
+ else if (token.startsWith("title")) {
title = getTokenValue(token);
- else if (token.startsWith("charset"))
+ }
+ else if (token.startsWith("charset")) {
charset = getTokenValue(token);
+ }
}
// Set the target to this PI's href if the parameters are
// null or match the corresponding attributes of this PI.
- if ( ((_PImedia == null) || (_PImedia.equals(media))) &&
- ((_PItitle == null) || (_PImedia.equals(title))) &&
- ((_PIcharset == null) || (_PImedia.equals(charset))) ) {
+ if ((_PImedia == null || _PImedia.equals(media)) &&
+ (_PItitle == null || _PImedia.equals(title)) &&
+ (_PIcharset == null || _PImedia.equals(charset)))
+ {
_target = href;
}
}
@@ -1337,10 +1366,12 @@
/**
* IGNORED - all ignorable whitespace is ignored
*/
- public void ignorableWhitespace(char[] ch, int start, int length) { }
+ public void ignorableWhitespace(char[] ch, int start, int length) {
+ }
/**
* IGNORED - we do not have to do anything with skipped entities
*/
- public void skippedEntity(String name) { }
+ public void skippedEntity(String name) {
+ }
}
1.4.2.1.2.3 +10 -6
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/QName.java
Index: QName.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/QName.java,v
retrieving revision 1.4.2.1.2.2
retrieving revision 1.4.2.1.2.3
diff -u -r1.4.2.1.2.2 -r1.4.2.1.2.3
--- QName.java 30 Jan 2003 00:39:26 -0000 1.4.2.1.2.2
+++ QName.java 12 Feb 2003 16:35:21 -0000 1.4.2.1.2.3
@@ -64,6 +64,10 @@
package org.apache.xalan.xsltc.compiler;
+/**
+ * Qualified name class. Local name, prefix and namespace components
+ * are internalized to speed up qname comparison.
+ */
final class QName {
/**
@@ -94,9 +98,9 @@
private int _hashCode;
public QName(String namespace, String prefix, String localname) {
- _namespace = namespace;
- _prefix = prefix;
- _localname = localname;
+ _namespace = namespace.intern();
+ _prefix = prefix.intern();
+ _localname = localname.intern();
_stringRep = (namespace.length() == 0) ? localname :
(namespace + ':' + localname);
@@ -118,8 +122,8 @@
public boolean equals(Object other) {
try {
final QName temp = (QName) other;
- return (_namespace.equals(temp._namespace) &&
- _localname.equals(temp._localname));
+ return (_namespace == temp._namespace &&
+ _localname == temp._localname);
}
catch (ClassCastException e) {
return false;
1.1.2.5 +43 -100
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/StaticContext.java
Index: StaticContext.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Attic/StaticContext.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- StaticContext.java 30 Jan 2003 00:39:26 -0000 1.1.2.4
+++ StaticContext.java 12 Feb 2003 16:35:21 -0000 1.1.2.5
@@ -66,6 +66,7 @@
import java.util.Stack;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
@@ -387,18 +388,6 @@
return null; // TODO
}
- // -- XPath 1.0 compatible flag --------------------------------------
-
- private boolean _xpath10CompatibleFlag = true;
-
- public boolean getXPath10CompatibleFlag() {
- return _xpath10CompatibleFlag;
- }
-
- public void setXPath10CompatibleFlag(boolean flag) {
- _xpath10CompatibleFlag = flag;
- }
-
// -- Base URI -------------------------------------------------------
private String _baseURI;
@@ -413,22 +402,52 @@
// -- Default NS for elements and types ------------------------------
- private String _defaultElementNamespace;
-
- public String getDefaultElementNamespace() {
- return _defaultElementNamespace;
+ /**
+ * Finds the nearest declaration of the default XPath namespace as
+ * declared by [xsl:]default-xpath-namespace.
+ */
+ public String getDefaultXPathNamespace() {
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null) {
+ String result = parent.getDefaultXPathNamespace();
+ if (result != null) {
+ return result;
+ }
+ }
+ return ""; // TODO
}
- public void setDefaultElementNamespace(String uri) {
- _defaultElementNamespace = uri;
- }
+ // -- Namespace exclusions ------------------------------------------
- public String getDefaultTypeNamespace() {
- return getDefaultElementNamespace();
+ /**
+ * Check if a namespace URI should not be declared in the output
+ * (unless used). Searches upward in the AST for excluded URI
+ * declarations.
+ */
+ public boolean getExcludeResultURI(String uri) {
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null) {
+ HashSet set = _currentNode.getExcludeResultURIs();
+ if (set != null && set.contains(uri)) return true;
+ parent = parent.getParent();
+ }
+ return false;
}
- public void setDefaultTypeNamespace(String uri) {
- setDefaultElementNamespace(uri);
+ // -- Extension element prefixes ------------------------------------
+
+ /**
+ * Check if a namespace URI corresponds to an extension namespace.
+ * Searches upward in the AST for extension URI declarations.
+ */
+ public boolean getExtensionElementURI(String uri) {
+ SyntaxTreeNode parent = _currentNode;
+ while (parent != null) {
+ HashSet set = _currentNode.getExtensionElementURIs();
+ if (set != null && set.contains(uri)) return true;
+ parent = parent.getParent();
+ }
+ return false;
}
// -- Default NS for functions --------------------------------------
@@ -451,82 +470,6 @@
public void setSchemaType(QName name, Type type) {
// TODO;
- }
-
- // -- Namespace exclusions ------------------------------------------
-
- private HashMap _excludedURI = null;
-
- /**
- * Register a namespace URI so that it will not be declared in the
- * output unless it is actually referenced in the output.
- */
- public void setExcludeURI(String uri) {
- // The null-namespace cannot be excluded
- if (uri == null) return;
-
- // Create new HashMap of exlcuded URIs if none exists
- if (_excludedURI == null) _excludedURI = new HashMap();
-
- // Register the namespace URI
- Integer refcnt = (Integer)_excludedURI.get(uri);
- if (refcnt == null)
- refcnt = new Integer(1);
- else
- refcnt = new Integer(refcnt.intValue() + 1);
- _excludedURI.put(uri, refcnt);
- }
-
- /**
- * Exclude a series of namespaces given by a list of whitespace
- * separated namespace prefixes.
- */
- public void setExcludePrefixes(String prefixes) {
- if (prefixes != null) {
- StringTokenizer tokens = new StringTokenizer(prefixes);
- while (tokens.hasMoreTokens()) {
- final String prefix = tokens.nextToken();
- final String uri;
- if (prefix.equals("#default"))
- uri = getNamespace(Constants.EMPTYSTRING);
- else
- uri = getNamespace(prefix);
- if (uri != null) setExcludeURI(uri);
- }
- }
- }
-
- /**
- * Check if a namespace should not be declared in the output
- * (unless used).
- */
- public boolean getExcludeUri(String uri) {
- if (uri != null && _excludedURI != null) {
- final Integer refcnt = (Integer)_excludedURI.get(uri);
- return (refcnt != null && refcnt.intValue() > 0);
- }
- return false;
- }
-
- /**
- * Turn off namespace declaration exclusion.
- */
- public void setUnexcludePrefixes(String prefixes) {
- if (_excludedURI == null) return;
- if (prefixes != null) {
- StringTokenizer tokens = new StringTokenizer(prefixes);
- while (tokens.hasMoreTokens()) {
- final String prefix = tokens.nextToken();
- final String uri;
- if (prefix.equals("#default"))
- uri = getNamespace(Constants.EMPTYSTRING);
- else
- uri = getNamespace(prefix);
- Integer refcnt = (Integer)_excludedURI.get(uri);
- if (refcnt != null)
- _excludedURI.put(uri, new Integer(refcnt.intValue() -
1));
- }
- }
}
// -- SHOULD BE MOVED OUT OF THIS CLASS !!!! -------------------------
1.43.2.1.2.7 +4 -16
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
Index: Stylesheet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
retrieving revision 1.43.2.1.2.6
retrieving revision 1.43.2.1.2.7
diff -u -r1.43.2.1.2.6 -r1.43.2.1.2.7
--- Stylesheet.java 30 Jan 2003 00:39:23 -0000 1.43.2.1.2.6
+++ Stylesheet.java 12 Feb 2003 16:35:21 -0000 1.43.2.1.2.7
@@ -347,18 +347,6 @@
return (_extensions.get(uri) != null);
}
- public void excludeExtensionPrefixes(Parser parser) {
- final StaticContext scontext = getStaticContext();
- final String excludePrefixes = getAttribute("exclude-result-prefixes");
- final String extensionPrefixes =
getAttribute("extension-element-prefixes");
-
- // Exclude XSLT uri
- scontext.setExcludeURI(Constants.XSLT_URI);
- scontext.setExcludePrefixes(excludePrefixes);
- scontext.setExcludePrefixes(extensionPrefixes);
- extensionURI(extensionPrefixes, scontext);
- }
-
/**
* Parse the version and uri fields of the stylesheet and add an
* entry to the symbol table mapping the name <tt>__stylesheet_</tt>
@@ -396,20 +384,20 @@
// method) as its only child, so the Template class has a special
// method that handles this (parseSimplified()).
if (_simplified) {
- scontext.setExcludeURI(XSLT_URI);
+ addExcludeResultURI(XSLT_URI);
Template template = new Template();
template.parseSimplified(ccontext);
}
// Parse the children of this node
else {
- parseOwnChildren(ccontext);
+ parseContents(ccontext);
}
}
/**
* Parse all direct children of the <xsl:stylesheet/> element.
*/
- public final void parseOwnChildren(CompilerContext ccontext) {
+ protected void parseContents(CompilerContext ccontext) {
final Parser parser = ccontext.getParser();
final ArrayList contents = getContents();
final int count = contents.size();
1.20.2.1.2.7 +158 -11
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
Index: SyntaxTreeNode.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
retrieving revision 1.20.2.1.2.6
retrieving revision 1.20.2.1.2.7
diff -u -r1.20.2.1.2.6 -r1.20.2.1.2.7
--- SyntaxTreeNode.java 30 Jan 2003 00:39:24 -0000 1.20.2.1.2.6
+++ SyntaxTreeNode.java 12 Feb 2003 16:35:22 -0000 1.20.2.1.2.7
@@ -67,6 +67,8 @@
import java.util.Iterator;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.HashSet;
+import java.util.StringTokenizer;
import javax.xml.parsers.*;
@@ -100,11 +102,6 @@
protected Attributes _attributes = null;
/**
- * Namespace declarations of this element (as a mapping).
- */
- private HashMap _prefixMapping = null;
-
- /**
* Source line where this element occurs in the input file.
*/
private int _line;
@@ -126,6 +123,36 @@
protected static final SyntaxTreeNode Dummy = new Text();
/**
+ * Namespace declarations of this element (as a mapping).
+ */
+ private HashMap _prefixMapping = null;
+
+ /**
+ * Set of URIs to be excluded in the result for the scope defined
+ * by this node. These URIs are resolved from the value of the
+ * standard attribute [xsl:]exclude-result-prefixes.
+ */
+ private HashSet _excludeResultURIs = null;
+
+ /**
+ * Set of URIs of extension elements for the scope defined by
+ * this node. These URIs are resolved from the value of the
+ * standard attribute [xsl:]extension-element-prefixes.
+ */
+ private HashSet _extensionElementURIs = null;
+
+ /**
+ * Value of the standard attribute [xsl:]version. Defaults to 2.0
+ * if not present.
+ */
+ private float _version = 2.0f;
+
+ /**
+ * Value of the standard attribute [xsl:]default-xpath-namespace.
+ */
+ private String _defaultXPathNamespace = null;
+
+ /**
* Creates a new SyntaxTreeNode with a 'null' QName and no source file
* line number reference.
*/
@@ -243,12 +270,96 @@
// -- Node's attributes ------------------------------------------
/**
- * Set the attributes for this SyntaxTreeNode.
+ * Set the attributes for this SyntaxTreeNode. As a side effect,
+ * process standard attributes [xsl:]version, [xsl:]default-
+ * xpath-namespace, [xsl:]exclude-result-prefixes [xsl:]extension-
+ * element-prefixes.
*
* @param attributes Attributes for the element.
*/
protected void setAttributes(Attributes attributes) {
+ // Set internal attributes object
_attributes = attributes;
+
+ // Process standard attributes
+ final int n = attributes.getLength();
+ StaticContext scontext = getStaticContext();
+ boolean isLiteralElement = (this instanceof LiteralElement);
+
+ for (int i = 0; i < n; i++) {
+ final String namespace = attributes.getURI(i);
+ final String localName = attributes.getLocalName(i);
+
+ // [xsl:]default-xpath-namespace
+ if (localName.equals("default-xpath-namespace") &&
+ (!isLiteralElement || namespace.equals(XSLT_URI)))
+ {
+ _defaultXPathNamespace = attributes.getValue(i);
+ }
+
+ // [xsl:]version (scoped)
+ if (localName.equals("version") &&
+ (!isLiteralElement || namespace.equals(XSLT_URI)))
+ {
+ try {
+ _version = Float.parseFloat(attributes.getValue(i));
+ }
+ catch (NumberFormatException e) {
+ // TODO
+ throw new ToDoException("report error if version is
ilegal");
+ }
+ }
+
+ // [xsl:]exclude-result-prefixes
+ if (localName.equals("exclude-result-prefixes") &&
+ (!isLiteralElement || namespace.equals(XSLT_URI)))
+ {
+ StringTokenizer tokens =
+ new StringTokenizer(attributes.getValue(i));
+
+ // Allocate HashSet if necessary
+ if (_excludeResultURIs != null) {
+ _excludeResultURIs = new HashSet();
+ }
+
+ // Resolve list of prefixes and add to set
+ while (tokens.hasMoreTokens()) {
+ String prefix = tokens.nextToken();
+ String uri = scontext.getNamespace(
+ prefix.equals("#default") ? "" : prefix);
+ if (uri == null) {
+ // TODO
+ throw new ToDoException("report error if undef prefix");
+ }
+ _excludeResultURIs.add(uri);
+ }
+ }
+
+ // [xsl:]extension-element-prefixes
+ if (localName.equals("extension-element-prefixes") &&
+ (!isLiteralElement || namespace.equals(XSLT_URI)))
+ {
+ StringTokenizer tokens =
+ new StringTokenizer(attributes.getValue(i));
+
+ // Allocate HashSet if necessary
+ if (_extensionElementURIs != null) {
+ _extensionElementURIs = new HashSet();
+ }
+
+ // Resolve list of prefixes and add to set
+ while (tokens.hasMoreTokens()) {
+ String prefix = tokens.nextToken();
+ String uri = scontext.getNamespace(
+ prefix.equals("#default") ? "" : prefix);
+ if (uri == null) {
+ // TODO
+ throw new ToDoException("report error if undef
prefix");
+ }
+ _extensionElementURIs.add(uri);
+ }
+ }
+ }
}
/**
@@ -281,7 +392,44 @@
return _attributes;
}
- // -- Node's NS declarations -------------------------------------
+ // -- Standard attributes --------------------------------------------
+
+ public float getVersion() {
+ return _version;
+ }
+
+ /**
+ * This method should only be called from StaticContext.
+ */
+ public String getDefaultXPathNamespace() {
+ return _defaultXPathNamespace;
+ }
+
+ /**
+ * This method should only be called from StaticContext.
+ */
+ public HashSet getExcludeResultURIs() {
+ return _excludeResultURIs;
+ }
+
+ /**
+ * This method should only be called from StaticContext.
+ */
+ public HashSet getExtensionElementURIs() {
+ return _extensionElementURIs;
+ }
+
+ /**
+ * Adds a single URI to the set of excluded ones.
+ */
+ public void addExcludeResultURI(String uri) {
+ if (_excludeResultURIs == null) {
+ _excludeResultURIs = new HashSet();
+ }
+ _excludeResultURIs.add(uri);
+ }
+
+ // -- Node's NS declarations ----------------------------------------
/**
* Sets the prefix mapping for the namespaces that were declared in this
@@ -356,15 +504,14 @@
* Parse all children of this syntax tree node. This method is normally
* called by the parse() method.
*/
- protected final void parseContents(CompilerContext ccontext) {
+ protected void parseContents(CompilerContext ccontext) {
ArrayList locals = null;
StaticContext scontext = getStaticContext();
final int count = _contents.size();
for (int i = 0; i < count; i++) {
SyntaxTreeNode child = (SyntaxTreeNode) _contents.get(i);
- scontext.setCurrentNode(child);
- child.parse(ccontext);
+ child.parse(ccontext);
// Is variable or parameter?
if (child instanceof VariableBase) {
1.7.8.1.2.6 +2 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Whitespace.java
Index: Whitespace.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Whitespace.java,v
retrieving revision 1.7.8.1.2.5
retrieving revision 1.7.8.1.2.6
diff -u -r1.7.8.1.2.5 -r1.7.8.1.2.6
--- Whitespace.java 30 Jan 2003 00:39:26 -0000 1.7.8.1.2.5
+++ Whitespace.java 12 Feb 2003 16:35:22 -0000 1.7.8.1.2.6
@@ -432,7 +432,7 @@
final Parser parser = classGen.getParser();
QName qname;
if (rule.getNamespace() != Constants.EMPTYSTRING )
- qname = parser.getQName(rule.getNamespace(), null,
+ qname = parser.getQName(rule.getNamespace(), "",
rule.getElement());
else
qname = parser.getQName(rule.getElement());
No revision
No revision
1.1.2.1 +76 -0
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Attic/ToDoException.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]