jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158751 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java test/org/apache/jackrabbit/test/api/query/ElementTest.java test/org/apache/jackrabbit/test/api/query/TestAll.java
Date Wed, 23 Mar 2005 10:07:19 GMT
Author: mreutegg
Date: Wed Mar 23 02:07:18 2005
New Revision: 158751

URL: http://svn.apache.org/viewcvs?view=rev&rev=158751
Log:
- Add support for element test in XPath as an alternative for predicate with @jcr:primaryType
expression.
- Test cases for element test.

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java?view=diff&r1=158750&r2=158751
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
Wed Mar 23 02:07:18 2005
@@ -78,6 +78,11 @@
     static final QName FN_POSITION = new QName("", "position");
 
     /**
+     * QName for element function.
+     */
+    static final QName FN_ELEMENT = new QName("", "element");
+
+    /**
      * QName for the full position function including bracket
      */
     static final QName FN_POSITION_FULL = new QName("", "position()");
@@ -333,6 +338,29 @@
                     node.childrenAccept(this, queryNode);
                 }
                 break;
+            case JJTELEMENTNAMEORWILDCARD:
+                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
+                    SimpleNode child = (SimpleNode) node.jjtGetChild(0);
+                    if (child.getId() != JJTANYNAME) {
+                        createNodeTest(child, queryNode);
+                    }
+                }
+                break;
+            case JJTTYPENAME:
+                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
+                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
+                    String ntName = ((SimpleNode) node.jjtGetChild(0)).getValue();
+                    try {
+                        QName nt = QName.fromJCRName(ntName, resolver);
+                        NodeTypeQueryNode nodeType = new NodeTypeQueryNode(loc, nt);
+                        loc.addPredicate(nodeType);
+                    } catch (IllegalNameException e) {
+                        exceptions.add(new InvalidQueryException("Not a valid name: " + ntName));
+                    } catch (UnknownPrefixException e) {
+                        exceptions.add(new InvalidQueryException("Unknown prefix in name:
" + ntName));
+                    }
+                }
+                break;
             case JJTOREXPR:
                 NAryQueryNode parent = (NAryQueryNode) queryNode;
                 queryNode = new OrQueryNode(parent);
@@ -430,7 +458,7 @@
     private void createNodeTest(SimpleNode node, QueryNode queryNode) {
         if (node.jjtGetNumChildren() > 0) {
             SimpleNode child = (SimpleNode) node.jjtGetChild(0);
-            if (child.getId() == JJTQNAME) {
+            if (child.getId() == JJTQNAME || child.getId() == JJTQNAMEFORITEMTYPE) {
                 try {
                     if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                         QName name = ISO9075.decode(QName.fromJCRName(child.getValue(), resolver));

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java?view=auto&rev=158751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java
Wed Mar 23 02:07:18 2005
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.query;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
+/**
+ * Tests the element test function in XPath.
+ *
+ * @tck.config testroot path to node that allows child nodes of type
+ * <code>nodetype</code> and <code>nt:base</code>.
+ * @tck.config nodetype node type name for nodes to create
+ * @tck.config nodename1 node name for a child node of type
+ * <code>nodetype</code> or <code>nt:base</code>
+ * @tck.config nodename2 node name for a child node of type
+ * <code>nodetype</code> or <code>nt:base</code>
+ * @tck.config nodename3 node name for a child node of type
+ * <code>nodetype</code> or <code>nt:base</code>
+ * 
+ * @test
+ * @sources ElementTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.ElementTest
+ * @keywords level2
+ */
+public class ElementTest extends AbstractQueryTest {
+
+    /**
+     * Tests the element test without arguments.
+     */
+    public void testElementTest() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        Node n2 = testRootNode.addNode(nodeName2, ntBase);
+        Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element()";
+        executeXPathQuery(superuser, query, new Node[]{n1, n2, n3});
+    }
+
+    /**
+     * Tests the element test with one any node argument.
+     */
+    public void testElementTestAnyNode() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        Node n2 = testRootNode.addNode(nodeName2, ntBase);
+        Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(*)";
+        executeXPathQuery(superuser, query, new Node[]{n1, n2, n3});
+    }
+
+    /**
+     * Tests the element test with an any node argument and a type argument
+     * that matches all nodes (nt:base).
+     */
+    public void testElementTestAnyNodeNtBase() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        Node n2 = testRootNode.addNode(nodeName2, ntBase);
+        Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(*, " + ntBase + ")";
+        executeXPathQuery(superuser, query, new Node[]{n1, n2, n3});
+    }
+
+    /**
+     * Tests the element test with an any node argument and a type argument
+     * that matches only certain child nodes.
+     */
+    public void testElementTestAnyNodeSomeNT() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.addNode(nodeName2, ntBase);
+        Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(*, " + testNodeType + ")";
+        executeXPathQuery(superuser, query, new Node[]{n1, n3});
+    }
+
+    /**
+     * Tests the element test with one single name test argument.
+     */
+    public void testElementTestNameTest() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.addNode(nodeName2, ntBase);
+        testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ")";
+        executeXPathQuery(superuser, query, new Node[]{n1});
+    }
+
+    /**
+     * Tests the element test with a name test argument and a type argument that
+     * matches all nodes (nt:base).
+     */
+    public void testElementTestNameTestNtBase() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.addNode(nodeName2, ntBase);
+        testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ", " + ntBase
+ ")";
+        executeXPathQuery(superuser, query, new Node[]{n1});
+    }
+
+    /**
+     * Tests the element test with a name test argument and a type argument that
+     * matches only certain child nodes.
+     */
+    public void testElementTestNameTestSomeNT() throws RepositoryException {
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.addNode(nodeName2, ntBase);
+        testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ", " + testNodeType
+ ")";
+        executeXPathQuery(superuser, query, new Node[]{n1});
+    }
+
+    /**
+     * Tests the element test with a name test argument and a type argument that
+     * matches only certain child nodes. Additonally this test requires that
+     * testroot allows same name sibling child nodes.
+     */
+    public void testElementTestNameTestSomeNTWithSNS() throws RepositoryException, NotExecutableException
{
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        if (!n1.getDefinition().allowSameNameSibs()) {
+            throw new NotExecutableException("Node at " + testRoot + " does not allow same
name siblings with name " + nodeName1);
+        }
+        testRootNode.addNode(nodeName1, ntBase);
+        Node n2 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.addNode(nodeName2, ntBase);
+        testRootNode.addNode(nodeName3, testNodeType);
+        testRootNode.save();
+
+        String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ", " + testNodeType
+ ")";
+        executeXPathQuery(superuser, query, new Node[]{n1, n2});
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/ElementTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java?view=diff&r1=158750&r2=158751
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Wed Mar 23 02:07:18 2005
@@ -46,6 +46,7 @@
         suite.addTestSuite(XPathQueryLevel2Test.class);
 
         suite.addTestSuite(DerefQueryLevel1Test.class);
+        suite.addTestSuite(ElementTest.class);
         suite.addTestSuite(GetLanguageTest.class);
         suite.addTestSuite(GetPersistentQueryPathLevel1Test.class);
         suite.addTestSuite(GetPersistentQueryPathTest.class);



Mime
View raw message