incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1404917 - /sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
Date Fri, 02 Nov 2012 10:55:29 GMT
Author: cziegeler
Date: Fri Nov  2 10:55:28 2012
New Revision: 1404917

URL: http://svn.apache.org/viewvc?rev=1404917&view=rev
Log:
Make preferences handling more configurable

Modified:
    sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java

Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java?rev=1404917&r1=1404916&r2=1404917&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
(original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
Fri Nov  2 10:55:28 2012
@@ -158,33 +158,37 @@ implements PortletPreferencesService {
     }
 
     /**
-     * Return the key for the preferences.
-     * The returned key starts with a slash
+     * Return the path for the preferences.
      */
-    private String getPreferencesKey(final PortletRequest request,
+    private String getPreferencesPath(final PortletRequest request,
             final SlingPortletWindowId windowId,
             final boolean read) {
-        String key = null;
+        String path = null;
         final PreferencesKeyGenerator generator = (PreferencesKeyGenerator) this.keyGeneratorTracker.getService();
         if ( generator != null ) {
-            key = generator.getPreferencesKey(windowId, request, read);
-            if ( key != null ) {
-                final String[] parts = key.split("/");
+            path = generator.getPreferencesKey(windowId, request, read);
+            if ( path != null ) {
+                final boolean isPath = path.charAt(0) == '/';
+                final String[] parts = (isPath ? path.substring(1) : path).split("/");
                 final StringBuilder sb = new StringBuilder();
+                if ( !isPath ) {
+                    sb.append(DEFAULT_USER_PREFS_PATH);
+                }
                 for(final String p : parts) {
                     sb.append('/');
                     sb.append(PortalUtil.encodePropertyName(p));
                 }
+                path = sb.toString();
             }
         } else {
             // anonymous is not allowed to change preferences!
             if ( !PortalUtil.isAnonymous(request) ) {
                 final Session userSession = PortalUtil.getUserSession(request);
-                key = "/" + userSession.getUserID() + '/' + PortalUtil.encodePropertyName(windowId.getStringId());
+                path = DEFAULT_USER_PREFS_PATH + '/' + userSession.getUserID() + '/' + PortalUtil.encodePropertyName(windowId.getStringId());
             }
 
         }
-        return key;
+        return path;
     }
 
     /**
@@ -195,15 +199,14 @@ implements PortletPreferencesService {
     throws PortletContainerException {
         final SlingPortletWindowId windowId = (SlingPortletWindowId)portletWindow.getId();
 
-        final String key = this.getPreferencesKey(request, windowId, true);
-        logger.debug("Getting stored preferences for {} at {}", windowId, key);
-        if ( key == null ) {
+        final String path = this.getPreferencesPath(request, windowId, true);
+        logger.debug("Getting stored preferences for {} at {}", windowId, path);
+        if ( path == null ) {
             return EMPTY_MAP;
         }
 
         Session adminSession = null;
         // check if preferences are stored in repository
-        final String path = DEFAULT_USER_PREFS_PATH + key;
         try {
             adminSession = this.repository.loginAdministrative(null);
             if ( !adminSession.itemExists(path) ) {
@@ -261,12 +264,11 @@ implements PortletPreferencesService {
                     throws PortletContainerException {
         final SlingPortletWindowId windowId = (SlingPortletWindowId)portletWindow.getId();
 
-        final String key = this.getPreferencesKey(request, windowId, false);
-        logger.debug("Setting stored preferences for {} at {}", windowId, key);
-        if ( key == null ) {
+        final String path = this.getPreferencesPath(request, windowId, false);
+        logger.debug("Setting stored preferences for {} at {}", windowId, path);
+        if ( path == null ) {
             throw new PortletContainerException("User is not allowed to store portlet preferences.");
         }
-        final String path = DEFAULT_USER_PREFS_PATH + key;
 
         Session adminSession = null;
         try {



Mime
View raw message