jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r792894 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/query/ main/java/org/apache/jackrabbit/spi/commons/query/xpath/ test/java/org/apache/jackrabbit/spi/commons/query/xpath/
Date Fri, 10 Jul 2009 11:53:02 GMT
Author: mreutegg
Date: Fri Jul 10 11:53:02 2009
New Revision: 792894

URL: http://svn.apache.org/viewvc?rev=792894&view=rev
Log:
JCR-977: jcr:deref in xpath predicates

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/RelationQueryNode.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormat.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormatTest.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/RelationQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/RelationQueryNode.java?rev=792894&r1=792893&r2=792894&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/RelationQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/RelationQueryNode.java
Fri Jul 10 11:53:02 2009
@@ -175,7 +175,11 @@
      */
     public void addPathElement(Path.Element element) {
         LocationStepQueryNode step = factory.createLocationStepQueryNode(relPath);
-        step.setNameTest(element.getName());
+        if (element.getName().equals(STAR_NAME_TEST)) {
+            step.setNameTest(null);
+        } else {
+            step.setNameTest(element.getName());
+        }
         relPath.addPathStep(step);
     }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormat.java?rev=792894&r1=792893&r2=792894&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormat.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormat.java
Fri Jul 10 11:53:02 2009
@@ -351,7 +351,17 @@
             } else if (relPath.getNumOperands() > 0 && relPath.getPathSteps()[0].getNameTest().equals(XPathQueryBuilder.FN_POSITION_FULL))
{
                 propPath.append(resolver.getJCRName(XPathQueryBuilder.FN_POSITION_FULL));
             } else {
-                visit(relPath, data);
+                LocationStepQueryNode[] steps = relPath.getPathSteps();
+                String slash = "";
+                for (int i = 0; i < steps.length; i++) {
+                    propPath.append(slash);
+                    slash = "/";
+                    if (i == steps.length - 1 && node.getOperation() != OPERATION_SIMILAR)
{
+                        // last step
+                        propPath.append("@");
+                    }
+                    visit(steps[i], propPath);
+                }
             }
 
             // surround name with property function
@@ -407,6 +417,7 @@
                 sb.append(resolver.getJCRName(XPathQueryBuilder.REP_SIMILAR));
                 sb.append("(").append(propPath).append(", ");
                 appendValue(node, sb);
+                sb.append(")");
             } else if (node.getOperation() == OPERATION_SPELLCHECK) {
                 sb.append(resolver.getJCRName(XPathQueryBuilder.REP_SPELLCHECK));
                 sb.append("(");

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormatTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormatTest.java?rev=792894&r1=792893&r2=792894&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormatTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/query/xpath/QueryFormatTest.java
Fri Jul 10 11:53:02 2009
@@ -20,6 +20,7 @@
 
 import javax.jcr.query.Query;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.NamespaceException;
 
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
@@ -28,6 +29,7 @@
 import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory;
 import org.apache.jackrabbit.spi.commons.query.QueryRootNode;
 import org.apache.jackrabbit.spi.commons.query.QueryParser;
+import org.apache.jackrabbit.spi.Name;
 
 import junit.framework.TestCase;
 
@@ -37,12 +39,39 @@
 public class QueryFormatTest extends TestCase {
 
     private static final NameResolver RESOLVER = new DefaultNamePathResolver(
-            new DummyNamespaceResolver());
+            new DummyNamespaceResolver() {
+                public String getURI(String prefix) throws NamespaceException {
+                    if (Name.NS_REP_PREFIX.equals(prefix)) {
+                        return Name.NS_REP_URI;
+                    } else {
+                        return super.getURI(prefix);
+                    }
+                }
+
+                public String getPrefix(String uri) {
+                    if (Name.NS_REP_URI.equals(uri)) {
+                        return Name.NS_REP_PREFIX;
+                    } else {
+                        return super.getPrefix(uri);
+                    }
+                }
+            });
 
-    private static final QueryNodeFactory FACTORY = new DefaultQueryNodeFactory(Collections.EMPTY_LIST);
+    private static final QueryNodeFactory FACTORY = new DefaultQueryNodeFactory(Collections.<Name>emptyList());
 
     public void testSelectWithOrderBy() throws InvalidQueryException {
-        String stmt = "//element(*, foo)/(@a|@b) order by @bar";
+        checkStatement("//element(*, foo)/(@a|@b) order by @bar");
+    }
+
+    public void testStarNameTest() throws Exception {
+        checkStatement("//element(*, foo)[foo/*/@bar = 'bla']");
+    }
+
+    public void testRepSimilar() throws Exception {
+        checkStatement("//element(*, foo)[rep:similar(foo, '/some/path')]");
+    }
+
+    protected void checkStatement(String stmt) throws InvalidQueryException {
         QueryRootNode root = QueryParser.parse(stmt, Query.XPATH, RESOLVER, FACTORY);
         assertEquals(stmt, QueryFormat.toString(root, RESOLVER));
     }



Mime
View raw message