diff options
author | Chris Burdess <dog@bluezoo.org> | 2005-07-09 20:38:33 +0000 |
---|---|---|
committer | Chris Burdess <dog@bluezoo.org> | 2005-07-09 20:38:33 +0000 |
commit | 55e6004315b2ec5cf1d801689fb67e08ef58a500 (patch) | |
tree | 85b23bd63d20011c08122fa0ccf7862456c274b5 | |
parent | 7a86e8a0bcbada1881ab8c46560094e2b466b943 (diff) | |
download | classpath-55e6004315b2ec5cf1d801689fb67e08ef58a500.tar.gz |
2005-07-09 Chris Burdess <dog@gnu.org>
* gnu/xml/transform/AbstractNumberNode.java,
gnu/xml/transform/ApplyImportsNode.java,
gnu/xml/transform/ApplyTemplatesNode.java,
gnu/xml/transform/AttributeNode.java,
gnu/xml/transform/Bindings.java,
gnu/xml/transform/CallTemplateNode.java,
gnu/xml/transform/CopyOfNode.java,
gnu/xml/transform/CurrentFunction.java,
gnu/xml/transform/DocumentFunction.java,
gnu/xml/transform/ElementAvailableFunction.java,
gnu/xml/transform/ElementNode.java,
gnu/xml/transform/ForEachNode.java,
gnu/xml/transform/FormatNumberFunction.java,
gnu/xml/transform/FunctionAvailableFunction.java,
gnu/xml/transform/GenerateIdFunction.java,
gnu/xml/transform/IfNode.java,
gnu/xml/transform/KeyFunction.java,
gnu/xml/transform/ParameterNode.java,
gnu/xml/transform/SortKey.java,
gnu/xml/transform/StreamSerializer.java,
gnu/xml/transform/Stylesheet.java,
gnu/xml/transform/SystemPropertyFunction.java,
gnu/xml/transform/TemplateNode.java,
gnu/xml/transform/TransformerImpl.java,
gnu/xml/transform/UnparsedEntityUriFunction.java,
gnu/xml/transform/ValueOfNode.java,
gnu/xml/transform/WhenNode.java,
gnu/xml/transform/WithParam.java,
gnu/xml/xpath/AndExpr.java,
gnu/xml/xpath/ArithmeticExpr.java,
gnu/xml/xpath/BooleanFunction.java,
gnu/xml/xpath/CeilingFunction.java,
gnu/xml/xpath/ConcatFunction.java,
gnu/xml/xpath/Constant.java,
gnu/xml/xpath/ContainsFunction.java,
gnu/xml/xpath/CountFunction.java,
gnu/xml/xpath/EqualityExpr.java,
gnu/xml/xpath/Expr.java,
gnu/xml/xpath/FalseFunction.java,
gnu/xml/xpath/FloorFunction.java,
gnu/xml/xpath/FunctionCall.java,
gnu/xml/xpath/IdFunction.java,
gnu/xml/xpath/LangFunction.java,
gnu/xml/xpath/LastFunction.java,
gnu/xml/xpath/LocalNameFunction.java,
gnu/xml/xpath/NameFunction.java,
gnu/xml/xpath/NameTest.java,
gnu/xml/xpath/NamespaceTest.java,
gnu/xml/xpath/NamespaceUriFunction.java,
gnu/xml/xpath/NegativeExpr.java,
gnu/xml/xpath/NodeTypeTest.java,
gnu/xml/xpath/NormalizeSpaceFunction.java,
gnu/xml/xpath/NotFunction.java,
gnu/xml/xpath/NumberFunction.java,
gnu/xml/xpath/OrExpr.java,
gnu/xml/xpath/ParenthesizedExpr.java,
gnu/xml/xpath/Pattern.java,
gnu/xml/xpath/PositionFunction.java,
gnu/xml/xpath/Predicate.java,
gnu/xml/xpath/RelationalExpr.java,
gnu/xml/xpath/Root.java,
gnu/xml/xpath/RoundFunction.java,
gnu/xml/xpath/Selector.java,
gnu/xml/xpath/StartsWithFunction.java,
gnu/xml/xpath/Steps.java,
gnu/xml/xpath/StringFunction.java,
gnu/xml/xpath/StringLengthFunction.java,
gnu/xml/xpath/SubstringAfterFunction.java,
gnu/xml/xpath/SubstringBeforeFunction.java,
gnu/xml/xpath/SubstringFunction.java,
gnu/xml/xpath/SumFunction.java,
gnu/xml/xpath/Test.java,
gnu/xml/xpath/TranslateFunction.java,
gnu/xml/xpath/TrueFunction.java,
gnu/xml/xpath/UnionExpr.java,
gnu/xml/xpath/VariableReference.java,
gnu/xml/xpath/XPathParser.java,
gnu/xml/xpath/XPathParser.y,
javax/xml/namespace/QName.java: Corrections to handling of XSL
variables and minor conformance updates.
80 files changed, 1178 insertions, 298 deletions
@@ -1,3 +1,86 @@ +2005-07-09 Chris Burdess <dog@gnu.org> + + * gnu/xml/transform/AbstractNumberNode.java, + gnu/xml/transform/ApplyImportsNode.java, + gnu/xml/transform/ApplyTemplatesNode.java, + gnu/xml/transform/AttributeNode.java, + gnu/xml/transform/Bindings.java, + gnu/xml/transform/CallTemplateNode.java, + gnu/xml/transform/CopyOfNode.java, + gnu/xml/transform/CurrentFunction.java, + gnu/xml/transform/DocumentFunction.java, + gnu/xml/transform/ElementAvailableFunction.java, + gnu/xml/transform/ElementNode.java, + gnu/xml/transform/ForEachNode.java, + gnu/xml/transform/FormatNumberFunction.java, + gnu/xml/transform/FunctionAvailableFunction.java, + gnu/xml/transform/GenerateIdFunction.java, + gnu/xml/transform/IfNode.java, + gnu/xml/transform/KeyFunction.java, + gnu/xml/transform/ParameterNode.java, + gnu/xml/transform/SortKey.java, + gnu/xml/transform/StreamSerializer.java, + gnu/xml/transform/Stylesheet.java, + gnu/xml/transform/SystemPropertyFunction.java, + gnu/xml/transform/TemplateNode.java, + gnu/xml/transform/TransformerImpl.java, + gnu/xml/transform/UnparsedEntityUriFunction.java, + gnu/xml/transform/ValueOfNode.java, + gnu/xml/transform/WhenNode.java, + gnu/xml/transform/WithParam.java, + gnu/xml/xpath/AndExpr.java, + gnu/xml/xpath/ArithmeticExpr.java, + gnu/xml/xpath/BooleanFunction.java, + gnu/xml/xpath/CeilingFunction.java, + gnu/xml/xpath/ConcatFunction.java, + gnu/xml/xpath/Constant.java, + gnu/xml/xpath/ContainsFunction.java, + gnu/xml/xpath/CountFunction.java, + gnu/xml/xpath/EqualityExpr.java, + gnu/xml/xpath/Expr.java, + gnu/xml/xpath/FalseFunction.java, + gnu/xml/xpath/FloorFunction.java, + gnu/xml/xpath/FunctionCall.java, + gnu/xml/xpath/IdFunction.java, + gnu/xml/xpath/LangFunction.java, + gnu/xml/xpath/LastFunction.java, + gnu/xml/xpath/LocalNameFunction.java, + gnu/xml/xpath/NameFunction.java, + gnu/xml/xpath/NameTest.java, + gnu/xml/xpath/NamespaceTest.java, + gnu/xml/xpath/NamespaceUriFunction.java, + gnu/xml/xpath/NegativeExpr.java, + gnu/xml/xpath/NodeTypeTest.java, + gnu/xml/xpath/NormalizeSpaceFunction.java, + gnu/xml/xpath/NotFunction.java, + gnu/xml/xpath/NumberFunction.java, + gnu/xml/xpath/OrExpr.java, + gnu/xml/xpath/ParenthesizedExpr.java, + gnu/xml/xpath/Pattern.java, + gnu/xml/xpath/PositionFunction.java, + gnu/xml/xpath/Predicate.java, + gnu/xml/xpath/RelationalExpr.java, + gnu/xml/xpath/Root.java, + gnu/xml/xpath/RoundFunction.java, + gnu/xml/xpath/Selector.java, + gnu/xml/xpath/StartsWithFunction.java, + gnu/xml/xpath/Steps.java, + gnu/xml/xpath/StringFunction.java, + gnu/xml/xpath/StringLengthFunction.java, + gnu/xml/xpath/SubstringAfterFunction.java, + gnu/xml/xpath/SubstringBeforeFunction.java, + gnu/xml/xpath/SubstringFunction.java, + gnu/xml/xpath/SumFunction.java, + gnu/xml/xpath/Test.java, + gnu/xml/xpath/TranslateFunction.java, + gnu/xml/xpath/TrueFunction.java, + gnu/xml/xpath/UnionExpr.java, + gnu/xml/xpath/VariableReference.java, + gnu/xml/xpath/XPathParser.java, + gnu/xml/xpath/XPathParser.y, + javax/xml/namespace/QName.java: Corrections to handling of XSL + variables and minor conformance updates. + 2005-07-09 Archie Cobbs <archie@dellroad.org> * java/net/URLClassLoader.java: disallow directories as resources diff --git a/gnu/xml/transform/AbstractNumberNode.java b/gnu/xml/transform/AbstractNumberNode.java index e0879c4c1..91029d6d0 100644 --- a/gnu/xml/transform/AbstractNumberNode.java +++ b/gnu/xml/transform/AbstractNumberNode.java @@ -306,6 +306,15 @@ abstract class AbstractNumberNode abstract int[] compute(Stylesheet stylesheet, Node context, int pos, int len) throws TransformerException; + public boolean references(QName var) + { + if (format.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/ApplyImportsNode.java b/gnu/xml/transform/ApplyImportsNode.java index 03e755a99..60dec85d3 100644 --- a/gnu/xml/transform/ApplyImportsNode.java +++ b/gnu/xml/transform/ApplyImportsNode.java @@ -81,6 +81,6 @@ final class ApplyImportsNode parent, nextSibling); } } - + } diff --git a/gnu/xml/transform/ApplyTemplatesNode.java b/gnu/xml/transform/ApplyTemplatesNode.java index 44255bab7..ab26058bc 100644 --- a/gnu/xml/transform/ApplyTemplatesNode.java +++ b/gnu/xml/transform/ApplyTemplatesNode.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import javax.xml.namespace.QName; import javax.xml.transform.TransformerException; @@ -111,14 +112,26 @@ final class ApplyTemplatesNode { if (withParams != null) { - // push the parameter context - stylesheet.bindings.push(false); - // set the parameters + // compute the parameter values + LinkedList values = new LinkedList(); for (Iterator i = withParams.iterator(); i.hasNext(); ) { WithParam p = (WithParam) i.next(); Object value = p.getValue(stylesheet, mode, context, pos, len); - stylesheet.bindings.set(p.name, value, false); + Object[] pair = new Object[2]; + pair[0] = p.name; + pair[1] = value; + values.add(pair); + } + // push the parameter context + stylesheet.bindings.push(Bindings.WITH_PARAM); + // set the parameters + for (Iterator i = values.iterator(); i.hasNext(); ) + { + Object[] pair = (Object[]) i.next(); + QName name = (QName) pair[0]; + Object value = pair[1]; + stylesheet.bindings.set(name, value, Bindings.WITH_PARAM); } } Collection ns = (Collection) ret; @@ -154,7 +167,7 @@ final class ApplyTemplatesNode if (withParams != null) { // pop the variable context - stylesheet.bindings.pop(false); + stylesheet.bindings.pop(Bindings.WITH_PARAM); } } // apply-templates doesn't have processable children @@ -165,6 +178,35 @@ final class ApplyTemplatesNode parent, nextSibling); } } + + public boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + if (withParams != null) + { + for (Iterator i = withParams.iterator(); i.hasNext(); ) + { + if (((WithParam) i.next()).references(var)) + { + return true; + } + } + } + if (sortKeys != null) + { + for (Iterator i = sortKeys.iterator(); i.hasNext(); ) + { + if (((SortKey) i.next()).references(var)) + { + return true; + } + } + } + return super.references(var); + } public String toString() { diff --git a/gnu/xml/transform/AttributeNode.java b/gnu/xml/transform/AttributeNode.java index 3e082f985..1e0eb1e96 100644 --- a/gnu/xml/transform/AttributeNode.java +++ b/gnu/xml/transform/AttributeNode.java @@ -237,6 +237,19 @@ final class AttributeNode } return ret; } + + public boolean references(QName var) + { + if (name != null && name.references(var)) + { + return true; + } + if (namespace != null && namespace.references(var)) + { + return true; + } + return super.references(var); + } public String toString() { diff --git a/gnu/xml/transform/Bindings.java b/gnu/xml/transform/Bindings.java index 7bea4e823..c372ea830 100644 --- a/gnu/xml/transform/Bindings.java +++ b/gnu/xml/transform/Bindings.java @@ -57,6 +57,10 @@ public class Bindings implements XPathVariableResolver, Cloneable { + static final int VARIABLE = 0; + static final int PARAM = 1; + static final int WITH_PARAM = 2; + final Stylesheet stylesheet; /** @@ -69,13 +73,21 @@ public class Bindings */ final LinkedList parameters; + /** + * Argument (with-param) value stack. + */ + final LinkedList withParameters; + Bindings(Stylesheet stylesheet) { this.stylesheet = stylesheet; variables = new LinkedList(); parameters = new LinkedList(); - push(true); - push(false); + withParameters = new LinkedList(); + for (int i = 0; i < 3; i++) + { + push(i); + } } public Object clone() @@ -90,53 +102,87 @@ public class Bindings } } - void push(boolean global) + void push(int type) { - if (global) + switch (type) { + case VARIABLE: variables.addFirst(new HashMap()); - } - else - { + break; + case PARAM: parameters.addFirst(new HashMap()); + break; + case WITH_PARAM: + withParameters.addFirst(new HashMap()); + break; } } - void pop(boolean global) + void pop(int type) { - if (global) + switch (type) { + case VARIABLE: variables.removeFirst(); - } - else - { + break; + case PARAM: parameters.removeFirst(); + break; + case WITH_PARAM: + withParameters.removeFirst(); + break; } } - public boolean containsKey(String name, boolean global) + public boolean containsKey(QName name, int type) { - Iterator i = global ? variables.iterator() : parameters.iterator(); - while (i.hasNext()) + Iterator i = null; + switch (type) { - Map ctx = (Map) i.next(); - if (ctx.containsKey(name)) + case VARIABLE: + i = variables.iterator(); + break; + case PARAM: + i = parameters.iterator(); + break; + case WITH_PARAM: + Map ctx = (Map) withParameters.getFirst(); + return ctx.containsKey(name); + } + if (i != null) + { + while (i.hasNext()) { - return true; + Map ctx = (Map) i.next(); + if (ctx.containsKey(name)) + { + return true; + } } } return false; } - public Object get(String name, Node context, int pos, int len) + public Object get(QName name, Node context, int pos, int len) { //System.err.println("bindings.get: "+name); //System.err.println("\t"+toString()); Object ret = null; - for (Iterator i = variables.iterator(); i.hasNext() && ret == null; ) + //if (parameters.size() > 1 && containsKey(name, PARAM)) + // check that template defines parameter { - Map vctx = (Map) i.next(); - ret = vctx.get(name); + Map cwp = (Map) withParameters.getFirst(); + ret = cwp.get(name); + //System.err.println("\twith-param: ret="+ret); + } + if (ret == null) + { + for (Iterator i = variables.iterator(); i.hasNext() && ret == null; ) + { + Map vctx = (Map) i.next(); + ret = vctx.get(name); + } + //System.err.println("\tvariable: ret="+ret); } if (ret == null) { @@ -145,6 +191,7 @@ public class Bindings Map pctx = (Map) i.next(); ret = pctx.get(name); } + //System.err.println("\tparam: ret="+ret); } /*if (ret instanceof Expr && context != null) { @@ -163,23 +210,29 @@ public class Bindings return ret; } - void set(String name, Object value, boolean global) + void set(QName name, Object value, int type) { - if (global) - { - Map context = (Map) variables.getFirst(); - context.put(name, value); - } - else + switch (type) { - Map context = (Map) parameters.getFirst(); - context.put(name, value); + case VARIABLE: + Map vctx = (Map) variables.getFirst(); + vctx.put(name, value); + break; + case PARAM: + Map pctx = (Map) parameters.getFirst(); + pctx.put(name, value); + break; + case WITH_PARAM: + Map wctx = (Map) withParameters.getFirst(); + wctx.put(name, value); + break; } + //System.err.println("Set "+name+"="+value); } public Object resolveVariable(QName qName) { - return get(qName.toString(), null, 1, 1); + return get(qName, null, 1, 1); } public String toString() @@ -187,6 +240,31 @@ public class Bindings StringBuffer buf = new StringBuffer(); boolean next = false; Collection seen = new HashSet(); + Map wctx = (Map) withParameters.getFirst(); + buf.append('('); + for (Iterator i = wctx.entrySet().iterator(); i.hasNext(); ) + { + if (next) + { + buf.append(','); + } + else + { + next = true; + } + Map.Entry entry = (Map.Entry) i.next(); + Object key = entry.getKey(); + if (!seen.contains(key)) + { + buf.append(key); + buf.append('='); + buf.append(entry.getValue()); + seen.add(key); + } + } + buf.append(')'); + next = false; + seen.clear(); buf.append('{'); for (Iterator i = variables.iterator(); i.hasNext(); ) { @@ -212,6 +290,10 @@ public class Bindings } } } + buf.append('}'); + next = false; + seen.clear(); + buf.append('['); for (Iterator i = parameters.iterator(); i.hasNext(); ) { Map ctx = (Map) i.next(); @@ -236,7 +318,8 @@ public class Bindings } } } - buf.append('}'); + buf.append(']'); return buf.toString(); } + } diff --git a/gnu/xml/transform/CallTemplateNode.java b/gnu/xml/transform/CallTemplateNode.java index 5b2543f80..b678219d7 100644 --- a/gnu/xml/transform/CallTemplateNode.java +++ b/gnu/xml/transform/CallTemplateNode.java @@ -39,6 +39,7 @@ package gnu.xml.transform; import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import javax.xml.namespace.QName; import javax.xml.transform.TransformerException; @@ -90,14 +91,30 @@ final class CallTemplateNode { if (withParams != null) { - // push the parameter context - stylesheet.bindings.push(false); - // set the parameters + // compute the parameter values + LinkedList values = new LinkedList(); for (Iterator i = withParams.iterator(); i.hasNext(); ) { WithParam p = (WithParam) i.next(); Object value = p.getValue(stylesheet, mode, context, pos, len); - stylesheet.bindings.set(p.name, value, false); + Object[] pair = new Object[2]; + pair[0] = p.name; + pair[1] = value; + values.add(pair); + } + // push the parameter context + stylesheet.bindings.push(Bindings.WITH_PARAM); + // set the parameters + for (Iterator i = values.iterator(); i.hasNext(); ) + { + Object[] pair = (Object[]) i.next(); + QName name = (QName) pair[0]; + Object value = pair[1]; + stylesheet.bindings.set(name, value, Bindings.WITH_PARAM); + if (stylesheet.debug) + { + System.err.println("with-param: " + name + " = " + value); + } } } TemplateNode t = stylesheet.getTemplate(mode, name); @@ -109,7 +126,7 @@ final class CallTemplateNode if (withParams != null) { // pop the variable context - stylesheet.bindings.pop(false); + stylesheet.bindings.pop(Bindings.WITH_PARAM); } // call-template doesn't have processable children if (next != null) @@ -120,6 +137,21 @@ final class CallTemplateNode } } + public boolean references(QName var) + { + if (withParams != null) + { + for (Iterator i = withParams.iterator(); i.hasNext(); ) + { + if (((WithParam) i.next()).references(var)) + { + return true; + } + } + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/CopyOfNode.java b/gnu/xml/transform/CopyOfNode.java index 6fe00f537..a43e3ba84 100644 --- a/gnu/xml/transform/CopyOfNode.java +++ b/gnu/xml/transform/CopyOfNode.java @@ -170,6 +170,15 @@ final class CopyOfNode } } + public boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/CurrentFunction.java b/gnu/xml/transform/CurrentFunction.java index 845793ac7..0395396bc 100644 --- a/gnu/xml/transform/CurrentFunction.java +++ b/gnu/xml/transform/CurrentFunction.java @@ -39,6 +39,7 @@ package gnu.xml.transform; import java.util.Collections; import java.util.List; +import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import org.w3c.dom.Node; @@ -89,6 +90,11 @@ final class CurrentFunction return new CurrentFunction(s); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "current()"; diff --git a/gnu/xml/transform/DocumentFunction.java b/gnu/xml/transform/DocumentFunction.java index 22dac75db..d8f6090be 100644 --- a/gnu/xml/transform/DocumentFunction.java +++ b/gnu/xml/transform/DocumentFunction.java @@ -43,6 +43,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.TreeSet; +import javax.xml.namespace.QName; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.xpath.XPathFunction; @@ -239,5 +240,17 @@ final class DocumentFunction f.setArguments(args2); return f; } + + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } } diff --git a/gnu/xml/transform/ElementAvailableFunction.java b/gnu/xml/transform/ElementAvailableFunction.java index 7cf00d325..84cb6207a 100644 --- a/gnu/xml/transform/ElementAvailableFunction.java +++ b/gnu/xml/transform/ElementAvailableFunction.java @@ -40,8 +40,10 @@ package gnu.xml.transform; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.TreeSet; +import javax.xml.namespace.QName; import javax.xml.namespace.NamespaceContext; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; @@ -165,5 +167,17 @@ class ElementAvailableFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/ElementNode.java b/gnu/xml/transform/ElementNode.java index 6736f0c74..d8f7f6db6 100644 --- a/gnu/xml/transform/ElementNode.java +++ b/gnu/xml/transform/ElementNode.java @@ -265,6 +265,19 @@ final class ElementNode } } + public boolean references(QName var) + { + if (name != null && name.references(var)) + { + return true; + } + if (namespace != null && namespace.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/ForEachNode.java b/gnu/xml/transform/ForEachNode.java index 7b38d479a..8f9220f67 100644 --- a/gnu/xml/transform/ForEachNode.java +++ b/gnu/xml/transform/ForEachNode.java @@ -139,6 +139,25 @@ final class ForEachNode } } + public boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + if (sortKeys != null) + { + for (Iterator i = sortKeys.iterator(); i.hasNext(); ) + { + if (((SortKey) i.next()).references(var)) + { + return true; + } + } + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/FormatNumberFunction.java b/gnu/xml/transform/FormatNumberFunction.java index aaa015b4a..34717b39c 100644 --- a/gnu/xml/transform/FormatNumberFunction.java +++ b/gnu/xml/transform/FormatNumberFunction.java @@ -40,7 +40,9 @@ package gnu.xml.transform; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import org.w3c.dom.Node; @@ -128,5 +130,17 @@ final class FormatNumberFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/FunctionAvailableFunction.java b/gnu/xml/transform/FunctionAvailableFunction.java index b7dfb6192..7daf7ea3f 100644 --- a/gnu/xml/transform/FunctionAvailableFunction.java +++ b/gnu/xml/transform/FunctionAvailableFunction.java @@ -40,9 +40,11 @@ package gnu.xml.transform; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.TreeSet; import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import org.w3c.dom.Node; @@ -171,5 +173,17 @@ class FunctionAvailableFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/GenerateIdFunction.java b/gnu/xml/transform/GenerateIdFunction.java index a7682c918..f0d3e6dd9 100644 --- a/gnu/xml/transform/GenerateIdFunction.java +++ b/gnu/xml/transform/GenerateIdFunction.java @@ -40,7 +40,9 @@ package gnu.xml.transform; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import org.w3c.dom.Node; @@ -122,5 +124,17 @@ final class GenerateIdFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/IfNode.java b/gnu/xml/transform/IfNode.java index a5de112ba..17e2486fe 100644 --- a/gnu/xml/transform/IfNode.java +++ b/gnu/xml/transform/IfNode.java @@ -98,6 +98,15 @@ final class IfNode } } + public boolean references(QName var) + { + if (test != null && test.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/KeyFunction.java b/gnu/xml/transform/KeyFunction.java index eb842f289..a705dc6b0 100644 --- a/gnu/xml/transform/KeyFunction.java +++ b/gnu/xml/transform/KeyFunction.java @@ -212,5 +212,17 @@ final class KeyFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/ParameterNode.java b/gnu/xml/transform/ParameterNode.java index ffa6ea5be..ef09ea5f9 100644 --- a/gnu/xml/transform/ParameterNode.java +++ b/gnu/xml/transform/ParameterNode.java @@ -53,24 +53,25 @@ import gnu.xml.xpath.Expr; */ final class ParameterNode extends TemplateNode + implements Comparable { - final String name; + final QName name; final Expr select; - final boolean global; + final int type; - ParameterNode(String name, Expr select, boolean global) + ParameterNode(QName name, Expr select, int type) { this.name = name; this.select = select; - this.global = global; + this.type = type; } TemplateNode clone(Stylesheet stylesheet) { TemplateNode ret = new ParameterNode(name, select.clone(stylesheet), - global); + type); if (children != null) { ret.children = children.clone(stylesheet); @@ -83,20 +84,20 @@ final class ParameterNode } void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) + Node context, int pos, int len, + Node parent, Node nextSibling) throws TransformerException { - boolean apply = global || !stylesheet.bindings.containsKey(name, global); - if (apply) + // push the variable context + stylesheet.bindings.push(type); + // set the variable + Object value = getValue(stylesheet, mode, context, pos, len); + if (value != null) { - // push the variable context - stylesheet.bindings.push(global); - // set the variable - Object value = getValue(stylesheet, mode, context, pos, len); - if (value != null) + stylesheet.bindings.set(name, value, type); + if (stylesheet.debug) { - stylesheet.bindings.set(name, value, global); + System.err.println(this + ": set to " + value); } } // variable and param don't process children as such @@ -107,11 +108,8 @@ final class ParameterNode context, pos, len, parent, nextSibling); } - if (apply) - { - // pop the variable context - stylesheet.bindings.pop(global); - } + // pop the variable context + stylesheet.bindings.pop(type); } Object getValue(Stylesheet stylesheet, QName mode, @@ -136,6 +134,38 @@ final class ParameterNode } } + public boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + return super.references(var); + } + + public int compareTo(Object other) + { + if (other instanceof ParameterNode) + { + ParameterNode pn = (ParameterNode) other; + boolean r1 = references(pn.name); + boolean r2 = pn.references(name); + if (r1 && r2) + { + throw new IllegalArgumentException("circular definitions"); + } + if (r1) + { + return 1; + } + if (r2) + { + return -1; + } + } + return 0; + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); @@ -147,9 +177,18 @@ final class ParameterNode buf.append(",select="); buf.append(select); } - if (global) + buf.append(",type="); + switch (type) { - buf.append(",global"); + case Bindings.VARIABLE: + buf.append("variable"); + break; + case Bindings.PARAM: + buf.append("param"); + break; + case Bindings.WITH_PARAM: + buf.append("with-param"); + break; } buf.append(']'); return buf.toString(); diff --git a/gnu/xml/transform/SortKey.java b/gnu/xml/transform/SortKey.java index 1ec9bdd57..d4ffb05e2 100644 --- a/gnu/xml/transform/SortKey.java +++ b/gnu/xml/transform/SortKey.java @@ -151,4 +151,29 @@ final class SortKey } } + boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + if (langTemplate != null && langTemplate.references(var)) + { + return true; + } + if (dataTypeTemplate != null && dataTypeTemplate.references(var)) + { + return true; + } + if (orderTemplate != null && orderTemplate.references(var)) + { + return true; + } + if (caseOrderTemplate != null && caseOrderTemplate.references(var)) + { + return true; + } + return false; + } + } diff --git a/gnu/xml/transform/StreamSerializer.java b/gnu/xml/transform/StreamSerializer.java index c309f03f5..eb045393d 100644 --- a/gnu/xml/transform/StreamSerializer.java +++ b/gnu/xml/transform/StreamSerializer.java @@ -646,13 +646,6 @@ public class StreamSerializer return ret; } - String hex(byte[] b) { - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < b.length; i++) - buf.append(Integer.toHexString(b[i])).append(' '); - return buf.toString(); - } - String encode(String text, boolean encodeCtl, boolean inAttr) { int len = text.length(); diff --git a/gnu/xml/transform/Stylesheet.java b/gnu/xml/transform/Stylesheet.java index 44a30c854..99431b699 100644 --- a/gnu/xml/transform/Stylesheet.java +++ b/gnu/xml/transform/Stylesheet.java @@ -354,13 +354,21 @@ class Stylesheet void initTopLevelVariables(Node context) throws TransformerException { - for (Iterator i = variables.iterator(); i.hasNext(); ) + current = context; + // Sort the variables into order + // See XSLT 11.4: "If the template or expression specifying the value of + // a global variable x references a global variable y, then the value + // for y must be computed before the value of x." + List topLevel = new ArrayList(variables); + Collections.sort(topLevel); + for (Iterator i = topLevel.iterator(); i.hasNext(); ) { ParameterNode var = (ParameterNode) i.next(); bindings.set(var.name, var.getValue(this, null, context, 1, 1), - var.global); + var.type); } + current = null; } // -- NamespaceContext -- @@ -380,6 +388,19 @@ class Stylesheet // TODO return Collections.singleton(getPrefix(namespaceURI)).iterator(); } + + final QName getQName(String name) + { + String localName = name, uri = null, prefix = null; + int ci = name.indexOf(':'); + if (ci != -1) + { + prefix = name.substring(0, ci); + localName = name.substring(ci + 1); + uri = getNamespaceURI(prefix); + } + return new QName(uri, localName, prefix); + } // -- Template selection -- @@ -713,9 +734,11 @@ class Stylesheet else if ("param".equals(name) || "variable".equals(name)) { - boolean global = "variable".equals(name); + int type = "variable".equals(name) ? + Bindings.VARIABLE : Bindings.PARAM; TemplateNode content = parse(node.getFirstChild()); - String paramName = getRequiredAttribute(attrs, "name", node); + QName paramName = + getQName(getRequiredAttribute(attrs, "name", node)); String select = getAttribute(attrs, "select"); ParameterNode param; if (select != null && select.length() > 0) @@ -728,15 +751,14 @@ class Stylesheet throw new TransformerConfigurationException(msg, l); } Expr expr = (Expr) xpath.compile(select); - param = new ParameterNode(paramName, expr, global); + param = new ParameterNode(paramName, expr, type); } else { - param = new ParameterNode(paramName, null, global); + param = new ParameterNode(paramName, null, type); param.children = content; } variables.add(param); - bindings.set(paramName, content, global); } else if ("include".equals(name) || "import".equals(name)) { @@ -860,20 +882,6 @@ class Stylesheet } } - final QName getQName(String name) - { - QName qName = QName.valueOf(name); - String prefix = qName.getPrefix(); - String uri = qName.getNamespaceURI(); - if (prefix != null && (uri == null || uri.length() == 0)) - { - uri = getNamespaceURI(prefix); - String localName = qName.getLocalPart(); - qName = new QName(uri, localName, prefix); - } - return qName; - } - final TemplateNode parseAttributeValueTemplate(String value, Node source) throws TransformerConfigurationException, XPathExpressionException { @@ -1501,11 +1509,13 @@ class Stylesheet else if ("param".equals(name) || "variable".equals(name)) { - boolean global = "variable".equals(name); + int type = "variable".equals(name) ? + Bindings.VARIABLE : Bindings.PARAM; NamedNodeMap attrs = node.getAttributes(); Node children = node.getFirstChild(); TemplateNode content = parse(children); - String paramName = getRequiredAttribute(attrs, "name", node); + QName paramName = + getQName(getRequiredAttribute(attrs, "name", node)); String select = getAttribute(attrs, "select"); ParameterNode ret; if (select != null) @@ -1518,11 +1528,11 @@ class Stylesheet throw new TransformerConfigurationException(msg, l); } Expr expr = (Expr) xpath.compile(select); - ret = new ParameterNode(paramName, expr, global); + ret = new ParameterNode(paramName, expr, type); } else { - ret = new ParameterNode(paramName, null, global); + ret = new ParameterNode(paramName, null, type); ret.children = content; } return ret; @@ -1563,6 +1573,11 @@ class Stylesheet if (!isPreserved(text)) { // Strip + /*String data = text.getData().trim(); + if (data.length() > 0) + { + text.setData(data); + } // else */ text.getParentNode().removeChild(text); return null; } @@ -1697,7 +1712,8 @@ class Stylesheet { NamedNodeMap attrs = node.getAttributes(); TemplateNode content = parse(node.getFirstChild()); - String name = getRequiredAttribute(attrs, "name", node); + QName name = + getQName(getRequiredAttribute(attrs, "name", node)); String select = getAttribute(attrs, "select"); if (select != null) { diff --git a/gnu/xml/transform/SystemPropertyFunction.java b/gnu/xml/transform/SystemPropertyFunction.java index 33616d396..038df0169 100644 --- a/gnu/xml/transform/SystemPropertyFunction.java +++ b/gnu/xml/transform/SystemPropertyFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.transform; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; @@ -124,5 +125,17 @@ final class SystemPropertyFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/TemplateNode.java b/gnu/xml/transform/TemplateNode.java index 7138a8bf4..36b25cf52 100644 --- a/gnu/xml/transform/TemplateNode.java +++ b/gnu/xml/transform/TemplateNode.java @@ -88,6 +88,19 @@ abstract class TemplateNode abstract TemplateNode clone(Stylesheet stylesheet); + public boolean references(QName var) + { + if (children != null && children.references(var)) + { + return true; + } + if (next != null && next.references(var)) + { + return true; + } + return false; + } + /** * Debugging */ diff --git a/gnu/xml/transform/TransformerImpl.java b/gnu/xml/transform/TransformerImpl.java index 546369e5b..a36aa6173 100644 --- a/gnu/xml/transform/TransformerImpl.java +++ b/gnu/xml/transform/TransformerImpl.java @@ -106,7 +106,7 @@ class TransformerImpl if (stylesheet != null) { // Set up parameter context for this transformer - stylesheet.bindings.push(false); + stylesheet.bindings.push(Bindings.PARAM); } } @@ -559,7 +559,7 @@ class TransformerImpl { if (stylesheet != null) { - stylesheet.bindings.set(name, value, false); + stylesheet.bindings.set(new QName(null, name), value, Bindings.PARAM); } } @@ -567,7 +567,7 @@ class TransformerImpl { if (stylesheet != null) { - return stylesheet.bindings.get(name, null, 1, 1); + return stylesheet.bindings.get(new QName(null, name), null, 1, 1); } return null; } @@ -576,8 +576,8 @@ class TransformerImpl { if (stylesheet != null) { - stylesheet.bindings.pop(false); - stylesheet.bindings.push(false); + stylesheet.bindings.pop(Bindings.PARAM); + stylesheet.bindings.push(Bindings.PARAM); } } diff --git a/gnu/xml/transform/UnparsedEntityUriFunction.java b/gnu/xml/transform/UnparsedEntityUriFunction.java index ca72b6534..92002f1f5 100644 --- a/gnu/xml/transform/UnparsedEntityUriFunction.java +++ b/gnu/xml/transform/UnparsedEntityUriFunction.java @@ -39,7 +39,9 @@ package gnu.xml.transform; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; import javax.xml.xpath.XPathFunctionException; import org.w3c.dom.DocumentType; @@ -114,5 +116,17 @@ final class UnparsedEntityUriFunction return f; } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + } diff --git a/gnu/xml/transform/ValueOfNode.java b/gnu/xml/transform/ValueOfNode.java index afff2cd99..430598a94 100644 --- a/gnu/xml/transform/ValueOfNode.java +++ b/gnu/xml/transform/ValueOfNode.java @@ -85,6 +85,10 @@ final class ValueOfNode throws TransformerException { Object ret = select.evaluate(context, pos, len); + /*if (stylesheet.debug) + { + System.err.println("value-of: " + select + " -> " + ret); + }*/ String value; if (ret instanceof Collection) { @@ -100,10 +104,10 @@ final class ValueOfNode { value = Expr._string(context, ret); } - /*if (stylesheet.debug) + if (stylesheet.debug) { System.err.println("value-of: "+context+" "+ select + " -> "+ value); - }*/ + } if (value != null && value.length() > 0) { Document doc = (parent instanceof Document) ? @@ -131,6 +135,15 @@ final class ValueOfNode } } + public boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/WhenNode.java b/gnu/xml/transform/WhenNode.java index b6dfaf03c..231f2693b 100644 --- a/gnu/xml/transform/WhenNode.java +++ b/gnu/xml/transform/WhenNode.java @@ -101,6 +101,15 @@ final class WhenNode } } + public boolean references(QName var) + { + if (test != null && test.references(var)) + { + return true; + } + return super.references(var); + } + public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); diff --git a/gnu/xml/transform/WithParam.java b/gnu/xml/transform/WithParam.java index 7c3379833..0fb09d61e 100644 --- a/gnu/xml/transform/WithParam.java +++ b/gnu/xml/transform/WithParam.java @@ -55,18 +55,18 @@ import gnu.xml.xpath.Expr; final class WithParam { - final String name; + final QName name; final Expr select; final TemplateNode content; - WithParam(String name, Expr select) + WithParam(QName name, Expr select) { this.name = name; this.select = select; content = null; } - WithParam(String name, TemplateNode content) + WithParam(QName name, TemplateNode content) { this.name = name; this.content = content; @@ -107,4 +107,17 @@ final class WithParam } } + boolean references(QName var) + { + if (select != null && select.references(var)) + { + return true; + } + if (content != null && content.references(var)) + { + return true; + } + return false; + } + } diff --git a/gnu/xml/xpath/AndExpr.java b/gnu/xml/xpath/AndExpr.java index 680e84792..dd2e1c9a1 100644 --- a/gnu/xml/xpath/AndExpr.java +++ b/gnu/xml/xpath/AndExpr.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -73,6 +74,11 @@ public final class AndExpr return new AndExpr(lhs.clone(context), rhs.clone(context)); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { return lhs + " and " + rhs; diff --git a/gnu/xml/xpath/ArithmeticExpr.java b/gnu/xml/xpath/ArithmeticExpr.java index f972d7d4a..3cef4adf3 100644 --- a/gnu/xml/xpath/ArithmeticExpr.java +++ b/gnu/xml/xpath/ArithmeticExpr.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -117,6 +118,11 @@ final class ArithmeticExpr return new ArithmeticExpr(lhs.clone(context), rhs.clone(context), op); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { StringBuffer buf = new StringBuffer(); diff --git a/gnu/xml/xpath/BooleanFunction.java b/gnu/xml/xpath/BooleanFunction.java index 018348ff2..256de0382 100644 --- a/gnu/xml/xpath/BooleanFunction.java +++ b/gnu/xml/xpath/BooleanFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -80,6 +81,11 @@ final class BooleanFunction { return new BooleanFunction(arg.clone(context)); } + + public boolean references(QName var) + { + return arg.references(var); + } public String toString() { diff --git a/gnu/xml/xpath/CeilingFunction.java b/gnu/xml/xpath/CeilingFunction.java index 50dc45d55..7db08fc5d 100644 --- a/gnu/xml/xpath/CeilingFunction.java +++ b/gnu/xml/xpath/CeilingFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -74,6 +75,11 @@ final class CeilingFunction { return new CeilingFunction(arg.clone(context)); } + + public boolean references(QName var) + { + return arg.references(var); + } public String toString() { diff --git a/gnu/xml/xpath/ConcatFunction.java b/gnu/xml/xpath/ConcatFunction.java index 60802081d..fddd7ae25 100644 --- a/gnu/xml/xpath/ConcatFunction.java +++ b/gnu/xml/xpath/ConcatFunction.java @@ -40,6 +40,7 @@ package gnu.xml.xpath; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -81,6 +82,18 @@ final class ConcatFunction return new ConcatFunction(args2); } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + public String toString() { StringBuffer buf = new StringBuffer("concat("); diff --git a/gnu/xml/xpath/Constant.java b/gnu/xml/xpath/Constant.java index ca7c1d674..d5ca764a1 100644 --- a/gnu/xml/xpath/Constant.java +++ b/gnu/xml/xpath/Constant.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -65,6 +66,11 @@ public final class Constant return new Constant(value); } + public boolean references(QName var) + { + return false; + } + public String toString() { String ret = value.toString(); diff --git a/gnu/xml/xpath/ContainsFunction.java b/gnu/xml/xpath/ContainsFunction.java index 3910d15ef..fc2f33faf 100644 --- a/gnu/xml/xpath/ContainsFunction.java +++ b/gnu/xml/xpath/ContainsFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -78,6 +79,11 @@ final class ContainsFunction return new ContainsFunction(arg1.clone(context), arg2.clone(context)); } + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var)); + } + public String toString() { return "contains(" + arg1 + "," + arg2 + ")"; diff --git a/gnu/xml/xpath/CountFunction.java b/gnu/xml/xpath/CountFunction.java index 4164f69f3..cb534bffc 100644 --- a/gnu/xml/xpath/CountFunction.java +++ b/gnu/xml/xpath/CountFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -74,6 +75,11 @@ final class CountFunction return new CountFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "count(" + arg + ")"; diff --git a/gnu/xml/xpath/EqualityExpr.java b/gnu/xml/xpath/EqualityExpr.java index 4f7c070bc..6d00cee89 100644 --- a/gnu/xml/xpath/EqualityExpr.java +++ b/gnu/xml/xpath/EqualityExpr.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.Iterator; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -247,6 +248,11 @@ final class EqualityExpr return new EqualityExpr(lhs.clone(context), rhs.clone(context), invert); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { if (invert) diff --git a/gnu/xml/xpath/Expr.java b/gnu/xml/xpath/Expr.java index 595782852..b4b55dcf9 100644 --- a/gnu/xml/xpath/Expr.java +++ b/gnu/xml/xpath/Expr.java @@ -177,6 +177,8 @@ public abstract class Expr public abstract Object evaluate(Node context, int pos, int len); public abstract Expr clone(Object context); + + public abstract boolean references(QName var); /* -- 4.1 Node Set Functions -- */ diff --git a/gnu/xml/xpath/FalseFunction.java b/gnu/xml/xpath/FalseFunction.java index ca07b7870..87660ec81 100644 --- a/gnu/xml/xpath/FalseFunction.java +++ b/gnu/xml/xpath/FalseFunction.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -58,6 +59,11 @@ final class FalseFunction return new FalseFunction(); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "false()"; diff --git a/gnu/xml/xpath/FloorFunction.java b/gnu/xml/xpath/FloorFunction.java index c8608cdc1..c03c0e7ed 100644 --- a/gnu/xml/xpath/FloorFunction.java +++ b/gnu/xml/xpath/FloorFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -75,6 +76,11 @@ final class FloorFunction return new FloorFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "floor(" + arg + ")"; diff --git a/gnu/xml/xpath/FunctionCall.java b/gnu/xml/xpath/FunctionCall.java index 97763e097..669efbf18 100644 --- a/gnu/xml/xpath/FunctionCall.java +++ b/gnu/xml/xpath/FunctionCall.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunction; @@ -129,6 +130,18 @@ public final class FunctionCall return new FunctionCall(r, name, args2); } + public boolean references(QName var) + { + for (Iterator i = args.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + public String toString() { StringBuffer buf = new StringBuffer(); diff --git a/gnu/xml/xpath/IdFunction.java b/gnu/xml/xpath/IdFunction.java index 164e141a7..749795419 100644 --- a/gnu/xml/xpath/IdFunction.java +++ b/gnu/xml/xpath/IdFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -88,6 +89,11 @@ public final class IdFunction return new IdFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "id(" + arg + ")"; diff --git a/gnu/xml/xpath/LangFunction.java b/gnu/xml/xpath/LangFunction.java index fbf3af1f9..2c2506d1b 100644 --- a/gnu/xml/xpath/LangFunction.java +++ b/gnu/xml/xpath/LangFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -102,6 +103,11 @@ final class LangFunction return new IdFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "lang(" + arg + ")"; diff --git a/gnu/xml/xpath/LastFunction.java b/gnu/xml/xpath/LastFunction.java index b24e0482d..751a0a9c1 100644 --- a/gnu/xml/xpath/LastFunction.java +++ b/gnu/xml/xpath/LastFunction.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -59,6 +60,11 @@ final class LastFunction return new LastFunction(); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "last()"; diff --git a/gnu/xml/xpath/LocalNameFunction.java b/gnu/xml/xpath/LocalNameFunction.java index 342d9331a..f8ace9cd5 100644 --- a/gnu/xml/xpath/LocalNameFunction.java +++ b/gnu/xml/xpath/LocalNameFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -79,6 +80,11 @@ final class LocalNameFunction arg.clone(context)); } + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } + public String toString() { return (arg == null) ? "local-name()" : "local-name(" + arg + ")"; diff --git a/gnu/xml/xpath/NameFunction.java b/gnu/xml/xpath/NameFunction.java index bd34325a0..dc5e61203 100644 --- a/gnu/xml/xpath/NameFunction.java +++ b/gnu/xml/xpath/NameFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -86,6 +87,11 @@ final class NameFunction return new NameFunction((arg == null) ? null : arg.clone(context)); } + + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } public String toString() { diff --git a/gnu/xml/xpath/NameTest.java b/gnu/xml/xpath/NameTest.java index dfbd62c63..c89ba4dd1 100644 --- a/gnu/xml/xpath/NameTest.java +++ b/gnu/xml/xpath/NameTest.java @@ -125,6 +125,11 @@ public final class NameTest return new NameTest(qName, anyLocalName, any); } + public boolean references(QName var) + { + return false; + } + public String toString () { if (any) diff --git a/gnu/xml/xpath/NamespaceTest.java b/gnu/xml/xpath/NamespaceTest.java index 16325c9da..6d41166bc 100644 --- a/gnu/xml/xpath/NamespaceTest.java +++ b/gnu/xml/xpath/NamespaceTest.java @@ -111,6 +111,11 @@ public final class NamespaceTest return new NamespaceTest(qName, anyLocalName, any); } + public boolean references(QName var) + { + return false; + } + public String toString () { if (any) diff --git a/gnu/xml/xpath/NamespaceUriFunction.java b/gnu/xml/xpath/NamespaceUriFunction.java index 9a42e7754..e67ec4206 100644 --- a/gnu/xml/xpath/NamespaceUriFunction.java +++ b/gnu/xml/xpath/NamespaceUriFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -78,6 +79,11 @@ final class NamespaceUriFunction return new NamespaceUriFunction((arg == null) ? null : arg.clone(context)); } + + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } public String toString() { diff --git a/gnu/xml/xpath/NegativeExpr.java b/gnu/xml/xpath/NegativeExpr.java index bb84eebf0..9e24aff81 100644 --- a/gnu/xml/xpath/NegativeExpr.java +++ b/gnu/xml/xpath/NegativeExpr.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -67,6 +68,11 @@ final class NegativeExpr return new NegativeExpr(expr.clone(context)); } + public boolean references(QName var) + { + return expr.references(var); + } + public String toString() { return "-" + expr; diff --git a/gnu/xml/xpath/NodeTypeTest.java b/gnu/xml/xpath/NodeTypeTest.java index 521104cdb..807374132 100644 --- a/gnu/xml/xpath/NodeTypeTest.java +++ b/gnu/xml/xpath/NodeTypeTest.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -106,6 +107,11 @@ public final class NodeTypeTest return new NodeTypeTest(type, data); } + public boolean references(QName var) + { + return false; + } + public String toString() { switch (type) diff --git a/gnu/xml/xpath/NormalizeSpaceFunction.java b/gnu/xml/xpath/NormalizeSpaceFunction.java index a61e118f2..b7358e8d8 100644 --- a/gnu/xml/xpath/NormalizeSpaceFunction.java +++ b/gnu/xml/xpath/NormalizeSpaceFunction.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.List; import java.util.StringTokenizer; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -91,6 +92,11 @@ final class NormalizeSpaceFunction return new NormalizeSpaceFunction(arg.clone(context)); } + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } + public String toString() { return (arg == null) ? "normalize-space()" : "normalize-space(" + arg + ")"; diff --git a/gnu/xml/xpath/NotFunction.java b/gnu/xml/xpath/NotFunction.java index dcb7ad4fb..bbed66a73 100644 --- a/gnu/xml/xpath/NotFunction.java +++ b/gnu/xml/xpath/NotFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -73,6 +74,11 @@ final class NotFunction return new NotFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "not(" + arg + ")"; diff --git a/gnu/xml/xpath/NumberFunction.java b/gnu/xml/xpath/NumberFunction.java index a27eb7a46..79553ce81 100644 --- a/gnu/xml/xpath/NumberFunction.java +++ b/gnu/xml/xpath/NumberFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -88,6 +89,11 @@ final class NumberFunction return new NumberFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "number(" + arg + ")"; diff --git a/gnu/xml/xpath/OrExpr.java b/gnu/xml/xpath/OrExpr.java index ca3fd2277..1085f5112 100644 --- a/gnu/xml/xpath/OrExpr.java +++ b/gnu/xml/xpath/OrExpr.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -73,6 +74,11 @@ public final class OrExpr return new OrExpr(lhs.clone(context), rhs.clone(context)); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { return lhs + " or " + rhs; diff --git a/gnu/xml/xpath/ParenthesizedExpr.java b/gnu/xml/xpath/ParenthesizedExpr.java index 6a8bb12fa..f343857c3 100644 --- a/gnu/xml/xpath/ParenthesizedExpr.java +++ b/gnu/xml/xpath/ParenthesizedExpr.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -76,6 +77,11 @@ final class ParenthesizedExpr return new ParenthesizedExpr(expr.clone(context)); } + public boolean references(QName var) + { + return expr.references(var); + } + public String toString() { return "(" + expr + ")"; diff --git a/gnu/xml/xpath/Pattern.java b/gnu/xml/xpath/Pattern.java index d992c6d4e..859ab5692 100644 --- a/gnu/xml/xpath/Pattern.java +++ b/gnu/xml/xpath/Pattern.java @@ -40,7 +40,7 @@ package gnu.xml.xpath; import org.w3c.dom.Node; /** - * Interface implemented by expressions that can for part of XSL patterns. + * Interface implemented by expressions that can form part of XSL patterns. * * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> */ diff --git a/gnu/xml/xpath/PositionFunction.java b/gnu/xml/xpath/PositionFunction.java index 790b0e005..3060eeaed 100644 --- a/gnu/xml/xpath/PositionFunction.java +++ b/gnu/xml/xpath/PositionFunction.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -59,6 +60,11 @@ final class PositionFunction return new PositionFunction(); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "position()"; diff --git a/gnu/xml/xpath/Predicate.java b/gnu/xml/xpath/Predicate.java index d495440fd..5538c55aa 100644 --- a/gnu/xml/xpath/Predicate.java +++ b/gnu/xml/xpath/Predicate.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -70,6 +71,11 @@ class Predicate { return new Predicate(expr.clone(context)); } + + public boolean references(QName var) + { + return expr.references(var); + } public String toString() { diff --git a/gnu/xml/xpath/RelationalExpr.java b/gnu/xml/xpath/RelationalExpr.java index 622d22901..5cbb6bb22 100644 --- a/gnu/xml/xpath/RelationalExpr.java +++ b/gnu/xml/xpath/RelationalExpr.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -93,6 +94,11 @@ final class RelationalExpr return new RelationalExpr(lhs.clone(context), rhs.clone(context), lt, eq); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { return lhs + " " + (lt ? "<" : ">") + (eq ? "=" : "") + " " + rhs; diff --git a/gnu/xml/xpath/Root.java b/gnu/xml/xpath/Root.java index cf8f8d17e..1f79b3958 100644 --- a/gnu/xml/xpath/Root.java +++ b/gnu/xml/xpath/Root.java @@ -39,6 +39,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.Collections; +import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -73,6 +74,11 @@ public final class Root return new Root(); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "/"; diff --git a/gnu/xml/xpath/RoundFunction.java b/gnu/xml/xpath/RoundFunction.java index 7f9ff2a96..bfbfd357d 100644 --- a/gnu/xml/xpath/RoundFunction.java +++ b/gnu/xml/xpath/RoundFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -82,6 +83,11 @@ final class RoundFunction return new RoundFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "round(" + arg + ")"; diff --git a/gnu/xml/xpath/Selector.java b/gnu/xml/xpath/Selector.java index 383893d92..598038064 100644 --- a/gnu/xml/xpath/Selector.java +++ b/gnu/xml/xpath/Selector.java @@ -44,6 +44,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.xml.XMLConstants; +import javax.xml.namespace.QName; import org.w3c.dom.Attr; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -424,6 +425,18 @@ public final class Selector return new Selector(axis, tests2); } + public boolean references(QName var) + { + for (int i = 0; i < tests.length; i++) + { + if (tests[i].references(var)) + { + return true; + } + } + return false; + } + public String toString() { StringBuffer buf = new StringBuffer(); @@ -436,7 +449,15 @@ public final class Selector buf.append("ancestor-or-self::"); break; case ATTRIBUTE: - buf.append("attribute::"); + if (tests.length == 0 || + (tests[0] instanceof NameTest)) + { + buf.append('@'); + } + else + { + buf.append("attribute::"); + } break; case CHILD: //buf.append("child::"); diff --git a/gnu/xml/xpath/StartsWithFunction.java b/gnu/xml/xpath/StartsWithFunction.java index 2cee8555f..ec021551e 100644 --- a/gnu/xml/xpath/StartsWithFunction.java +++ b/gnu/xml/xpath/StartsWithFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -78,6 +79,11 @@ final class StartsWithFunction return new StartsWithFunction(arg1.clone(context), arg2.clone(context)); } + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var)); + } + public String toString() { return "starts-with(" + arg1 + "," + arg2 + ")"; diff --git a/gnu/xml/xpath/Steps.java b/gnu/xml/xpath/Steps.java index e8cbc4e61..9ef6cd35f 100644 --- a/gnu/xml/xpath/Steps.java +++ b/gnu/xml/xpath/Steps.java @@ -43,6 +43,7 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Set; +import javax.xml.namespace.QName; import org.w3c.dom.Attr; import org.w3c.dom.Node; @@ -219,6 +220,18 @@ public final class Steps return new Steps(path2); } + public boolean references(QName var) + { + for (Iterator i = path.iterator(); i.hasNext(); ) + { + if (((Expr) i.next()).references(var)) + { + return true; + } + } + return false; + } + public String toString() { StringBuffer buf = new StringBuffer(); diff --git a/gnu/xml/xpath/StringFunction.java b/gnu/xml/xpath/StringFunction.java index fac15050a..0a4c681d1 100644 --- a/gnu/xml/xpath/StringFunction.java +++ b/gnu/xml/xpath/StringFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -105,6 +106,11 @@ final class StringFunction arg.clone(context)); } + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } + public String toString() { return (arg == null) ? "string()" : "string(" + arg + ")"; diff --git a/gnu/xml/xpath/StringLengthFunction.java b/gnu/xml/xpath/StringLengthFunction.java index 4545c895f..7f5ceafee 100644 --- a/gnu/xml/xpath/StringLengthFunction.java +++ b/gnu/xml/xpath/StringLengthFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -77,6 +78,11 @@ final class StringLengthFunction arg.clone(context)); } + public boolean references(QName var) + { + return (arg == null) ? false : arg.references(var); + } + public String toString() { return (arg == null) ? "string-length()" : "string-length(" + arg + ")"; diff --git a/gnu/xml/xpath/SubstringAfterFunction.java b/gnu/xml/xpath/SubstringAfterFunction.java index dcdff31f1..8144cf844 100644 --- a/gnu/xml/xpath/SubstringAfterFunction.java +++ b/gnu/xml/xpath/SubstringAfterFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -84,6 +85,11 @@ final class SubstringAfterFunction arg2.clone(context)); } + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var)); + } + public String toString() { return "substring-after(" + arg1 + "," + arg2 + ")"; diff --git a/gnu/xml/xpath/SubstringBeforeFunction.java b/gnu/xml/xpath/SubstringBeforeFunction.java index 4322bcd69..2d92a3e03 100644 --- a/gnu/xml/xpath/SubstringBeforeFunction.java +++ b/gnu/xml/xpath/SubstringBeforeFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -83,6 +84,11 @@ final class SubstringBeforeFunction arg2.clone(context)); } + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var)); + } + public String toString() { return "substring-before(" + arg1 + "," + arg2 + ")"; diff --git a/gnu/xml/xpath/SubstringFunction.java b/gnu/xml/xpath/SubstringFunction.java index a554045cf..d65c4facb 100644 --- a/gnu/xml/xpath/SubstringFunction.java +++ b/gnu/xml/xpath/SubstringFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -113,6 +114,12 @@ final class SubstringFunction (arg3 == null) ? null : arg3.clone(context)); } + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var) || + (arg3 == null) ? false : arg3.references(var)); + } + public String toString() { return (arg3 == null) ? "substring(" + arg1 + "," + arg2 + ")" : diff --git a/gnu/xml/xpath/SumFunction.java b/gnu/xml/xpath/SumFunction.java index 61452f809..93c2e806d 100644 --- a/gnu/xml/xpath/SumFunction.java +++ b/gnu/xml/xpath/SumFunction.java @@ -40,6 +40,7 @@ package gnu.xml.xpath; import java.util.Collection; import java.util.Iterator; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -86,6 +87,11 @@ final class SumFunction return new SumFunction(arg.clone(context)); } + public boolean references(QName var) + { + return arg.references(var); + } + public String toString() { return "sum(" + arg + ")"; diff --git a/gnu/xml/xpath/Test.java b/gnu/xml/xpath/Test.java index 1ea4bc473..94837ffac 100644 --- a/gnu/xml/xpath/Test.java +++ b/gnu/xml/xpath/Test.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -52,4 +53,6 @@ public abstract class Test public abstract Test clone(Object context); + public abstract boolean references(QName var); + } diff --git a/gnu/xml/xpath/TranslateFunction.java b/gnu/xml/xpath/TranslateFunction.java index b62180734..54e8b9c37 100644 --- a/gnu/xml/xpath/TranslateFunction.java +++ b/gnu/xml/xpath/TranslateFunction.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.xml.xpath; import java.util.List; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -117,6 +118,12 @@ final class TranslateFunction return new TranslateFunction(arg1.clone(context), arg2.clone(context), arg3.clone(context)); } + + public boolean references(QName var) + { + return (arg1.references(var) || arg2.references(var) || + arg3.references(var)); + } public String toString() { diff --git a/gnu/xml/xpath/TrueFunction.java b/gnu/xml/xpath/TrueFunction.java index 3dd68bd5a..6ad42d726 100644 --- a/gnu/xml/xpath/TrueFunction.java +++ b/gnu/xml/xpath/TrueFunction.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.xml.xpath; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -58,6 +59,11 @@ final class TrueFunction return new TrueFunction(); } + public boolean references(QName var) + { + return false; + } + public String toString() { return "true()"; diff --git a/gnu/xml/xpath/UnionExpr.java b/gnu/xml/xpath/UnionExpr.java index 58c28a4d1..5078713b6 100644 --- a/gnu/xml/xpath/UnionExpr.java +++ b/gnu/xml/xpath/UnionExpr.java @@ -43,6 +43,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.xml.namespace.QName; import org.w3c.dom.Node; /** @@ -94,6 +95,11 @@ public final class UnionExpr return new UnionExpr(lhs.clone(context), rhs.clone(context)); } + public boolean references(QName var) + { + return (lhs.references(var) || rhs.references(var)); + } + public String toString() { return lhs + " | " + rhs; diff --git a/gnu/xml/xpath/VariableReference.java b/gnu/xml/xpath/VariableReference.java index e53d1faa8..813a37f96 100644 --- a/gnu/xml/xpath/VariableReference.java +++ b/gnu/xml/xpath/VariableReference.java @@ -47,9 +47,9 @@ public class VariableReference { final XPathVariableResolver resolver; - final String name; + final QName name; - public VariableReference(XPathVariableResolver resolver, String name) + public VariableReference(XPathVariableResolver resolver, QName name) { this.resolver = resolver; this.name = name; @@ -64,8 +64,7 @@ public class VariableReference // Needs context to operate properly return ((Bindings) resolver).get(name, context, pos, len); } - QName qname = QName.valueOf(name); - return resolver.resolveVariable(qname); + return resolver.resolveVariable(name); } throw new IllegalStateException("no variable resolver"); } @@ -80,9 +79,22 @@ public class VariableReference return new VariableReference(r, name); } + public boolean references(QName var) + { + return name.equals(var); + } + public String toString() { - return "$" + name; + StringBuffer buf = new StringBuffer("$"); + String prefix = name.getPrefix(); + if (prefix != null && !"".equals(prefix)) + { + buf.append(prefix); + buf.append(':'); + } + buf.append(name.getLocalPart()); + return buf.toString(); } } diff --git a/gnu/xml/xpath/XPathParser.java b/gnu/xml/xpath/XPathParser.java index 01c744790..624dcd8d4 100644 --- a/gnu/xml/xpath/XPathParser.java +++ b/gnu/xml/xpath/XPathParser.java @@ -1,48 +1,50 @@ // created by jay 0.8 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de // line 2 "XPathParser.y" -/* XPathParser.java -- An XPath 1.0 parser. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ +/* + * XPathParser.java + * Copyright (C) 2004 The Free Software Foundation + * + * This file is part of GNU JAXP, a library. + * + * GNU JAXP is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNU JAXP is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under + * terms of your choice, provided that you also meet, for each linked + * independent module, the terms and conditions of the license of that + * module. An independent module is a module which is not derived from + * or based on this library. If you modify this library, you may extend + * this exception to your version of the library, but you are not + * obliged to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ package gnu.xml.xpath; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.xpath.XPathFunctionResolver; @@ -205,7 +207,7 @@ public class XPathParser return new FunctionCall(functionResolver, name, args); } - // line 210 "-" + // line 211 "-" // %token constants public static final int LITERAL = 257; @@ -474,13 +476,13 @@ public class XPathParser yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) { case 4: - // line 276 "XPathParser.y" + // line 277 "XPathParser.y" { yyVal = new Root(); } break; case 5: - // line 280 "XPathParser.y" + // line 281 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) @@ -498,7 +500,7 @@ case 5: } break; case 6: - // line 296 "XPathParser.y" + // line 297 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, @@ -521,7 +523,7 @@ case 6: } break; case 8: - // line 321 "XPathParser.y" + // line 322 "XPathParser.y" { Steps steps; if (yyVals[-2+yyTop] instanceof Steps) @@ -539,7 +541,7 @@ case 8: } break; case 9: - // line 337 "XPathParser.y" + // line 338 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, @@ -562,37 +564,37 @@ case 9: } break; case 10: - // line 361 "XPathParser.y" + // line 362 "XPathParser.y" { yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); } break; case 11: - // line 365 "XPathParser.y" + // line 366 "XPathParser.y" { yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); } break; case 12: - // line 369 "XPathParser.y" + // line 370 "XPathParser.y" { yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); } break; case 13: - // line 373 "XPathParser.y" + // line 374 "XPathParser.y" { yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST); } break; case 14: - // line 377 "XPathParser.y" + // line 378 "XPathParser.y" { yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST); } break; case 15: - // line 384 "XPathParser.y" + // line 385 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); @@ -600,7 +602,7 @@ case 15: } break; case 16: - // line 390 "XPathParser.y" + // line 391 "XPathParser.y" { List list = (List)yyVals[-1+yyTop]; list.add(yyVals[0+yyTop]); @@ -608,133 +610,133 @@ case 16: } break; case 17: - // line 414 "XPathParser.y" + // line 415 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR); } break; case 18: - // line 418 "XPathParser.y" + // line 419 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR_OR_SELF); } break; case 19: - // line 422 "XPathParser.y" + // line 423 "XPathParser.y" { yyVal = new Integer(Selector.ATTRIBUTE); } break; case 20: - // line 426 "XPathParser.y" + // line 427 "XPathParser.y" { yyVal = new Integer(Selector.CHILD); } break; case 21: - // line 430 "XPathParser.y" + // line 431 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT); } break; case 22: - // line 434 "XPathParser.y" + // line 435 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT_OR_SELF); } break; case 23: - // line 438 "XPathParser.y" + // line 439 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING); } break; case 24: - // line 442 "XPathParser.y" + // line 443 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING_SIBLING); } break; case 25: - // line 446 "XPathParser.y" + // line 447 "XPathParser.y" { yyVal = new Integer(Selector.NAMESPACE); } break; case 26: - // line 450 "XPathParser.y" + // line 451 "XPathParser.y" { yyVal = new Integer(Selector.PARENT); } break; case 27: - // line 454 "XPathParser.y" + // line 455 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING); } break; case 28: - // line 458 "XPathParser.y" + // line 459 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING_SIBLING); } break; case 29: - // line 462 "XPathParser.y" + // line 463 "XPathParser.y" { yyVal = new Integer(Selector.SELF); } break; case 31: - // line 471 "XPathParser.y" + // line 472 "XPathParser.y" { yyVal = new NodeTypeTest(Node.PROCESSING_INSTRUCTION_NODE, (String) yyVals[-1+yyTop]); } break; case 32: - // line 476 "XPathParser.y" + // line 477 "XPathParser.y" { yyVal = new NodeTypeTest(((Short) yyVals[-1+yyTop]).shortValue()); } break; case 33: - // line 483 "XPathParser.y" + // line 484 "XPathParser.y" { yyVal = new Predicate((Expr) yyVals[-1+yyTop]); } break; case 35: - // line 491 "XPathParser.y" + // line 492 "XPathParser.y" { yyVal = new ParenthesizedExpr((Expr) yyVals[-1+yyTop]); } break; case 36: - // line 495 "XPathParser.y" + // line 496 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break; case 37: - // line 499 "XPathParser.y" + // line 500 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break; case 39: - // line 507 "XPathParser.y" + // line 508 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST); } break; case 40: - // line 511 "XPathParser.y" + // line 512 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); } break; case 41: - // line 518 "XPathParser.y" + // line 519 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); @@ -742,7 +744,7 @@ case 41: } break; case 42: - // line 524 "XPathParser.y" + // line 525 "XPathParser.y" { List list = (List) yyVals[0+yyTop]; list.add(0, yyVals[-2+yyTop]); @@ -750,13 +752,13 @@ case 42: } break; case 44: - // line 534 "XPathParser.y" + // line 535 "XPathParser.y" { yyVal = new UnionExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 47: - // line 543 "XPathParser.y" + // line 544 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) @@ -774,7 +776,7 @@ case 47: } break; case 48: - // line 559 "XPathParser.y" + // line 560 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, @@ -797,7 +799,7 @@ case 48: } break; case 50: - // line 584 "XPathParser.y" + // line 585 "XPathParser.y" { Predicate filter = (Predicate) yyVals[0+yyTop]; Selector s = new Selector(Selector.SELF, @@ -818,170 +820,171 @@ case 50: } break; case 52: - // line 607 "XPathParser.y" + // line 608 "XPathParser.y" { yyVal = new OrExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 54: - // line 615 "XPathParser.y" + // line 616 "XPathParser.y" { yyVal = new AndExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 56: - // line 623 "XPathParser.y" + // line 624 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false); } break; case 57: - // line 627 "XPathParser.y" + // line 628 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true); } break; case 59: - // line 635 "XPathParser.y" + // line 636 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, false); } break; case 60: - // line 639 "XPathParser.y" + // line 640 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, false); } break; case 61: - // line 643 "XPathParser.y" + // line 644 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, true); } break; case 62: - // line 647 "XPathParser.y" + // line 648 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, true); } break; case 64: - // line 655 "XPathParser.y" + // line 656 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.ADD); } break; case 65: - // line 659 "XPathParser.y" + // line 660 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.SUBTRACT); } break; case 67: - // line 667 "XPathParser.y" + // line 668 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MULTIPLY); } break; case 68: - // line 671 "XPathParser.y" + // line 672 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.DIVIDE); } break; case 69: - // line 675 "XPathParser.y" + // line 676 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MODULO); } break; case 71: - // line 683 "XPathParser.y" + // line 684 "XPathParser.y" { yyVal = new NegativeExpr((Expr) yyVals[0+yyTop]); } break; case 72: - // line 690 "XPathParser.y" + // line 691 "XPathParser.y" { yyVal = new Double((String) yyVals[0+yyTop] + ".0"); } break; case 73: - // line 694 "XPathParser.y" + // line 695 "XPathParser.y" { yyVal = new Double((String) yyVals[-1+yyTop] + ".0"); } break; case 74: - // line 698 "XPathParser.y" + // line 699 "XPathParser.y" { yyVal = new Double((String) yyVals[-2+yyTop] + "." + (String) yyVals[0+yyTop]); } break; case 75: - // line 702 "XPathParser.y" + // line 703 "XPathParser.y" { yyVal = new Double("0." + (String) yyVals[0+yyTop]); } break; case 77: - // line 731 "XPathParser.y" + // line 732 "XPathParser.y" { - yyVal = new VariableReference(variableResolver, (String) yyVals[0+yyTop]); + String name = (String) yyVals[0+yyTop]; + yyVal = new VariableReference(variableResolver, getQName(name)); } break; case 78: - // line 738 "XPathParser.y" + // line 740 "XPathParser.y" { yyVal = new NameTest(null, true, true); } break; case 79: - // line 742 "XPathParser.y" + // line 744 "XPathParser.y" { QName qName = getQName((String) yyVals[-2+yyTop]); yyVal = new NameTest(qName, true, false); } break; case 80: - // line 747 "XPathParser.y" + // line 749 "XPathParser.y" { QName qName = getQName((String) yyVals[0+yyTop]); yyVal = new NameTest(qName, false, false); } break; case 82: - // line 756 "XPathParser.y" + // line 758 "XPathParser.y" { yyVal = (String) yyVals[-2+yyTop] + ':' + (String) yyVals[0+yyTop]; } break; case 83: - // line 763 "XPathParser.y" + // line 765 "XPathParser.y" { yyVal = new Short(Node.COMMENT_NODE); } break; case 84: - // line 767 "XPathParser.y" + // line 769 "XPathParser.y" { yyVal = new Short(Node.TEXT_NODE); } break; case 85: - // line 771 "XPathParser.y" + // line 773 "XPathParser.y" { yyVal = new Short(Node.PROCESSING_INSTRUCTION_NODE); } break; case 86: - // line 775 "XPathParser.y" + // line 777 "XPathParser.y" { yyVal = new Short((short) 0); } break; - // line 986 "-" + // line 988 "-" } yyTop -= YyLenClass.yyLen[yyN]; yyState = yyStates[yyTop]; @@ -1455,7 +1458,7 @@ case 86: } /* End of class YyNameClass */ - // line 781 "XPathParser.y" + // line 783 "XPathParser.y" } - // line 1461 "-" + // line 1463 "-" diff --git a/gnu/xml/xpath/XPathParser.y b/gnu/xml/xpath/XPathParser.y index f8a60363b..d7dc4f1e8 100644 --- a/gnu/xml/xpath/XPathParser.y +++ b/gnu/xml/xpath/XPathParser.y @@ -1,40 +1,41 @@ %{ -/* XPathParser.java -- An XPath 1.0 parser. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ +/* + * XPathParser.java + * Copyright (C) 2004 The Free Software Foundation + * + * This file is part of GNU JAXP, a library. + * + * GNU JAXP is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNU JAXP is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under + * terms of your choice, provided that you also meet, for each linked + * independent module, the terms and conditions of the license of that + * module. An independent module is a module which is not derived from + * or based on this library. If you modify this library, you may extend + * this exception to your version of the library, but you are not + * obliged to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ package gnu.xml.xpath; @@ -729,7 +730,8 @@ function_name: variable_reference: DOLLAR qname { - $$ = new VariableReference(variableResolver, (String) $2); + String name = (String) $2; + $$ = new VariableReference(variableResolver, getQName(name)); } ; diff --git a/javax/xml/namespace/QName.java b/javax/xml/namespace/QName.java index 2e8d1243c..c1ec4519d 100644 --- a/javax/xml/namespace/QName.java +++ b/javax/xml/namespace/QName.java @@ -1,39 +1,40 @@ -/* QName.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ +/* + * QName.java + * Copyright (C) 2004 The Free Software Foundation + * + * This file is part of GNU JAXP, a library. + * + * GNU JAXP is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNU JAXP is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under + * terms of your choice, provided that you also meet, for each linked + * independent module, the terms and conditions of the license of that + * module. An independent module is a module which is not derived from + * or based on this library. If you modify this library, you may extend + * this exception to your version of the library, but you are not + * obliged to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ package javax.xml.namespace; @@ -43,7 +44,7 @@ import javax.xml.XMLConstants; * An XML * <a href='http://www.w3.org/TR/REC-xml-names/#ns-qualnames'>qualified name</a>. * - * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a) + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> * @since 1.3 */ public class QName @@ -53,6 +54,7 @@ public class QName private final String localPart; private final String prefix; private final String qName; + int hashCode = -1; public QName(String namespaceURI, String localPart) { @@ -126,7 +128,16 @@ public class QName public final int hashCode() { - return qName.hashCode(); + if (hashCode == -1) + { + StringBuffer buf = new StringBuffer(); + buf.append('{'); + buf.append(namespaceURI); + buf.append('}'); + buf.append(localPart); + hashCode = buf.toString().hashCode(); + } + return hashCode; } public String toString() |