Author: julien(a)jboss.com
Date: 2008-01-31 09:11:59 -0500 (Thu, 31 Jan 2008)
New Revision: 9686
Removed:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/ModesInterceptor.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/WindowStatesInterceptor.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
modules/portlet/trunk/test/src/test/resources/portlet-test-war/WEB-INF/jboss-beans.xml
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jboss-beans.xml
Log:
- support for next possible portlet modes
- removed ModesInterceptor and WindowStatesInterceptor to simplify
Deleted:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/ModesInterceptor.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/ModesInterceptor.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/ModesInterceptor.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -1,100 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.aspects.portlet;
-
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.portlet.info.CapabilitiesInfo;
-import org.jboss.portal.portlet.info.ModeInfo;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.invocation.PortletInterceptor;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.container.PortletContainerInvoker;
-import org.jboss.portal.portlet.container.PortletContainer;
-import org.jboss.portal.common.util.ContentInfo;
-import org.jboss.portal.Mode;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * The ModesInterceptor computes the mode for the request as well as the supported
modes.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 7226 $
- */
-public class ModesInterceptor extends PortletInterceptor
-{
-
- protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
- {
- if ((invocation.getContext()).getMode() == null)
- {
- throw new InvocationException("No mode has been provided");
- }
-
- // Compute the supported modes.
- Set modes = getModes(invocation);
-
- // Set the modes on the invocation
- invocation.setSupportedModes(modes);
-
- // Continue the invocation
- return invocation.invokeNext();
- }
-
- /** Compute the supported modes for this invocation. */
- protected Set<Mode> getModes(PortletInvocation invocation)
- {
- // Get content type
- ContentInfo si = invocation.getContext().getMarkupInfo();
- String contentType = si.getContentType().toString();
-
- // Get the modes for this content type
- PortletContainer container =
(PortletContainer)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
PortletContainerInvoker.PORTLET_CONTAINER);
- PortletInfo containerInfo = container.getInfo();
- CapabilitiesInfo capabilities = containerInfo.getCapabilities();
-
- // Add all the modes
- Set<Mode> modes = new HashSet<Mode>();
- for (ModeInfo modeInfo : capabilities.getModes(contentType))
- {
- modes.add(modeInfo.getMode());
- }
-
- // Restrict with what the portal can provide
- Set<Mode> portalModes = invocation.getPortalContext().getModes();
- modes.retainAll(portalModes);
-
- // If user is not logged in then remove the edit mode
- // commenting out for now since it breaks tests
-// AccessMode accessMode = invocation.getInstanceContext().getAccessMode();
-// if (accessMode == AccessMode.READ_ONLY)
-// {
-// modes.remove(Mode.EDIT);
-// }
-
- //
- return modes;
- }
-}
Deleted:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/WindowStatesInterceptor.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/WindowStatesInterceptor.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/aspects/portlet/WindowStatesInterceptor.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -1,69 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.aspects.portlet;
-
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.portlet.invocation.PortletInterceptor;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.WindowState;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The WindowStatesInterceptor computes the window state for the request as well as the
supported window states.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 7028 $
- */
-public class WindowStatesInterceptor extends PortletInterceptor
-{
-
- protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
- {
- if (invocation.getContext().getWindowState() == null)
- {
- throw new InvocationException("No window state has been provided");
- }
-
- // Compute the supported window states
- Set windowStates = getWindowStates(invocation);
-
- //
- invocation.setSupportedWindowStates(windowStates);
-
- // Continue the invocation
- return invocation.invokeNext();
- }
-
- /**
- * Compute the supported window states for this invocation.
- *
- * @param invocation the invocation
- * @return the set of window states
- */
- protected Set<WindowState> getWindowStates(PortletInvocation invocation)
- {
- return new
HashSet<WindowState>(invocation.getPortalContext().getWindowStates());
- }
-}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -27,7 +27,7 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.common.util.SimpleMultiValuedPropertyMap;
-import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.util.ContentInfo;
import org.jboss.portal.portlet.container.PortletContainerInvoker;
import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
@@ -45,6 +45,9 @@
import org.jboss.portal.portlet.spi.WindowContext;
import org.jboss.portal.portlet.spi.ClientContext;
import org.jboss.portal.portlet.state.PropertyContext;
+import org.jboss.portal.portlet.info.CapabilitiesInfo;
+import org.jboss.portal.portlet.info.ModeInfo;
+import org.jboss.portal.Mode;
import javax.portlet.PortalContext;
import javax.portlet.PortletMode;
@@ -63,6 +66,7 @@
import java.util.Map;
import java.util.Set;
import java.util.List;
+import java.util.HashSet;
/**
* PortletRequest implemention. The parameter implementation is left to subclasses that
can implement it differently.
@@ -100,6 +104,12 @@
/** . */
protected final PortletRequestParameterMap requestParameterMap;
+ /** . */
+ protected final Set<Mode> supportedModes;
+
+ /** . */
+ protected final Set<org.jboss.portal.WindowState> supportedWindowStates;
+
public PortletRequestImpl(PortletInvocation invocation)
{
PortletContainerImpl container =
(PortletContainerImpl)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
PortletContainerInvoker.PORTLET_CONTAINER);
@@ -125,6 +135,8 @@
this.preferences = new PortletPreferencesImpl(prefs, containerPrefs, validator,
mode);
this.navigationInfo = navigationInfo;
this.requestParameterMap = PortletRequestParameterMap.create(navigationInfo,
invocation.getContext());
+ this.supportedModes = buildSupportedModes();
+ this.supportedWindowStates = buildSupportedWindowState();
}
// PLT.11.1.1
@@ -346,7 +358,7 @@
}
else
{
- return
invocation.getSupportedModes().contains(org.jboss.portal.Mode.create(portletMode.toString()));
+ return
supportedModes.contains(org.jboss.portal.Mode.create(portletMode.toString()));
}
}
@@ -354,7 +366,7 @@
public boolean isWindowStateAllowed(WindowState windowState)
{
- return
invocation.getSupportedWindowStates().contains(org.jboss.portal.WindowState.create(windowState.toString()));
+ return
supportedWindowStates.contains(org.jboss.portal.WindowState.create(windowState.toString()));
}
//
@@ -520,4 +532,39 @@
protected void initProperties(MultiValuedPropertyMap<String> properties)
{
}
+
+ /**
+ * Build the initial set of supported modes.
+ *
+ * @return the set of portlet modes
+ */
+ private Set<Mode> buildSupportedModes()
+ {
+ // Get content type
+ ContentInfo si = invocation.getContext().getMarkupInfo();
+ String contentType = si.getContentType().toString();
+
+ // Get the modes for this content type
+ CapabilitiesInfo capabilities = container.getInfo().getCapabilities();
+
+ // Add all the modes
+ Set<Mode> modes = new HashSet<Mode>();
+ for (ModeInfo modeInfo : capabilities.getModes(contentType))
+ {
+ modes.add(modeInfo.getMode());
+ }
+
+ //
+ return modes;
+ }
+
+ /**
+ * Build the initial set of supported modes.
+ *
+ * @return the set of portlet modes
+ */
+ private Set<org.jboss.portal.WindowState> buildSupportedWindowState()
+ {
+ return new
HashSet<org.jboss.portal.WindowState>(invocation.getPortalContext().getWindowStates());
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -22,12 +22,16 @@
******************************************************************************/
package org.jboss.portal.portlet.impl.jsr168.api;
-import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.Mode;
import javax.portlet.RenderResponse;
import javax.portlet.PortletMode;
import java.util.Collection;
+import java.util.Set;
+import java.util.LinkedHashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -41,6 +45,9 @@
super(invocation, preq);
}
+ /** . */
+ private Set<Mode> nextModes;
+
public void setTitle(String s)
{
fragment.setTitle(s);
@@ -48,6 +55,47 @@
public void setNextPossiblePortletModes(Collection<PortletMode> portletModes)
{
- throw new NotYetImplemented();
+ if (portletModes != null && portletModes.size() > 0)
+ {
+ if (this.nextModes == null)
+ {
+ nextModes = new LinkedHashSet<Mode>(portletModes.size());
+ }
+ else
+ {
+ nextModes.clear();
+ }
+
+ //
+ for (PortletMode portletMode : portletModes)
+ {
+ if (portletMode != null)
+ {
+ Mode mode = Mode.create(portletMode.toString());
+
+ //
+ if (preq.supportedModes.contains(mode))
+ {
+ nextModes.add(mode);
+ }
+ }
+ else
+ {
+ // Log
+ }
+ }
+ }
}
+
+ public PortletInvocationResponse getResponse()
+ {
+ PortletInvocationResponse response = super.getResponse();
+ if (response instanceof FragmentResponse)
+ {
+ FragmentResponse fragment = (FragmentResponse)response;
+ fragment.setNextModes(nextModes != null ? nextModes : preq.supportedModes);
+ }
+ return response;
+ }
+
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -85,12 +85,6 @@
/** The window context. */
protected WindowContext windowContext;
- /** The window states this portlet can accept. */
- protected Set supportedWindowStates;
-
- /** The modes this portlet can accept. */
- protected Set supportedModes;
-
/** The dispatched request. */
protected HttpServletRequest dreq;
@@ -132,26 +126,6 @@
this.target = target;
}
- public Set getSupportedWindowStates()
- {
- return supportedWindowStates;
- }
-
- public void setSupportedWindowStates(Set supportedWindowStates)
- {
- this.supportedWindowStates = supportedWindowStates;
- }
-
- public Set getSupportedModes()
- {
- return supportedModes;
- }
-
- public void setSupportedModes(Set supportedModes)
- {
- this.supportedModes = supportedModes;
- }
-
/**
* Returns the dispatched http servlet request.
*
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-01-31
14:11:59 UTC (rev 9686)
@@ -24,11 +24,13 @@
import org.jboss.portal.portlet.cache.CacheControl;
import org.jboss.portal.portlet.impl.jsr168.ContentBuffer;
+import org.jboss.portal.Mode;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.Set;
/**
* Data produced.
@@ -60,12 +62,16 @@
/** . */
private CacheControl cacheControl;
+ /** . */
+ private Set<Mode> nextModes;
+
public FragmentResponse()
{
this.buffer = new ContentBuffer();
this.title = null;
this.cacheControl = null;
this.properties = null;
+ this.nextModes = null;
}
public ResponseProperties getProperties()
@@ -184,4 +190,14 @@
{
return buffer;
}
+
+ public Set<Mode> getNextModes()
+ {
+ return nextModes;
+ }
+
+ public void setNextModes(Set<Mode> nextModes)
+ {
+ this.nextModes = nextModes;
+ }
}
Modified:
modules/portlet/trunk/test/src/test/resources/portlet-test-war/WEB-INF/jboss-beans.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/portlet-test-war/WEB-INF/jboss-beans.xml 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/test/src/test/resources/portlet-test-war/WEB-INF/jboss-beans.xml 2008-01-31
14:11:59 UTC (rev 9686)
@@ -82,8 +82,6 @@
class="org.jboss.portal.portlet.aspects.portlet.ContextDispatcherInterceptor">
<property name="servletContainerFactory"><inject
bean="ServletContainerFactory"/></property>
</bean>
- <bean name="WindowStatesInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.WindowStatesInterceptor"/>
- <bean name="ModesInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.ModesInterceptor"/>
<bean name="ProducerCacheInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.ProducerCacheInterceptor"/>
<bean name="ContainerStackFactory"
class="org.jboss.portal.portlet.test.InterceptorStackFactoryImpl">
<property name="interceptors">
@@ -91,8 +89,6 @@
<inject bean="ValveInterceptor"/>
<inject bean="SecureTransportInterceptor"/>
<inject bean="ContextDispatcherInterceptor"/>
- <inject bean="WindowStatesInterceptor"/>
- <inject bean="ModesInterceptor"/>
<inject bean="ProducerCacheInterceptor"/>
</array>
</property>
Modified:
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jboss-beans.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jboss-beans.xml 2008-01-31
13:38:03 UTC (rev 9685)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jboss-beans.xml 2008-01-31
14:11:59 UTC (rev 9686)
@@ -70,8 +70,6 @@
class="org.jboss.portal.portlet.aspects.portlet.ContextDispatcherInterceptor">
<property name="servletContainerFactory"><inject
bean="ServletContainerFactory"/></property>
</bean>
- <bean name="WindowStatesInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.WindowStatesInterceptor"/>
- <bean name="ModesInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.ModesInterceptor"/>
<bean name="ProducerCacheInterceptor"
class="org.jboss.portal.portlet.aspects.portlet.ProducerCacheInterceptor"/>
<bean name="ContainerStackFactory"
class="org.jboss.portal.portlet.test.InterceptorStackFactoryImpl">
<property name="interceptors">
@@ -79,8 +77,6 @@
<inject bean="ValveInterceptor"/>
<inject bean="SecureTransportInterceptor"/>
<inject bean="ContextDispatcherInterceptor"/>
- <inject bean="WindowStatesInterceptor"/>
- <inject bean="ModesInterceptor"/>
<inject bean="ProducerCacheInterceptor"/>
</array>
</property>