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/23 17:20:42 UTC

svn commit: r915409 [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...

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepository.java Tue Feb 23 16:20:40 2010
@@ -106,12 +106,12 @@
      * ----- Repository -----
      */
 
-    public Connection getConnection(Map<String, Serializable> parameters) {
+    public Connection getConnection(Map<String, Serializable> params) {
         // TODO credentials
         return new SimpleConnection(this);
     }
 
-    public SPI getSPI() {
+    public SPI getSPI(Map<String, Serializable> params) {
         // TODO credentials
         return new SimpleConnection(this);
     }

Added: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepositoryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepositoryService.java?rev=915409&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepositoryService.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleRepositoryService.java Tue Feb 23 16:20:40 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.Collection;
+import java.util.Collections;
+
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryEntry;
+import org.apache.chemistry.RepositoryService;
+
+/**
+ * Simple repository service holding one repository instance.
+ */
+public class SimpleRepositoryService implements RepositoryService {
+
+    protected final Repository repository;
+
+    public SimpleRepositoryService(Repository repository) {
+        this.repository = repository;
+    }
+
+    public Repository getDefaultRepository() {
+        return repository;
+    }
+
+    public Collection<RepositoryEntry> getRepositories() {
+        return Collections.<RepositoryEntry> singleton(repository);
+    }
+
+    public Repository getRepository(String repositoryId) {
+        return repository.getId().equals(repositoryId) ? repository : null;
+    }
+
+}

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

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

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java Tue Feb 23 16:20:40 2010
@@ -45,7 +45,6 @@
 import org.apache.chemistry.CapabilityJoin;
 import org.apache.chemistry.CapabilityQuery;
 import org.apache.chemistry.CapabilityRendition;
-import org.apache.chemistry.Connection;
 import org.apache.chemistry.ListPage;
 import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.Paging;
@@ -90,12 +89,11 @@
         this(repository, null);
     }
 
-    public SPI getSPI() {
-        // TODO parameters
-        return (SPI) getConnection(null);
+    public SPI getSPI(Map<String, Serializable> params) {
+        return getConnection(params);
     }
 
-    public Connection getConnection(Map<String, Serializable> parameters) {
+    public JcrConnection getConnection(Map<String, Serializable> params) {
         try {
             return new JcrConnection(repository.login(creds, workspace), this);
         } catch (RepositoryException e) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java Tue Feb 23 16:20:40 2010
@@ -24,7 +24,13 @@
 
 package org.apache.chemistry.shell.app;
 
-import org.apache.chemistry.atompub.client.APPContentManager;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryManager;
+import org.apache.chemistry.atompub.client.APPRepositoryService;
 import org.apache.chemistry.shell.cmds.cmis.Cat;
 import org.apache.chemistry.shell.cmds.cmis.CreateFile;
 import org.apache.chemistry.shell.cmds.cmis.CreateFolder;
@@ -44,7 +50,7 @@
  */
 public class ChemistryApp extends AbstractApplication {
 
-    protected APPContentManager cm;
+    protected APPRepositoryService repositoryService;
 
     public ChemistryApp() {
         registry.registerCommand(new DumpTree());
@@ -58,31 +64,30 @@
         registry.registerCommand(new Remove());
         registry.registerCommand(new Cat());
         registry.registerCommand(new Put());
-        registry.registerCommand(new Query());        
+        registry.registerCommand(new Query());
     }
 
     @Override
     protected void doConnect() {
-        cm = new APPContentManager(serverUrl.toExternalForm());
-        if (username != null) {
-            cm.login(username, new String(password));
-        }
+        Map<String, Serializable> params = new HashMap<String, Serializable>();
+        params.put(Repository.PARAM_USERNAME, username);
+        params.put(Repository.PARAM_PASSWORD, new String(password));
+        repositoryService = new APPRepositoryService(
+                serverUrl.toExternalForm(), params);
+        RepositoryManager.getInstance().registerService(repositoryService);
     }
 
     public void disconnect() {
-        cm = null;
+        RepositoryManager.getInstance().unregisterService(repositoryService);
+        repositoryService = null;
     }
 
     public boolean isConnected() {
-        return cm != null;
+        return repositoryService != null;
     }
 
     public Context getRootContext() {
         return new ChemistryRootContext(this);
     }
 
-    public APPContentManager getContentManager() {
-        return cm;
-    }
-
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java Tue Feb 23 16:20:40 2010
@@ -30,10 +30,7 @@
 
 import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Folder;
-import org.apache.chemistry.ObjectEntry;
-import org.apache.chemistry.Repository;
 import org.apache.chemistry.atompub.client.APPConnection;
-import org.apache.chemistry.atompub.client.APPContentManager;
 import org.apache.chemistry.shell.util.ColorHelper;
 import org.apache.chemistry.shell.util.Path;
 
@@ -41,7 +38,6 @@
 
     //public static final String CONN_KEY = "chemistry.connection";
 
-    protected final APPContentManager cm;
     protected final APPConnection conn;
     protected final CMISObject entry;
 
@@ -53,7 +49,6 @@
         super(app, path);
         this.conn = conn;
         this.entry = entry;
-        cm = app.getContentManager();
     }
 
     @Override
@@ -61,26 +56,6 @@
         return (ChemistryApp)app;
     }
 
-    // Not used
-    public APPConnection getConnection() {
-        return conn;
-    }
-
-    // Not used
-    public CMISObject getEntry() {
-        return entry;
-    }
-
-    // Not used
-    public APPContentManager getContentManager() {
-        return cm;
-    }
-
-    // Not used
-    public Repository getRepository() {
-        return conn.getRepository();
-    }
-
     public Context getContext(String name) {
         load();
         CMISObject e = children.get(name);
@@ -140,27 +115,6 @@
         return null;
     }
 
-    // Not used
-    public CMISObject getObjectByAbsolutePath(String path) {
-        ObjectEntry entry = conn.getObjectByPath(path, null);
-        if (entry!=null) {
-            return conn.getObject(entry);
-        } else {
-            return null;
-        }
-    }
-
-    // Not used
-    public CMISObject resolveObject(String path) {
-        Path p = resolvePath(path);
-        ObjectEntry entry = conn.getObjectByPath(p.toString(), null);
-        if (entry!=null) {
-            return conn.getObject(entry);
-        } else {
-            return null;
-        }
-    }
-
     public String id() {
         return "Object "+entry.getId()+" of type "+entry.getTypeId();
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java Tue Feb 23 16:20:40 2010
@@ -24,31 +24,29 @@
 
 package org.apache.chemistry.shell.app;
 
+import java.io.Serializable;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryEntry;
+import org.apache.chemistry.RepositoryManager;
 import org.apache.chemistry.atompub.client.APPConnection;
-import org.apache.chemistry.atompub.client.APPContentManager;
-import org.apache.chemistry.atompub.client.ContentManager;
 import org.apache.chemistry.shell.util.ColorHelper;
 import org.apache.chemistry.shell.util.Path;
 
 public class ChemistryRootContext extends AbstractContext {
 
-    protected Map<String, Repository> repos;
     protected String[] keys;
+
     protected String[] ls;
 
     public ChemistryRootContext(ChemistryApp app) {
         super(app, Path.ROOT);
     }
 
-    public APPContentManager getContentManager() {
-        return ((ChemistryApp) app).getContentManager();
-    }
-
     @Override
     public ChemistryApp getApplication() {
         return (ChemistryApp) app;
@@ -60,19 +58,23 @@
 
     public Context getContext(String name) {
         load();
-        ContentManager cm = getContentManager();
-        if (cm == null) {
-            Console.getDefault().error("Not connected: cannot browse repository");
+        ChemistryApp app = getApplication();
+        if (!app.isConnected()) {
+            Console.getDefault().error(
+                    "Not connected: cannot browse repository");
             return null;
         }
-        Repository r = repos.get(name); // TODO  atompub client is using IDs to get repositories ...
-        Repository repo = cm.getRepository(r.getId());
-        if (repo != null) {
-            APPConnection conn = (APPConnection) repo.getConnection(null);
-            CMISObject entry = conn.getRootFolder();
-            return new ChemistryContext((ChemistryApp) app, path.append(name), conn, entry);
+        Repository repo = RepositoryManager.getInstance().getRepository(name);
+        if (repo == null) {
+            return null;
         }
-        return null;
+        Map<String, Serializable> params = new HashMap<String, Serializable>();
+        params.put(Repository.PARAM_USERNAME, app.username);
+        params.put(Repository.PARAM_PASSWORD, new String(app.password));
+        APPConnection conn = (APPConnection) repo.getConnection(params);
+        CMISObject entry = conn.getRootFolder();
+        return new ChemistryContext((ChemistryApp) app, path.append(name),
+                conn, entry);
     }
 
     public String[] ls() {
@@ -90,21 +92,24 @@
     }
 
     protected boolean load() {
-        if (keys == null) {
-            ContentManager cm = getContentManager();
-            if (cm == null) {
-                Console.getDefault().error("Not connected: cannot browse repository");
-                return false;
-            }
-            Repository[] repos = cm.getRepositories();
-            this.repos = new HashMap<String, Repository>();
-            keys = new String[repos.length];
-            ls = new String[repos.length];
-            for (int i=0; i<repos.length; i++) {
-                keys[i] = repos[i].getName();
-                this.repos.put(repos[i].getName(), repos[i]);
-                ls[i] = ColorHelper.decorateNameByType(repos[i].getName(), "Repository");
-            }
+        if (keys != null) {
+            return true;
+        }
+        if (!getApplication().isConnected()) {
+            Console.getDefault().error(
+                    "Not connected: cannot browse repository");
+            return false;
+        }
+        Collection<RepositoryEntry> repos = RepositoryManager.getInstance().getRepositories();
+        int size = repos.size();
+        keys = new String[size];
+        ls = new String[size];
+        int i = 0;
+        for (RepositoryEntry repo : repos) {
+            String name = repo.getName();
+            keys[i] = name;
+            ls[i] = ColorHelper.decorateNameByType(name, "Repository");
+            i++;
         }
         return true;
     }
@@ -112,14 +117,10 @@
     public void reset() {
         keys = null;
         ls = null;
-        APPContentManager cm = getContentManager();
-        if (cm != null) {
-            cm.refresh();
-        }
     }
 
     public String id() {
-        return "CMIS server: "+app.getServerUrl();
+        return "CMIS server: " + app.getServerUrl();
     }
 
 }

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=915409&r1=915408&r2=915409&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 Tue Feb 23 16:20:40 2010
@@ -541,6 +541,7 @@
 
         assertNotNull("dog not found", dog);
         ContentStream cs = dog.getContentStream();
+        assertNotNull(cs);
         assertTrue(cs.getLength() != 0);
         assertEquals("dog.jpg", cs.getFileName());
         assertEquals("image/jpeg", cs.getMimeType());

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java Tue Feb 23 16:20:40 2010
@@ -25,8 +25,11 @@
 import javax.servlet.Servlet;
 
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryManager;
+import org.apache.chemistry.RepositoryService;
 import org.apache.chemistry.atompub.server.jaxrs.AbderaResource;
 import org.apache.chemistry.atompub.server.servlet.CMISServlet;
+import org.apache.chemistry.impl.simple.SimpleRepositoryService;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
@@ -56,12 +59,18 @@
     public static final int DEFAULT_PORT = 8082;
 
     public static void main(String[] args) throws Exception {
-        Repository repository = BasicHelper.makeSimpleRepository(ROOT_ID);
-        new MainServlet().run(args, repository, "/cmis", "/repository");
+        RepositoryService repositoryService = new SimpleRepositoryService(
+                BasicHelper.makeSimpleRepository(ROOT_ID));
+        RepositoryManager.getInstance().registerService(repositoryService);
+        try {
+            new MainServlet().run(args, "/cmis", "/repository");
+        } finally {
+            RepositoryManager.getInstance().unregisterService(repositoryService);
+        }
     }
 
-    public void run(String[] args, Repository repository, String contextPath,
-            String cmisService) throws Exception {
+    public void run(String[] args, String contextPath, String cmisService)
+            throws Exception {
         String host = DEFAULT_HOST;
         int port = DEFAULT_PORT;
         int minutes = DEFAULT_MINUTES;
@@ -92,15 +101,14 @@
         connector.setPort(port);
         server.setConnectors(new Connector[] { connector });
         if (jaxrs) {
-            setUpJAXRS(server, contextPath, repository);
+            setUpJAXRS(server, contextPath);
         } else {
-            setUpAbderaServlet(server, contextPath, repository);
+            setUpAbderaServlet(server, contextPath);
         }
         server.start();
 
         String url = "http://" + host + ':' + port + contextPath + cmisService;
-        log.warn(getServerName(repository) + " started, AtomPub service url: "
-                + url);
+        log.warn("CMIS repository started, AtomPub service url: " + url);
         try {
             Thread.sleep(1000 * 60 * minutes);
             server.stop();
@@ -112,15 +120,12 @@
             }
         }
 
-        log.warn(getServerName(repository) + " stopped");
-    }
-
-    protected static String getServerName(Repository repository) {
-        return "CMIS repository " + repository.getInfo().getProductName();
+        log.warn("CMIS repository stopped");
     }
 
-    protected void setUpAbderaServlet(Server server, String contextPath,
-            Repository repository) throws Exception {
+    protected void setUpAbderaServlet(Server server, String contextPath)
+            throws Exception {
+        Repository repository = RepositoryManager.getInstance().getDefaultRepository();
         Servlet servlet = new CMISServlet(repository);
         Context context = new Context(server, contextPath, Context.SESSIONS);
         context.addServlet(new ServletHolder(servlet), "/*");
@@ -131,12 +136,12 @@
 
     protected File tmpDir;
 
-    protected void setUpJAXRS(Server server, String contextPath,
-            Repository repository) throws Exception {
+    protected void setUpJAXRS(Server server, String contextPath)
+            throws Exception {
         if (!"/cmis".equals(contextPath)) {
-            throw new RuntimeException("AbderaResource implies a context of /cmis");
+            throw new RuntimeException(
+                    "AbderaResource implies a context of /cmis");
         }
-        AbderaResource.repository = repository; // TODO inject differently
         AbderaResource.pathMunger = null; // TODO
         tmpDir = makeTmpDir();
         String webApp = makeWebApp(tmpDir);

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java?rev=915409&r1=915408&r2=915409&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java Tue Feb 23 16:20:40 2010
@@ -19,8 +19,7 @@
 import javax.servlet.Servlet;
 
 import org.apache.chemistry.Repository;
-import org.apache.chemistry.atompub.client.APPContentManager;
-import org.apache.chemistry.atompub.client.ContentManager;
+import org.apache.chemistry.atompub.client.APPRepositoryService;
 import org.apache.chemistry.atompub.server.servlet.CMISServlet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -79,8 +78,8 @@
     @Override
     public Repository makeRepository() throws Exception {
         String serverUrl = startServer();
-        ContentManager cm = new APPContentManager(serverUrl);
-        return cm.getDefaultRepository();
+        APPRepositoryService rs = new APPRepositoryService(serverUrl, null);
+        return rs.getDefaultRepository();
     }
 
     @Override