You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/11/03 19:34:04 UTC

svn commit: r470937 - /xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java

Author: mrglavas
Date: Fri Nov  3 10:34:03 2006
New Revision: 470937

URL: http://svn.apache.org/viewvc?view=rev&rev=470937
Log:
Fixing JIRA Issue #1206:
http://issues.apache.org/jira/browse/XERCESJ-1206

XPath expressions containing child:: or attribute:: are allowed 
by the schema spec. The XPath scanner now accepts them.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java?view=diff&rev=470937&r1=470936&r2=470937
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xpath/XPath.java Fri Nov  3 10:34:03 2006
@@ -161,7 +161,10 @@
                     token == XPath.Tokens.EXPRTOKEN_NAMETEST_ANY ||
                     token == XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE ||
                     token == XPath.Tokens.EXPRTOKEN_OPERATOR_DOUBLE_SLASH ||
-                    token == XPath.Tokens.EXPRTOKEN_OPERATOR_UNION
+                    token == XPath.Tokens.EXPRTOKEN_OPERATOR_UNION ||
+                    token == XPath.Tokens.EXPRTOKEN_AXISNAME_CHILD ||
+                    token == XPath.Tokens.EXPRTOKEN_AXISNAME_ATTRIBUTE ||
+                    token == XPath.Tokens.EXPRTOKEN_DOUBLE_COLON
                     //
                     ) {
                     super.addToken(tokens, token);
@@ -190,7 +193,7 @@
         // 'abc' '/' '/' 'def' 'ghi'
         boolean expectingStep = true;
 
-        while(xtokens.hasMore()) {
+        while (xtokens.hasMore()) {
             final int token = xtokens.nextToken();
 
             switch (token) {
@@ -200,7 +203,6 @@
                     expectingStep=true;
                     break;
                 }
-
                 case XPath.Tokens.EXPRTOKEN_ATSIGN: {
                     check(expectingStep);
                     Step step = new Step(
@@ -210,6 +212,19 @@
                     expectingStep=false;
                     break;
                 }
+                case XPath.Tokens.EXPRTOKEN_AXISNAME_ATTRIBUTE: {
+                    check(expectingStep);
+                    // If we got here we're expecting attribute::
+                    if (xtokens.nextToken() != XPath.Tokens.EXPRTOKEN_DOUBLE_COLON) {
+                        throw new XPathException("c-general-xpath");
+                    }
+                    Step step = new Step(
+                            new Axis(Axis.ATTRIBUTE),
+                            parseNodeTest(xtokens.nextToken(),xtokens,context));
+                    stepsVector.addElement(step);
+                    expectingStep = false;
+                    break;
+                }
                 case XPath.Tokens.EXPRTOKEN_NAMETEST_ANY:
                 case XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE:
                 case XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME: {
@@ -221,7 +236,19 @@
                     expectingStep=false;
                     break;
                 }
-
+                case XPath.Tokens.EXPRTOKEN_AXISNAME_CHILD: {
+                    check(expectingStep);
+                    // If we got here we're expecting child::
+                    if (xtokens.nextToken() != XPath.Tokens.EXPRTOKEN_DOUBLE_COLON) {
+                        throw new XPathException("c-general-xpath");
+                    }
+                    Step step = new Step(
+                            new Axis(Axis.CHILD),
+                            parseNodeTest(xtokens.nextToken(),xtokens,context));
+                    stepsVector.addElement(step);
+                    expectingStep = false;
+                    break;
+                }
                 case XPath.Tokens.EXPRTOKEN_PERIOD: {
                     check(expectingStep);
                     expectingStep=false;
@@ -253,13 +280,18 @@
                     }
                     break;
                 }
-
                 case XPath.Tokens.EXPRTOKEN_OPERATOR_DOUBLE_SLASH:{
-                    // this cannot appear in arbitrary position.
+                    // this cannot appear in an arbitrary position.
                     // it is only allowed right after '.' when
                     // '.' is the first token of a location path.
                     throw new XPathException("c-general-xpath");
                 }
+                case XPath.Tokens.EXPRTOKEN_DOUBLE_COLON: {
+                    // :: cannot appear in an arbitrary position.
+                    // We only expect this token if the xpath
+                    // contains child:: or attribute::
+                    throw new XPathException("c-general-xpath");
+                }
                 case XPath.Tokens.EXPRTOKEN_OPERATOR_SLASH: {
                     check(!expectingStep);
                     expectingStep=true;
@@ -318,8 +350,7 @@
             return new NodeTest(new QName(prefix, localpart, rawname, uri));
         
         default:
-            // assertion error
-            throw new InternalError();
+            throw new XPathException("c-general-xpath");
         }
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org