jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1227247 - in /jackrabbit/branches/2.4: ./ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/ jackrabbit-jcr2dav/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/ jackrabbit-spi/src/main/java/o...
Date Wed, 04 Jan 2012 18:08:03 GMT
Author: jukka
Date: Wed Jan  4 18:08:03 2012
New Revision: 1227247

URL: http://svn.apache.org/viewvc?rev=1227247&view=rev
Log:
2.4: Merged revision 1227240 (JCR-3198).

Modified:
    jackrabbit/branches/2.4/   (props changed)
    jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
    jackrabbit/branches/2.4/jackrabbit-jcr2dav/pom.xml
    jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
    jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
    jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
    jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
    jackrabbit/branches/2.4/jackrabbit-spi2dav/pom.xml
    jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
    jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
    jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
    jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java

Propchange: jackrabbit/branches/2.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan  4 18:08:03 2012
@@ -1,2 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
+/jackrabbit/trunk:1227240

Modified: jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
Wed Jan  4 18:08:03 2012
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.webdav.DavR
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
 import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
 import org.apache.jackrabbit.webdav.search.QueryGrammerSet;
@@ -45,16 +46,10 @@ import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
-import javax.jcr.query.qom.Source;
-import javax.jcr.query.qom.Join;
-import javax.jcr.query.qom.Selector;
-import javax.jcr.query.qom.QueryObjectModel;
 
 import java.util.Map;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Arrays;
 
 /**
  * <code>SearchResourceImpl</code>...
@@ -81,7 +76,10 @@ public class SearchResourceImpl implemen
             QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
             String[] langs = qMgr.getSupportedQueryLanguages();
             for (String lang : langs) {
-                // todo: define proper namespace
+                // Note: Existing clients already assume that the
+                // query languages returned in the DASL header are
+                // not prefixed with any namespace, so we probably
+                // shouldn't use an explicit namespace here.
                 qgs.addQueryLanguage(lang, Namespace.EMPTY_NAMESPACE);
             }
         } catch (RepositoryException e) {
@@ -97,8 +95,22 @@ public class SearchResourceImpl implemen
      */
     public MultiStatus search(SearchInfo sInfo) throws DavException {
         try {
-            return queryResultToMultiStatus(getQuery(sInfo));
+            QueryResult result = getQuery(sInfo).execute();
 
+            MultiStatus ms = new MultiStatus();
+
+            if (ItemResourceConstants.NAMESPACE.equals(
+                    sInfo.getLanguageNameSpace())) {
+                ms.setResponseDescription(
+                        "Columns: " + encode(result.getColumnNames())
+                        + "\nSelectors: " + encode(result.getSelectorNames()));
+            } else {
+                ms.setResponseDescription(encode(result.getColumnNames()));
+            }
+
+            queryResultToMultiStatus(result, ms);
+
+            return ms;
         } catch (RepositoryException e) {
             throw new JcrDavException(e);
         }
@@ -196,44 +208,34 @@ public class SearchResourceImpl implemen
      * Webdav compatible form.
      * @throws RepositoryException if an error occurs.
      */
-    private MultiStatus queryResultToMultiStatus(Query query)
+    private void queryResultToMultiStatus(QueryResult result, MultiStatus ms)
             throws RepositoryException {
-        QueryResult qResult = query.execute();
-        MultiStatus ms = new MultiStatus();
-
         List<String> columnNames = new ArrayList<String>();
-        columnNames.addAll(Arrays.asList(qResult.getColumnNames()));
-        StringBuffer responseDescription = new StringBuffer();
-        String delim = "";
-        for (String columnName : columnNames) {
-            responseDescription.append(delim);
-            responseDescription.append(ISO9075.encode(columnName));
-            delim = " ";
-        }
-        ms.setResponseDescription(responseDescription.toString());
 
         ValueFactory vf = getRepositorySession().getValueFactory();
         List<RowValue> descr = new ArrayList<RowValue>();
-        for (Iterator<String> it = columnNames.iterator(); it.hasNext(); ) {
-            String columnName = it.next();
+        for (String columnName : result.getColumnNames()) {
             if (!isPathOrScore(columnName)) {
+                columnNames.add(columnName);
                 descr.add(new PlainValue(columnName, null, vf));
-            } else {
-                it.remove();
             }
         }
+
         // add path and score for each selector
-        List<String> sn = new ArrayList<String>();
-        collectSelectorNames(query, qResult, sn);
-        for (String selectorName : sn) {
+        String[] sns = result.getSelectorNames();
+        boolean join = sns.length > 1;
+        for (String selectorName : sns) {
             descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
             columnNames.add(JcrConstants.JCR_PATH);
             descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
             columnNames.add(JcrConstants.JCR_SCORE);
         }
+
+        int n = 0;
+        String root = getHref("/");
         String[] selectorNames = createSelectorNames(descr);
         String[] colNames = columnNames.toArray(new String[columnNames.size()]);
-        RowIterator rowIter = qResult.getRows();
+        RowIterator rowIter = result.getRows();
         while (rowIter.hasNext()) {
             Row row = rowIter.nextRow();
             List<Value> values = new ArrayList<Value>();
@@ -241,27 +243,49 @@ public class SearchResourceImpl implemen
                 values.add(rv.getValue(row));
             }
 
-            /*
-             * get the path for the first selector and build a webdav compliant
-             * resource path based on it.
-             * 
-             * Use Row#getPath(String) which works for both simple rows and join
-             * rows (in contrast to Row#getPath()).
-             * 
-             * see also https://issues.apache.org/jira/browse/JCR-3089
-             */
-            final String itemPath = row.getPath(sn.get(0));
             // create a new ms-response for this row of the result set
-            DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(),
locator.getWorkspacePath(), itemPath, false);
-            String href = loc.getHref(true);
+            String href;
+            if (join) {
+                // We need a distinct href for each join result row to
+                // allow the MultiStatus response to keep them separate
+                href = root + "?" + n++;
+            } else {
+                href = getHref(row.getPath());
+            }
             MultiStatusResponse resp = new MultiStatusResponse(href, null);
+
             // build the s-r-property
             SearchResultProperty srp = new SearchResultProperty(colNames,
                     selectorNames, values.toArray(new Value[values.size()]));
             resp.add(srp);
             ms.addResponse(resp);
         }
-        return ms;
+    }
+
+    /**
+     * Returns the resource location of the given query result row.
+     * The result rows of join queries have no meaningful single resource
+     * location, so we'll just default to the root node for all such rows.
+     *
+     * @param row query result row
+     * @param join flag to indicate a join query
+     * @return resource location of the row
+     */
+    private String getHref(String path) throws RepositoryException {
+        DavResourceLocator l = locator.getFactory().createResourceLocator(
+                locator.getPrefix(), locator.getWorkspacePath(), path, false);
+        return l.getHref(true);
+    }
+
+    private String encode(String[] names) {
+        StringBuilder builder = new StringBuilder();
+        String delim = "";
+        for (String name : names) {
+            builder.append(delim);
+            builder.append(ISO9075.encode(name));
+            delim = " ";
+        }
+        return builder.toString();
     }
 
     private static String[] createSelectorNames(Iterable<RowValue> rows)
@@ -376,31 +400,4 @@ public class SearchResourceImpl implemen
         }
     }
 
-    private static void collectSelectorNames(Query query,
-                                             QueryResult result,
-                                             List<String> sn) throws RepositoryException
{
-        if (query instanceof QueryObjectModel) {
-            QueryObjectModel qom = (QueryObjectModel) query;
-            collectSelectorNames(qom.getSource(), sn);
-        } else {
-            sn.addAll(Arrays.asList(result.getSelectorNames()));
-        }
-    }
-
-    private static void collectSelectorNames(Source source, List<String> sn) {
-        if (source instanceof Join) {
-            collectSelectorNames((Join) source, sn);
-        } else {
-            collectSelectorNames((Selector) source, sn);
-        }
-    }
-
-    private static void collectSelectorNames(Join join, List<String> sn) {
-        collectSelectorNames(join.getLeft(), sn);
-        collectSelectorNames(join.getRight(), sn);
-    }
-
-    private static void collectSelectorNames(Selector s, List<String> sn) {
-        sn.add(s.getSelectorName());
-    }
 }
\ No newline at end of file

Modified: jackrabbit/branches/2.4/jackrabbit-jcr2dav/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-jcr2dav/pom.xml?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-jcr2dav/pom.xml (original)
+++ jackrabbit/branches/2.4/jackrabbit-jcr2dav/pom.xml Wed Jan  4 18:08:03 2012
@@ -82,13 +82,6 @@
                       org.apache.jackrabbit.test.api.query.SetOffsetTest#testSetOffset
                       <!-- JCR-2533 : missing impl of checkQueryStatement -->
                       org.apache.jackrabbit.test.api.query.qom.BindVariableValueTest
-                      <!-- JCR-2535 : Row.getPath() called with multiple selectors (server-side)
-->
-                      org.apache.jackrabbit.test.api.query.qom.ChildNodeJoinConditionTest
-                      org.apache.jackrabbit.test.api.query.qom.ColumnTest#testMultiColumn
-                      org.apache.jackrabbit.test.api.query.qom.DescendantNodeJoinConditionTest
-                      org.apache.jackrabbit.test.api.query.qom.EquiJoinConditionTest
-                      org.apache.jackrabbit.test.api.query.qom.OrderingTest#testMultipleSelectors
-                      org.apache.jackrabbit.test.api.query.qom.SameNodeJoinConditionTest
                       <!-- JCR-2112 : simple versioning not implemented -->
                       org.apache.jackrabbit.test.api.version.simple
                       <!-- JCR-2104 : activities and configuration -->

Modified: jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
Wed Jan  4 18:08:03 2012
@@ -19,8 +19,6 @@ package org.apache.jackrabbit.jcr2spi.qu
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
@@ -66,13 +64,7 @@ class QueryResultImpl implements QueryRe
      * {@inheritDoc}
      */
     public String[] getSelectorNames() throws RepositoryException {
-        Name[] names = queryInfo.getSelectorNames();
-        String[] sn = new String[names.length];
-        NameResolver resolver = mgrProvider.getNameResolver();
-        for (int i = 0; i < sn.length; i++) {
-            sn[i] = resolver.getJCRName(names[i]);
-        }
-        return sn;
+        return queryInfo.getSelectorNames();
     }
 
     /**

Modified: jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
Wed Jan  4 18:08:03 2012
@@ -291,7 +291,7 @@ class RowIteratorImpl implements RowIter
          * @see Row#getNode(String)
          */
         public Node getNode(String selectorName) throws RepositoryException {
-            return getNode(row.getNodeId(resolver.getQName(selectorName)));
+            return getNode(row.getNodeId(selectorName));
         }
 
         /**
@@ -329,7 +329,7 @@ class RowIteratorImpl implements RowIter
          * @see Row#getScore(String)
          */
         public double getScore(String selectorName) throws RepositoryException {
-            return row.getScore(resolver.getQName(selectorName));
+            return row.getScore(selectorName);
         }
 
         /**

Modified: jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
Wed Jan  4 18:08:03 2012
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.spi;
 
 import javax.jcr.RangeIterator;
+import javax.jcr.RepositoryException;
+
 import java.util.Map;
 
 /**
@@ -46,9 +48,9 @@ public interface QueryInfo {
     public String[] getColumnNames();
 
     /**
-     * @return an array of <code>Name</code>s representing the selector names
of
+     * @return an array of <code>String</code>s representing the selector names
of
      *         the query result.
      * @see javax.jcr.query.QueryResult#getSelectorNames()
      */
-    public Name[] getSelectorNames();
+    public String[] getSelectorNames();
 }

Modified: jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
Wed Jan  4 18:08:03 2012
@@ -35,7 +35,7 @@ public interface QueryResultRow {
      * @see javax.jcr.query.Row#getNode()
      * @see javax.jcr.query.Row#getNode(String)
      */
-    public NodeId getNodeId(Name selectorName);
+    public NodeId getNodeId(String selectorName);
 
     /**
      * Returns score for the given <code>selectorName</code> of this result row.
@@ -44,7 +44,7 @@ public interface QueryResultRow {
      *                     default selector.
      * @return score for the given selector in this result row.
      */
-    public double getScore(Name selectorName);
+    public double getScore(String selectorName);
 
     /**
      * Returns an array of <code>QValue</code>s.

Modified: jackrabbit/branches/2.4/jackrabbit-spi2dav/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2dav/pom.xml?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2dav/pom.xml (original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2dav/pom.xml Wed Jan  4 18:08:03 2012
@@ -79,13 +79,6 @@
                   org.apache.jackrabbit.test.api.query.SetOffsetTest#testSetOffset
                   <!-- JCR-2533 : missing impl of checkQueryStatement -->
                   org.apache.jackrabbit.test.api.query.qom.BindVariableValueTest
-                  <!-- JCR-2535 : Row.getPath() called with multiple selectors (server-side)
-->
-                  org.apache.jackrabbit.test.api.query.qom.ChildNodeJoinConditionTest
-                  org.apache.jackrabbit.test.api.query.qom.ColumnTest#testMultiColumn
-                  org.apache.jackrabbit.test.api.query.qom.DescendantNodeJoinConditionTest
-                  org.apache.jackrabbit.test.api.query.qom.EquiJoinConditionTest
-                  org.apache.jackrabbit.test.api.query.qom.OrderingTest#testMultipleSelectors
-                  org.apache.jackrabbit.test.api.query.qom.SameNodeJoinConditionTest
                   <!-- JCR-2112 : simple versioning not implemented -->
                   org.apache.jackrabbit.test.api.version.simple
                   <!-- JCR-2104 : activities and configuration -->

Modified: jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
Wed Jan  4 18:08:03 2012
@@ -18,8 +18,6 @@ package org.apache.jackrabbit.spi2dav;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
@@ -29,26 +27,24 @@ import org.apache.jackrabbit.spi.QueryIn
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.QueryResultRow;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * <code>QueryInfoImpl</code>...
  */
 public class QueryInfoImpl implements QueryInfo {
 
-    /**
-     * Logger instance for this class.
-     */
-    private static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
+    private static final String COLUMNS = "Columns: ";
+
+    private static final String SELECTORS = "Selectors: ";
+
+    private final List<String> columnNames = new ArrayList<String>();
 
-    private final String[] columnNames;
+    private final List<String> selectorNames = new ArrayList<String>();
 
     private final List<QueryResultRow> results = new ArrayList<QueryResultRow>();
 
@@ -58,23 +54,45 @@ public class QueryInfoImpl implements Qu
         throws RepositoryException {
 
         String responseDescription = ms.getResponseDescription();
-        if (responseDescription != null) {
-            String[] cn = responseDescription.split(" ");
-            this.columnNames = new String[cn.length];
-            for (int i = 0; i < cn.length; i++) {
-                columnNames[i] = ISO9075.decode(cn[i]);
+        if (responseDescription == null) {
+            throw new RepositoryException(
+                    "Missing column infos: Unable to build QueryInfo object.");
+        }
+        if (responseDescription.startsWith(COLUMNS)) {
+            for (String line : responseDescription.split("\n")) {
+                if (line.startsWith(COLUMNS)) {
+                    decode(line.substring(COLUMNS.length()), columnNames);
+                } else if (line.startsWith(SELECTORS)) {
+                    decode(line.substring(SELECTORS.length()), selectorNames);
+                }
             }
         } else {
-            throw new RepositoryException("Missing column infos: Unable to build QueryInfo
object.");
+            // Backwards compatibility with old servers that only provide
+            // the list of columns as the response description
+            decode(responseDescription, columnNames);
         }
 
         for (MultiStatusResponse response : ms.getResponses()) {
-            results.add(new QueryResultRowImpl(response, columnNames, resolver,
+            results.add(new QueryResultRowImpl(
+                    response, getColumnNames(), resolver,
                     qValueFactory, valueFactory, idFactory));
         }
     }
 
     /**
+     * Splits the given string at spaces and ISO9075-decodes the parts.
+     *
+     * @param string source string
+     * @param list where the decoded parts get added
+     */
+    private void decode(String string, List<String> list) {
+        String[] parts = string.split(" ");
+        for (int i = 0; i < parts.length; i++) {
+            list.add(ISO9075.decode(parts[i]));
+        }
+    }
+
+    /**
      * @see QueryInfo#getRows()
      */
     public RangeIterator getRows() {
@@ -85,27 +103,13 @@ public class QueryInfoImpl implements Qu
      * @see QueryInfo#getColumnNames()
      */
     public String[] getColumnNames() {
-        String[] names = new String[columnNames.length];
-        System.arraycopy(columnNames, 0, names, 0, columnNames.length);
-        return names;
+        return columnNames.toArray(new String[columnNames.size()]);
     }
 
     /**
      * @see QueryInfo#getSelectorNames()
      */
-    public Name[] getSelectorNames() {
-        if (results.isEmpty()) {
-            // TODO: this is not correct
-            return Name.EMPTY_ARRAY;
-        } else {
-            Set<Name> uniqueNames = new HashSet<Name>();
-            QueryResultRowImpl row = (QueryResultRowImpl) results.get(0);
-            for (Name n : row.getSelectorNames()) {
-                if (n != null) {
-                    uniqueNames.add(n);
-                }
-            }
-            return uniqueNames.toArray(new Name[uniqueNames.size()]);
-        }
+    public String[] getSelectorNames() {
+        return selectorNames.toArray(new String[selectorNames.size()]);
     }
 }

Modified: jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
Wed Jan  4 18:08:03 2012
@@ -29,7 +29,6 @@ import org.apache.jackrabbit.commons.web
 import org.apache.jackrabbit.commons.webdav.QueryUtil;
 import org.apache.jackrabbit.spi.QueryResultRow;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.IdFactory;
@@ -54,16 +53,14 @@ public class QueryResultRowImpl implemen
 
     private static final DavPropertyName SEARCH_RESULT_PROPERTY = DavPropertyName.create(JcrRemotingConstants.JCR_QUERY_RESULT_LN,
ItemResourceConstants.NAMESPACE);
 
-    private final Map<Name, NodeId> nodeIds = new HashMap<Name, NodeId>();
+    private final Map<String, NodeId> nodeIds = new HashMap<String, NodeId>();
 
-    private final Map<Name, Double> scores = new HashMap<Name, Double>();
+    private final Map<String, Double> scores = new HashMap<String, Double>();
 
     private final Map<String, QValue> qValues = new HashMap<String, QValue>();
 
     private final String[] columnNames;
 
-    private final Name[] selectorNames;
-
     public QueryResultRowImpl(MultiStatusResponse response,
                               String[] columnNames,
                               NamePathResolver resolver,
@@ -72,6 +69,7 @@ public class QueryResultRowImpl implemen
                               IdFactory idFactory)
             throws RepositoryException {
         this.columnNames = columnNames;
+
         DavPropertySet okSet = response.getProperties(DavServletResponse.SC_OK);
 
         String jcrPath = resolver.getJCRName(NameConstants.JCR_PATH);
@@ -86,24 +84,22 @@ public class QueryResultRowImpl implemen
         String[] names = colList.toArray(new String[colList.size()]);
         Value[] values = valList.toArray(new Value[valList.size()]);
 
-        this.selectorNames = new Name[selList.size()];
         for (int i = 0; i < values.length; i++) {
             try {
                 String selectorName = selList.get(i);
                 QValue v = (values[i] == null) ? null : ValueFormat.getQValue(values[i],
resolver, qValueFactory);
-                this.selectorNames[i] = (selectorName == null) ? null : resolver.getQName(selectorName);
                 if (jcrScore.equals(names[i])) {
                     Double score = 0.0;
                     if (v != null) {
                         score = v.getDouble();
                     }
-                    scores.put(this.selectorNames[i], score);
+                    scores.put(selectorName, score);
                 } else if (jcrPath.equals(names[i])) {
                     NodeId id = null;
                     if (v != null) {
                         id = idFactory.createNodeId((String) null, v.getPath());
                     }
-                    nodeIds.put(this.selectorNames[i], id);
+                    nodeIds.put(selectorName, id);
                 }
                 qValues.put(names[i], v);
             } catch (RepositoryException e) {
@@ -113,26 +109,26 @@ public class QueryResultRowImpl implemen
         }
     }
 
-    public NodeId getNodeId(Name selectorName) {
+    public NodeId getNodeId(String selectorName) {
+        if (selectorName == null && scores.size() == 1) {
+            return nodeIds.values().iterator().next();
+        }
+
         NodeId id = nodeIds.get(selectorName);
-        if (id == null) {
-            if (nodeIds.size() == 1) {
-                return nodeIds.values().iterator().next();
-            } else {
-                throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
-            }
+        if (id == null && !nodeIds.containsKey(selectorName)) {
+            throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
         }
         return id;
     }
 
-    public double getScore(Name selectorName) {
+    public double getScore(String selectorName) {
+        if (selectorName == null && scores.size() == 1) {
+            return scores.values().iterator().next();
+        }
+
         Double score = scores.get(selectorName);
-        if (score == null) {
-            if (scores.size() == 1) {
-                return scores.values().iterator().next();
-            } else {
-                throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
-            }
+        if (score == null && !nodeIds.containsKey(selectorName)) {
+            throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
         }
         return score;
     }
@@ -145,7 +141,4 @@ public class QueryResultRowImpl implemen
         return values;
     }
 
-    Name[] getSelectorNames() {
-        return selectorNames;
-    }
 }

Modified: jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Wed Jan  4 18:08:03 2012
@@ -1945,8 +1945,9 @@ public class RepositoryServiceImpl imple
         SearchMethod method = null;
         try {
             String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
-            SearchInfo sInfo = new SearchInfo(language,
-                    Namespace.EMPTY_NAMESPACE, statement, namespaces);
+            SearchInfo sInfo = new SearchInfo(
+                    language, ItemResourceConstants.NAMESPACE,
+                    statement, namespaces);
 
             if (limit != -1) {
                 sInfo.setNumberResults(limit);

Modified: jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
Wed Jan  4 18:08:03 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.spi2jcr;
 
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorDecorator;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -30,8 +29,6 @@ import javax.jcr.query.Row;
 import javax.jcr.RepositoryException;
 import javax.jcr.RangeIterator;
 import java.util.NoSuchElementException;
-import java.util.List;
-import java.util.Arrays;
 
 /**
  * <code>QueryInfoImpl</code> implements a <code>QueryInfo</code>
based on a
@@ -72,7 +69,7 @@ class QueryInfoImpl implements QueryInfo
     /**
      * The names of the selectors in the query result.
      */
-    private final Name[] selectorNames;
+    private final String[] selectorNames;
 
     /**
      * Creates a new query info based on a given <code>result</code>.
@@ -94,7 +91,7 @@ class QueryInfoImpl implements QueryInfo
         this.resolver = resolver;
         this.qValueFactory = qValueFactory;
         this.columnNames = result.getColumnNames();
-        this.selectorNames = getSelectorNames(result, resolver);
+        this.selectorNames = result.getSelectorNames();
     }
 
     /**
@@ -125,28 +122,14 @@ class QueryInfoImpl implements QueryInfo
      * {@inheritDoc}
      */
     public String[] getColumnNames() {
-        String[] names = new String[columnNames.length];
-        System.arraycopy(columnNames, 0, names, 0, columnNames.length);
-        return names;
+        return columnNames;
     }
 
     /**
      * {@inheritDoc}
      */
-    public Name[] getSelectorNames() {
-        Name[] names = new Name[selectorNames.length];
-        System.arraycopy(selectorNames, 0, names, 0, selectorNames.length);
-        return names;
-    }
-
-    private static Name[] getSelectorNames(QueryResult result,
-                                           NamePathResolver resolver)
-            throws RepositoryException {
-        List<String> sn = Arrays.asList(result.getSelectorNames());
-        Name[] selectorNames = new Name[sn.size()];
-        for (int i = 0; i < sn.size(); i++) {
-            selectorNames[i] = resolver.getQName(sn.get(i));
-        }
+    public String[] getSelectorNames() {
         return selectorNames;
     }
+
 }

Modified: jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java?rev=1227247&r1=1227246&r2=1227247&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
Wed Jan  4 18:08:03 2012
@@ -26,7 +26,6 @@ import org.apache.jackrabbit.spi.QueryRe
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
@@ -44,12 +43,12 @@ class QueryResultRowImpl implements Quer
     /**
      * The node ids of the underlying row.
      */
-    private final Map<Name, NodeId> nodeIds = new HashMap<Name, NodeId>();
+    private final Map<String, NodeId> nodeIds = new HashMap<String, NodeId>();
 
     /**
      * The score values for this row.
      */
-    private final Map<Name, Double> scores = new HashMap<Name, Double>();
+    private final Map<String, Double> scores = new HashMap<String, Double>();
 
     /**
      * The QValues for this row.
@@ -70,7 +69,7 @@ class QueryResultRowImpl implements Quer
      */
     public QueryResultRowImpl(Row row,
                               String[] columnNames,
-                              Name[] selectorNames,
+                              String[] selectorNames,
                               IdFactoryImpl idFactory,
                               NamePathResolver resolver,
                               QValueFactory qValueFactory) throws RepositoryException {
@@ -83,21 +82,20 @@ class QueryResultRowImpl implements Quer
                 values[i] = ValueFormat.getQValue(v, resolver, qValueFactory);
             }
         }
-        List<Name> selNames = new ArrayList<Name>();
+        List<String> selNames = new ArrayList<String>();
         selNames.addAll(Arrays.asList(selectorNames));
         if (selNames.isEmpty()) {
             selNames.add(null); // default selector
         }
-        for (Name sn : selNames) {
+        for (String sn : selNames) {
             Node n;
             double score;
             if (sn == null) {
                 n = row.getNode();
                 score = row.getScore();
             } else {
-                String selName = resolver.getJCRName(sn);
-                n = row.getNode(selName);
-                score = row.getScore(selName);
+                n = row.getNode(sn);
+                score = row.getScore(sn);
             }
             NodeId id = null;
             if (n != null) {
@@ -108,7 +106,7 @@ class QueryResultRowImpl implements Quer
         }
     }
 
-    public NodeId getNodeId(Name selectorName) {
+    public NodeId getNodeId(String selectorName) {
         if (nodeIds.containsKey(selectorName)) {
             return nodeIds.get(selectorName);
         } else {
@@ -120,7 +118,7 @@ class QueryResultRowImpl implements Quer
         }
     }
 
-    public double getScore(Name selectorName) {
+    public double getScore(String selectorName) {
         Double score;
         if (scores.containsKey(selectorName)) {
             score = scores.get(selectorName);



Mime
View raw message