Update Jackrabbit container package name
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 24 Feb 2011 11:39:53 +0000 (11:39 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 24 Feb 2011 11:39:53 +0000 (11:39 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4183 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

30 files changed:
eclipse/plugins/org.argeo.jcr.ui.explorer/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.jcr.ui.explorer/plugin.xml
eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerActivator.java [deleted file]
eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerPerspective.java
eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerPlugin.java [new file with mode: 0644]
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringCommandHandler.java
eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/SpringExtensionFactory.java
server/modules/org.argeo.server.jackrabbit.repo/META-INF/MANIFEST.MF
server/modules/org.argeo.server.jackrabbit.repo/META-INF/spring/jackrabbit-osgi.xml
server/modules/org.argeo.server.jackrabbit.repo/META-INF/spring/jackrabbit.xml
server/modules/org.argeo.server.jackrabbit.repo/jackrabbit.properties [deleted file]
server/modules/org.argeo.server.jackrabbit.repo/localrepo.properties [new file with mode: 0644]
server/modules/org.argeo.server.jackrabbit.repo/repository-h2.xml [new file with mode: 0644]
server/modules/org.argeo.server.jackrabbit.repo/repository-postgresql.xml [new file with mode: 0644]
server/modules/org.argeo.server.jackrabbit.repo/repository.xml [deleted file]
server/modules/org.argeo.server.jackrabbit.webapp.war/META-INF/MANIFEST.MF
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/CachingSessionProvider.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/ExtendedDispatcherServlet.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/JcrRemotingServlet.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/WebDavServlet.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java [deleted file]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/CachingSessionProvider.java [deleted file]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/ExtendedDispatcherServlet.java [deleted file]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/JcrRemotingServlet.java [deleted file]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java [deleted file]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/WebDavServlet.java [deleted file]
server/runtime/org.argeo.server.jcr/.classpath
server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd [new file with mode: 0644]

index 9c645c9217803ec052cf654795e887c097397543..3b162fa67a1e9d0bd04e384a3a93929d86edf47e 100644 (file)
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
 Bundle-Name: JCR Explorer
 Bundle-SymbolicName: org.argeo.jcr.ui.explorer;singleton:=true
 Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.argeo.eclipse.ui.jcr.explorer.JcrExplorerActivator
+Bundle-Activator: org.argeo.eclipse.ui.jcr.explorer.JcrExplorerPlugin
 Bundle-Vendor: Argeo
 Require-Bundle: org.eclipse.ui;resolution:=optional,
  org.eclipse.core.runtime
index 8b3957cf8a0b175ab52ce6195398b0f677b1af14..578166569d266a732f5ed4471230c3737eaec05d 100644 (file)
@@ -1,23 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
-   <extension
-         point="org.eclipse.ui.perspectiveExtensions">
-      <perspectiveExtension
-            targetID="jcrExplorerPerspective">
-         <view
-               relative="upperLeft"
-               relationship="stack"
-               id="browserView">
-         </view>
-      </perspectiveExtension>
-   </extension>
    <extension
          point="org.eclipse.ui.perspectives">
       <perspective
             class="org.argeo.eclipse.ui.jcr.explorer.JcrExplorerPerspective"
             icon="icons/nodes.gif"
-            id="jcrExplorerPerspective"
+            id="org.argeo.jcr.ui.explorer.perspective"
             name="JCR Explorer">
       </perspective>
    </extension>
          point="org.eclipse.ui.views">
           <view
                 class="org.argeo.eclipse.spring.SpringExtensionFactory"
-                id="browserView"
-                name="Browser">
+                id="org.argeo.jcr.ui.explorer.browserView"
+                name="JCR Browser">
           </view>
    </extension>
    <extension
            point="org.eclipse.ui.editors">
             <editor
                  class="org.argeo.eclipse.spring.SpringExtensionFactory"
-              id="genericJcrQueryEditor"
+              id="org.argeo.jcr.ui.explorer.genericJcrQueryEditor"
               name="JCR Query"
               icon="icons/nodes.gif"
               default="false">
@@ -43,7 +32,7 @@
          point="org.eclipse.ui.commands">
                <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="openGenericJcrQueryEditor"
+            id="org.argeo.jcr.ui.explorer.openGenericJcrQueryEditor"
             name="OpenGenericJcrQueryEditor ">
        </command>
     </extension>
@@ -58,7 +47,7 @@
               mnemonic="Queries"
               id="queryMenu">
                 <command
-                      commandId="openGenericJcrQueryEditor"
+                      commandId="org.argeo.jcr.ui.explorer.openGenericJcrQueryEditor"
                       disabledIcon="icons/saveDisabled.gif"
                       icon="icons/results.gif"
                       label="JCR Query"
diff --git a/eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerActivator.java b/eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerActivator.java
deleted file mode 100644 (file)
index 9a00a70..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.argeo.eclipse.ui.jcr.explorer;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class JcrExplorerActivator extends AbstractUIPlugin {
-
-       // The plug-in ID
-       public static final String PLUGIN_ID = "org.argeo.eclipse.ui.jcr.explorer"; //$NON-NLS-1$
-
-       // The shared instance
-       private static JcrExplorerActivator plugin;
-       
-       /**
-        * The constructor
-        */
-       public JcrExplorerActivator() {
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
-        */
-       public void start(BundleContext context) throws Exception {
-               super.start(context);
-               plugin = this;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
-        */
-       public void stop(BundleContext context) throws Exception {
-               plugin = null;
-               super.stop(context);
-       }
-
-       /**
-        * Returns the shared instance
-        *
-        * @return the shared instance
-        */
-       public static JcrExplorerActivator getDefault() {
-               return plugin;
-       }
-
-}
index cdce20e59fa6cca6cd618b7561f302c186ae7a9f..020bf06ae4e88f3a0c14057bb83846c721b0f112 100644 (file)
@@ -5,13 +5,15 @@ import org.eclipse.ui.IPageLayout;
 import org.eclipse.ui.IPerspectiveFactory;
 
 public class JcrExplorerPerspective implements IPerspectiveFactory {
+       public static String BROWSER_VIEW_ID = JcrExplorerPlugin.ID
+                       + ".browserView";
 
        public void createInitialLayout(IPageLayout layout) {
                layout.setEditorAreaVisible(true);
 
-               IFolderLayout main = layout.createFolder("upperLeft", IPageLayout.LEFT,
-                               0.5f, layout.getEditorArea());
-
+               IFolderLayout upperLeft = layout.createFolder(JcrExplorerPlugin.ID
+                               + ".upperLeft", IPageLayout.LEFT, 0.4f, layout.getEditorArea());
+               upperLeft.addView(BROWSER_VIEW_ID);
        }
 
 }
diff --git a/eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerPlugin.java b/eclipse/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/eclipse/ui/jcr/explorer/JcrExplorerPlugin.java
new file mode 100644 (file)
index 0000000..5beb52a
--- /dev/null
@@ -0,0 +1,56 @@
+package org.argeo.eclipse.ui.jcr.explorer;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class JcrExplorerPlugin extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String ID = "org.argeo.jcr.ui.explorer"; //$NON-NLS-1$
+
+       // The shared instance
+       private static JcrExplorerPlugin plugin;
+
+       /**
+        * The constructor
+        */
+       public JcrExplorerPlugin() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+        * )
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+        * )
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        * 
+        * @return the shared instance
+        */
+       public static JcrExplorerPlugin getDefault() {
+               return plugin;
+       }
+
+}
index 0356f57d2e850acd5cbb9930dca51974cd43bd4c..ce0521bda6b0033d7e6fb0e2c8f5b66d8703ae1c 100644 (file)
@@ -48,6 +48,13 @@ public class SpringCommandHandler implements IHandler {
 
                        // retrieve the command via its id
                        String beanName = event.getCommand().getId();
+
+                       if (!applicationContext.containsBean(beanName)) {
+                               if (beanName.startsWith(bundleSymbolicName))
+                                       beanName = beanName
+                                                       .substring(bundleSymbolicName.length() + 1);
+                       }
+
                        if (!applicationContext.containsBean(beanName))
                                throw new ExecutionException("No bean found with name "
                                                + beanName + " in bundle " + bundleSymbolicName);
@@ -62,7 +69,7 @@ public class SpringCommandHandler implements IHandler {
                        return handler.execute(event);
                } catch (Exception e) {
                        // TODO: use eclipse error management
-//                     log.error(e);
+                       // log.error(e);
                        throw new ExecutionException("Cannot execute Spring command "
                                        + commandId + " in bundle " + bundleSymbolicName, e);
                }
index f20e1d1249f70c8e3a73fddaee6226ac9ee0e95d..aa0295d56a80fd3e18a8fb1ea0d9af8f244c4f27 100644 (file)
@@ -63,9 +63,9 @@ public class SpringExtensionFactory implements IExecutableExtensionFactory,
        public void setInitializationData(IConfigurationElement config,\r
                        String propertyName, Object data) throws CoreException {\r
                String bundleSymbolicName = config.getContributor().getName();\r
-               ApplicationContext appContext = ApplicationContextTracker\r
+               ApplicationContext applicationContext = ApplicationContextTracker\r
                                .getApplicationContext(bundleSymbolicName);\r
-               if (appContext == null)\r
+               if (applicationContext == null)\r
                        throw new ArgeoException(\r
                                        "Cannot find application context for bundle "\r
                                                        + bundleSymbolicName);\r
@@ -75,7 +75,15 @@ public class SpringExtensionFactory implements IExecutableExtensionFactory,
                        throw new ArgeoException("Cannot find bean name for extension "\r
                                        + config);\r
 \r
-               this.bean = appContext.getBean(beanName);\r
+               if (!applicationContext.containsBean(beanName)) {\r
+                       if (beanName.startsWith(bundleSymbolicName))\r
+                               beanName = beanName.substring(bundleSymbolicName.length() + 1);\r
+               }\r
+\r
+               if (!applicationContext.containsBean(beanName))\r
+                       throw new ArgeoException("No bean with name '" + beanName + "'");\r
+\r
+               this.bean = applicationContext.getBean(beanName);\r
                if (this.bean instanceof IExecutableExtension) {\r
                        ((IExecutableExtension) this.bean).setInitializationData(config,\r
                                        propertyName, data);\r
index 9a48e044c5c4a1b9b38cf39ad3ccd1034dc14346..a7181d1b763a74dc8ff351c9ba70f720bf7a2d8a 100644 (file)
@@ -8,5 +8,5 @@ Import-Package: javax.jcr,
  org.apache.jackrabbit.core.config,
  org.apache.lucene.util;version="2.4.1",
  org.apache.xalan.processor,
- org.argeo.server.jackrabbit,
+ org.argeo.jackrabbit,
  org.springframework.beans.factory.config
index 8ad34c315931e7ca20c498e31ba09c4c1a24bcf1..7a3c71ad5245e5dc386650cfc82b0adb85b001ed 100644 (file)
@@ -8,7 +8,7 @@
 \r
        <service ref="remoteJcrRepository" interface="javax.jcr.Repository">\r
                <service-properties>\r
-                       <beans:entry key="argeo.jcr.repository.name" value="remote_repo" />\r
+                       <beans:entry key="argeo.jcr.repository.name" value="local" />\r
                </service-properties>\r
        </service>\r
 \r
index d6ef7ec88ce037a8110458ecb126f78f871770f4..0ac070e02f8fddcc82e193adc5d06432537c7cff 100644 (file)
                </property>
        </bean>
 
-       <bean id="remoteJcrRepository" class="org.argeo.server.jackrabbit.JackrabbitContainer">
+       <bean id="localJcrRepository" class="org.argeo.jackrabbit.JackrabbitContainer">
                <property name="uri"
                        value="http://localhost:7070/org.argeo.server.jcr.webapp/remoting/repo" />
-<!--           <property name="namespaces">-->
-<!--                   <map>-->
-<!--                           <entry key="slc" value="http://www.argeo.org/slc" />-->
-<!--                   </map>-->
-<!--           </property>-->
-<!--           <property name="cndFiles">-->
-<!--                   <list>-->
-<!--                           <value>classpath:/org/argeo/slc/repo/repo.cnd</value>-->
-<!--                   </list>-->
-<!--           </property>-->
+               <property name="homeDirectory" value="${slc.jackrabbit.home}" />
+               <property name="configuration" value="${slc.jackrabbit.configuration}" />
+               <property name="variables" value="osgibundle:/jackrabbit.properties" />
+               <property name="namespaces">
+                       <map>
+                               <entry key="argeo" value="http://www.argeo.org/argeo" />
+                       </map>
+               </property>
+               <property name="cndFiles">
+                       <list>
+                               <value>classpath:/org/argeo/jcr/argeo.cnd</value>
+                       </list>
+               </property>
        </bean>
 </beans>
\ No newline at end of file
diff --git a/server/modules/org.argeo.server.jackrabbit.repo/jackrabbit.properties b/server/modules/org.argeo.server.jackrabbit.repo/jackrabbit.properties
deleted file mode 100644 (file)
index 41eab59..0000000
+++ /dev/null
@@ -1 +0,0 @@
-argeo.jackrabbit.repo.configuration=osgibundle:repository.xml
\ No newline at end of file
diff --git a/server/modules/org.argeo.server.jackrabbit.repo/localrepo.properties b/server/modules/org.argeo.server.jackrabbit.repo/localrepo.properties
new file mode 100644 (file)
index 0000000..c046ca4
--- /dev/null
@@ -0,0 +1 @@
+argeo.localrepo.configuration=osgibundle:repository.xml
\ No newline at end of file
diff --git a/server/modules/org.argeo.server.jackrabbit.repo/repository-h2.xml b/server/modules/org.argeo.server.jackrabbit.repo/repository-h2.xml
new file mode 100644 (file)
index 0000000..7b1d3bf
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0"?>
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
+                            "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+<Repository>
+       <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+               <param name="path" value="${rep.home}/repository" />
+       </FileSystem>
+
+       <Security appName="Jackrabbit">
+               <SecurityManager
+                       class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
+                       workspaceName="security">
+               </SecurityManager>
+               <AccessManager
+                       class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
+                       <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+               </AccessManager>
+
+               <LoginModule
+                       class="org.springframework.security.providers.jaas.SecurityContextLoginModule">
+               </LoginModule>
+<!--           <LoginModule-->
+<!--                   class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">-->
+<!--                   <param name="anonymousId" value="anonymous" />-->
+<!--                   <param name="adminId" value="admin" />-->
+<!--           </LoginModule>-->
+       </Security>
+
+       <Workspaces rootPath="${rep.home}/workspaces"
+               defaultWorkspace="default" />
+
+       <Workspace name="${wsp.name}">
+               <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+                       <param name="path" value="${wsp.home}" />
+               </FileSystem>
+               <PersistenceManager
+                       class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+                       <param name="url" value="jdbc:h2:file:${rep.home}/h2/sebi_db" />
+                       <param name="schemaObjectPrefix" value="${wsp.name}_" />
+               </PersistenceManager>
+               <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+                       <param name="path" value="${wsp.home}/index" />
+                       <param name="extractorPoolSize" value="2" />
+                       <param name="supportHighlighting" value="true" />
+               </SearchIndex>
+       </Workspace>
+
+       <Versioning rootPath="${rep.home}/version">
+               <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+                       <param name="path" value="${rep.home}/version" />
+               </FileSystem>
+               <PersistenceManager
+                       class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+                       <param name="url" value="jdbc:h2:file:${rep.home}/h2/sebi_version" />
+                       <param name="schemaObjectPrefix" value="version_" />
+               </PersistenceManager>
+       </Versioning>
+
+       <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+               <param name="path" value="${rep.home}/repository/index" />
+               <param name="extractorPoolSize" value="2" />
+               <param name="supportHighlighting" value="true" />
+       </SearchIndex>
+</Repository>
diff --git a/server/modules/org.argeo.server.jackrabbit.repo/repository-postgresql.xml b/server/modules/org.argeo.server.jackrabbit.repo/repository-postgresql.xml
new file mode 100644 (file)
index 0000000..9f95adf
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0"?>
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
+                            "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+<Repository>
+       <!-- Shared datasource -->
+       <DataSources>
+               <DataSource name="dataSource">
+                       <param name="driver" value="org.postgresql.Driver" />
+                       <param name="url" value="${slc.jackrabbit.dburl}" />
+                       <param name="user" value="${slc.jackrabbit.dbuser}" />
+                       <param name="password" value="${slc.jackrabbit.dbpassword}" />
+                       <param name="databaseType" value="postgresql" />
+                       <param name="maxPoolSize" value="10" />
+               </DataSource>
+       </DataSources>
+
+       <!-- File system and datastore -->
+       <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+               <param name="dataSourceName" value="dataSource" />
+               <param name="schema" value="postgresql" />
+               <param name="schemaObjectPrefix" value="fs_" />
+       </FileSystem>
+       <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
+               <param name="dataSourceName" value="dataSource" />
+               <param name="schemaObjectPrefix" value="ds_" />
+       </DataStore>
+
+       <!-- Workspace templates -->
+       <Workspaces rootPath="${rep.home}/workspaces"
+               defaultWorkspace="default" />
+       <Workspace name="${wsp.name}">
+               <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+                       <param name="dataSourceName" value="dataSource" />
+                       <param name="schema" value="postgresql" />
+                       <param name="schemaObjectPrefix" value="${wsp.name}_fs_" />
+               </FileSystem>
+               <PersistenceManager
+                       class="org.apache.jackrabbit.core.persistence.pool.PostgreSQLPersistenceManager">
+                       <param name="dataSourceName" value="dataSource" />
+                       <param name="schemaObjectPrefix" value="${wsp.name}_pm_" />
+               </PersistenceManager>
+               <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+                       <param name="path" value="${wsp.home}/index" />
+               </SearchIndex>
+       </Workspace>
+
+       <!-- Versioning -->
+       <Versioning rootPath="${rep.home}/version">
+               <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+                       <param name="dataSourceName" value="dataSource" />
+                       <param name="schema" value="postgresql" />
+                       <param name="schemaObjectPrefix" value="fs_ver_" />
+               </FileSystem>
+               <PersistenceManager
+                       class="org.apache.jackrabbit.core.persistence.pool.PostgreSQLPersistenceManager">
+                       <param name="dataSourceName" value="dataSource" />
+                       <param name="schemaObjectPrefix" value="pm_ver_" />
+               </PersistenceManager>
+       </Versioning>
+
+       <!-- Indexing -->
+       <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+               <param name="path" value="${rep.home}/repository/index" />
+               <param name="extractorPoolSize" value="2" />
+               <param name="supportHighlighting" value="true" />
+       </SearchIndex>
+
+       <!-- Security -->
+       <Security appName="Jackrabbit">
+               <SecurityManager
+                       class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
+                       workspaceName="security">
+               </SecurityManager>
+               <AccessManager
+                       class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
+               </AccessManager>
+<!--            <LoginModule -->
+<!--            class="org.springframework.security.providers.jaas.SecurityContextLoginModule"> -->
+<!--            </LoginModule> -->
+               <LoginModule
+                       class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+                       <param name="anonymousId" value="anonymous" />
+                       <param name="adminId" value="admin" />
+               </LoginModule>
+       </Security>
+</Repository>
\ No newline at end of file
diff --git a/server/modules/org.argeo.server.jackrabbit.repo/repository.xml b/server/modules/org.argeo.server.jackrabbit.repo/repository.xml
deleted file mode 100644 (file)
index abc40bb..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-<?xml version="1.0"?>
-       <!--
-               Licensed to the Apache Software Foundation (ASF) under one or more
-               contributor license agreements. See the NOTICE file distributed with
-               this work for additional information regarding copyright ownership.
-               The ASF licenses this file to You 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.
-       -->
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
-                            "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
-       <!--
-               Example Repository Configuration File Used by -
-               org.apache.jackrabbit.core.config.RepositoryConfigTest.java -
-       -->
-<Repository>
-       <!--
-               virtual file system where the repository stores global state (e.g.
-               registered namespaces, custom node types, etc.)
-       -->
-       <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-               <param name="path" value="${rep.home}/repository" />
-       </FileSystem>
-
-       <!--
-        security configuration
-    -->
-       <Security appName="Jackrabbit">
-               <!--
-                       security manager: class: FQN of class implementing the
-                       JackrabbitSecurityManager interface
-               -->
-               <SecurityManager
-                       class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
-                       workspaceName="security">
-                       <!--
-                               workspace access: class: FQN of class implementing the
-                               WorkspaceAccessManager interface
-                       -->
-                       <!-- <WorkspaceAccessManager class="..."/> -->
-                       <!-- <param name="config" value="${rep.home}/security.xml"/> -->
-               </SecurityManager>
-
-               <!--
-                       access manager: class: FQN of class implementing the AccessManager
-                       interface
-               -->
-               <AccessManager
-                       class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
-                       <!-- <param name="config" value="${rep.home}/access.xml"/> -->
-               </AccessManager>
-
-               <LoginModule
-                       class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
-                       <!--
-                               anonymous user name ('anonymous' is the default value)
-                       -->
-                       <param name="anonymousId" value="anonymous" />
-                       <!--
-                               administrator user id (default value if param is missing is 'admin')
-                       -->
-                       <param name="adminId" value="admin" />
-               </LoginModule>
-       </Security>
-
-       <!--
-               location of workspaces root directory and name of default workspace
-       -->
-       <Workspaces rootPath="${rep.home}/workspaces"
-               defaultWorkspace="default" />
-       <!--
-               workspace configuration template: used to create the initial workspace
-               if there's no workspace yet
-       -->
-       <Workspace name="${wsp.name}">
-               <!--
-                       virtual file system of the workspace: class: FQN of class
-                       implementing the FileSystem interface
-               -->
-               <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-                       <param name="path" value="${wsp.home}" />
-               </FileSystem>
-               <!--
-                       persistence manager of the workspace: class: FQN of class
-                       implementing the PersistenceManager interface
-               -->
-               
-                       <PersistenceManager
-                       class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
-                       <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
-                       <param name="schemaObjectPrefix" value="${wsp.name}_"/>
-                       </PersistenceManager>
-               <!-- 
-               <PersistenceManager
-                       class="org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager">
-                       <param name="url" value="jdbc:hsqldb:mem:db;create=true" />
-                       <param name="driver" value="org.hsqldb.jdbcDriver" />
-                       <param name="user" value="sa" />
-                       <param name="password" value="password" />
-                       <param name="schemaObjectPrefix" value="${wsp.name}_" />
-               </PersistenceManager>
-                -->
-               <!--
-                       Search index and the file system it uses. class: FQN of class
-                       implementing the QueryHandler interface
-               -->
-               <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
-                       <param name="path" value="${wsp.home}/index" />
-                       <param name="extractorPoolSize" value="2" />
-                       <param name="supportHighlighting" value="true" />
-               </SearchIndex>
-       </Workspace>
-
-       <!--
-        Configures the versioning
-    -->
-       <Versioning rootPath="${rep.home}/version">
-               <!--
-                       Configures the filesystem to use for versioning for the respective
-                       persistence manager
-               -->
-               <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-                       <param name="path" value="${rep.home}/version" />
-               </FileSystem>
-
-               <!--
-                       Configures the persistence manager to be used for persisting version
-                       state. Please note that the current versioning implementation is
-                       based on a 'normal' persistence manager, but this could change in
-                       future implementations.
-               -->
-               
-                       <PersistenceManager
-                       class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
-                       <param name="url"
-                       value="jdbc:derby:${rep.home}/version/db;create=true"/> <param
-                       name="schemaObjectPrefix" value="version_"/> </PersistenceManager>
-               
-               <!-- 
-               <PersistenceManager
-                       class="org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager">
-                       <param name="url" value="jdbc:hsqldb:mem:versions;create=true" />
-                       <param name="driver" value="org.hsqldb.jdbcDriver" />
-                       <param name="user" value="sa" />
-                       <param name="password" value="password" />
-                       <param name="schemaObjectPrefix" value="version_" />
-               </PersistenceManager>
-                -->
-       </Versioning>
-
-       <!--
-               Search index for content that is shared repository wide (/jcr:system
-               tree, contains mainly versions)
-       -->
-       <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
-               <param name="path" value="${rep.home}/repository/index" />
-               <param name="extractorPoolSize" value="2" />
-               <param name="supportHighlighting" value="true" />
-       </SearchIndex>
-</Repository>
index 828e95a14c570f331775b80b0b43d8c6ccc8b786..f103c00f10b1f0198bd1913954897f4b828b3920 100644 (file)
@@ -9,8 +9,8 @@ Import-Package: javax.jcr,
  javax.servlet,
  javax.servlet.http,
  javax.servlet.resources,
+ org.argeo.jackrabbit.webdav,
  org.argeo.jcr,
- org.argeo.server.jackrabbit.webdav,
  org.springframework.osgi.web.context.support;version="1.2.1",
  org.springframework.security;version="2.0.6.RELEASE",
  org.springframework.security.ui.webapp;version="2.0.6.RELEASE",
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java
new file mode 100644 (file)
index 0000000..8b35d0b
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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.
+ */
+
+package org.argeo.jackrabbit;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.core.RepositoryFactoryImpl;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.config.RepositoryConfigurationParser;
+import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory;
+import org.argeo.ArgeoException;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.xml.sax.InputSource;
+
+/**
+ * Wrapper around a Jackrabbit repository which allows to configure it in Spring
+ * and expose it as a {@link Repository}.
+ */
+public class JackrabbitContainer implements InitializingBean, DisposableBean,
+               Repository, ResourceLoaderAware {
+       private Log log = LogFactory.getLog(JackrabbitContainer.class);
+
+       private Resource configuration;
+       private File homeDirectory;
+       private Resource variables;
+
+       private Boolean inMemory = false;
+       private String uri = null;
+
+       private Repository repository;
+
+       private ResourceLoader resourceLoader;
+
+       /** Node type definitions in CND format */
+       private List<byte[]> cnds = new ArrayList<byte[]>();
+       private List<String> cndFiles = new ArrayList<String>();
+
+       /** Namespaces to register: key is prefix, value namespace */
+       private Map<String, String> namespaces = new HashMap<String, String>();
+
+       private Boolean autocreateWorkspaces = false;
+
+       public void afterPropertiesSet() throws Exception {
+               // Load cnds as resources
+               for (String resUrl : cndFiles) {
+                       Resource res = resourceLoader.getResource(resUrl);
+                       byte[] arr = IOUtils.toByteArray(res.getInputStream());
+                       cnds.add(arr);
+               }
+
+               if (uri != null && !uri.trim().equals("")) {
+                       Map<String, String> params = new HashMap<String, String>();
+                       params.put(JcrUtils.REPOSITORY_URI, uri);
+                       repository = new Jcr2davRepositoryFactory().getRepository(params);
+                       if (repository == null)
+                               throw new ArgeoException("Remote Davex repository " + uri
+                                               + " not found");
+                       log.info("Initialized Jackrabbit repository " + repository
+                                       + " from uri " + uri);
+               } else {
+                       if (inMemory && homeDirectory.exists()) {
+                               FileUtils.deleteDirectory(homeDirectory);
+                               log.warn("Deleted Jackrabbit home directory " + homeDirectory);
+                       }
+
+                       RepositoryConfig config;
+                       InputStream in = configuration.getInputStream();
+                       InputStream propsIn = null;
+                       try {
+                               Properties vars = new Properties();
+                               if (variables != null) {
+                                       propsIn = variables.getInputStream();
+                                       vars.load(propsIn);
+                               }
+                               // override with system properties
+                               vars.putAll(System.getProperties());
+                               vars.put(
+                                               RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
+                                               homeDirectory.getCanonicalPath());
+                               config = RepositoryConfig.create(new InputSource(in), vars);
+                       } catch (Exception e) {
+                               throw new RuntimeException("Cannot read configuration", e);
+                       } finally {
+                               IOUtils.closeQuietly(in);
+                               IOUtils.closeQuietly(propsIn);
+                       }
+
+                       if (inMemory)
+                               repository = new TransientRepository(config);
+                       else
+                               repository = RepositoryImpl.create(config);
+
+                       log.info("Initialized Jackrabbit repository " + repository + " in "
+                                       + homeDirectory + " with config " + configuration);
+               }
+       }
+
+       public void destroy() throws Exception {
+               if (repository != null) {
+                       if (repository instanceof JackrabbitRepository)
+                               ((JackrabbitRepository) repository).shutdown();
+                       else if (repository instanceof RepositoryImpl)
+                               ((RepositoryImpl) repository).shutdown();
+                       else if (repository instanceof TransientRepository)
+                               ((TransientRepository) repository).shutdown();
+               }
+
+               if (inMemory)
+                       if (homeDirectory.exists()) {
+                               FileUtils.deleteDirectory(homeDirectory);
+                               if (log.isDebugEnabled())
+                                       log.debug("Deleted Jackrabbit home directory "
+                                                       + homeDirectory);
+                       }
+
+               if (uri != null)
+                       log.info("Destroyed Jackrabbit repository with uri " + uri);
+               else
+                       log.info("Destroyed Jackrabbit repository " + repository + " in "
+                                       + homeDirectory + " with config " + configuration);
+       }
+
+       // JCR REPOSITORY (delegated)
+       public String getDescriptor(String key) {
+               return repository.getDescriptor(key);
+       }
+
+       public String[] getDescriptorKeys() {
+               return repository.getDescriptorKeys();
+       }
+
+       public Session login() throws LoginException, RepositoryException {
+               Session session = repository.login();
+               processNewSession(session);
+               return session;
+       }
+
+       public Session login(Credentials credentials, String workspaceName)
+                       throws LoginException, NoSuchWorkspaceException,
+                       RepositoryException {
+               Session session;
+               try {
+                       session = repository.login(credentials, workspaceName);
+               } catch (NoSuchWorkspaceException e) {
+                       if (autocreateWorkspaces)
+                               session = createWorkspaceAndLogsIn(credentials, workspaceName);
+                       else
+                               throw e;
+               }
+               processNewSession(session);
+               return session;
+       }
+
+       public Session login(Credentials credentials) throws LoginException,
+                       RepositoryException {
+               Session session = repository.login(credentials);
+               processNewSession(session);
+               return session;
+       }
+
+       public Session login(String workspaceName) throws LoginException,
+                       NoSuchWorkspaceException, RepositoryException {
+               Session session;
+               try {
+                       session = repository.login(workspaceName);
+               } catch (NoSuchWorkspaceException e) {
+                       if (autocreateWorkspaces)
+                               session = createWorkspaceAndLogsIn(null, workspaceName);
+                       else
+                               throw e;
+               }
+               processNewSession(session);
+               return session;
+       }
+
+       protected synchronized void processNewSession(Session session) {
+               try {
+                       NamespaceHelper namespaceHelper = new NamespaceHelper(session);
+                       namespaceHelper.registerNamespaces(namespaces);
+
+                       for (byte[] arr : cnds)
+                               CndImporter.registerNodeTypes(new InputStreamReader(
+                                               new ByteArrayInputStream(arr)), session, true);
+               } catch (Exception e) {
+                       throw new ArgeoException("Cannot process new session", e);
+               }
+       }
+
+       /**
+        * Logs in to the default workspace, creates the required workspace, logs
+        * out, logs in to the required workspace.
+        */
+       protected Session createWorkspaceAndLogsIn(Credentials credentials,
+                       String workspaceName) throws RepositoryException {
+               if (workspaceName == null)
+                       throw new ArgeoException("No workspace specified.");
+               Session session = repository.login(credentials);
+               session.getWorkspace().createWorkspace(workspaceName);
+               session.logout();
+               return repository.login(credentials, workspaceName);
+       }
+
+       public void setResourceLoader(ResourceLoader resourceLoader) {
+               this.resourceLoader = resourceLoader;
+       }
+
+       public boolean isStandardDescriptor(String key) {
+               return repository.isStandardDescriptor(key);
+       }
+
+       public boolean isSingleValueDescriptor(String key) {
+               return repository.isSingleValueDescriptor(key);
+       }
+
+       public Value getDescriptorValue(String key) {
+               return repository.getDescriptorValue(key);
+       }
+
+       public Value[] getDescriptorValues(String key) {
+               return repository.getDescriptorValues(key);
+       }
+
+       // BEANS METHODS
+       public void setHomeDirectory(File homeDirectory) {
+               this.homeDirectory = homeDirectory;
+       }
+
+       public void setConfiguration(Resource configuration) {
+               this.configuration = configuration;
+       }
+
+       public void setInMemory(Boolean inMemory) {
+               this.inMemory = inMemory;
+       }
+
+       public void setNamespaces(Map<String, String> namespaces) {
+               this.namespaces = namespaces;
+       }
+
+       public void setCndFiles(List<String> cndFiles) {
+               this.cndFiles = cndFiles;
+       }
+
+       public void setVariables(Resource variables) {
+               this.variables = variables;
+       }
+
+       public void setUri(String uri) {
+               this.uri = uri;
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/CachingSessionProvider.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/CachingSessionProvider.java
new file mode 100644 (file)
index 0000000..05b5e86
--- /dev/null
@@ -0,0 +1,70 @@
+package org.argeo.jackrabbit.webdav;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.server.SessionProvider;
+
+public class CachingSessionProvider implements SessionProvider {
+       private static final String JCR_SESSIONS_ATTRIBUTE = "jcrSessions";
+
+       private final static Log log = LogFactory
+                       .getLog(CachingSessionProvider.class);
+
+       private Credentials credentials = null;
+
+       public CachingSessionProvider() {
+       }
+
+       public CachingSessionProvider(Credentials credentials) {
+               this.credentials = credentials;
+       }
+
+       @SuppressWarnings("unchecked")
+       public Session getSession(HttpServletRequest request, Repository rep,
+                       String workspace) throws LoginException, ServletException,
+                       RepositoryException {
+               HttpSession httpSession = request.getSession();
+
+               if (httpSession.getAttribute(JCR_SESSIONS_ATTRIBUTE) == null) {
+                       httpSession
+                                       .setAttribute(JCR_SESSIONS_ATTRIBUTE, Collections
+                                                       .synchronizedMap(new HashMap<String, Session>()));
+               }
+               Map<String, Session> sessions = (Map<String, Session>) httpSession
+                               .getAttribute(JCR_SESSIONS_ATTRIBUTE);
+               if (!sessions.containsKey(workspace)) {
+                       Session session = rep.login(credentials, workspace);
+                       sessions.put(workspace, session);
+                       return session;
+               } else {
+                       Session session = sessions.get(workspace);
+                       if (!session.isLive()) {
+                               sessions.remove(workspace);
+                               session = rep.login(credentials, workspace);
+                               sessions.put(workspace, session);
+                       }
+                       return session;
+               }
+       }
+
+       public void releaseSession(Session session) {
+               if (log.isDebugEnabled())
+                       log.debug("Releasing JCR session " + session);
+               // session.logout();
+               // FIXME: find a way to log out when the HTTP session is expired
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/ExtendedDispatcherServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/ExtendedDispatcherServlet.java
new file mode 100644 (file)
index 0000000..a40919e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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.
+ */
+
+package org.argeo.jackrabbit.webdav;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.springframework.web.servlet.DispatcherServlet;
+
+public class ExtendedDispatcherServlet extends DispatcherServlet {
+       private static final long serialVersionUID = -5584673209855752009L;
+
+       private final static Log log = LogFactory
+                       .getLog(ExtendedDispatcherServlet.class);
+
+       protected void service(HttpServletRequest request,
+                       HttpServletResponse response) throws ServletException,
+                       java.io.IOException {
+               // see http://forum.springsource.org/showthread.php?t=53472
+               try {
+                       if (log.isTraceEnabled())
+                               log.trace("Received request " + request);
+                       doService(request, response);
+               } catch (Exception e) {
+                       throw new ArgeoException("Cannot process request", e);
+               }
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/JcrRemotingServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/JcrRemotingServlet.java
new file mode 100644 (file)
index 0000000..0af6693
--- /dev/null
@@ -0,0 +1,30 @@
+package org.argeo.jackrabbit.webdav;
+
+import javax.jcr.Repository;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.server.SessionProvider;
+
+public class JcrRemotingServlet extends
+               org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet {
+
+       private static final long serialVersionUID = 3131835511468341309L;
+
+       private final Repository repository;
+
+       public JcrRemotingServlet(Repository repository) {
+               this.repository = repository;
+       }
+
+       @Override
+       protected Repository getRepository() {
+               return repository;
+       }
+
+       @Override
+       protected SessionProvider getSessionProvider() {
+               return new CachingSessionProvider(new SimpleCredentials("demo",
+                               "demo".toCharArray()));
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java
new file mode 100644 (file)
index 0000000..8e266a9
--- /dev/null
@@ -0,0 +1,133 @@
+package org.argeo.jackrabbit.webdav;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
+import org.argeo.ArgeoException;
+import org.argeo.jcr.RepositoryRegister;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.ServletContextAware;
+import org.springframework.web.servlet.HandlerExecutionChain;
+import org.springframework.web.servlet.HandlerMapping;
+
+public class MultipleRepositoryHandlerMapping implements HandlerMapping,
+               ApplicationContextAware, ServletContextAware {
+       private final static Log log = LogFactory
+                       .getLog(MultipleRepositoryHandlerMapping.class);
+
+       private ConfigurableApplicationContext applicationContext;
+       private ServletContext servletContext;
+
+       private RepositoryRegister repositoryRegister;
+
+       public HandlerExecutionChain getHandler(HttpServletRequest request)
+                       throws Exception {
+               if (log.isTraceEnabled()) {
+                       log.trace("getContextPath=" + request.getContextPath());
+                       log.trace("getServletPath=" + request.getServletPath());
+                       log.trace("getPathInfo=" + request.getPathInfo());
+               }
+
+               String repositoryName = extractRepositoryName(request);
+               String pathPrefix = request.getServletPath() + '/' + repositoryName;
+               String beanName = pathPrefix;
+
+               if (!applicationContext.containsBean(beanName)) {
+                       Repository repository = repositoryRegister.getRepositories().get(
+                                       repositoryName);
+                       HttpServlet servlet = createServlet(repository, pathPrefix);
+                       applicationContext.getBeanFactory().registerSingleton(beanName,
+                                       servlet);
+                       // TODO: unregister it as well
+               }
+               HttpServlet remotingServlet = (HttpServlet) applicationContext
+                               .getBean(beanName);
+               return new HandlerExecutionChain(remotingServlet);
+       }
+
+       protected HttpServlet createServlet(Repository repository, String pathPrefix)
+                       throws ServletException {
+               JcrRemotingServlet jcrRemotingServlet = new JcrRemotingServlet(
+                               repository);
+               Properties initParameters = new Properties();
+               initParameters.setProperty(
+                               JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX,
+                               pathPrefix);
+               jcrRemotingServlet.init(new DelegatingServletConfig(pathPrefix.replace(
+                               '/', '_'), initParameters));
+               return jcrRemotingServlet;
+       }
+
+       /** The repository name is the first part of the path info */
+       protected String extractRepositoryName(HttpServletRequest request) {
+               String pathInfo = request.getPathInfo();
+               // TODO: optimize by checking character by character
+               String[] tokens = pathInfo.split("/");
+               StringBuffer currName = new StringBuffer("");
+               tokens: for (String token : tokens) {
+                       if (token.equals(""))
+                               continue tokens;
+                       currName.append(token);
+                       if (repositoryRegister.getRepositories().containsKey(
+                                       currName.toString()))
+                               return currName.toString();
+                       currName.append('/');
+               }
+               throw new ArgeoException("No repository can be found for request "
+                               + pathInfo);
+       }
+
+       public void setApplicationContext(ApplicationContext applicationContext)
+                       throws BeansException {
+               this.applicationContext = (ConfigurableApplicationContext) applicationContext;
+       }
+
+       public void setServletContext(ServletContext servletContext) {
+               this.servletContext = servletContext;
+       }
+
+       public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
+               this.repositoryRegister = repositoryRegister;
+       }
+
+       private class DelegatingServletConfig implements ServletConfig {
+               private String name;
+               private Properties initParameters;
+
+               public DelegatingServletConfig(String name, Properties initParameters) {
+                       super();
+                       this.name = name;
+                       this.initParameters = initParameters;
+               }
+
+               public String getServletName() {
+                       return name;
+               }
+
+               public ServletContext getServletContext() {
+                       return servletContext;
+               }
+
+               public String getInitParameter(String paramName) {
+                       return initParameters.getProperty(paramName);
+               }
+
+               public Enumeration getInitParameterNames() {
+                       return initParameters.keys();
+               }
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/WebDavServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/webdav/WebDavServlet.java
new file mode 100644 (file)
index 0000000..a9ed8ef
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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.
+ */
+
+package org.argeo.jackrabbit.webdav;
+
+import java.io.IOException;
+
+import javax.jcr.Repository;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.webdav.simple.ResourceConfig;
+import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
+import org.argeo.ArgeoException;
+import org.springframework.core.io.Resource;
+
+public class WebDavServlet extends SimpleWebdavServlet {
+
+       private static final long serialVersionUID = 1L;
+       private final static Log log = LogFactory.getLog(WebDavServlet.class);
+
+       private Repository repository;
+       private Resource resourceConfiguration;
+
+       public WebDavServlet() {
+
+       }
+
+       @Override
+       public void init() throws ServletException {
+               super.init();
+
+               if (resourceConfiguration != null) {
+                       ResourceConfig resourceConfig = new ResourceConfig(null);
+                       try {
+                               resourceConfig.parse(resourceConfiguration.getURL());
+                       } catch (IOException e) {
+                               throw new ArgeoException("Cannot parse resource configuration "
+                                               + resourceConfiguration, e);
+                       }
+                       setResourceConfig(resourceConfig);
+               }
+       }
+
+       @Override
+       protected void service(HttpServletRequest request,
+                       HttpServletResponse response) throws ServletException, IOException {
+               if (log.isTraceEnabled())
+                       log.trace("Received request " + request);
+               super.service(request, response);
+
+               if (log.isTraceEnabled()) {
+                       log.trace("Webdav response: " + response);
+                       // response.
+               }
+       }
+
+       public Repository getRepository() {
+               return repository;
+       }
+
+       public void setRepository(Repository repository) {
+               this.repository = repository;
+       }
+
+       public void setResourceConfiguration(Resource resourceConfig) {
+               this.resourceConfiguration = resourceConfig;
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java
deleted file mode 100644 (file)
index c828d70..0000000
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * 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.
- */
-
-package org.argeo.server.jackrabbit;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.api.JackrabbitRepository;
-import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.jackrabbit.commons.NamespaceHelper;
-import org.apache.jackrabbit.commons.cnd.CndImporter;
-import org.apache.jackrabbit.core.RepositoryFactoryImpl;
-import org.apache.jackrabbit.core.RepositoryImpl;
-import org.apache.jackrabbit.core.TransientRepository;
-import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.jackrabbit.core.config.RepositoryConfigurationParser;
-import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory;
-import org.argeo.ArgeoException;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ResourceLoaderAware;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.xml.sax.InputSource;
-
-/**
- * Wrapper around a Jackrabbit repository which allows to configure it in Spring
- * and expose it as a {@link Repository}.
- */
-public class JackrabbitContainer implements InitializingBean, DisposableBean,
-               Repository, ResourceLoaderAware {
-       private Log log = LogFactory.getLog(JackrabbitContainer.class);
-
-       private Resource configuration;
-       private File homeDirectory;
-       private Resource variables;
-
-       private Boolean inMemory = false;
-       private String uri = null;
-
-       private Repository repository;
-
-       private ResourceLoader resourceLoader;
-
-       /** Node type definitions in CND format */
-       private List<byte[]> cnds = new ArrayList<byte[]>();
-       private List<String> cndFiles = new ArrayList<String>();
-
-       /** Namespaces to register: key is prefix, value namespace */
-       private Map<String, String> namespaces = new HashMap<String, String>();
-
-       private Boolean autocreateWorkspaces = false;
-
-       public void afterPropertiesSet() throws Exception {
-               // Load cnds as resources
-               for (String resUrl : cndFiles) {
-                       Resource res = resourceLoader.getResource(resUrl);
-                       byte[] arr = IOUtils.toByteArray(res.getInputStream());
-                       cnds.add(arr);
-               }
-
-               if (uri != null) {
-                       // Thread.currentThread().setContextClassLoader(
-                       // getClass().getClassLoader());
-                       // repository = JcrUtils.getRepository(uri);
-                       Map<String, String> params = new HashMap<String, String>();
-                       params.put(JcrUtils.REPOSITORY_URI, uri);
-                       repository = new Jcr2davRepositoryFactory().getRepository(params);
-                       if (repository == null)
-                               throw new ArgeoException("Remote Davex repository " + uri
-                                               + " not found");
-                       log.info("Initialized Jackrabbit repository " + repository
-                                       + " from uri " + uri);
-               } else {
-                       if (inMemory && homeDirectory.exists()) {
-                               FileUtils.deleteDirectory(homeDirectory);
-                               log.warn("Deleted Jackrabbit home directory " + homeDirectory);
-                       }
-
-                       RepositoryConfig config;
-                       InputStream in = configuration.getInputStream();
-                       InputStream propsIn = null;
-                       try {
-                               Properties vars = new Properties();
-                               if (variables != null) {
-                                       propsIn = variables.getInputStream();
-                                       vars.load(propsIn);
-                               }
-                               // override with system properties
-                               vars.putAll(System.getProperties());
-                               vars.put(
-                                               RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
-                                               homeDirectory.getCanonicalPath());
-                               config = RepositoryConfig.create(new InputSource(in), vars);
-                       } catch (Exception e) {
-                               throw new RuntimeException("Cannot read configuration", e);
-                       } finally {
-                               IOUtils.closeQuietly(in);
-                               IOUtils.closeQuietly(propsIn);
-                       }
-
-                       if (inMemory)
-                               repository = new TransientRepository(config);
-                       else
-                               repository = RepositoryImpl.create(config);
-
-                       log.info("Initialized Jackrabbit repository " + repository + " in "
-                                       + homeDirectory + " with config " + configuration);
-               }
-       }
-
-       public void destroy() throws Exception {
-               if (repository != null) {
-                       if (repository instanceof JackrabbitRepository)
-                               ((JackrabbitRepository) repository).shutdown();
-                       else if (repository instanceof RepositoryImpl)
-                               ((RepositoryImpl) repository).shutdown();
-                       else if (repository instanceof TransientRepository)
-                               ((TransientRepository) repository).shutdown();
-               }
-
-               if (inMemory)
-                       if (homeDirectory.exists()) {
-                               FileUtils.deleteDirectory(homeDirectory);
-                               if (log.isDebugEnabled())
-                                       log.debug("Deleted Jackrabbit home directory "
-                                                       + homeDirectory);
-                       }
-
-               if (uri != null)
-                       log.info("Destroyed Jackrabbit repository with uri " + uri);
-               else
-                       log.info("Destroyed Jackrabbit repository " + repository + " in "
-                                       + homeDirectory + " with config " + configuration);
-       }
-
-       // JCR REPOSITORY (delegated)
-       public String getDescriptor(String key) {
-               return repository.getDescriptor(key);
-       }
-
-       public String[] getDescriptorKeys() {
-               return repository.getDescriptorKeys();
-       }
-
-       public Session login() throws LoginException, RepositoryException {
-               Session session = repository.login();
-               processNewSession(session);
-               return session;
-       }
-
-       public Session login(Credentials credentials, String workspaceName)
-                       throws LoginException, NoSuchWorkspaceException,
-                       RepositoryException {
-               Session session;
-               try {
-                       session = repository.login(credentials, workspaceName);
-               } catch (NoSuchWorkspaceException e) {
-                       if (autocreateWorkspaces)
-                               session = createWorkspaceAndLogsIn(credentials, workspaceName);
-                       else
-                               throw e;
-               }
-               processNewSession(session);
-               return session;
-       }
-
-       public Session login(Credentials credentials) throws LoginException,
-                       RepositoryException {
-               Session session = repository.login(credentials);
-               processNewSession(session);
-               return session;
-       }
-
-       public Session login(String workspaceName) throws LoginException,
-                       NoSuchWorkspaceException, RepositoryException {
-               Session session;
-               try {
-                       session = repository.login(workspaceName);
-               } catch (NoSuchWorkspaceException e) {
-                       if (autocreateWorkspaces)
-                               session = createWorkspaceAndLogsIn(null, workspaceName);
-                       else
-                               throw e;
-               }
-               processNewSession(session);
-               return session;
-       }
-
-       protected synchronized void processNewSession(Session session) {
-               try {
-                       NamespaceHelper namespaceHelper = new NamespaceHelper(session);
-                       namespaceHelper.registerNamespaces(namespaces);
-
-                       for (byte[] arr : cnds)
-                               CndImporter.registerNodeTypes(new InputStreamReader(
-                                               new ByteArrayInputStream(arr)), session, true);
-               } catch (Exception e) {
-                       throw new ArgeoException("Cannot process new session", e);
-               }
-       }
-
-       /**
-        * Logs in to the default workspace, creates the required workspace, logs
-        * out, logs in to the required workspace.
-        */
-       protected Session createWorkspaceAndLogsIn(Credentials credentials,
-                       String workspaceName) throws RepositoryException {
-               if (workspaceName == null)
-                       throw new ArgeoException("No workspace specified.");
-               Session session = repository.login(credentials);
-               session.getWorkspace().createWorkspace(workspaceName);
-               session.logout();
-               return repository.login(credentials, workspaceName);
-       }
-
-       public void setResourceLoader(ResourceLoader resourceLoader) {
-               this.resourceLoader = resourceLoader;
-       }
-
-       public boolean isStandardDescriptor(String key) {
-               return repository.isStandardDescriptor(key);
-       }
-
-       public boolean isSingleValueDescriptor(String key) {
-               return repository.isSingleValueDescriptor(key);
-       }
-
-       public Value getDescriptorValue(String key) {
-               return repository.getDescriptorValue(key);
-       }
-
-       public Value[] getDescriptorValues(String key) {
-               return repository.getDescriptorValues(key);
-       }
-
-       // BEANS METHODS
-       public void setHomeDirectory(File homeDirectory) {
-               this.homeDirectory = homeDirectory;
-       }
-
-       public void setConfiguration(Resource configuration) {
-               this.configuration = configuration;
-       }
-
-       public void setInMemory(Boolean inMemory) {
-               this.inMemory = inMemory;
-       }
-
-       public void setNamespaces(Map<String, String> namespaces) {
-               this.namespaces = namespaces;
-       }
-
-       public void setCndFiles(List<String> cndFiles) {
-               this.cndFiles = cndFiles;
-       }
-
-       public void setVariables(Resource variables) {
-               this.variables = variables;
-       }
-
-       public void setUri(String uri) {
-               this.uri = uri;
-       }
-
-}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/CachingSessionProvider.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/CachingSessionProvider.java
deleted file mode 100644 (file)
index a8771ae..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.argeo.server.jackrabbit.webdav;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.server.SessionProvider;
-
-public class CachingSessionProvider implements SessionProvider {
-       private static final String JCR_SESSIONS_ATTRIBUTE = "jcrSessions";
-
-       private final static Log log = LogFactory
-                       .getLog(CachingSessionProvider.class);
-
-       private Credentials credentials = null;
-
-       public CachingSessionProvider() {
-       }
-
-       public CachingSessionProvider(Credentials credentials) {
-               this.credentials = credentials;
-       }
-
-       @SuppressWarnings("unchecked")
-       public Session getSession(HttpServletRequest request, Repository rep,
-                       String workspace) throws LoginException, ServletException,
-                       RepositoryException {
-               HttpSession httpSession = request.getSession();
-
-               if (httpSession.getAttribute(JCR_SESSIONS_ATTRIBUTE) == null) {
-                       httpSession
-                                       .setAttribute(JCR_SESSIONS_ATTRIBUTE, Collections
-                                                       .synchronizedMap(new HashMap<String, Session>()));
-               }
-               Map<String, Session> sessions = (Map<String, Session>) httpSession
-                               .getAttribute(JCR_SESSIONS_ATTRIBUTE);
-               if (!sessions.containsKey(workspace)) {
-                       Session session = rep.login(credentials, workspace);
-                       sessions.put(workspace, session);
-                       return session;
-               } else {
-                       Session session = sessions.get(workspace);
-                       if (!session.isLive()) {
-                               sessions.remove(workspace);
-                               session = rep.login(credentials, workspace);
-                               sessions.put(workspace, session);
-                       }
-                       return session;
-               }
-       }
-
-       public void releaseSession(Session session) {
-               if (log.isDebugEnabled())
-                       log.debug("Releasing JCR session " + session);
-               // session.logout();
-               // FIXME: find a way to log out when the HTTP session is expired
-       }
-
-}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/ExtendedDispatcherServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/ExtendedDispatcherServlet.java
deleted file mode 100644 (file)
index 8c961c1..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * 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.
- */
-
-package org.argeo.server.jackrabbit.webdav;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.springframework.web.servlet.DispatcherServlet;
-
-public class ExtendedDispatcherServlet extends DispatcherServlet {
-       private static final long serialVersionUID = -5584673209855752009L;
-
-       private final static Log log = LogFactory
-                       .getLog(ExtendedDispatcherServlet.class);
-
-       protected void service(HttpServletRequest request,
-                       HttpServletResponse response) throws ServletException,
-                       java.io.IOException {
-               // see http://forum.springsource.org/showthread.php?t=53472
-               try {
-                       if (log.isTraceEnabled())
-                               log.trace("Received request " + request);
-                       doService(request, response);
-               } catch (Exception e) {
-                       throw new ArgeoException("Cannot process request", e);
-               }
-       }
-
-}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/JcrRemotingServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/JcrRemotingServlet.java
deleted file mode 100644 (file)
index add064b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.argeo.server.jackrabbit.webdav;
-
-import javax.jcr.Repository;
-import javax.jcr.SimpleCredentials;
-
-import org.apache.jackrabbit.server.SessionProvider;
-
-public class JcrRemotingServlet extends
-               org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet {
-
-       private static final long serialVersionUID = 3131835511468341309L;
-
-       private final Repository repository;
-
-       public JcrRemotingServlet(Repository repository) {
-               this.repository = repository;
-       }
-
-       @Override
-       protected Repository getRepository() {
-               return repository;
-       }
-
-       @Override
-       protected SessionProvider getSessionProvider() {
-               return new CachingSessionProvider(new SimpleCredentials("demo",
-                               "demo".toCharArray()));
-       }
-
-}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/MultipleRepositoryHandlerMapping.java
deleted file mode 100644 (file)
index a8591dc..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-package org.argeo.server.jackrabbit.webdav;
-
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.jcr.Repository;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.webdav.jcr.JCRWebdavServerServlet;
-import org.argeo.ArgeoException;
-import org.argeo.jcr.RepositoryRegister;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.web.context.ServletContextAware;
-import org.springframework.web.servlet.HandlerExecutionChain;
-import org.springframework.web.servlet.HandlerMapping;
-
-public class MultipleRepositoryHandlerMapping implements HandlerMapping,
-               ApplicationContextAware, ServletContextAware {
-       private final static Log log = LogFactory
-                       .getLog(MultipleRepositoryHandlerMapping.class);
-
-       private ConfigurableApplicationContext applicationContext;
-       private ServletContext servletContext;
-
-       private RepositoryRegister repositoryRegister;
-
-       public HandlerExecutionChain getHandler(HttpServletRequest request)
-                       throws Exception {
-               if (log.isTraceEnabled()) {
-                       log.trace("getContextPath=" + request.getContextPath());
-                       log.trace("getServletPath=" + request.getServletPath());
-                       log.trace("getPathInfo=" + request.getPathInfo());
-               }
-
-               String repositoryName = extractRepositoryName(request);
-               String pathPrefix = request.getServletPath() + '/' + repositoryName;
-               String beanName = pathPrefix;
-
-               if (!applicationContext.containsBean(beanName)) {
-                       Repository repository = repositoryRegister.getRepositories().get(
-                                       repositoryName);
-                       HttpServlet servlet = createServlet(repository, pathPrefix);
-                       applicationContext.getBeanFactory().registerSingleton(beanName,
-                                       servlet);
-                       // TODO: unregister it as well
-               }
-               HttpServlet remotingServlet = (HttpServlet) applicationContext
-                               .getBean(beanName);
-               return new HandlerExecutionChain(remotingServlet);
-       }
-
-       protected HttpServlet createServlet(Repository repository, String pathPrefix)
-                       throws ServletException {
-               JcrRemotingServlet jcrRemotingServlet = new JcrRemotingServlet(
-                               repository);
-               Properties initParameters = new Properties();
-               initParameters.setProperty(
-                               JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX,
-                               pathPrefix);
-               jcrRemotingServlet.init(new DelegatingServletConfig(pathPrefix.replace(
-                               '/', '_'), initParameters));
-               return jcrRemotingServlet;
-       }
-
-       /** The repository name is the first part of the path info */
-       protected String extractRepositoryName(HttpServletRequest request) {
-               String pathInfo = request.getPathInfo();
-               // TODO: optimize by checking character by character
-               String[] tokens = pathInfo.split("/");
-               StringBuffer currName = new StringBuffer("");
-               tokens: for (String token : tokens) {
-                       if (token.equals(""))
-                               continue tokens;
-                       currName.append(token);
-                       if (repositoryRegister.getRepositories().containsKey(
-                                       currName.toString()))
-                               return currName.toString();
-                       currName.append('/');
-               }
-               throw new ArgeoException("No repository can be found for request "
-                               + pathInfo);
-       }
-
-       public void setApplicationContext(ApplicationContext applicationContext)
-                       throws BeansException {
-               this.applicationContext = (ConfigurableApplicationContext) applicationContext;
-       }
-
-       public void setServletContext(ServletContext servletContext) {
-               this.servletContext = servletContext;
-       }
-
-       public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
-               this.repositoryRegister = repositoryRegister;
-       }
-
-       private class DelegatingServletConfig implements ServletConfig {
-               private String name;
-               private Properties initParameters;
-
-               public DelegatingServletConfig(String name, Properties initParameters) {
-                       super();
-                       this.name = name;
-                       this.initParameters = initParameters;
-               }
-
-               public String getServletName() {
-                       return name;
-               }
-
-               public ServletContext getServletContext() {
-                       return servletContext;
-               }
-
-               public String getInitParameter(String paramName) {
-                       return initParameters.getProperty(paramName);
-               }
-
-               public Enumeration getInitParameterNames() {
-                       return initParameters.keys();
-               }
-       }
-
-}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/WebDavServlet.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/webdav/WebDavServlet.java
deleted file mode 100644 (file)
index 2ca729d..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * 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.
- */
-
-package org.argeo.server.jackrabbit.webdav;
-
-import java.io.IOException;
-
-import javax.jcr.Repository;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.webdav.simple.ResourceConfig;
-import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
-import org.argeo.ArgeoException;
-import org.springframework.core.io.Resource;
-
-public class WebDavServlet extends SimpleWebdavServlet {
-
-       private static final long serialVersionUID = 1L;
-       private final static Log log = LogFactory.getLog(WebDavServlet.class);
-
-       private Repository repository;
-       private Resource resourceConfiguration;
-
-       public WebDavServlet() {
-
-       }
-
-       @Override
-       public void init() throws ServletException {
-               super.init();
-
-               if (resourceConfiguration != null) {
-                       ResourceConfig resourceConfig = new ResourceConfig(null);
-                       try {
-                               resourceConfig.parse(resourceConfiguration.getURL());
-                       } catch (IOException e) {
-                               throw new ArgeoException("Cannot parse resource configuration "
-                                               + resourceConfiguration, e);
-                       }
-                       setResourceConfig(resourceConfig);
-               }
-       }
-
-       @Override
-       protected void service(HttpServletRequest request,
-                       HttpServletResponse response) throws ServletException, IOException {
-               if (log.isTraceEnabled())
-                       log.trace("Received request " + request);
-               super.service(request, response);
-
-               if (log.isTraceEnabled()) {
-                       log.trace("Webdav response: " + response);
-                       // response.
-               }
-       }
-
-       public Repository getRepository() {
-               return repository;
-       }
-
-       public void setRepository(Repository repository) {
-               this.repository = repository;
-       }
-
-       public void setResourceConfiguration(Resource resourceConfig) {
-               this.resourceConfiguration = resourceConfig;
-       }
-
-}
index c9f26bd8e704463f8beb64862d982d3f2b45f2ae..762e65304a45132d5d1e220c1529aa25d8e5da91 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+       <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
        <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
        <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
diff --git a/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd b/server/runtime/org.argeo.server.jcr/src/main/resources/org/argeo/jcr/argeo.cnd
new file mode 100644 (file)
index 0000000..2439511
--- /dev/null
@@ -0,0 +1,9 @@
+<argeo = 'http://www.argeo.org/argeo'>
+
+// HOME DIRECTORIES
+[argeo:home] > nt:base, mix:created, mix:lastModified
++ * (argeo:userHome) *
+
+[argeo:userHome] > mix:created, mix:lastModified
+mixin
+- argeo:userId (STRING)