Author: julien(a)jboss.com
Date: 2008-04-11 15:12:09 -0400 (Fri, 11 Apr 2008)
New Revision: 10536
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerStateControllerContext.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/CoreEventControllerContext.java
Modified:
branches/JBoss_Portal_Branch_2_7/core/build.xml
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java
Log:
work on integrating portlet controller with 2.7
Modified: branches/JBoss_Portal_Branch_2_7/core/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/build.xml 2008-04-11 13:49:20 UTC (rev 10535)
+++ branches/JBoss_Portal_Branch_2_7/core/build.xml 2008-04-11 19:12:09 UTC (rev 10536)
@@ -327,6 +327,7 @@
<include name="portal-portlet-federation-lib.jar"/>
<include name="portal-portlet-management-lib.jar"/>
<include name="portal-portlet-bridge-lib.jar"/>
+ <include name="portal-portlet-controller-lib.jar"/>
</fileset>
<fileset dir="${portlet.portlet.lib}"
includes="portlet-api.jar"/>
<fileset dir="${jboss.portal/modules/identity.root}/lib"
includes="portal-identity-lib.jar"/>
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -0,0 +1,169 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.core.controller.portlet;
+
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
+import org.jboss.portal.core.model.portal.Window;
+
+import javax.xml.namespace.QName;
+import java.util.Set;
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerPageNavigationalState implements PageNavigationalState
+{
+
+ /** . */
+ private final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ private final Map<String, Window> windows;
+
+ /** . */
+ private final boolean mutable;
+
+ /** . */
+ private final Map<String, WindowNavigationalState> updates;
+
+ public ControllerPageNavigationalState(
+ NavigationalStateContext navigationalStateContext,
+ Map<String, Window> windows,
+ boolean mutable)
+ {
+ this.navigationalStateContext = navigationalStateContext;
+ this.windows = windows;
+ this.mutable = mutable;
+ this.updates = new HashMap<String, WindowNavigationalState>();
+ }
+
+ public ControllerPageNavigationalState(
+ ControllerPageNavigationalState that,
+ boolean mutable)
+ {
+ this.navigationalStateContext = that.navigationalStateContext;
+ this.windows = new HashMap<String, Window>(that.windows);
+ this.mutable = mutable;
+ this.updates = new HashMap<String, WindowNavigationalState>(that.updates);
+ }
+
+ public Set<String> getWindowIds()
+ {
+ return windows.keySet();
+ }
+
+ public WindowNavigationalState getWindowNavigationalState(String s) throws
IllegalArgumentException
+ {
+ WindowNavigationalState update = updates.get(s);
+
+ //
+ if (update != null)
+ {
+ return update;
+ }
+
+ //
+ Window window = windows.get(s);
+
+ //
+ org.jboss.portal.core.model.portal.navstate.WindowNavigationalState wns =
navigationalStateContext.getWindowNavigationalState(window.getId().toString());
+
+ //
+ if (wns == null)
+ {
+ return null;
+ }
+
+ //
+ return new WindowNavigationalState(wns.getContentState(), wns.getMode(),
wns.getWindowState());
+ }
+
+ public void setWindowNavigationalState(String s, WindowNavigationalState
windowNavigationalState) throws IllegalArgumentException, IllegalStateException
+ {
+ if (!mutable)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ updates.put(s, windowNavigationalState);
+
+ //
+// Window window = windows.get(s);
+//
+// //
+// org.jboss.portal.core.model.portal.navstate.WindowNavigationalState wns = new
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState(
+// windowNavigationalState.getWindowState(),
+// windowNavigationalState.getMode(),
+// windowNavigationalState.getPortletNavigationalState()
+// );
+//
+// //
+// navigationalStateContext.setWindowNavigationalState(window.getId().toString(),
wns);
+ }
+
+ public ParameterMap getPublicNavigationalState(String s) throws
IllegalArgumentException
+ {
+ return new ParameterMap();
+ }
+
+ public Set<QName> getPublicNames()
+ {
+ return Collections.emptySet();
+ }
+
+ public String[] getPublicNavigationalState(QName qName) throws
IllegalArgumentException
+ {
+ return new String[0];
+ }
+
+ public void setPublicNavigationalState(QName qName, String[] strings) throws
IllegalArgumentException, IllegalStateException
+ {
+ if (!mutable)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ throw new NotYetImplemented();
+ }
+
+ public void removePublicNavigationalState(QName qName) throws
IllegalArgumentException, IllegalStateException
+ {
+ if (!mutable)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ throw new NotYetImplemented();
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -0,0 +1,180 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.core.controller.portlet;
+
+import org.jboss.portal.portlet.controller.PortletControllerContext;
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.model.instance.InstanceContainer;
+import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.core.impl.model.content.portlet.PortletContent;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
+import org.jboss.portal.common.NotYetImplemented;
+
+import javax.servlet.http.Cookie;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerPortletControllerContext implements PortletControllerContext
+{
+
+ /** . */
+ private final ControllerContext controllerContext;
+
+ /** A map of window name -> portlet info. */
+ private final Map<String, PortletInfo> infos;
+
+ /** A map of window name -> window. */
+ private final Map<String, Window> windows;
+
+ /** A map of window name -> portlet info. */
+ private final Map<String, Instance> instances;
+
+ /** . */
+ private final ControllerStateControllerContext stateControllerContext;
+
+ /** . */
+ private final CoreEventControllerContext eventControllerContext;
+
+ public ControllerPortletControllerContext(
+ ControllerContext controllerContext,
+ Page page,
+ InstanceContainer instanceContainer)
+ {
+ Map<String, PortletInfo> infos = new HashMap<String, PortletInfo>();
+ Map<String, Instance> instances = new HashMap<String, Instance>();
+ Map<String, Window> windows = new HashMap<String, Window>();
+
+ //
+ for (PortalObject child : page.getChildren(PortalObject.WINDOW_MASK))
+ {
+ Window window = (Window)child;
+
+ //
+ Content content = window.getContent();
+
+ //
+ if (content instanceof PortletContent)
+ {
+ PortletContent portletContent = (PortletContent)content;
+
+ //
+ String instanceRef = portletContent.getInstanceRef();
+ Instance instance = instanceContainer.getDefinition(instanceRef);
+
+ //
+ if (instance != null)
+ {
+ try
+ {
+ Portlet portlet = instance.getPortlet();
+ infos.put(window.getName(), portlet.getInfo());
+ instances.put(window.getName(), instance);
+ windows.put(window.getName(), window);
+ }
+ catch (PortletInvokerException ignore)
+ {
+ }
+ }
+ }
+ }
+
+ // State controller context
+ NavigationalStateContext nsContext =
(NavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+
+ //
+ this.stateControllerContext = new ControllerStateControllerContext(nsContext,
windows);
+ this.eventControllerContext = new CoreEventControllerContext();
+ this.controllerContext = controllerContext;
+ this.windows = windows;
+ this.infos = infos;
+ this.instances = instances;
+ }
+
+ public PortletInfo getPortletInfo(String windowId)
+ {
+ return infos.get(windowId);
+ }
+
+ public PortletInvocationContext createPortletInvocationContext(String s,
PageNavigationalState pageNavigationalState)
+ {
+ Window window = windows.get(s);
+
+ //
+ return PortletInvocationFactory.createInvocationContext(controllerContext,
window);
+ }
+
+ public PortletInvocationResponse invoke(ActionInvocation actionInvocation) throws
PortletInvokerException
+ {
+ PortletInvocationFactory.contextualizeAction(actionInvocation);
+
+ //
+ Window window = PortletInvocationFactory.getTargetWindow(actionInvocation);
+
+ //
+ Instance instance = instances.get(window.getName());
+
+ //
+ return instance.invoke(actionInvocation);
+ }
+
+ public PortletInvocationResponse invoke(List<Cookie> cookies, EventInvocation
eventInvocation) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInvocationResponse invoke(ResourceInvocation resourceInvocation) throws
PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public EventControllerContext getEventControllerContext()
+ {
+ return eventControllerContext;
+ }
+
+ public StateControllerContext getStateControllerContext()
+ {
+ return stateControllerContext;
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerStateControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerStateControllerContext.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerStateControllerContext.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.core.controller.portlet;
+
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerStateControllerContext implements StateControllerContext
+{
+
+ /** . */
+ private final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ private final Map<String, Window> windows;
+
+ public ControllerStateControllerContext(NavigationalStateContext
navigationalStateContext, Map<String, Window> windows)
+ {
+ this.navigationalStateContext = navigationalStateContext;
+ this.windows = windows;
+ }
+
+ public PageNavigationalState clonePageNavigationalState(PageNavigationalState
pageNavigationalState, boolean mutable)
+ {
+ return new
ControllerPageNavigationalState((ControllerPageNavigationalState)pageNavigationalState,
mutable);
+ }
+
+ public PageNavigationalState createPageNavigationalState(boolean mutable)
+ {
+ return new ControllerPageNavigationalState(navigationalStateContext, windows,
mutable);
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/CoreEventControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/CoreEventControllerContext.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/CoreEventControllerContext.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.core.controller.portlet;
+
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.event.EventPhaseContext;
+import org.jboss.portal.portlet.controller.event.Event;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.common.NotYetImplemented;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class CoreEventControllerContext implements EventControllerContext
+{
+ public void eventProduced(EventPhaseContext eventPhaseContext, Event event, Event
event1)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void eventConsumed(EventPhaseContext eventPhaseContext, Event event,
PortletInvocationResponse portletInvocationResponse)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void eventFailed(EventPhaseContext eventPhaseContext, Event event, Throwable
throwable)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void eventDiscarded(EventPhaseContext eventPhaseContext, Event event, int i)
+ {
+ throw new NotYetImplemented();
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2008-04-11
13:49:20 UTC (rev 10535)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -59,6 +59,23 @@
public static ThreadLocal<UserContext> userContextTL = new
ThreadLocal<UserContext>();
+ public static InvokePortletCommandFactory
createInvokePortletCommandFactory(ControllerContext controllerContext, Window window)
+ {
+ return new InternalInvokePortletCommandFactory(window, controllerContext);
+ }
+
+ public static PortletInvocationContext createInvocationContext(ControllerContext
controllerContext, InvokePortletCommandFactory cpc)
+ {
+ MarkupInfo markupInfo =
(MarkupInfo)controllerContext.getServerInvocation().getResponse().getContentInfo();
+ return new ControllerPortletInvocationContext(cpc, controllerContext, markupInfo);
+ }
+
+ public static PortletInvocationContext createInvocationContext(ControllerContext
controllerContext, Window window)
+ {
+ InvokePortletCommandFactory ipcf =
createInvokePortletCommandFactory(controllerContext, window);
+ return createInvocationContext(controllerContext, ipcf);
+ }
+
public static RenderInvocation createRender(
ControllerContext controllerContext,
Mode mode,
@@ -68,11 +85,10 @@
Portal portal)
{
PortletContextFactory cf = new PortletContextFactory(controllerContext, portal,
window);
- InternalInvokePortletCommandFactory cpc = new
InternalInvokePortletCommandFactory(window, controllerContext);
+ InvokePortletCommandFactory cpc =
createInvokePortletCommandFactory(controllerContext, window);
return createRender(controllerContext, mode, windowState, navigationalState, cf,
cpc);
}
-
public static ActionInvocation createAction(
ControllerContext controllerContext,
Mode mode,
@@ -84,7 +100,7 @@
Portal portal)
{
PortletContextFactory cf = new PortletContextFactory(controllerContext, portal,
window);
- InternalInvokePortletCommandFactory cpc = new
InternalInvokePortletCommandFactory(window, controllerContext);
+ InvokePortletCommandFactory cpc =
createInvokePortletCommandFactory(controllerContext, window);
return createAction(controllerContext, mode, windowState, navigationalState,
interactionState, form, cf, cpc);
}
@@ -98,33 +114,20 @@
PortletContextFactory cf,
InvokePortletCommandFactory cpc)
{
- MarkupInfo markupInfo =
(MarkupInfo)controllerContext.getServerInvocation().getResponse().getContentInfo();
-
- PortletInvocationContext portletInvocationContext = new
ControllerPortletInvocationContext(cpc, controllerContext, mode, windowState,
navigationalState, markupInfo);
+ PortletInvocationContext portletInvocationContext =
createInvocationContext(controllerContext, cpc);
//
ActionInvocation action = new ActionInvocation(portletInvocationContext);
-
+
+ //
action.setForm(form);
action.setMode(mode);
action.setWindowState(windowState);
action.setNavigationalState(navigationalState);
action.setInteractionState(interactionState);
-
- UserContext userContext = cf.createUserContext();
//
- controllerContextTL.set(controllerContext);
- userContextTL.set(userContext);
-
- // Contextualize
- action.setSecurityContext(cf.createSecurityContext());
- action.setRequestContext(cf.createRequestContext());
- action.setPortalContext(cf.createPortalContext());
- action.setWindowContext(cf.createWindowContext());
- action.setUserContext(userContext);
- action.setServerContext(cf.createServerContext());
- action.setClientContext(cf.createClientContext());
+ contextualizeAction(controllerContext, cf, action);
//
return action;
@@ -138,26 +141,34 @@
PortletContextFactory cf,
InvokePortletCommandFactory cpc)
{
- MarkupInfo markupInfo =
(MarkupInfo)controllerContext.getServerInvocation().getResponse().getContentInfo();
+ PortletInvocationContext portletInvocationContext =
createInvocationContext(controllerContext, cpc);
- PortletInvocationContext portletInvocationContext = new
ControllerPortletInvocationContext(cpc, controllerContext, mode, windowState,
navigationalState, markupInfo);
-
//
RenderInvocation render = new RenderInvocation(portletInvocationContext);
+ //
render.setMode(mode);
render.setWindowState(windowState);
render.setNavigationalState(navigationalState);
//
+ return contextualizeRender(controllerContext, cf, render);
+ }
+
+ public static RenderInvocation contextualizeRender(
+ ControllerContext controllerContext,
+ PortletContextFactory cf,
+ RenderInvocation render)
+ {
render.setAttribute(PortletInvocation.INVOCATION_SCOPE,
"controller_context", controllerContext);
-
+
+ //
UserContext userContext = cf.createUserContext();
//
controllerContextTL.set(controllerContext);
userContextTL.set(userContext);
-
+
// Contextualize
render.setSecurityContext(cf.createSecurityContext());
render.setPortalContext(cf.createPortalContext());
@@ -165,48 +176,46 @@
render.setUserContext(cf.createUserContext());
render.setServerContext(cf.createServerContext());
render.setClientContext(cf.createClientContext());
+
//
return render;
}
- public static class ControllerPortletInvocationContext extends
AbstractPortletInvocationContext
+ public static Window getTargetWindow(ActionInvocation action)
{
- private InvokePortletCommandFactory cmdFactory;
- private ControllerContext controllerContext;
+ ControllerPortletInvocationContext cpic =
(ControllerPortletInvocationContext)action.getContext();
+ InternalInvokePortletCommandFactory iipcf =
(InternalInvokePortletCommandFactory)cpic.cmdFactory;
+ return iipcf.window;
+ }
- public ControllerPortletInvocationContext(InvokePortletCommandFactory cmdFactory,
ControllerContext controllerContext, Mode mode, WindowState windowState, StateString
navigationalState, MarkupInfo markupInfo)
- {
- super(markupInfo);
+ public static void contextualizeAction(ActionInvocation action)
+ {
+ ControllerPortletInvocationContext cpic =
(ControllerPortletInvocationContext)action.getContext();
+ Window window = getTargetWindow(action);
+ contextualizeAction(cpic.controllerContext, new
PortletContextFactory(cpic.controllerContext, window.getPage().getPortal(), window),
action);
+ }
- //
- this.cmdFactory = cmdFactory;
- this.controllerContext = controllerContext;
+ public static void contextualizeAction(
+ ControllerContext controllerContext,
+ PortletContextFactory cf,
+ ActionInvocation action)
+ {
+ UserContext userContext = cf.createUserContext();
- //
- addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
- addResolver(PortletInvocation.REQUEST_SCOPE, controllerContext);
- addResolver(PortletInvocation.PRINCIPAL_SCOPE, controllerContext);
-// addResolver(PortletInvocation.REQUEST_PROPERTIES_SCOPE,
EmptyAttributeResolver.getInstance());
-// addResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, new
MapAttributeResolver());
- }
+ //
+ controllerContextTL.set(controllerContext);
+ userContextTL.set(userContext);
- public HttpServletRequest getClientRequest() throws IllegalStateException
- {
- return
controllerContext.getServerInvocation().getServerContext().getClientRequest();
- }
-
- public HttpServletResponse getClientResponse() throws IllegalStateException
- {
- return
controllerContext.getServerInvocation().getServerContext().getClientResponse();
- }
-
- public String renderURL(ContainerURL containerURL,
org.jboss.portal.portlet.URLFormat urlFormat)
- {
- return PortletInvocationFactory.renderURL(controllerContext, cmdFactory,
containerURL, urlFormat.getWantSecure(), urlFormat.getWantAuthenticated(),
urlFormat.getWantRelative());
- }
+ // Contextualize
+ action.setSecurityContext(cf.createSecurityContext());
+ action.setRequestContext(cf.createRequestContext());
+ action.setPortalContext(cf.createPortalContext());
+ action.setWindowContext(cf.createWindowContext());
+ action.setUserContext(userContext);
+ action.setServerContext(cf.createServerContext());
+ action.setClientContext(cf.createClientContext());
}
-
public static String renderURL(
ControllerContext controllerContext,
InvokePortletCommandFactory factory,
@@ -243,6 +252,48 @@
return controllerContext.renderURL(cmd, info, URLFormat.newInstance(relative,
true));
}
+ public static class ControllerPortletInvocationContext extends
AbstractPortletInvocationContext
+ {
+
+ /** . */
+ private InvokePortletCommandFactory cmdFactory;
+
+ /** . */
+ private ControllerContext controllerContext;
+
+ public ControllerPortletInvocationContext(
+ InvokePortletCommandFactory cmdFactory,
+ ControllerContext controllerContext,
+ MarkupInfo markupInfo)
+ {
+ super(markupInfo);
+
+ //
+ this.cmdFactory = cmdFactory;
+ this.controllerContext = controllerContext;
+
+ //
+ addResolver(PortletInvocation.INVOCATION_SCOPE, new MapAttributeResolver());
+ addResolver(PortletInvocation.REQUEST_SCOPE, controllerContext);
+ addResolver(PortletInvocation.PRINCIPAL_SCOPE, controllerContext);
+ }
+
+ public HttpServletRequest getClientRequest() throws IllegalStateException
+ {
+ return
controllerContext.getServerInvocation().getServerContext().getClientRequest();
+ }
+
+ public HttpServletResponse getClientResponse() throws IllegalStateException
+ {
+ return
controllerContext.getServerInvocation().getServerContext().getClientResponse();
+ }
+
+ public String renderURL(ContainerURL containerURL,
org.jboss.portal.portlet.URLFormat urlFormat)
+ {
+ return PortletInvocationFactory.renderURL(controllerContext, cmdFactory,
containerURL, urlFormat.getWantSecure(), urlFormat.getWantAuthenticated(),
urlFormat.getWantRelative());
+ }
+ }
+
private static class InternalInvokePortletCommandFactory implements
InvokePortletCommandFactory
{
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java 2008-04-11
13:49:20 UTC (rev 10535)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/action/InvokePortletWindowActionCommand.java 2008-04-11
19:12:09 UTC (rev 10536)
@@ -24,63 +24,29 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.common.io.Serialization;
-import org.jboss.portal.common.io.SerializationFilter;
-import org.jboss.portal.common.util.Base64;
import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerException;
import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.controller.NoSuchResourceException;
import org.jboss.portal.core.controller.command.info.ActionCommandInfo;
import org.jboss.portal.core.controller.command.info.CommandInfo;
-import org.jboss.portal.core.controller.command.response.RedirectionResponse;
import org.jboss.portal.core.controller.portlet.ControllerResponseFactory;
+import org.jboss.portal.core.controller.portlet.ControllerPortletControllerContext;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.instance.Instance;
-import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectId;
-import org.jboss.portal.core.model.portal.PortalObjectPath;
import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.model.portal.command.response.UpdateWindowResponse;
-import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.identity.User;
-import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.URLFormat;
import org.jboss.portal.portlet.controller.PortletController;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
-import org.jboss.portal.portlet.controller.event.EventControllerContext;
-import org.jboss.portal.portlet.controller.impl.AbstractPortletControllerContext;
-import org.jboss.portal.portlet.controller.impl.PortletURLRenderer;
-import org.jboss.portal.portlet.controller.impl.URLParameterConstants;
-import org.jboss.portal.portlet.controller.impl.request.ControllerRequestFactory;
-import org.jboss.portal.portlet.controller.impl.request.ControllerRequestParameterNames;
-import org.jboss.portal.portlet.controller.request.ControllerRequest;
import org.jboss.portal.portlet.controller.request.PortletActionRequest;
import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
import org.jboss.portal.portlet.controller.response.PortletResponse;
-import org.jboss.portal.portlet.controller.response.ResourceResponse;
-import org.jboss.portal.portlet.controller.state.AbstractPageNavigationalState;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
-import org.jboss.portal.portlet.controller.state.PageNavigationalStateSerialization;
-import org.jboss.portal.portlet.controller.state.StateControllerContext;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.web.IllegalRequestException;
-import org.jboss.portal.web.WebRequest;
+import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Set;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
@@ -184,309 +150,65 @@
{
try
{
- // State controller context
- NavigationalStateContext nsContext =
(NavigationalStateContext)context.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+ ControllerPortletControllerContext cpcc = new
ControllerPortletControllerContext(
+ context,
+ page,
+ context.getController().getInstanceContainer()
+ );
- ActionStateControllerContext stateControllerContext = new
ActionStateControllerContext(nsContext);
+ //
+ PageNavigationalState pageNS =
cpcc.getStateControllerContext().createPageNavigationalState(false);
- // Portlet controller context
- PortletControllerContext controllerContext;
- HttpServletRequest clientRequest =
context.getServerInvocation().getServerContext().getClientRequest();
- HttpServletResponse clientResponse =
context.getServerInvocation().getServerContext().getClientResponse();
- try
- {
- controllerContext = new ActionPortletControllerContext(clientRequest,
clientResponse, stateControllerContext);
- }
- catch (IOException e)
- {
- throw new ControllerException("Couldn't create
PortletControllerContext!", e);
- }
+ //
+ WindowNavigationalState windowNS =
pageNS.getWindowNavigationalState(window.getName());
- // The type of invocation
- String type = (String)clientRequest.getAttribute(URLParameterConstants.TYPE);
+ //
+ PortletActionRequest actionRequest = new PortletActionRequest(
+ window.getName(),
+ interactionState,
+ formParameters,
+ windowNS,
+ pageNS
+ );
- // Process only portlet type
- // The request decoded if not null
- PageNavigationalState pageNavigationalState = null;
- if (URLParameterConstants.PORTLET_TYPE.equals(type))
- {
- WebRequest wr;
- try
- {
- wr = new WebRequest(clientRequest);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new ControllerException("Couldn't create web
request!", e);
- }
+ //
+ PortletController controller = new PortletController();
- PageNavigationalStateSerialization stateSerialization = new
PageNavigationalStateSerialization(stateControllerContext);
- ControllerRequestFactory factory = new
ControllerRequestFactory(stateSerialization);
- ControllerRequest request = factory.createRequest(wr);
+ //
+ org.jboss.portal.portlet.controller.response.ControllerResponse cr =
controller.process(cpcc, actionRequest);
- org.jboss.portal.portlet.controller.response.ControllerResponse
controllerResponse;
- controllerResponse = new PortletController().process(controllerContext,
request);
+ //
+ if (cr instanceof PageUpdateResponse)
+ {
+ PageUpdateResponse pageUpdate = (PageUpdateResponse)cr;
//
- if (controllerResponse instanceof PageUpdateResponse)
- {
- PageUpdateResponse pageUpdate = (PageUpdateResponse)controllerResponse;
+ PageNavigationalState pageNavigationalState =
pageUpdate.getPageNavigationalState();
- //
- pageNavigationalState = pageUpdate.getPageNavigationalState();
+ //
+ WindowNavigationalState windowNavigationalState =
pageNavigationalState.getWindowNavigationalState(window.getName());
- // We perform a send redirect on actions
- if (request instanceof PortletActionRequest)
- {
- PortletURLRenderer renderer = new
PortletURLRenderer(pageUpdate.getPageNavigationalState(),
- clientRequest, clientResponse, stateSerialization);
+ // Julien : this will not work with several portlets updated, either update
directly the
+ // nav state of all portlets or put all the nav state in the URL !!!!
+ UpdateNavigationalStateResponse windowUpdate = new
UpdateNavigationalStateResponse();
+ windowUpdate.setMode(windowNavigationalState.getMode());
+ windowUpdate.setWindowState(windowNavigationalState.getWindowState());
+
windowUpdate.setNavigationalState(windowNavigationalState.getPortletNavigationalState());
- //
- String url = renderer.renderURL(new URLFormat(null, null, true,
null));
- return new RedirectionResponse(url);
- }
- }
- else if (controllerResponse instanceof ResourceResponse)
- {
- // todo: deal with this later
-
- throw new NotYetImplemented("Resources are not currently
supported!");
-
- /* ResourceResponse resourceResponse =
(ResourceResponse)controllerResponse;
- PortletInvocationResponse pir = resourceResponse.getResponse();
-
- //
- if (pir instanceof ContentResponse)
- {
- ContentResponse contentResponse = (ContentResponse)pir;
-
- //
- if (contentResponse.getType() == ContentResponse.TYPE_EMPTY)
- {
- clientResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
- }
- else
- {
- String contentType = contentResponse.getContentType();
- if (contentType != null)
- {
- clientResponse.setContentType(contentType);
- }
-
- //
- if (contentResponse.getType() == ContentResponse.TYPE_BYTES)
- {
- ServletOutputStream out = null;
- try
- {
- out = clientResponse.getOutputStream();
- out.write(contentResponse.getBytes());
- }
- catch (IOException e)
- {
- throw new ControllerException("Couldn't output
bytes!", e);
- }
- finally
- {
- IOTools.safeClose(out);
- }
- }
- else
- {
- Writer writer = null;
- try
- {
- writer = clientResponse.getWriter();
- writer.write(contentResponse.getChars());
- }
- catch (IOException e)
- {
- throw new ControllerException("Couldn't output
chars!", e);
- }
- finally
- {
- IOTools.safeClose(writer);
- }
- }
- }
- }
- else
- {
- // todo
- }*/
- }
- else if (controllerResponse instanceof PortletResponse)
- {
- PortletResponse portletResponse = (PortletResponse)controllerResponse;
-
- // Let core deal with the response
- return ControllerResponseFactory.createActionResponse(targetId,
portletResponse.getResponse());
-
- }
- else
- {
- throw new PortletInvokerException("Unexpected response type: " +
controllerResponse.getClass().getName());
- }
+ //
+ return ControllerResponseFactory.createActionResponse(targetId,
windowUpdate);
}
else
{
- PageNavigationalStateSerialization serialization = new
PageNavigationalStateSerialization(controllerContext.getStateControllerContext());
- // The nav state provided with the request
- // Unmarshall portal navigational state if it is provided
- pageNavigationalState = null;
- String blah =
clientRequest.getParameter(ControllerRequestParameterNames.PAGE_NAVIGATIONAL_STATE);
- if (blah != null)
- {
- byte[] bytes = Base64.decode(blah, true);
- pageNavigationalState = IOTools.unserialize(serialization,
SerializationFilter.COMPRESSOR, bytes);
- }
+ PortletResponse portletResponse = (PortletResponse)cr;
+
+ //
+ return ControllerResponseFactory.createActionResponse(targetId,
portletResponse.getResponse());
}
}
catch (PortletInvokerException e)
{
return ControllerResponseFactory.createResponse(e);
}
-
- return new UpdateWindowResponse(targetId);
}
-
- private class ActionPortletControllerContext extends AbstractPortletControllerContext
- {
- private final StateControllerContext stateControllerContext;
-
- public ActionPortletControllerContext(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, ActionStateControllerContext
stateControllerContext)
- throws IllegalRequestException, IOException
- {
- super(httpServletRequest, httpServletResponse);
- stateControllerContext.setPortletControllerContext(this);
- this.stateControllerContext = stateControllerContext;
- }
-
- protected Portlet getPortlet(String windowId) throws PortletInvokerException
- {
- PortalObjectId id = PortalObjectId.parse(windowId,
PortalObjectPath.CANONICAL_FORMAT);
- PortalObject portalObject =
context.getController().getPortalObjectContainer().getObject(id);
- if (portalObject instanceof Window)
- {
- Window window = (Window)portalObject;
- Instance instance = getInstance(window);
- if (instance != null)
- {
- return instance.getPortlet();
- }
- }
-
- return null;
- }
-
- protected PortletInvocationResponse invoke(PortletInvocation portletInvocation)
throws PortletInvokerException
- {
- return instance.invoke(portletInvocation);
- }
-
- protected Serialization<PageNavigationalState>
getPageNavigationalStateSerialization()
- {
- return new PageNavigationalStateSerialization(stateControllerContext);
- }
-
- public EventControllerContext getEventControllerContext()
- {
- return null;
- }
-
- public StateControllerContext getStateControllerContext()
- {
- return stateControllerContext;
- }
- }
-
- private static class ActionPageNavigationalState extends
AbstractPageNavigationalState
- {
- private ActionStateControllerContext controllerContext;
-
- private ActionPageNavigationalState(ActionStateControllerContext controllerContext,
boolean modifiable)
- {
- super(modifiable);
- this.controllerContext = controllerContext;
- }
-
- private NavigationalStateContext getNSContext()
- {
- return controllerContext.nsContext;
- }
-
- private PortletControllerContext getPCContext()
- {
- return controllerContext.controllerContext;
- }
-
- public Set<String> getWindowIds()
- {
- return getNSContext().getKeys();
- }
-
- public WindowNavigationalState getWindowNavigationalState(String windowId) throws
IllegalArgumentException
- {
- org.jboss.portal.core.model.portal.navstate.WindowNavigationalState coreNS =
getNSContext().getWindowNavigationalState(windowId);
-
- if (coreNS != null)
- {
- return new WindowNavigationalState(coreNS.getContentState(),
coreNS.getMode(), coreNS.getWindowState());
- }
- else
- {
- return null;
- }
- }
-
- public void setWindowNavigationalState(String windowId, WindowNavigationalState
windowNS) throws IllegalArgumentException, IllegalStateException
- {
- if (windowNS != null)
- {
- org.jboss.portal.core.model.portal.navstate.WindowNavigationalState coreNS =
- new
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState(windowNS.getWindowState(),
- windowNS.getMode(), windowNS.getPortletNavigationalState());
- getNSContext().setWindowNavigationalState(windowId, coreNS);
- }
- else
- {
- getNSContext().setWindowNavigationalState(windowId, null);
- }
- }
-
- protected PortletInfo getPortletInfo(String windowId)
- {
- return getPCContext().getPortletInfo(windowId);
- }
- }
-
- private static class ActionStateControllerContext implements StateControllerContext
- {
- private PortletControllerContext controllerContext;
- private NavigationalStateContext nsContext;
-
- public ActionStateControllerContext(NavigationalStateContext nsContext)
- {
- this.nsContext = nsContext;
- }
-
- public PageNavigationalState clonePageNavigationalState(PageNavigationalState
pageNavigationalState, boolean modifiable)
- {
- if (pageNavigationalState != null)
- {
- return new ActionPageNavigationalState(this, modifiable);
- }
- return null;
- }
-
- public PageNavigationalState createPageNavigationalState(boolean modifiable)
- {
- return new ActionPageNavigationalState(this, modifiable);
- }
-
- public void setPortletControllerContext(PortletControllerContext
portletControllerContext)
- {
- this.controllerContext = portletControllerContext;
- }
- }
}