Author: fmeschbe
Date: Fri May 30 04:30:48 2008
New Revision: 661655

URL: http://svn.apache.org/viewvc?rev=661655&view=rev
Log:
SLING-488 Reset default workspace to actual default workspace used
by the Repository.login method if the default workspace is not
configured in Sling.

Modified:
    
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java

Modified: 
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java?rev=661655&r1=661654&r2=661655&view=diff
==============================================================================
--- 
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
 (original)
+++ 
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
 Fri May 30 04:30:48 2008
@@ -172,11 +172,23 @@
      * sure the SLING-256 rule is enforced.
      */
     public final String getDefaultWorkspace() {
-        if (defaultWorkspace == null || defaultWorkspace.trim().length() == 0) 
{
-            // SLING-256
-            return null;
+        return defaultWorkspace;
+    }
+
+    private void setDefaultWorkspace(String defaultWorkspace) {
+        // normalize the default workspace name: trim leading and trailing
+        // blanks and set to null in case the trimmed name is empty
+        if (defaultWorkspace != null) {
+            defaultWorkspace = defaultWorkspace.trim();
+            if (defaultWorkspace.length() == 0) {
+                defaultWorkspace = null;
+            }
         }
-        return this.defaultWorkspace;
+
+        log(LogService.LOG_DEBUG,
+            "setDefaultWorkspace: Setting the default workspace to "
+                + defaultWorkspace);
+        this.defaultWorkspace = defaultWorkspace;
     }
 
     /**
@@ -225,7 +237,19 @@
         try {
             log(LogService.LOG_DEBUG, "login: Logging in to workspace '"
                 + workspace + "'");
-            return this.getPoolManager().login(credentials, workspace);
+            Session session = getPoolManager().login(credentials, workspace);
+
+            // if the defualt workspace is null, acquire a session from the 
pool
+            // and use the workspace used as the new default workspace
+            if (workspace == null) {
+                String defaultWorkspace = session.getWorkspace().getName();
+                log(LogService.LOG_DEBUG, "login: Using " + defaultWorkspace
+                    + " as the default workspace instead of 'null'");
+                setDefaultWorkspace(defaultWorkspace);
+            }
+
+            return session;
+
         } catch (NoSuchWorkspaceException nswe) {
             // if the desired workspace is the default workspace, try to create
             // (but not if using the repository-supplied default workspace)
@@ -577,14 +601,8 @@
         @SuppressWarnings("unchecked")
         Dictionary<String, Object> properties = 
componentContext.getProperties();
 
-        // ensure the default workspace is not null and not empty
-        this.defaultWorkspace = this.getProperty(properties,
-            PROPERTY_DEFAULT_WORKSPACE, null);
-        if (this.defaultWorkspace != null
-            && this.defaultWorkspace.length() == 0) {
-            this.defaultWorkspace = null;
-        }
-
+        setDefaultWorkspace(this.getProperty(properties,
+            PROPERTY_DEFAULT_WORKSPACE, null));
         this.anonUser = this.getProperty(properties, PROPERTY_ANONYMOUS_USER,
             DEFAULT_ANONYMOUS_USER);
         this.anonPass = this.getProperty(properties, PROPERTY_ANONYMOUS_PASS,


Reply via email to