portlet integration not in this milestone
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.action.portlet;
|
||||
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletMode;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.webflow.action.AbstractAction;
|
||||
import org.springframework.webflow.context.portlet.PortletExternalContext;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
/**
|
||||
* Action implementation that changes a PortletResponse mode. The action only generates the
|
||||
* {@link org.springframework.webflow.action.AbstractAction#success()} event. All error cases result in an exception
|
||||
* being thrown.
|
||||
* <p>
|
||||
* This class is usefull when you want to change the current PortletMode before entering a specific state, e.g. it can
|
||||
* be the first state in a subflow.
|
||||
* <p>
|
||||
* Note: if you can, change the PortletMode using Portlet URLs (PortletURL class or portlet TAG).
|
||||
*
|
||||
* @author J.Enrique Ruiz
|
||||
* @author Cesar Ordinana
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class SetPortletModeAction extends AbstractAction {
|
||||
|
||||
/**
|
||||
* The portlet mode to set can be specified in an action state action attribute with this name ("portletMode").
|
||||
*/
|
||||
public static final String PORTLET_MODE_ATTRIBUTE = "portletMode";
|
||||
|
||||
/**
|
||||
* The default portlet mode. Default is "view".
|
||||
*/
|
||||
private PortletMode portletMode = PortletMode.VIEW;
|
||||
|
||||
/**
|
||||
* Returns the mode that will be set in the response.
|
||||
*/
|
||||
public PortletMode getPortletMode() {
|
||||
return portletMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mode that will be set in the response.
|
||||
*/
|
||||
public void setPortletMode(PortletMode portletMode) {
|
||||
Assert.notNull(portletMode, "The portlet mode is required and cannot be null");
|
||||
this.portletMode = portletMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PortletMode.
|
||||
* @param context the action execution context, for accessing and setting data in "flow scope" or "request scope"
|
||||
* @return the action result event
|
||||
* @throws Exception an <b>unrecoverable</b> exception occured, either checked or unchecked
|
||||
*/
|
||||
protected Event doExecute(RequestContext context) throws Exception {
|
||||
Assert.isInstanceOf(PortletExternalContext.class, context.getExternalContext(), "'"
|
||||
+ ClassUtils.getShortName(this.getClass()) + "' can only work with 'PortletExternalContext': ");
|
||||
PortletExternalContext portletContext = (PortletExternalContext) context.getExternalContext();
|
||||
if (portletContext.getResponse() instanceof ActionResponse) {
|
||||
PortletMode mode = (PortletMode) context.getAttributes().get(PORTLET_MODE_ATTRIBUTE, PortletMode.class,
|
||||
getPortletMode());
|
||||
((ActionResponse) portletContext.getResponse()).setPortletMode(mode);
|
||||
return success();
|
||||
} else {
|
||||
// portlet mode and the window state can be changed through
|
||||
// ActionResponse only, if this is not the case, it means that this
|
||||
// action has been invoked directly in a RenderRequest
|
||||
throw new IllegalStateException("SetPortletModeAction can only be invoked within a Action request -- "
|
||||
+ "make sure you are not invoking it in a RenderRequest");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
Action implementations that define logic specific to flows executing in a JSR-168 Portlet environment.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
import org.springframework.binding.collection.SharedMap;
|
||||
import org.springframework.binding.collection.StringKeyedMapAdapter;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A shared map backed by the Portlet context for accessing application scoped attributes.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class PortletContextMap extends StringKeyedMapAdapter implements SharedMap {
|
||||
|
||||
/**
|
||||
* The wrapped portlet context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* Create a new map wrapping given portlet context.
|
||||
*/
|
||||
public PortletContextMap(PortletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
protected Object getAttribute(String key) {
|
||||
return context.getAttribute(key);
|
||||
}
|
||||
|
||||
protected void setAttribute(String key, Object value) {
|
||||
context.setAttribute(key, value);
|
||||
}
|
||||
|
||||
protected void removeAttribute(String key) {
|
||||
context.removeAttribute(key);
|
||||
}
|
||||
|
||||
protected Iterator getAttributeNames() {
|
||||
return CollectionUtils.toIterator(context.getAttributeNames());
|
||||
}
|
||||
|
||||
public Object getMutex() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletSession;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.webflow.context.ExternalContext;
|
||||
import org.springframework.webflow.context.FlowDefinitionRequestInfo;
|
||||
import org.springframework.webflow.context.FlowExecutionRequestInfo;
|
||||
import org.springframework.webflow.context.RequestPath;
|
||||
import org.springframework.webflow.core.FlowException;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.core.collection.LocalParameterMap;
|
||||
import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.core.collection.ParameterMap;
|
||||
import org.springframework.webflow.core.collection.SharedAttributeMap;
|
||||
|
||||
/**
|
||||
* Provides contextual information about a JSR-168 Portlet environment that has called into Spring Web Flow.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class PortletExternalContext implements ExternalContext {
|
||||
|
||||
/**
|
||||
* The context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
/**
|
||||
* An accessor for the portlet request parameter map.
|
||||
*/
|
||||
private ParameterMap requestParameterMap;
|
||||
|
||||
/**
|
||||
* An accessor for the portlet request attribute map.
|
||||
*/
|
||||
private MutableAttributeMap requestMap;
|
||||
|
||||
/**
|
||||
* An accessor for the local portlet session map.
|
||||
*/
|
||||
private SharedAttributeMap sessionMap;
|
||||
|
||||
/**
|
||||
* An accessor for the global portlet session map.
|
||||
*/
|
||||
private SharedAttributeMap globalSessionMap;
|
||||
|
||||
/**
|
||||
* An accessor for the portlet context application map.
|
||||
*/
|
||||
private SharedAttributeMap applicationMap;
|
||||
|
||||
/**
|
||||
* An accessor for the portlet user info map.
|
||||
*/
|
||||
private MutableAttributeMap userInfoMap;
|
||||
|
||||
/**
|
||||
* Create an external context wrapping given Portlet context, request and response.
|
||||
* @param context the Portlet context
|
||||
* @param request the Portlet request
|
||||
* @param response the Portlet response
|
||||
*/
|
||||
public PortletExternalContext(PortletContext context, PortletRequest request, PortletResponse response) {
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.requestParameterMap = new LocalParameterMap(new PortletRequestParameterMap(request));
|
||||
this.requestMap = new LocalAttributeMap(new PortletRequestMap(request));
|
||||
this.sessionMap = new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.PORTLET_SCOPE));
|
||||
this.globalSessionMap = new LocalSharedAttributeMap(new PortletSessionMap(request,
|
||||
PortletSession.APPLICATION_SCOPE));
|
||||
this.applicationMap = new LocalSharedAttributeMap(new PortletContextMap(context));
|
||||
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
|
||||
this.userInfoMap = userInfo != null ? new LocalAttributeMap(userInfo) : null;
|
||||
}
|
||||
|
||||
public ParameterMap getRequestParameterMap() {
|
||||
return requestParameterMap;
|
||||
}
|
||||
|
||||
public MutableAttributeMap getRequestMap() {
|
||||
return requestMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getSessionMap() {
|
||||
return sessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getGlobalSessionMap() {
|
||||
return globalSessionMap;
|
||||
}
|
||||
|
||||
public SharedAttributeMap getApplicationMap() {
|
||||
return applicationMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PortletRequest#USER_INFO} map as a mutable attribute map.
|
||||
* @return the Portlet user info
|
||||
*/
|
||||
public MutableAttributeMap getUserInfoMap() {
|
||||
return userInfoMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped Portlet context.
|
||||
*/
|
||||
public Object getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped Portlet request.
|
||||
*/
|
||||
public Object getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped Portlet response.
|
||||
*/
|
||||
public Object getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getFlowId() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String getFlowExecutionKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public RequestPath getRequestPath() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String getRequestMethod() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public PrintWriter getResponseWriter() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String buildFlowDefinitionUrl(FlowDefinitionRequestInfo urlInfo) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String buildFlowExecutionUrl(FlowExecutionRequestInfo urlInfo, boolean contextRelative) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String encode(String string) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void sendFlowDefinitionRedirect(FlowDefinitionRequestInfo urlInfo) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void sendFlowExecutionRedirect(FlowExecutionRequestInfo urlInfo) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void sendExternalRedirect(String resourceUrl) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void setPausedResult(String flowExecutionKey) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void setEndedResult(String flowExecutionKey) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public void setExceptionResult(FlowException e) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public boolean isResponseCommitted() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("requestParameterMap", getRequestParameterMap()).toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
|
||||
import org.springframework.binding.collection.StringKeyedMapAdapter;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Map backed by the Portlet request for accessing request scoped attributes.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class PortletRequestMap extends StringKeyedMapAdapter {
|
||||
|
||||
/**
|
||||
* The wrapped portlet request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* Create a new map wrapping the attributes of given portlet request.
|
||||
*/
|
||||
public PortletRequestMap(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
protected Object getAttribute(String key) {
|
||||
return request.getAttribute(key);
|
||||
}
|
||||
|
||||
protected void setAttribute(String key, Object value) {
|
||||
request.setAttribute(key, value);
|
||||
}
|
||||
|
||||
protected void removeAttribute(String key) {
|
||||
request.removeAttribute(key);
|
||||
}
|
||||
|
||||
protected Iterator getAttributeNames() {
|
||||
return CollectionUtils.toIterator(request.getAttributeNames());
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
|
||||
import org.springframework.binding.collection.CompositeIterator;
|
||||
import org.springframework.binding.collection.StringKeyedMapAdapter;
|
||||
import org.springframework.web.portlet.multipart.MultipartActionRequest;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Map backed by the Portlet request parameter map for accessing request local portlet parameters.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class PortletRequestParameterMap extends StringKeyedMapAdapter {
|
||||
|
||||
/**
|
||||
* The wrapped portlet request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* Create a new map wrapping the parameters of given portlet request.
|
||||
*/
|
||||
public PortletRequestParameterMap(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
protected Object getAttribute(String key) {
|
||||
if (request instanceof MultipartActionRequest) {
|
||||
MultipartActionRequest multipartRequest = (MultipartActionRequest) request;
|
||||
Object data = multipartRequest.getFileMap().get(key);
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
String[] parameters = request.getParameterValues(key);
|
||||
if (parameters == null) {
|
||||
return null;
|
||||
} else if (parameters.length == 1) {
|
||||
return parameters[0];
|
||||
} else {
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setAttribute(String key, Object value) {
|
||||
throw new UnsupportedOperationException("PortletRequest parameter maps are immutable");
|
||||
}
|
||||
|
||||
protected void removeAttribute(String key) {
|
||||
throw new UnsupportedOperationException("PortletRequest parameter maps are immutable");
|
||||
}
|
||||
|
||||
protected Iterator getAttributeNames() {
|
||||
if (request instanceof MultipartActionRequest) {
|
||||
MultipartActionRequest multipartRequest = (MultipartActionRequest) request;
|
||||
CompositeIterator iterator = new CompositeIterator();
|
||||
iterator.add(multipartRequest.getFileMap().keySet().iterator());
|
||||
iterator.add(CollectionUtils.toIterator(request.getParameterNames()));
|
||||
return iterator;
|
||||
} else {
|
||||
return CollectionUtils.toIterator(request.getParameterNames());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
|
||||
import org.springframework.binding.collection.SharedMap;
|
||||
import org.springframework.binding.collection.StringKeyedMapAdapter;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
import org.springframework.webflow.context.servlet.HttpSessionMapBindingListener;
|
||||
import org.springframework.webflow.core.collection.AttributeMapBindingListener;
|
||||
import org.springframework.webflow.core.collection.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Shared map backed by the Portlet session for accessing session scoped attributes in a Portlet environment.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class PortletSessionMap extends StringKeyedMapAdapter implements SharedMap {
|
||||
|
||||
/**
|
||||
* The wrapped portlet request, providing access to the session.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The scope to access in the session, either APPLICATION (global) or PORTLET.
|
||||
*/
|
||||
private int scope;
|
||||
|
||||
/**
|
||||
* Create a new map wrapping the session associated with given request.
|
||||
* @param request the current portlet request
|
||||
* @param scope the scope to access in the session, either {@link PortletSession#APPLICATION_SCOPE} (global) or
|
||||
* {@link PortletSession#PORTLET_SCOPE}
|
||||
*/
|
||||
public PortletSessionMap(PortletRequest request, int scope) {
|
||||
this.request = request;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the portlet session associated with the wrapped request, or null if no such session exits.
|
||||
*/
|
||||
private PortletSession getSession() {
|
||||
return request.getPortletSession(false);
|
||||
}
|
||||
|
||||
protected Object getAttribute(String key) {
|
||||
PortletSession session = getSession();
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
Object value = session.getAttribute(key, scope);
|
||||
if (value instanceof HttpSessionMapBindingListener) {
|
||||
// unwrap
|
||||
return ((HttpSessionMapBindingListener) value).getListener();
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setAttribute(String key, Object value) {
|
||||
PortletSession session = request.getPortletSession(true);
|
||||
if (value instanceof AttributeMapBindingListener) {
|
||||
// wrap
|
||||
session.setAttribute(key, new HttpSessionMapBindingListener((AttributeMapBindingListener) value, this),
|
||||
scope);
|
||||
} else {
|
||||
session.setAttribute(key, value, scope);
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeAttribute(String key) {
|
||||
PortletSession session = getSession();
|
||||
if (session != null) {
|
||||
session.removeAttribute(key, scope);
|
||||
}
|
||||
}
|
||||
|
||||
protected Iterator getAttributeNames() {
|
||||
PortletSession session = getSession();
|
||||
return session == null ? CollectionUtils.EMPTY_ITERATOR : CollectionUtils.toIterator(session
|
||||
.getAttributeNames(scope));
|
||||
}
|
||||
|
||||
public Object getMutex() {
|
||||
PortletSession session = request.getPortletSession(true);
|
||||
Object mutex = session.getAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, scope);
|
||||
return mutex != null ? mutex : session;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
The representation of a client request into Spring Web Flow from a JSR-168 Portlet environment.
|
||||
<p>
|
||||
Portlets are specified in the <a href="http://www.jcp.org/en/jsr/detail?id=168">Java Portlet Standard</a>.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.action.portlet;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockActionRequest;
|
||||
import org.springframework.mock.web.portlet.MockActionResponse;
|
||||
import org.springframework.mock.web.portlet.MockPortletContext;
|
||||
import org.springframework.mock.web.portlet.MockRenderRequest;
|
||||
import org.springframework.mock.web.portlet.MockRenderResponse;
|
||||
import org.springframework.webflow.context.portlet.PortletExternalContext;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link SetPortletModeAction} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class SetPortletModeActionTests extends TestCase {
|
||||
|
||||
private SetPortletModeAction tested;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
tested = new SetPortletModeAction();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
tested = null;
|
||||
}
|
||||
|
||||
public void testDoExecute() throws Exception {
|
||||
MockActionResponse mockActionResponse = new MockActionResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(new MockPortletContext(),
|
||||
new MockActionRequest(), mockActionResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
|
||||
// perform test
|
||||
Event result = tested.doExecute(mockRequestContext);
|
||||
|
||||
assertEquals(tested.getEventFactorySupport().getSuccessEventId(), result.getId());
|
||||
assertEquals(tested.getPortletMode(), mockActionResponse.getPortletMode());
|
||||
}
|
||||
|
||||
public void testDoExecuteWithPortletModeAsAttribute() throws Exception {
|
||||
MockActionResponse mockActionResponse = new MockActionResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(new MockPortletContext(),
|
||||
new MockActionRequest(), mockActionResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
mockRequestContext.setAttribute(SetPortletModeAction.PORTLET_MODE_ATTRIBUTE, PortletMode.HELP);
|
||||
|
||||
// perform test
|
||||
Event result = tested.doExecute(mockRequestContext);
|
||||
|
||||
assertEquals(tested.getEventFactorySupport().getSuccessEventId(), result.getId());
|
||||
assertEquals(PortletMode.HELP, mockActionResponse.getPortletMode());
|
||||
}
|
||||
|
||||
public void testDoExecuteWithWrongResponseClass() throws Exception {
|
||||
MockRenderResponse mockRenderResponse = new MockRenderResponse();
|
||||
PortletExternalContext externalContext = new PortletExternalContext(new MockPortletContext(),
|
||||
new MockRenderRequest(), mockRenderResponse);
|
||||
MockRequestContext mockRequestContext = new MockRequestContext();
|
||||
mockRequestContext.setExternalContext(externalContext);
|
||||
mockRequestContext.setAttribute(SetPortletModeAction.PORTLET_MODE_ATTRIBUTE, PortletMode.HELP);
|
||||
|
||||
// perform test
|
||||
try {
|
||||
tested.doExecute(mockRequestContext);
|
||||
fail("ActionExecutionException expected");
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockPortletContext;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link PortletContextMap} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PortletContextMapTests extends TestCase {
|
||||
|
||||
private PortletContextMap tested;
|
||||
|
||||
private MockPortletContext context;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = new MockPortletContext();
|
||||
tested = new PortletContextMap(context);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
context = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
public void testGetAttribute() {
|
||||
context.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some key");
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
assertEquals("Some value", context.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testRemoveAttribute() {
|
||||
context.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
tested.removeAttribute("Some key");
|
||||
assertNull(context.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testGetAttributeNames() {
|
||||
context.setAttribute("Some key", "Some value");
|
||||
context.removeAttribute("javax.servlet.context.tempdir");
|
||||
// perform test
|
||||
Iterator names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
String name = (String) names.next();
|
||||
assertEquals("Some key", name);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockPortletRequest;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link PortletRequestMap} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PortletRequestMapTests extends TestCase {
|
||||
|
||||
private PortletRequestMap tested;
|
||||
|
||||
private MockPortletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
tested = new PortletRequestMap(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
public void testGetAttribute() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some key");
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
assertEquals("Some value", request.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testRemoveAttribute() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
tested.removeAttribute("Some key");
|
||||
assertNull(request.getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testGetAttributeNames() {
|
||||
request.setAttribute("Some key", "Some value");
|
||||
request.removeAttribute("javax.servlet.context.tempdir");
|
||||
// perform test
|
||||
Iterator names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
String name = (String) names.next();
|
||||
assertEquals("Some key", name);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockPortletRequest;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link PortletRequestParameterMap} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PortletRequestParameterMapTests extends TestCase {
|
||||
|
||||
private PortletRequestParameterMap tested;
|
||||
|
||||
private MockPortletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
tested = new PortletRequestParameterMap(request);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
public void testGetAttribute() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some param");
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
try {
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
fail("UnsupportedOperationException expected");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testRemoveAttribute() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
try {
|
||||
tested.removeAttribute("Some param");
|
||||
fail("UnsupportedOperationException expected");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAttributeNames() {
|
||||
request.setParameter("Some param", "Some value");
|
||||
// perform test
|
||||
Iterator names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
String name = (String) names.next();
|
||||
assertEquals("Some param", name);
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.webflow.context.portlet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.portlet.PortletSession;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.portlet.MockPortletRequest;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
/**
|
||||
* Unit test for the {@link PortletSessionMap} class.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PortletSessionMapTests extends TestCase {
|
||||
|
||||
private PortletSessionMap tested;
|
||||
|
||||
private MockPortletRequest request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
tested = new PortletSessionMap(request, PortletSession.PORTLET_SCOPE);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
request = null;
|
||||
tested = null;
|
||||
}
|
||||
|
||||
public void testGetAttribute() {
|
||||
request.getPortletSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some key");
|
||||
assertEquals("Some value", result);
|
||||
}
|
||||
|
||||
public void testGetAttributeNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
Object result = tested.getAttribute("Some key");
|
||||
assertNull("No value expected", result);
|
||||
}
|
||||
|
||||
public void testSetAttribute() {
|
||||
// perform test
|
||||
tested.setAttribute("Some key", "Some value");
|
||||
assertEquals("Some value", request.getPortletSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testRemoveAttribute() {
|
||||
request.getPortletSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
tested.removeAttribute("Some key");
|
||||
assertNull(request.getPortletSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testRemoveAttributeNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
tested.removeAttribute("Some key");
|
||||
assertNull(request.getPortletSession().getAttribute("Some key"));
|
||||
}
|
||||
|
||||
public void testGetAttributeNames() {
|
||||
request.getPortletSession().setAttribute("Some key", "Some value");
|
||||
// perform test
|
||||
Iterator names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertTrue("More elements", names.hasNext());
|
||||
String name = (String) names.next();
|
||||
assertEquals("Some key", name);
|
||||
}
|
||||
|
||||
public void testGetAttributeNamesNullSession() {
|
||||
request.setSession(null);
|
||||
// perform test
|
||||
Iterator names = tested.getAttributeNames();
|
||||
assertNotNull("Null result unexpected", names);
|
||||
assertFalse("No elements expected", names.hasNext());
|
||||
}
|
||||
|
||||
public void testGetSessionAsMutex() {
|
||||
Object mutex = tested.getMutex();
|
||||
assertSame(mutex, request.getPortletSession());
|
||||
}
|
||||
|
||||
public void testGetSessionMutex() {
|
||||
Object object = new Object();
|
||||
request.getPortletSession().setAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, object);
|
||||
Object mutex = tested.getMutex();
|
||||
assertSame(mutex, object);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user