You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/02/12 16:23:59 UTC

svn commit: r909458 [2/2] - in /incubator/chemistry/trunk/chemistry: chemistry-api/src/main/java/org/apache/chemistry/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-client/src/main/java/org/apache/chemist...

Added: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java?rev=909458&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java Fri Feb 12 15:23:54 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.atompub.abdera;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+import org.apache.chemistry.atompub.AtomPubCMIS;
+
+/**
+ * Element wrapping for a cmisra:pathSegment.
+ */
+public class PathSegmentElement extends ExtensibleElementWrapper {
+
+    /**
+     * Constructor used when parsing XML.
+     */
+    public PathSegmentElement(Element internal) {
+        super(internal);
+    }
+
+    /**
+     * Constructor used when generating XML.
+     */
+    public PathSegmentElement(Factory factory, String pathSegment) {
+        super(factory, AtomPubCMIS.PATH_SEGMENT);
+        setText(pathSegment);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PathSegmentElement.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=909458&r1=909457&r2=909458&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java Fri Feb 12 15:23:54 2010
@@ -64,6 +64,7 @@
 import org.apache.chemistry.Rendition;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.SPI;
+import org.apache.chemistry.Tree;
 import org.apache.chemistry.Type;
 import org.apache.chemistry.Unfiling;
 import org.apache.chemistry.Updatability;
@@ -164,39 +165,38 @@
      * ----- Navigation Services -----
      */
 
-    /**
-     * Accumulates descendants into a list recursively.
-     */
-    // TODO optimized paging
-    protected void accumulate(ObjectId folder, int depth, Inclusion inclusion,
-            String orderBy, BaseType baseType, List<ObjectEntry> list) {
-        List<ObjectEntry> children = getChildren(folder, inclusion, orderBy,
-                null);
-        for (ObjectEntry child : children) {
+    protected List<Tree<ObjectEntry>> getTreeChildren(ObjectId entry,
+            int depth, Inclusion inclusion, String orderBy, BaseType baseType) {
+        List<Tree<ObjectEntry>> children = new ArrayList<Tree<ObjectEntry>>();
+        for (ObjectEntry child : getChildren(entry, inclusion, orderBy, null)) {
             BaseType childBaseType = child.getBaseType();
-            if (baseType == null || baseType == childBaseType) {
-                list.add(child);
+            if (baseType != null && baseType != childBaseType) {
+                continue;
             }
-            if (childBaseType == BaseType.FOLDER && depth != 1) {
-                accumulate(child, depth - 1, inclusion, orderBy, baseType, list);
+            List<Tree<ObjectEntry>> c;
+            if (childBaseType != BaseType.FOLDER || depth == 1) {
+                c = null;
+            } else {
+                c = getTreeChildren(child, depth - 1, inclusion, orderBy,
+                        baseType);
             }
+            children.add(new SimpleTree<ObjectEntry>(child, c));
         }
+        return children;
     }
 
-    public List<ObjectEntry> getFolderTree(ObjectId folder, int depth,
+    public Tree<ObjectEntry> getFolderTree(ObjectId folder, int depth,
             Inclusion inclusion) {
         checkFolder(folder);
-        List<ObjectEntry> list = new ArrayList<ObjectEntry>();
-        accumulate(folder, depth, inclusion, null, BaseType.FOLDER, list);
-        return list;
+        return new SimpleTree<ObjectEntry>(null, getTreeChildren(folder, depth,
+                inclusion, null, BaseType.FOLDER));
     }
 
-    public List<ObjectEntry> getDescendants(ObjectId folder, int depth,
+    public Tree<ObjectEntry> getDescendants(ObjectId folder, int depth,
             String orderBy, Inclusion inclusion) {
         checkFolder(folder);
-        List<ObjectEntry> list = new ArrayList<ObjectEntry>();
-        accumulate(folder, depth, inclusion, orderBy, null, list);
-        return list;
+        return new SimpleTree<ObjectEntry>(null, getTreeChildren(folder, depth,
+                inclusion, orderBy, null));
     }
 
     public ListPage<ObjectEntry> getChildren(ObjectId folder,

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java?rev=909458&r1=909457&r2=909458&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java Fri Feb 12 15:23:54 2010
@@ -42,6 +42,8 @@
 
     protected ChangeInfo changeInfo;
 
+    protected String pathSegment;
+
     public SimpleObjectEntry(SimpleData data, Connection connection) {
         this.data = data;
         this.connection = connection;
@@ -68,6 +70,14 @@
         this.changeInfo = changeInfo;
     }
 
+    public String getPathSegment() {
+        return pathSegment;
+    }
+
+    public void setPathSegment(String pathSegment) {
+        this.pathSegment = pathSegment;
+    }
+
     public Map<String, Serializable> getValues() {
         HashMap<String, Serializable> map = new HashMap<String, Serializable>(
                 data);

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java?rev=909458&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java Fri Feb 12 15:23:54 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ *
+ * Authors:
+ *     Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.impl.simple;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.chemistry.Tree;
+
+/**
+ * A simple implementation of {@link Tree}.
+ */
+public class SimpleTree<T> implements Tree<T> {
+
+    private static final long serialVersionUID = 1L;
+
+    protected T node;
+
+    protected List<Tree<T>> children;
+
+    public SimpleTree(T node, List<Tree<T>> children) {
+        setNode(node);
+        setChildren(children);
+    }
+
+    public T getNode() {
+        return node;
+    }
+
+    public List<Tree<T>> getChildren() {
+        return children;
+    }
+
+    public void setNode(T node) {
+        this.node = node;
+    }
+
+    public void setChildren(List<Tree<T>> children) {
+        if (children == null) {
+            children = Collections.emptyList();
+        }
+        this.children = children;
+    }
+
+    public int size() {
+        int n = 0;
+        if (node != null) {
+            n++;
+        }
+        for (Tree<T> t : children) {
+            n += t.size();
+        }
+        return n;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTree.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java?rev=909458&r1=909457&r2=909458&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java Fri Feb 12 15:23:54 2010
@@ -55,6 +55,7 @@
 import org.apache.chemistry.Rendition;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.SPI;
+import org.apache.chemistry.Tree;
 import org.apache.chemistry.Unfiling;
 import org.apache.chemistry.VersioningState;
 import org.apache.chemistry.impl.simple.SimpleListPage;
@@ -335,13 +336,13 @@
         return null;
     }
 
-    public List<ObjectEntry> getFolderTree(ObjectId folderId, int depth,
+    public Tree<ObjectEntry> getFolderTree(ObjectId folderId, int depth,
             Inclusion inclusion) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
 
-    public List<ObjectEntry> getDescendants(ObjectId folderId, int depth,
+    public Tree<ObjectEntry> getDescendants(ObjectId folderId, int depth,
             String orderBy, Inclusion inclusion) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java?rev=909458&r1=909457&r2=909458&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrObjectEntry.java Fri Feb 12 15:23:54 2010
@@ -76,6 +76,10 @@
         throw new UnsupportedOperationException();
     }
 
+    public String getPathSegment() {
+        return null;
+    }
+
     public Boolean getBoolean(String id) {
         try {
             return Boolean.valueOf(node.getProperty(JcrCmisMap.cmisToJcr(id)).getBoolean());

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=909458&r1=909457&r2=909458&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java Fri Feb 12 15:23:54 2010
@@ -53,6 +53,7 @@
 import org.apache.chemistry.RepositoryCapabilities;
 import org.apache.chemistry.RepositoryInfo;
 import org.apache.chemistry.SPI;
+import org.apache.chemistry.Tree;
 import org.apache.chemistry.Type;
 import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.impl.simple.SimpleObjectId;
@@ -313,7 +314,8 @@
         assertEquals(1, res.size());
 
         // SCORE
-        res = conn.query("SELECT cmis:name, SCORE() FROM cmis:document WHERE CONTAINS('small')",
+        res = conn.query(
+                "SELECT cmis:name, SCORE() FROM cmis:document WHERE CONTAINS('small')",
                 false);
         assertEquals(1, res.size());
     }
@@ -398,7 +400,7 @@
 
     public void testGetFolderTree() {
         Folder root = conn.getRootFolder();
-        List<ObjectEntry> desc = spi.getFolderTree(root, 4, null);
+        Tree<ObjectEntry> desc = spi.getFolderTree(root, 4, null);
         assertEquals(2, desc.size());
 
         ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
@@ -418,7 +420,7 @@
 
     public void testGetDescendants() {
         Folder root = conn.getRootFolder();
-        List<ObjectEntry> desc = spi.getDescendants(root, 4, null, null);
+        Tree<ObjectEntry> desc = spi.getDescendants(root, 4, null, null);
         assertEquals(6, desc.size());
 
         ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
@@ -437,29 +439,29 @@
     }
 
     public void testTrees() throws Exception {
-        List<ObjectEntry> list;
+        Tree<ObjectEntry> desc;
 
         Folder root = conn.getRootFolder();
-        list = spi.getDescendants(root, -1, null, null);
-        assertEquals(6, list.size());
-        list = spi.getDescendants(root, 1, null, null);
-        assertEquals(1, list.size());
-        list = spi.getDescendants(root, 2, null, null);
-        assertEquals(3, list.size());
-        list = spi.getDescendants(root, 3, null, null);
-        assertEquals(6, list.size());
-        list = spi.getDescendants(root, 4, null, null);
-        assertEquals(6, list.size());
+        desc = spi.getDescendants(root, -1, null, null);
+        assertEquals(6, desc.size());
+        desc = spi.getDescendants(root, 1, null, null);
+        assertEquals(1, desc.size());
+        desc = spi.getDescendants(root, 2, null, null);
+        assertEquals(3, desc.size());
+        desc = spi.getDescendants(root, 3, null, null);
+        assertEquals(6, desc.size());
+        desc = spi.getDescendants(root, 4, null, null);
+        assertEquals(6, desc.size());
 
         ObjectEntry fold1 = spi.getObjectByPath("/folder 1", null);
-        list = spi.getDescendants(fold1, -1, null, null);
-        assertEquals(5, list.size());
-        list = spi.getDescendants(fold1, 1, null, null);
-        assertEquals(2, list.size());
-        list = spi.getDescendants(fold1, 2, null, null);
-        assertEquals(5, list.size());
-        list = spi.getDescendants(fold1, 3, null, null);
-        assertEquals(5, list.size());
+        desc = spi.getDescendants(fold1, -1, null, null);
+        assertEquals(5, desc.size());
+        desc = spi.getDescendants(fold1, 1, null, null);
+        assertEquals(2, desc.size());
+        desc = spi.getDescendants(fold1, 2, null, null);
+        assertEquals(5, desc.size());
+        desc = spi.getDescendants(fold1, 3, null, null);
+        assertEquals(5, desc.size());
     }
 
     public void testGetFolderParent() {