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/02/27 08:29:14 UTC

svn commit: r381279 - /xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java

Author: mrglavas
Date: Sun Feb 26 23:29:09 2006
New Revision: 381279

URL: http://svn.apache.org/viewcvs?rev=381279&view=rev
Log:
Fixing JIRA Bug #1137:
http://issues.apache.org/jira/browse/XERCESJ-1137

The code which corrects field XPaths so that they start with "./" did not
handle a union of XPath expressions. Only the first XPath in the union was 
being fixed up. I've fixed that problem though the code should probably
be replaced with a more efficient solution since it could generate many
temporary objects.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java?rev=381279&r1=381278&r2=381279&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Field.java Sun Feb 26 23:29:09 2006
@@ -16,6 +16,8 @@
 
 package org.apache.xerces.impl.xs.identity;
 
+import java.util.StringTokenizer;
+
 import org.apache.xerces.impl.xpath.XPathException;
 import org.apache.xerces.impl.xs.util.ShortListImpl;
 import org.apache.xerces.util.SymbolTable;
@@ -107,15 +109,7 @@
         public XPath(String xpath, 
                      SymbolTable symbolTable,
                      NamespaceContext context) throws XPathException {
-            // NOTE: We have to prefix the field XPath with "./" in
-            //       order to handle selectors such as "@attr" that 
-            //       select the attribute because the fields could be
-            //       relative to the selector element. -Ac
-            //       Unless xpath starts with a descendant node -Achille Fokoue
-            //      ... or a / or a . - NG
-            super(((xpath.trim().startsWith("/") ||xpath.trim().startsWith("."))?
-                    xpath:"./"+xpath), 
-                  symbolTable, context);
+            super(fixupXPath(xpath), symbolTable, context);
             
             // verify that only one attribute is selected per branch
             for (int i=0;i<fLocationPaths.length;i++) {
@@ -129,6 +123,35 @@
                 }
             }
         } // <init>(String,SymbolTable,NamespacesContext)
+        
+        private static String fixupXPath(String xpath) {
+            // NOTE: We have to prefix the field XPath with "./" in
+            //       order to handle selectors such as "@attr" that 
+            //       select the attribute because the fields could be
+            //       relative to the selector element. -Ac
+            //       Unless xpath starts with a descendant node -Achille Fokoue
+            //      ... or a / or a . - NG
+            int union = xpath.indexOf('|');
+            if (union == -1) {
+                return ((xpath.trim().startsWith("/") || xpath.trim().startsWith(".")) ?
+                        xpath : "./"+xpath);
+            }
+            else {
+                // REVISIT: Replace with a more efficient solution.
+                StringBuffer buffer = new StringBuffer(xpath.length());
+                StringTokenizer tokenizer = new StringTokenizer(xpath, "|");
+                int length = tokenizer.countTokens();
+                for (int i = length - 1; i >= 0; --i) {
+                    String token = tokenizer.nextToken();
+                    buffer.append(((token.trim().startsWith("/") || token.trim().startsWith(".")) ?
+                            token : "./"+token));
+                    if (i > 0) {
+                        buffer.append('|');
+                    }
+                }
+                return buffer.toString();
+            }
+        }
 
     } // class XPath
 



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