You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/09/12 21:17:40 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/patterns AncestorStepPattern.java NodeTest.java StepPattern.java
mmidy 00/09/12 12:17:38
Modified: java/src/org/apache/xpath VariableStack.java
java/src/org/apache/xpath/compiler Compiler.java
OpCodes.java XPathParser.java
java/src/org/apache/xpath/patterns AncestorStepPattern.java
NodeTest.java StepPattern.java
Log:
Fix problem with a match pattern like id()//node() and for document('a',/)
Revision Changes Path
1.3 +16 -0 xml-xalan/java/src/org/apache/xpath/VariableStack.java
Index: VariableStack.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/VariableStack.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- VariableStack.java 2000/07/17 20:40:14 1.2
+++ VariableStack.java 2000/09/12 19:17:32 1.3
@@ -236,6 +236,22 @@
throws SAXException
{
int nElems = getCurrentStackFrameIndex();
+
+ // Look in the current frame
+ int nSize = size();
+ for(int i = (nSize - 1); i >= nElems; i--)
+ {
+ Object obj = this.elementAt(i);
+ if(obj == m_elemFrameBoundry)
+ {
+ break;
+ }
+ else if(((Arg)obj).equals(name))
+ {
+ return ((Arg)obj).getVal();
+ }
+ }
+
// Sub 1 extra for the context marker.
for(int i = (nElems - 1); i >= 0; i--)
{
1.4 +3 -0 xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Compiler.java 2000/08/07 21:26:22 1.3
+++ Compiler.java 2000/09/12 19:17:32 1.4
@@ -534,6 +534,9 @@
case OpCodes.NODETYPE_ROOT:
return NodeFilter.SHOW_DOCUMENT;
+ case OpCodes.NODETYPE_FUNCTEST:
+ return NodeTest.SHOW_BYFUNCTION;
+
case OpCodes.NODENAME:
switch(axesType)
{
1.3 +10 -0 xml-xalan/java/src/org/apache/xpath/compiler/OpCodes.java
Index: OpCodes.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/OpCodes.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OpCodes.java 2000/07/30 22:40:24 1.2
+++ OpCodes.java 2000/09/12 19:17:32 1.3
@@ -579,6 +579,16 @@
/**
* <meta name="usage" content="advanced"/>
+ * [NODETYPE_ANY]
+ * No size or arguments.
+ *
+ * returns:
+ * XBoolean
+ */
+ public static final int NODETYPE_FUNCTEST = 1034;
+
+ /**
+ * <meta name="usage" content="advanced"/>
* [FROM_stepType]
* [length, including predicates]
* [length of just the step, without the predicates]
1.2 +11 -3 xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java
Index: XPathParser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XPathParser.java 2000/07/05 14:45:38 1.1
+++ XPathParser.java 2000/09/12 19:17:33 1.2
@@ -1194,7 +1194,7 @@
nextToken();
}
consumeExpected('(');
- while(!tokenIs(')'))
+ while(!tokenIs(')') && m_token != null)
{
if(tokenIs(','))
{
@@ -1303,7 +1303,13 @@
m_ops.m_opMap[m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - 2] = 4;
m_ops.m_opMap[m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - 1] = OpCodes.NODETYPE_NODE;
}
- else
+ // There is probably a better way to test for this
+ // transition... but it gets real hairy if you try
+ // to do it in basis().
+ else if(tokenIs('*') ||
+ tokenIs('@') ||
+ tokenIs('/') ||
+ Character.isLetter(m_token.charAt(0)))
{
Basis();
@@ -1656,9 +1662,11 @@
if(tokenIs('/') && lookahead('/', 1))
{
appendOp(4, OpCodes.MATCH_ANY_ANCESTOR);
+
// Tell how long the step is without the predicate
m_ops.m_opMap[m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - 2] = 4;
- m_ops.m_opMap[m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - 1] = OpCodes.NODETYPE_ROOT;
+ m_ops.m_opMap[m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - 1] = OpCodes.NODETYPE_FUNCTEST;
+ nextToken();
nextToken();
}
}
1.3 +22 -0 xml-xalan/java/src/org/apache/xpath/patterns/AncestorStepPattern.java
Index: AncestorStepPattern.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/AncestorStepPattern.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AncestorStepPattern.java 2000/08/07 21:26:24 1.2
+++ AncestorStepPattern.java 2000/09/12 19:17:34 1.3
@@ -21,6 +21,28 @@
super(whatToShow);
}
+ /**
+ * Overide the super method so that we can handle
+ * match patterns starting with a function such as id()//
+ */
+ public XObject execute(XPathContext xctxt)
+ throws org.xml.sax.SAXException
+ {
+ int whatToShow = getWhatToShow();
+ if(whatToShow == NodeTest.SHOW_BYFUNCTION)
+ {
+ XObject score = NodeTest.SCORE_NONE;
+ if(null != m_relativePathPattern)
+ {
+ score = m_relativePathPattern.execute(xctxt);
+ }
+ return score;
+ }
+ else
+ return super.execute(xctxt);
+ }
+
+
public XObject executeRelativePathPattern(XPathContext xctxt)
throws org.xml.sax.SAXException
{
1.4 +6 -0 xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java
Index: NodeTest.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NodeTest.java 2000/08/07 02:53:46 1.3
+++ NodeTest.java 2000/09/12 19:17:35 1.4
@@ -25,6 +25,12 @@
public static final int SHOW_NAMESPACE = 0x00001000;
/**
+ * Special bitmap for match patterns starting with a function.
+ * Make sure this does not conflict with dom.traversal.NodeFilter
+ */
+ public static final int SHOW_BYFUNCTION = 0x00010000;
+
+ /**
* This attribute determines which node types are accepted.
* These constants are defined in the <code>NodeFilter</code>
* interface.
1.4 +18 -12 xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
Index: StepPattern.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StepPattern.java 2000/08/07 22:05:15 1.3
+++ StepPattern.java 2000/09/12 19:17:35 1.4
@@ -189,19 +189,25 @@
public XObject executeRelativePathPattern(XPathContext xctxt)
throws org.xml.sax.SAXException
{
- XObject score;
- try
+ XObject score;
+ Node parent = xctxt.getDOMHelper().getParentOfNode(xctxt.getCurrentNode());
+ if (null != parent)
{
- Node parent = xctxt.getDOMHelper().getParentOfNode(xctxt.getCurrentNode());
- xctxt.pushCurrentNode(parent);
- score = execute(xctxt);
- if(score != NodeTest.SCORE_NONE)
- score = SCORE_OTHER;
- }
- finally
- {
- xctxt.popCurrentNode();
- }
+ try
+ {
+ xctxt.pushCurrentNode(parent);
+ score = execute(xctxt);
+ if(score != NodeTest.SCORE_NONE)
+ score = SCORE_OTHER;
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
+ }
+ }
+ else
+ score = NodeTest.SCORE_NONE;
+
return score;
}