You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by at...@apache.org on 2011/09/15 03:47:34 UTC

svn commit: r1170921 - in /portals/pluto/branches/pluto-2.0.x: pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java

Author: ate
Date: Thu Sep 15 01:47:33 2011
New Revision: 1170921

URL: http://svn.apache.org/viewvc?rev=1170921&view=rev
Log:
PLUTO-609: Candidate reimplementation for new interpretation of PLT.17.1 concerning getting and setting of null values for portlet preferences.
See: https://issues.apache.org/jira/browse/PLUTO-609?focusedCommentId=13105053#comment-13105053 for details
 

Modified:
    portals/pluto/branches/pluto-2.0.x/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java
    portals/pluto/branches/pluto-2.0.x/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java

Modified: portals/pluto/branches/pluto-2.0.x/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-2.0.x/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java?rev=1170921&r1=1170920&r2=1170921&view=diff
==============================================================================
--- portals/pluto/branches/pluto-2.0.x/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java (original)
+++ portals/pluto/branches/pluto-2.0.x/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletPreferencesImpl.java Thu Sep 15 01:47:33 2011
@@ -28,15 +28,15 @@ import javax.portlet.PreferencesValidato
 import javax.portlet.ReadOnlyException;
 import javax.portlet.ValidatorException;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.pluto.container.PortletPreference;
 import org.apache.pluto.container.PortletContainer;
 import org.apache.pluto.container.PortletContainerException;
-import org.apache.pluto.container.PortletPreference;
 import org.apache.pluto.container.PortletPreferencesService;
 import org.apache.pluto.container.PortletWindow;
 import org.apache.pluto.container.om.portlet.PortletDefinition;
 import org.apache.pluto.container.util.StringManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of the <code>javax.portlet.PortletPreferences</code>
@@ -138,21 +138,17 @@ public class PortletPreferencesImpl impl
     }
 
     public String getValue(String key, String defaultValue) {
-        if (key == null) {
-            throw new IllegalArgumentException(
-                    EXCEPTIONS.getString("error.null", "Preference key "));
-        }
-        PortletPreference pref = preferences.get(key);
-        if (pref == null) {
-            return defaultValue;
-        }
-        
-        String[] values = pref.getValues();
-        if (values == null || values.length == 0) {
-            return null;
+        String[] values = getValues(key, new String[] { defaultValue });
+        String value = defaultValue;
+        if (values != null) {
+            if (values.length == 0) {
+                value = null;
+            }
+            else if (values[0] != null) {
+                value = values[0];
+            }
         }
-        
-        return values[0];
+        return value;
     }
 
     public String[] getValues(String key, String[] defaultValues) {
@@ -160,12 +156,15 @@ public class PortletPreferencesImpl impl
             throw new IllegalArgumentException(
             		EXCEPTIONS.getString("error.null", "Preference key "));
         }
+        String[] values = null;
         PortletPreference pref = preferences.get(key);
-        if (pref == null) {
-            return defaultValues;
+        if (pref != null) {
+            values = pref.getValues();
         }
-        
-        return pref.getValues();
+        if (values == null) {
+            values = defaultValues;
+        }
+        return values;
     }
 
     public void setValue(String key, String value) throws ReadOnlyException {
@@ -174,10 +173,11 @@ public class PortletPreferencesImpl impl
             		"error.preference.readonly", key));
         }
         PortletPreference pref = preferences.get(key);
+        String[] values = value == null ? new String[0] : new String[] { value };
         if (pref != null) {
-            pref.setValues(new String[] { value });
+            pref.setValues(values);
         } else {
-            pref = new PortletPreferenceImpl(key, new String[] { value });
+            pref = new PortletPreferenceImpl(key, values);
             preferences.put(key, pref);
         }
     }
@@ -187,6 +187,9 @@ public class PortletPreferencesImpl impl
             throw new ReadOnlyException(EXCEPTIONS.getString(
             		"error.preference.readonly", key));
         }
+        if (values == null) {
+            values = new String[0];
+        }
         PortletPreference pref = preferences.get(key);
         if (pref != null) {
             pref.setValues(values);

Modified: portals/pluto/branches/pluto-2.0.x/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-2.0.x/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java?rev=1170921&r1=1170920&r2=1170921&view=diff
==============================================================================
--- portals/pluto/branches/pluto-2.0.x/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java (original)
+++ portals/pluto/branches/pluto-2.0.x/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java Thu Sep 15 01:47:33 2011
@@ -182,10 +182,11 @@ public class PreferenceCommonTest extend
         }
 
         String value = preferences.getValue("TEST", DEF_VALUE);
-        if (DEF_VALUE.equals(value)) {
+        // see PLUTO-609: behavioral change!
+        if (null == value) {
         	result.setReturnCode(TestResult.PASSED);
         } else {
-        	TestUtils.failOnAssertion("preference value", value, DEF_VALUE, result);
+        	TestUtils.failOnAssertion("preference value", value, null, result);
         }
         return result;
     }