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
<?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">
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>
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"
+++ /dev/null
-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;
- }
-
-}
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);
}
}
--- /dev/null
+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;
+ }
+
+}
// 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);
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);
}
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
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
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
\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
</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
+++ /dev/null
-argeo.jackrabbit.repo.configuration=osgibundle:repository.xml
\ No newline at end of file
--- /dev/null
+argeo.localrepo.configuration=osgibundle:repository.xml
\ No newline at end of file
--- /dev/null
+<?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>
--- /dev/null
+<?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
+++ /dev/null
-<?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>
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",
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+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
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+
+}
--- /dev/null
+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()));
+ }
+
+}
--- /dev/null
+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();
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-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
- }
-
-}
+++ /dev/null
-/*
- * 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);
- }
- }
-
-}
+++ /dev/null
-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()));
- }
-
-}
+++ /dev/null
-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();
- }
- }
-
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
<?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"/>
--- /dev/null
+<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)