jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r553213 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Date Wed, 04 Jul 2007 14:07:03 GMT
Author: mreutegg
Date: Wed Jul  4 07:07:02 2007
New Revision: 553213

URL: http://svn.apache.org/viewvc?view=rev&rev=553213
Log:
JCR-981: XPath relative path support missing for "is null" and "is not null"

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?view=diff&rev=553213&r1=553212&r2=553213
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Wed Jul  4 07:07:02 2007
@@ -38,6 +38,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.commons.collections.map.ReferenceMap;
@@ -235,6 +236,11 @@
     private final List exceptions = new ArrayList();
 
     /**
+     * Temporary relative path
+     */
+    private Path.PathBuilder tmpRelPath;
+
+    /**
      * Creates a new <code>XPathQueryBuilder</code> instance.
      *
      * @param statement the XPath statement.
@@ -361,6 +367,7 @@
                         RelationQueryNode isNull
                                 = new RelationQueryNode(queryNode,
                                         RelationQueryNode.OPERATION_NULL);
+                        applyRelativePath(isNull);
                         node.childrenAccept(this, isNull);
                         NotQueryNode notNode = (NotQueryNode) queryNode;
                         NAryQueryNode parent = (NAryQueryNode) notNode.getParent();
@@ -368,9 +375,10 @@
                         parent.addOperand(isNull);
                     } else {
                         // not null expression
-                        RelationQueryNode notNull
-                                = new RelationQueryNode(queryNode,
+                        RelationQueryNode notNull =
+                                new RelationQueryNode(queryNode,
                                         RelationQueryNode.OPERATION_NOT_NULL);
+                        applyRelativePath(notNull);
                         node.childrenAccept(this, notNull);
                         ((NAryQueryNode) queryNode).addOperand(notNull);
                     }
@@ -380,6 +388,15 @@
                     } else if (queryNode.getType() == QueryNode.TYPE_TEXTSEARCH
                             || queryNode.getType() == QueryNode.TYPE_RELATION) {
                         node.childrenAccept(this, queryNode);
+                    } else {
+                        // step within a predicate
+                        RelationQueryNode tmp = new RelationQueryNode(
+                                null, RelationQueryNode.OPERATION_NOT_NULL);
+                        node.childrenAccept(this, tmp);
+                        if (tmpRelPath == null) {
+                            tmpRelPath = new Path.PathBuilder();
+                        }
+                        tmpRelPath.addLast(tmp.getRelativePath().getNameElement());
                     }
                 }
                 break;
@@ -508,6 +525,26 @@
     }
 
     //----------------------< internal >----------------------------------------
+
+    /**
+     * Applies {@link #tmpRelPath} to <code>node</code> and reset the path to
+     * <code>null</code>.
+     *
+     * @param node a relation query node.
+     */
+    private void applyRelativePath(RelationQueryNode node) {
+        if (tmpRelPath != null) {
+            try {
+                Path relPath = tmpRelPath.getPath();
+                for (int i = 0; i < relPath.getLength(); i++) {
+                    node.addPathElement(relPath.getElement(i));
+                }
+            } catch (MalformedPathException e) {
+                // should never happen
+            }
+            tmpRelPath = null;
+        }
+    }
 
     /**
      * Creates a <code>LocationStepQueryNode</code> at the current position



Mime
View raw message