You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2006/02/23 16:18:23 UTC

svn commit: r380142 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit: api/JackrabbitWorkspace.java core/RepositoryImpl.java core/SessionImpl.java core/WorkspaceImpl.java core/config/RepositoryConfig.java

Author: mreutegg
Date: Thu Feb 23 07:18:17 2006
New Revision: 380142

URL: http://svn.apache.org/viewcvs?rev=380142&view=rev
Log:
Provide a second createWorkspace() method that allows to explicitly specify a workspace configuration template.

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java?rev=380142&r1=380141&r2=380142&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java Thu Feb 23 07:18:17 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.api;
 
+import org.xml.sax.InputSource;
+
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Workspace;
@@ -36,7 +38,21 @@
      *                               already exists or if another error occurs
      * @see #getAccessibleWorkspaceNames()
      */
-	void createWorkspace(String workspaceName)
-		throws AccessDeniedException, RepositoryException;
+    void createWorkspace(String workspaceName)
+            throws AccessDeniedException, RepositoryException;
 
+    /**
+     * Creates a workspace with the given name and a workspace configuration
+     * template.
+     *
+     * @param workspaceName name of the new workspace
+     * @param workspaceTemplate the configuration template of the new workspace
+     * @throws AccessDeniedException if the current session is not allowed to
+     *                               create the workspace
+     * @throws RepositoryException   if a workspace with the given name
+     *                               already exists or if another error occurs
+     * @see #getAccessibleWorkspaceNames()
+     */
+    public void createWorkspace(String workspaceName, InputSource workspaceTemplate)
+            throws AccessDeniedException, RepositoryException;
 }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=380142&r1=380141&r2=380142&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java Thu Feb 23 07:18:17 2006
@@ -45,6 +45,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.log4j.Logger;
+import org.xml.sax.InputSource;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -662,6 +663,31 @@
 
         // create the workspace configuration
         WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName);
+        WorkspaceInfo info = createWorkspaceInfo(config);
+        wspInfos.put(workspaceName, info);
+    }
+
+    /**
+     * Creates a workspace with the given name and given workspace configuration
+     * template.
+     *
+     * @param workspaceName  name of the new workspace
+     * @param configTemplate the workspace configuration template of the new
+     *                       workspace
+     * @throws RepositoryException if a workspace with the given name already
+     *                             exists or if another error occurs
+     * @see SessionImpl#createWorkspace(String,InputSource)
+     */
+    protected synchronized void createWorkspace(String workspaceName,
+                                                InputSource configTemplate)
+            throws RepositoryException {
+        if (wspInfos.containsKey(workspaceName)) {
+            throw new RepositoryException("workspace '"
+                    + workspaceName + "' already exists.");
+        }
+
+        // create the workspace configuration
+        WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName, configTemplate);
         WorkspaceInfo info = createWorkspaceInfo(config);
         wspInfos.put(workspaceName, info);
     }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=380142&r1=380141&r2=380142&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SessionImpl.java Thu Feb 23 07:18:17 2006
@@ -452,6 +452,24 @@
     }
 
     /**
+     * Creates a workspace with the given name and a workspace configuration
+     * template.
+     *
+     * @param workspaceName  name of the new workspace
+     * @param configTemplate the configuration template of the new workspace
+     * @throws AccessDeniedException if the current session is not allowed to
+     *                               create the workspace
+     * @throws RepositoryException   if a workspace with the given name already
+     *                               exists or if another error occurs
+     */
+    protected void createWorkspace(String workspaceName,
+                                   InputSource configTemplate)
+            throws AccessDeniedException, RepositoryException {
+        // @todo verify that this session has the right privileges for this operation
+        rep.createWorkspace(workspaceName, configTemplate);
+    }
+
+    /**
      * Notify the listeners that this session is about to be closed.
      */
     protected void notifyLoggingOut() {

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java?rev=380142&r1=380141&r2=380142&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java Thu Feb 23 07:18:17 2006
@@ -177,6 +177,7 @@
     }
 
     //--------------------------------------------------< JackrabbitWorkspace >
+
     /**
      * Creates a workspace with the given name.
      *
@@ -193,6 +194,26 @@
         sanityCheck();
 
         session.createWorkspace(workspaceName);
+    }
+
+    /**
+     * Creates a workspace with the given name and a workspace configuration
+     * template.
+     *
+     * @param workspaceName name of the new workspace
+     * @param configTemplate the configuration template of the new workspace
+     * @throws AccessDeniedException if the current session is not allowed to
+     *                               create the workspace
+     * @throws RepositoryException   if a workspace with the given name
+     *                               already exists or if another error occurs
+     * @see #getAccessibleWorkspaceNames()
+     */
+    public void createWorkspace(String workspaceName, InputSource configTemplate)
+            throws AccessDeniedException, RepositoryException {
+        // check state of this instance
+        sanityCheck();
+
+        session.createWorkspace(workspaceName, configTemplate);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?rev=380142&r1=380141&r2=380142&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java Thu Feb 23 07:18:17 2006
@@ -438,7 +438,9 @@
     }
 
     /**
-     * Creates a new workspace configuration with the specified name.
+     * Creates a new workspace configuration with the specified name and the
+     * specified workspace <code>template</.
+     * <p/>
      * This method creates a workspace configuration subdirectory,
      * copies the workspace configuration template into it, and finally
      * adds the created workspace configuration to the repository.
@@ -446,11 +448,13 @@
      * the caller.
      *
      * @param name workspace name
+     * @param template the workspace template
      * @return created workspace configuration
      * @throws ConfigurationException if creating the workspace configuration
      *                                failed
      */
-    public synchronized WorkspaceConfig createWorkspaceConfig(String name)
+    private synchronized WorkspaceConfig internalCreateWorkspaceConfig(String name,
+                                                                       Element template)
             throws ConfigurationException {
 
         // The physical workspace home directory on disk (TODO encode name?)
@@ -541,6 +545,52 @@
                     "Failed to load the created configuration for workspace "
                     + name + ".");
         }
+    }
+
+    /**
+     * Creates a new workspace configuration with the specified name.
+     * This method creates a workspace configuration subdirectory,
+     * copies the workspace configuration template into it, and finally
+     * adds the created workspace configuration to the repository.
+     * The initialized workspace configuration object is returned to
+     * the caller.
+     *
+     * @param name workspace name
+     * @return created workspace configuration
+     * @throws ConfigurationException if creating the workspace configuration
+     *                                failed
+     */
+    public WorkspaceConfig createWorkspaceConfig(String name)
+            throws ConfigurationException {
+
+        // use workspace template from repository.xml
+        return internalCreateWorkspaceConfig(name, template);
+    }
+
+    /**
+     * Creates a new workspace configuration with the specified name. This
+     * method uses the provided workspace <code>template</code> to create the
+     * repository config instead of the template that is present in the
+     * repository configuration.
+     * <p/>
+     * This method creates a workspace configuration subdirectory,
+     * copies the workspace configuration template into it, and finally
+     * adds the created workspace configuration to the repository.
+     * The initialized workspace configuration object is returned to
+     * the caller.
+     *
+     * @param name workspace name
+     * @param template the workspace template
+     * @return created workspace configuration
+     * @throws ConfigurationException if creating the workspace configuration
+     *                                failed
+     */
+    public WorkspaceConfig createWorkspaceConfig(String name,
+                                                 InputSource template)
+            throws ConfigurationException {
+        ConfigurationParser parser = new ConfigurationParser(new Properties());
+        Element workspaceTemplate = parser.parseXML(template);
+        return internalCreateWorkspaceConfig(name, workspaceTemplate);
     }
 
     /**