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 2009/08/05 02:05:02 UTC

svn commit: r801034 - 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-server/src/main/java/org/apache/chemistry/ato...

Author: fguillaume
Date: Wed Aug  5 00:05:02 2009
New Revision: 801034

URL: http://svn.apache.org/viewvc?rev=801034&view=rev
Log:
renamed SPI#getFolderByPath to SPI#getObjectByPath, implemented it

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java Wed Aug  5 00:05:02 2009
@@ -313,17 +313,17 @@
             boolean includeAllowableActions, boolean includeRelationships);
 
     /**
-     * Gets the properties of a folder, given its path.
+     * Gets the properties of an object, given its path.
      *
-     * @param path the folder path
+     * @param path the object path
      * @param filter the properties filter, or {@code null} for all properties
      * @param includeAllowableActions {@code true} to include allowable actions
      * @param includeRelationships {@code true} if relationships should be
      *            included as well
-     * @return the properties of the folder, or {@code null} if the object is
+     * @return the properties of the object, or {@code null} if the object is
      *         not found
      */
-    ObjectEntry getFolderByPath(String path, String filter,
+    ObjectEntry getObjectByPath(String path, String filter,
             boolean includeAllowableActions, boolean includeRelationships);
 
     /**

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java Wed Aug  5 00:05:02 2009
@@ -424,10 +424,35 @@
         throw new UnsupportedOperationException();
     }
 
-    public ObjectEntry getFolderByPath(String path, String filter,
+    public ObjectEntry getObjectByPath(String path, String filter,
             boolean includeAllowableActions, boolean includeRelationships) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        if (!path.startsWith("/")) {
+            throw new IllegalArgumentException("Path must start with / : "
+                    + path);
+        }
+        if (!path.equals("/") && path.endsWith("/")) {
+            throw new IllegalArgumentException("Path must not end with / : "
+                    + path);
+        }
+        URITemplate uriTemplate = repository.getURITemplate(AtomPubCMIS.URITMPL_FOLDER_BY_PATH);
+        if (uriTemplate == null) {
+            throw new UnsupportedOperationException("Cannot get object by path");
+        }
+        // TODO proper URI template syntax and encoding
+        String encodedPath = path.replace(" ", "%20");
+        String href = uriTemplate.template.replace("{path}", encodedPath);
+
+        Response resp = connector.get(new Request(href));
+        if (!resp.isOk()) {
+            if (resp.getStatusCode() == 404) {
+                // object not found, signature says return null
+                return null;
+            }
+            throw new ContentManagerException(
+                    "Remote server returned error code: "
+                            + resp.getStatusCode());
+        }
+        return (APPObjectEntry) resp.getObject(new ReadContext(this));
     }
 
     public Folder getFolder(String path) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java Wed Aug  5 00:05:02 2009
@@ -58,7 +58,6 @@
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
 import org.apache.chemistry.atompub.abdera.ObjectElement;
-import org.apache.chemistry.impl.simple.SimpleObjectId;
 import org.apache.chemistry.util.GregorianCalendar;
 
 /**
@@ -242,7 +241,7 @@
         }
 
         SPI spi = repository.getSPI(); // TODO XXX connection leak
-        ObjectId folderId = new SimpleObjectId(id);
+        ObjectId folderId = spi.newObjectId(id);
         ObjectId objectId;
         switch (type.getBaseType()) {
         case DOCUMENT:
@@ -359,15 +358,29 @@
     }
 
     @Override
-    public ObjectEntry getEntry(String id, RequestContext request)
+    public ObjectEntry getEntry(String resourceName, RequestContext request)
             throws ResponseContextException {
         SPI spi = repository.getSPI(); // TODO XXX connection leak
-        return spi.getProperties(spi.newObjectId(id), null, false, false);
+        if ("path".equals(getType())) {
+            String path = "/" + resourceName;
+            // TODO decode properly
+            path = path.replace("%20", " ");
+            return spi.getObjectByPath(path, null, false, false);
+        } else { // object
+            String id = resourceName;
+            return spi.getProperties(spi.newObjectId(id), null, false, false);
+        }
     }
 
     @Override
     public String getResourceName(RequestContext request) {
-        return request.getTarget().getParameter("objectid");
+        String name;
+        if ("path".equals(getType())) {
+            name = "path";
+        } else {
+            name = "objectid";
+        }
+        return request.getTarget().getParameter(name);
     }
 
     @Override

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java Wed Aug  5 00:05:02 2009
@@ -71,6 +71,8 @@
                 TargetType.TYPE_ENTRY, "objectid"); // XXX entry?
         targetResolver.setPattern("/type/([^/?]+)", TargetType.TYPE_ENTRY,
                 "typeid");
+        targetResolver.setPattern("/path/([^?]*)", TargetType.TYPE_ENTRY,
+                "path");
 
         // media
         targetBuilder.setTemplate(TargetType.TYPE_MEDIA,
@@ -149,10 +151,10 @@
         list.add(new URITemplate(AtomPubCMIS.URITMPL_ENTRY_BY_ID, //
                 AtomPub.MEDIA_TYPE_ATOM_ENTRY, //
                 base + "object/{id}"));
+        list.add(new URITemplate(AtomPubCMIS.URITMPL_FOLDER_BY_PATH, //
+                AtomPub.MEDIA_TYPE_ATOM_ENTRY, //
+                base + "path{path}"));
         if (false) { // TODO
-            list.add(new URITemplate(AtomPubCMIS.URITMPL_FOLDER_BY_PATH, //
-                    AtomPub.MEDIA_TYPE_ATOM_ENTRY, //
-                    base + "objectpath/{path}"));
             list.add(new URITemplate(AtomPubCMIS.URITMPL_QUERY, //
                     AtomPub.MEDIA_TYPE_ATOM_FEED, //
                     base + "query?q={q}"));

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java Wed Aug  5 00:05:02 2009
@@ -57,6 +57,9 @@
             // TODO has a different feed type than children
             return new CMISChildrenCollection(null, null, repository);
         }
+        if (paths.startsWith("/path/")) {
+            return new CMISChildrenCollection("path", null, repository);
+        }
         if (paths.startsWith("/file/")) {
             return new CMISChildrenCollection(null, null, repository);
         }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java?rev=801034&r1=801033&r2=801034&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java Wed Aug  5 00:05:02 2009
@@ -116,7 +116,7 @@
 
     public static final String URITMPL_ENTRY_BY_ID = "entrybyid";
 
-    public static final String URITMPL_FOLDER_BY_PATH = "folderbypath";
+    public static final String URITMPL_FOLDER_BY_PATH = "folderbypath"; // TODO-0.63
 
     public static final String URITMPL_QUERY = "query";
 

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=801034&r1=801033&r2=801034&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 Wed Aug  5 00:05:02 2009
@@ -70,7 +70,7 @@
 
     public SimpleConnection(SimpleRepository repository) {
         this.repository = repository;
-        rootFolder = (SimpleFolder) getObject(repository.getInfo().getRootFolderId());
+        rootFolder = (SimpleFolder) getObject(repository.getRootFolderId());
     }
 
     public Connection getConnection() {
@@ -455,6 +455,7 @@
 
     public ObjectEntry getProperties(ObjectId object, String filter,
             boolean includeAllowableActions, boolean includeRelationships) {
+        // TODO filter, includeAllowableActions, includeRelationships
         SimpleData data = repository.datas.get(object.getId());
         if (data == null) {
             return null;
@@ -462,10 +463,42 @@
         return new SimpleObjectEntry(data, this);
     }
 
-    public ObjectEntry getFolderByPath(String path, String filter,
+    public ObjectEntry getObjectByPath(String path, String filter,
             boolean includeAllowableActions, boolean includeRelationships) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        // TODO filter, includeAllowableActions, includeRelationships
+        if (!path.startsWith("/")) {
+            throw new IllegalArgumentException("Path must start with / : "
+                    + path);
+        }
+        if (!path.equals("/") && path.endsWith("/")) {
+            throw new IllegalArgumentException("Path must not end with / : "
+                    + path);
+        }
+        String id = repository.getRootFolderId().getId();
+        String[] segments = path.substring(1).split("/");
+        if (!path.equals("/")) {
+            for (String segment : segments) {
+                if ("".equals(segment)) {
+                    throw new IllegalArgumentException(
+                            "Path must not contain // : " + path);
+                }
+                String foundId = null;
+                for (String childId : repository.children.get(id)) {
+                    SimpleData data = repository.datas.get(childId);
+                    String name = (String) data.get(Property.NAME);
+                    if (segment.equals(name)) {
+                        foundId = childId;
+                        break;
+                    }
+                }
+                if (foundId == null) {
+                    // not found
+                    return null;
+                }
+                id = foundId;
+            }
+        }
+        return new SimpleObjectEntry(repository.datas.get(id), this);
     }
 
     public Folder getFolder(String path) {

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=801034&r1=801033&r2=801034&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 Wed Aug  5 00:05:02 2009
@@ -380,7 +380,7 @@
         return null;
     }
 
-    public ObjectEntry getFolderByPath(String path, String filter,
+    public ObjectEntry getObjectByPath(String path, String filter,
             boolean includeAllowableActions, boolean includeRelationships) {
         try {
             if (path == null || path.equals("") || path.equals("/")) {

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=801034&r1=801033&r2=801034&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 Wed Aug  5 00:05:02 2009
@@ -155,6 +155,21 @@
         assertEquals(2, res.size());
     }
 
+    public void testGetObjectByPath() {
+        Folder root = conn.getRootFolder();
+        assertEquals(ROOT_FOLDER_NAME, root.getName());
+        assertNotNull(spi.getObjectByPath("/", null, false, false));
+        assertNotNull(spi.getObjectByPath("/folder 1", null, false, false));
+        assertNotNull(spi.getObjectByPath("/folder 1/doc 1", null, false, false));
+        assertNotNull(spi.getObjectByPath("/folder 1/folder 2", null, false,
+                false));
+        assertNotNull(spi.getObjectByPath("/folder 1/folder 2/doc 2", null,
+                false, false));
+        assertNotNull(spi.getObjectByPath("/folder 1/folder 2/doc 3", null,
+                false, false));
+        assertNull(spi.getObjectByPath("/notsuchname", null, false, false));
+    }
+
     public void testGetChildren() {
         boolean[] hasMoreItems = new boolean[1];
         Folder root = conn.getRootFolder();