001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2007, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.wsrp.producer;
023:
024: import org.jboss.portal.common.util.MarkupInfo;
025: import org.jboss.portal.portlet.StateString;
026: import org.jboss.portal.portlet.invocation.ActionInvocation;
027: import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
028: import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
029: import org.jboss.portal.portlet.invocation.response.RenderResponse;
030: import org.jboss.portal.portlet.spi.PortalContext;
031: import org.jboss.portal.portlet.spi.SecurityContext;
032: import org.jboss.portal.portlet.spi.UserContext;
033: import org.jboss.portal.portlet.spi.WindowContext;
034: import org.jboss.portal.portlet.state.AccessMode;
035: import org.jboss.portal.wsrp.WSRPExceptionFactory;
036: import org.jboss.portal.wsrp.WSRPTypeFactory;
037: import org.jboss.portal.wsrp.WSRPUtils;
038: import org.jboss.portal.wsrp.core.InteractionParams;
039: import org.jboss.portal.wsrp.core.InvalidHandleFault;
040: import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
041: import org.jboss.portal.wsrp.core.MarkupParams;
042: import org.jboss.portal.wsrp.core.MissingParametersFault;
043: import org.jboss.portal.wsrp.core.OperationFailedFault;
044: import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
045: import org.jboss.portal.wsrp.core.PortletContext;
046: import org.jboss.portal.wsrp.core.RegistrationContext;
047: import org.jboss.portal.wsrp.core.RuntimeContext;
048: import org.jboss.portal.wsrp.core.StateChange;
049: import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
050: import org.jboss.portal.wsrp.core.UnsupportedModeFault;
051: import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
052: import org.jboss.portal.wsrp.core.UpdateResponse;
053:
054: /**
055: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
056: * @version $Revision: 8784 $
057: * @since 2.6
058: */
059: class ActionRequestProcessor extends RequestProcessor {
060: private final PerformBlockingInteraction performBlockingInteraction;
061: private final InteractionParams interactionParams;
062:
063: public ActionRequestProcessor(WSRPProducerImpl producer,
064: PerformBlockingInteraction performBlockingInteraction,
065: InteractionParams interactionParams)
066: throws UnsupportedMimeTypeFault,
067: UnsupportedWindowStateFault, InvalidHandleFault,
068: UnsupportedModeFault, MissingParametersFault,
069: InvalidRegistrationFault, OperationFailedFault {
070: super (producer);
071: this .performBlockingInteraction = performBlockingInteraction;
072: this .interactionParams = interactionParams;
073: prepareInvocation();
074: }
075:
076: RegistrationContext getRegistrationContext() {
077: return performBlockingInteraction.getRegistrationContext();
078: }
079:
080: RuntimeContext getRuntimeContext() {
081: return performBlockingInteraction.getRuntimeContext();
082: }
083:
084: MarkupParams getMarkupParams() {
085: return performBlockingInteraction.getMarkupParams();
086: }
087:
088: PortletContext getPortletContext() {
089: return performBlockingInteraction.getPortletContext();
090: }
091:
092: org.jboss.portal.wsrp.core.UserContext getUserContext() {
093: return performBlockingInteraction.getUserContext();
094: }
095:
096: String getContextName() {
097: return MarkupHandler.PBI;
098: }
099:
100: AccessMode getAccessMode() {
101: StateChange stateChange = interactionParams
102: .getPortletStateChange();
103: WSRPExceptionFactory
104: .throwMissingParametersFaultIfValueIsMissing(
105: stateChange, "portletStateChange",
106: "InteractionParams");
107: return WSRPUtils.getAccessModeFromStateChange(stateChange);
108: }
109:
110: void initInvocation(StateString navigationalState,
111: SecurityContext securityContext, MarkupInfo markupInfo,
112: PortalContext portalContext, UserContext userContext,
113: WindowContext windowContext) {
114:
115: StateString interactionState = createNavigationalState(interactionParams
116: .getInteractionState());
117:
118: WSRPActionContext actionContext = WSRPActionContext
119: .createActionContext(navigationalState,
120: securityContext, markupInfo, portalContext,
121: userContext, instanceContext, windowContext,
122: markupRequest, interactionState,
123: interactionParams);
124: setInvocation(new ActionInvocation(actionContext));
125: actionContext.contextualize(invocation);
126: invocation.setTarget(portlet.getContext());
127: }
128:
129: Object processResponse(PortletInvocationResponse response) {
130: if (response instanceof RenderResponse) {
131: RenderResponse renderResult = (RenderResponse) response;
132: UpdateResponse updateResponse = WSRPTypeFactory
133: .createUpdateResponse();
134: updateResponse
135: .setNewMode(WSRPUtils
136: .convertJSR168PortletModeNameToWSRPName(getNewStateOrNull(
137: renderResult, true)));
138: updateResponse
139: .setNewWindowState(WSRPUtils
140: .convertJSR168WindowStateNameToWSRPName(getNewStateOrNull(
141: renderResult, false)));
142: StateString ns = renderResult.getNavigationalState();
143: updateResponse.setNavigationalState(ns != null ? ns
144: .getStringValue() : null);
145:
146: // deal with implicit cloning and state modification
147: if (instanceContext.wasModified()) {
148: PortletContext updatedPortletContext = WSRPUtils
149: .convertToWSRPPortletContext(instanceContext
150: .getPortletContext());
151: updateResponse.setPortletContext(updatedPortletContext);
152: }
153:
154: return WSRPTypeFactory
155: .createBlockingInteractionResponse(updateResponse);
156: } else {
157: // result should be HTTPRedirectionResult
158: HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse) response;
159: return WSRPTypeFactory
160: .createBlockingInteractionResponse(redirectionResult
161: .getLocation());
162: }
163: }
164:
165: private String getNewStateOrNull(RenderResponse renderResult,
166: boolean forMode) {
167: Object state = forMode ? renderResult.getMode() : renderResult
168: .getWindowState();
169: return state != null ? state.toString() : null;
170: }
171: }
|