Author: julien(a)jboss.com
Date: 2007-03-19 18:13:03 -0400 (Mon, 19 Mar 2007)
New Revision: 6757
Modified:
trunk/portlet-server/src/main/org/jboss/portal/portlet/test/PortletController.java
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletPreferencesImpl.java
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyContext.java
trunk/portlet/src/main/org/jboss/portal/portlet/state/PropertyContext.java
trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestContext.java
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestParameters.java
Log:
better implementation of portlet preferences
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletPreferencesImpl.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletPreferencesImpl.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/api/PortletPreferencesImpl.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -29,6 +29,7 @@
import org.jboss.portal.portlet.state.PropertyContext;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPreferenceInfo;
import org.jboss.portal.portlet.impl.jsr168.info.ContainerPreferencesInfo;
+import org.jboss.portal.portlet.info.PreferenceInfo;
import javax.portlet.PortletPreferences;
import javax.portlet.PreferencesValidator;
@@ -97,7 +98,7 @@
public Enumeration getNames()
{
// Clone the system names
- Set names = new HashSet(prefs.getPortletKeys());
+ Set names = new HashSet(containerPrefs.getKeys());
// Add the user
names.addAll(prefs.getKeys());
@@ -145,7 +146,7 @@
value = prefs.getValue(key);
// If does not exist or read only use what the default one
- if (value == null || isReadOnly(key))
+ if (value == null || isDDReadOnly(key))
{
ContainerPreferenceInfo containerPref =
containerPrefs.getContainerPreference(key);
if (containerPref != null)
@@ -157,6 +158,24 @@
return value;
}
+ /**
+ * Return true if the preferences is marked as read only in the portlet.xml
deployment
+ * descriptor.
+ *
+ * @param key the preference key
+ * @return the read only value
+ */
+ private boolean isDDReadOnly(String key)
+ {
+ PreferenceInfo pref = containerPrefs.getPreference(key);
+ if (pref != null)
+ {
+ return Boolean.TRUE.equals(pref.isReadOnly());
+ }
+ return false;
+ }
+
+
public String getValue(String key, String def) throws IllegalArgumentException
{
if (key == null)
@@ -200,13 +219,13 @@
if (mode == ACTION)
{
// The accurate value is to combine what the portlet developer and the consumer
specifies
- return prefs.isReadOnly() || prefs.isReadOnly(key);
+ return prefs.isReadOnly() || isDDReadOnly(key);
}
else
{
// During render we cannot be aware of the consumer
// intent with respect to the access mode of the current state
- return prefs.isReadOnly(key);
+ return isDDReadOnly(key);
}
}
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyContext.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyContext.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyContext.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -23,8 +23,6 @@
package org.jboss.portal.portlet.state;
import org.jboss.portal.common.value.Value;
-import org.jboss.portal.portlet.info.PreferenceInfo;
-import org.jboss.portal.portlet.info.PreferencesInfo;
import java.util.Collections;
import java.util.Set;
@@ -45,39 +43,37 @@
/** The state has been succesfully updated. */
public static final int UPDATE_SUCCESSFUL = 2;
+ /** True if render phase. */
+ private final boolean render;
+
/** The user prefs. */
private PropertyMap prefs;
- /** The runtime preferences info for the system. */
- private PreferencesInfo portletPrefs;
-
/** The access mode. */
- private AccessMode access;
+ private final AccessMode access;
/** State change status. */
private int status;
/**
- * Create a new object. If the userPrefs argument is null then the object is
considered as globally read only.
+ * Create a new object.
*
- * @param userPrefs the user prefs
- * @param portletPrefs the portlet prefs
+ * @param prefs the user prefs
* @throws IllegalArgumentException if the portletPrefs are null
*/
- public AbstractPropertyContext(AccessMode access, PropertyMap userPrefs,
PreferencesInfo portletPrefs) throws IllegalArgumentException
+ public AbstractPropertyContext(
+ AccessMode access,
+ PropertyMap prefs,
+ boolean render) throws IllegalArgumentException
{
if (access == null)
{
throw new IllegalArgumentException("No access mode provided");
}
- if (portletPrefs == null)
- {
- throw new IllegalArgumentException("No null portlet prefs can be
provided");
- }
this.access = access;
- this.prefs = userPrefs;
- this.portletPrefs = portletPrefs;
+ this.prefs = prefs;
this.status = NO_CHANGE;
+ this.render = render;
}
public void update(PropertyChange[] changes) throws IllegalStateException
@@ -129,23 +125,12 @@
return prefs.getProperty(key);
}
- public Set getPortletKeys() throws IllegalArgumentException
+ public boolean isReadOnly()
{
- return portletPrefs.getKeys();
- }
-
- public boolean isReadOnly(String key) throws IllegalArgumentException
- {
- PreferenceInfo pref = portletPrefs.getPreference(key);
- if (pref != null)
+ if (render)
{
- return Boolean.TRUE.equals(pref.isReadOnly());
+ throw new IllegalStateException("Not authorized to call this method during
the render phase");
}
- return false;
- }
-
- public boolean isReadOnly()
- {
return access == AccessMode.READ_ONLY;
}
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/state/PropertyContext.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/state/PropertyContext.java 2007-03-19
20:58:40 UTC (rev 6756)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/state/PropertyContext.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -59,8 +59,9 @@
* during the render request will produce a non accurate value.
*
* @return true if the preferences are read only
+ * @throws IllegalStateException if this is called during render phase
*/
- boolean isReadOnly();
+ boolean isReadOnly() throws IllegalStateException;
/**
* Update the preferences.
@@ -69,21 +70,4 @@
* @throws IllegalArgumentException if any change is not valid
*/
void update(PropertyChange[] changes) throws IllegalStateException;
-
- /**
- * Return the key set.
- *
- * @return the system key set
- * @throws IllegalArgumentException if the array is null
- */
- Set getPortletKeys() throws IllegalArgumentException;
-
- /**
- * Say if the property key is marked as read only or not.
- *
- * @param key the requested key
- * @return the read only value
- * @throws IllegalArgumentException if the key or the array is null
- */
- boolean isReadOnly(String key) throws IllegalArgumentException;
}
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -37,6 +37,7 @@
import org.jboss.portal.portlet.info.PreferencesInfo;
import org.jboss.portal.portlet.invocation.ActionInvocation;
import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.spi.InstanceContext;
import org.jboss.portal.portlet.state.AbstractPropertyContext;
@@ -217,8 +218,10 @@
// Create prefs
PortletInfo info = portlet.getInfo();
- PreferencesInfo prefsInfo = info.getPreferences();
- AbstractPropertyContext prefs = new AbstractPropertyContext(access,
context.isStateful() ? ((StatefulContext)context).getProperties() : null, prefsInfo);
+ AbstractPropertyContext prefs = new AbstractPropertyContext(
+ access,
+ context.isStateful() ? ((StatefulContext)context).getProperties() : null,
+ invocation instanceof RenderInvocation);
//
PortletInvocationResponse response;
Modified:
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestContext.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestContext.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestContext.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -62,4 +62,13 @@
{
return httpTestContext.rewriteURLForNode(url, nodeId);
}
+
+ public String getParameter(String parameterName)
+ {
+ if (parameterName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return
(String)httpTestContext.getParametrization().getParameterValue(parameterName).get();
+ }
}
Modified:
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestParameters.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestParameters.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestParameters.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -35,7 +35,8 @@
* The "mutable" literal means that the portal will allow the portlet
container to modify
* the state and take in account any clone operation done during the request. The
"immutable"
* literal means that the portal will call the portlet container without allowing him
to
- * perform cloning operations.
+ * perform cloning operations. When the parameter is not specific explicitely the
default
+ * behavior should be to treat the value a mutable.
*/
public static final String PORTAL_PORTLET_STATE_MANAGEMENT =
"portal.portlet_state_management";
Modified:
trunk/portlet-server/src/main/org/jboss/portal/portlet/test/PortletController.java
===================================================================
---
trunk/portlet-server/src/main/org/jboss/portal/portlet/test/PortletController.java 2007-03-19
20:58:40 UTC (rev 6756)
+++
trunk/portlet-server/src/main/org/jboss/portal/portlet/test/PortletController.java 2007-03-19
22:13:03 UTC (rev 6757)
@@ -24,6 +24,8 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.test.framework.portlet.PortletTestDriver;
+import org.jboss.portal.test.framework.portlet.PortletTestParameters;
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.invocation.EmptyAttributeResolver;
import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
@@ -123,9 +125,6 @@
public void handle(ServerInvocation invocation) throws ServerException
{
-
-// PortletTestDriver.getInstance().
-
try
{
String requestPath = invocation.getServerContext().getPortalRequestPath();
@@ -389,22 +388,47 @@
writer.close();
}
- /** An instance context implementation that stores */
+ /**
+ * An instance context implementation that stores the cloned context in the HTTP
session of the user.
+ */
protected class InstanceContextImpl implements InstanceContext
{
+ /** . */
+ private static final String CLONE_OF = "clone_of_";
+
+ /** . */
+ private boolean anonymous;
+
+ /** . */
private HttpServletRequest req;
+
+ /** . */
private AccessMode accessMode;
+
+ /** . */
private PortletContext portletContext;
+
+ /** . */
private PortletContext cloneContext;
- private static final String CLONE_OF = "clone_of_";
- public InstanceContextImpl(Portlet portlet, HttpServletRequest req)
+ public InstanceContextImpl(Portlet portlet, HttpServletRequest req, boolean
anonymous)
{
this.portletContext = portlet.getContext();
this.req = req;
- this.cloneContext = (PortletContext)req.getSession().getAttribute(CLONE_OF +
portlet.getContext().getId());
- this.accessMode = cloneContext == null ? AccessMode.CLONE_BEFORE_WRITE :
AccessMode.READ_WRITE;
+ this.anonymous = anonymous;
+
+ //
+ if (anonymous)
+ {
+ this.accessMode = AccessMode.READ_ONLY;
+ this.cloneContext = null;
+ }
+ else
+ {
+ this.accessMode = cloneContext == null ? AccessMode.CLONE_BEFORE_WRITE :
AccessMode.READ_WRITE;
+ this.cloneContext = (PortletContext)req.getSession().getAttribute(CLONE_OF +
portlet.getContext().getId());
+ }
}
public String getId()
@@ -414,6 +438,10 @@
public void onStateEvent(StateEvent event)
{
+ if (anonymous)
+ {
+ throw new IllegalStateException("The portal should not receive event
callbacks in anonymous mode");
+ }
req.getSession().setAttribute(CLONE_OF + this.portletContext.getId(),
event.getPortletContext());
}
@@ -515,11 +543,13 @@
public void update(final ServerInvocation serverInvocation, PortletInvocation
invocation)
{
+ String ppsm =
PortletTestDriver.getPortletTestContext().getParameter(PortletTestParameters.PORTAL_PORTLET_STATE_MANAGEMENT);
+ boolean anonymous = "immutable".equals(ppsm);
final PortletInvocationContextImpl invocationContext =
(PortletInvocationContextImpl)invocation.getPortletContext();
PortalContext portalContext = new TestPortalContext();
SecurityContext securityContext = new
AbstractSecurityContext(invocationContext.getClientRequest());
RequestContext requestContext = new
AbstractRequestContext(invocationContext.getClientRequest(),
invocationContext.getClientResponse());
- InstanceContext instanceContext = new
InstanceContextImpl(invocationContext.portlet, invocationContext.getClientRequest());
+ InstanceContext instanceContext = new
InstanceContextImpl(invocationContext.portlet, invocationContext.getClientRequest(),
anonymous);
//
WindowContext windowContext = new WindowContext()