diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java index cd32b7278c..0775e5782d 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -27,8 +27,7 @@ import org.springframework.util.StringUtils; * of specified config locations. Serves as base class for XML-based application * context implementations such as {@link ClassPathXmlApplicationContext} and * {@link FileSystemXmlApplicationContext}, as well as - * {@link org.springframework.web.context.support.XmlWebApplicationContext} and - * {@link org.springframework.web.portlet.context.XmlPortletApplicationContext}. + * {@link org.springframework.web.context.support.XmlWebApplicationContext}. * * @author Juergen Hoeller * @since 2.5.2 diff --git a/spring-context/src/main/java/org/springframework/ui/ModelMap.java b/spring-context/src/main/java/org/springframework/ui/ModelMap.java index 5db8b7fb7b..dad6b113b6 100644 --- a/spring-context/src/main/java/org/springframework/ui/ModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ModelMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -27,16 +27,14 @@ import org.springframework.util.Assert; * Implementation of {@link java.util.Map} for use when building model data for use * with UI tools. Supports chained calls and generation of model attribute names. * - *

This class serves as generic model holder for both Servlet and Portlet MVC, - * but is not tied to either of those. Check out the {@link Model} interface for - * a Java-5-based interface variant that serves the same purpose. + *

This class serves as generic model holder for Servlet MVC but is not tied to it. + * Check out the {@link Model} interface for an interface variant. * * @author Rob Harrop * @author Juergen Hoeller * @since 2.0 * @see Conventions#getVariableName * @see org.springframework.web.servlet.ModelAndView - * @see org.springframework.web.portlet.ModelAndView */ @SuppressWarnings("serial") public class ModelMap extends LinkedHashMap { diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index b80bce63cf..3aceff41ba 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -92,8 +92,7 @@ import org.springframework.util.StringUtils; * *

This generic data binder can be used in any kind of environment. * It is typically used by Spring web MVC controllers, via the web-specific - * subclasses {@link org.springframework.web.bind.ServletRequestDataBinder} - * and {@link org.springframework.web.portlet.bind.PortletRequestDataBinder}. + * subclass {@link org.springframework.web.bind.ServletRequestDataBinder}. * * @author Rod Johnson * @author Juergen Hoeller diff --git a/spring-core/src/main/java/org/springframework/core/io/ContextResource.java b/spring-core/src/main/java/org/springframework/core/io/ContextResource.java index 0493cfa7a0..5f4e807db0 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ContextResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ContextResource.java @@ -18,15 +18,14 @@ package org.springframework.core.io; /** * Extended interface for a resource that is loaded from an enclosing - * 'context', e.g. from a {@link javax.servlet.ServletContext} or a - * {@link javax.portlet.PortletContext} but also from plain classpath paths - * or relative file system paths (specified without an explicit prefix, - * hence applying relative to the local {@link ResourceLoader}'s context). + * 'context', e.g. from a {@link javax.servlet.ServletContext} but also + * from plain classpath paths or relative file system paths (specified + * without an explicit prefix, hence applying relative to the local + * {@link ResourceLoader}'s context). * * @author Juergen Hoeller * @since 2.5 * @see org.springframework.web.context.support.ServletContextResource - * @see org.springframework.web.portlet.context.PortletContextResource */ public interface ContextResource extends Resource { diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java deleted file mode 100644 index a687ccb671..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionRequest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2002-2009 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.mock.web.portlet; - -import javax.portlet.ActionRequest; -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; -import javax.portlet.PortletMode; - -/** - * Mock implementation of the {@link javax.portlet.ActionRequest} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockActionRequest extends MockClientDataRequest implements ActionRequest { - - /** - * Create a new MockActionRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @see org.springframework.mock.web.portlet.MockPortalContext - * @see org.springframework.mock.web.portlet.MockPortletContext - */ - public MockActionRequest() { - super(); - } - - /** - * Create a new MockActionRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param actionName the name of the action to trigger - */ - public MockActionRequest(String actionName) { - super(); - setParameter(ActionRequest.ACTION_NAME, actionName); - } - - /** - * Create a new MockActionRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param portletMode the mode that the portlet runs in - */ - public MockActionRequest(PortletMode portletMode) { - super(); - setPortletMode(portletMode); - } - - /** - * Create a new MockActionRequest with a default {@link MockPortalContext}. - * @param portletContext the PortletContext that the request runs in - */ - public MockActionRequest(PortletContext portletContext) { - super(portletContext); - } - - /** - * Create a new MockActionRequest. - * @param portalContext the PortalContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockActionRequest(PortalContext portalContext, PortletContext portletContext) { - super(portalContext, portletContext); - } - - - @Override - protected String getLifecyclePhase() { - return ACTION_PHASE; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java deleted file mode 100644 index 423cbb0c34..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockActionResponse.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.IOException; -import java.util.Map; -import javax.portlet.ActionResponse; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletModeException; -import javax.portlet.WindowState; -import javax.portlet.WindowStateException; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.ActionResponse} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockActionResponse extends MockStateAwareResponse implements ActionResponse { - - private boolean redirectAllowed = true; - - private String redirectedUrl; - - - /** - * Create a new MockActionResponse with a default {@link MockPortalContext}. - * @see MockPortalContext - */ - public MockActionResponse() { - super(); - } - - /** - * Create a new MockActionResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - */ - public MockActionResponse(PortalContext portalContext) { - super(portalContext); - } - - - @Override - public void setWindowState(WindowState windowState) throws WindowStateException { - if (this.redirectedUrl != null) { - throw new IllegalStateException("Cannot set WindowState after sendRedirect has been called"); - } - super.setWindowState(windowState); - this.redirectAllowed = false; - } - - @Override - public void setPortletMode(PortletMode portletMode) throws PortletModeException { - if (this.redirectedUrl != null) { - throw new IllegalStateException("Cannot set PortletMode after sendRedirect has been called"); - } - super.setPortletMode(portletMode); - this.redirectAllowed = false; - } - - @Override - public void setRenderParameters(Map parameters) { - if (this.redirectedUrl != null) { - throw new IllegalStateException("Cannot set render parameters after sendRedirect has been called"); - } - super.setRenderParameters(parameters); - this.redirectAllowed = false; - } - - @Override - public void setRenderParameter(String key, String value) { - if (this.redirectedUrl != null) { - throw new IllegalStateException("Cannot set render parameters after sendRedirect has been called"); - } - super.setRenderParameter(key, value); - this.redirectAllowed = false; - } - - @Override - public void setRenderParameter(String key, String[] values) { - if (this.redirectedUrl != null) { - throw new IllegalStateException("Cannot set render parameters after sendRedirect has been called"); - } - super.setRenderParameter(key, values); - this.redirectAllowed = false; - } - - @Override - public void sendRedirect(String location) throws IOException { - if (!this.redirectAllowed) { - throw new IllegalStateException( - "Cannot call sendRedirect after windowState, portletMode, or renderParameters have been set"); - } - Assert.notNull(location, "Redirect URL must not be null"); - this.redirectedUrl = location; - } - - @Override - public void sendRedirect(String location, String renderUrlParamName) throws IOException { - sendRedirect(location); - if (renderUrlParamName != null) { - setRenderParameter(renderUrlParamName, location); - } - } - - public String getRedirectedUrl() { - return this.redirectedUrl; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java deleted file mode 100644 index 28662358c0..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockBaseURL.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.net.URLEncoder; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import javax.portlet.BaseURL; -import javax.portlet.PortletSecurityException; - -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Mock implementation of the {@link javax.portlet.BaseURL} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public abstract class MockBaseURL implements BaseURL { - - public static final String URL_TYPE_RENDER = "render"; - - public static final String URL_TYPE_ACTION = "action"; - - private static final String ENCODING = "UTF-8"; - - - protected final Map parameters = new LinkedHashMap(); - - private boolean secure = false; - - private final Map properties = new LinkedHashMap(); - - - //--------------------------------------------------------------------- - // BaseURL methods - //--------------------------------------------------------------------- - - @Override - public void setParameter(String key, String value) { - Assert.notNull(key, "Parameter key must be null"); - Assert.notNull(value, "Parameter value must not be null"); - this.parameters.put(key, new String[] {value}); - } - - @Override - public void setParameter(String key, String[] values) { - Assert.notNull(key, "Parameter key must be null"); - Assert.notNull(values, "Parameter values must not be null"); - this.parameters.put(key, values); - } - - @Override - public void setParameters(Map parameters) { - Assert.notNull(parameters, "Parameters Map must not be null"); - this.parameters.clear(); - this.parameters.putAll(parameters); - } - - public Set getParameterNames() { - return this.parameters.keySet(); - } - - public String getParameter(String name) { - String[] arr = this.parameters.get(name); - return (arr != null && arr.length > 0 ? arr[0] : null); - } - - public String[] getParameterValues(String name) { - return this.parameters.get(name); - } - - @Override - public Map getParameterMap() { - return Collections.unmodifiableMap(this.parameters); - } - - @Override - public void setSecure(boolean secure) throws PortletSecurityException { - this.secure = secure; - } - - public boolean isSecure() { - return this.secure; - } - - @Override - public void write(Writer out) throws IOException { - out.write(toString()); - } - - @Override - public void write(Writer out, boolean escapeXML) throws IOException { - out.write(toString()); - } - - @Override - public void addProperty(String key, String value) { - String[] values = this.properties.get(key); - if (values != null) { - this.properties.put(key, StringUtils.addStringToArray(values, value)); - } - else { - this.properties.put(key, new String[] {value}); - } - } - - @Override - public void setProperty(String key, String value) { - this.properties.put(key, new String[] {value}); - } - - public Map getProperties() { - return Collections.unmodifiableMap(this.properties); - } - - - protected String encodeParameter(String name, String value) { - try { - return URLEncoder.encode(name, ENCODING) + "=" + URLEncoder.encode(value, ENCODING); - } - catch (UnsupportedEncodingException ex) { - return null; - } - } - - protected String encodeParameter(String name, String[] values) { - try { - StringBuilder sb = new StringBuilder(); - for (int i = 0, n = values.length; i < n; i++) { - sb.append(i > 0 ? ";" : "").append(URLEncoder.encode(name, ENCODING)).append("=") - .append(URLEncoder.encode(values[i], ENCODING)); - } - return sb.toString(); - } - catch (UnsupportedEncodingException ex) { - return null; - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java deleted file mode 100644 index 109133a2b6..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockCacheControl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import javax.portlet.CacheControl; - -/** - * Mock implementation of the {@link javax.portlet.CacheControl} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockCacheControl implements CacheControl { - - private int expirationTime = 0; - - private boolean publicScope = false; - - private String etag; - - private boolean useCachedContent = false; - - - @Override - public int getExpirationTime() { - return this.expirationTime; - } - - @Override - public void setExpirationTime(int time) { - this.expirationTime = time; - } - - @Override - public boolean isPublicScope() { - return this.publicScope; - } - - @Override - public void setPublicScope(boolean publicScope) { - this.publicScope = publicScope; - } - - @Override - public String getETag() { - return this.etag; - } - - @Override - public void setETag(String token) { - this.etag = token; - } - - @Override - public boolean useCachedContent() { - return this.useCachedContent; - } - - @Override - public void setUseCachedContent(boolean useCachedContent) { - this.useCachedContent = useCachedContent; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java deleted file mode 100644 index 15f6f59c94..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockClientDataRequest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import javax.portlet.ClientDataRequest; -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; - -/** - * Mock implementation of the {@link javax.portlet.ClientDataRequest} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockClientDataRequest extends MockPortletRequest implements ClientDataRequest { - - private String characterEncoding; - - private byte[] content; - - private String contentType; - - private String method; - - - /** - * Create a new MockClientDataRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @see org.springframework.mock.web.portlet.MockPortalContext - * @see org.springframework.mock.web.portlet.MockPortletContext - */ - public MockClientDataRequest() { - super(); - } - - /** - * Create a new MockClientDataRequest with a default {@link MockPortalContext}. - * @param portletContext the PortletContext that the request runs in - */ - public MockClientDataRequest(PortletContext portletContext) { - super(portletContext); - } - - /** - * Create a new MockClientDataRequest. - * @param portalContext the PortalContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockClientDataRequest(PortalContext portalContext, PortletContext portletContext) { - super(portalContext, portletContext); - } - - - public void setContent(byte[] content) { - this.content = content; - } - - @Override - public InputStream getPortletInputStream() throws IOException { - if (this.content != null) { - return new ByteArrayInputStream(this.content); - } - else { - return null; - } - } - - @Override - public void setCharacterEncoding(String characterEncoding) { - this.characterEncoding = characterEncoding; - } - - @Override - public BufferedReader getReader() throws UnsupportedEncodingException { - if (this.content != null) { - InputStream sourceStream = new ByteArrayInputStream(this.content); - Reader sourceReader = (this.characterEncoding != null) ? - new InputStreamReader(sourceStream, this.characterEncoding) : new InputStreamReader(sourceStream); - return new BufferedReader(sourceReader); - } - else { - return null; - } - } - - @Override - public String getCharacterEncoding() { - return this.characterEncoding; - } - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - @Override - public String getContentType() { - return this.contentType; - } - - @Override - public int getContentLength() { - return (this.content != null ? content.length : -1); - } - - public void setMethod(String method) { - this.method = method; - } - - @Override - public String getMethod() { - return this.method; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java deleted file mode 100644 index d9d139b010..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEvent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.Serializable; -import javax.portlet.Event; -import javax.xml.namespace.QName; - -/** - * Mock implementation of the {@link javax.portlet.Event} interface. - * - * @author Juergen Hoeller - * @since 3.0 - * @see MockEventRequest - */ -public class MockEvent implements Event { - - private final QName name; - - private final Serializable value; - - - /** - * Create a new MockEvent with the given name. - * @param name the name of the event - */ - public MockEvent(QName name) { - this.name = name; - this.value = null; - } - - /** - * Create a new MockEvent with the given name and value. - * @param name the name of the event - * @param value the associated payload of the event - */ - public MockEvent(QName name, Serializable value) { - this.name = name; - this.value = value; - } - - /** - * Create a new MockEvent with the given name. - * @param name the name of the event - */ - public MockEvent(String name) { - this.name = new QName(name); - this.value = null; - } - - /** - * Create a new MockEvent with the given name and value. - * @param name the name of the event - * @param value the associated payload of the event - */ - public MockEvent(String name, Serializable value) { - this.name = new QName(name); - this.value = value; - } - - - @Override - public QName getQName() { - return this.name; - } - - @Override - public String getName() { - return this.name.getLocalPart(); - } - - @Override - public Serializable getValue() { - return this.value; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java deleted file mode 100644 index 1690ace066..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventRequest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import javax.portlet.Event; -import javax.portlet.EventRequest; -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; - -/** - * Mock implementation of the {@link javax.portlet.EventRequest} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockEventRequest extends MockPortletRequest implements EventRequest { - - private final Event event; - - private String method; - - - /** - * Create a new MockEventRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param event the event that this request wraps - * @see MockEvent - */ - public MockEventRequest(Event event) { - super(); - this.event = event; - } - - /** - * Create a new MockEventRequest with a default {@link MockPortalContext}. - * @param event the event that this request wraps - * @param portletContext the PortletContext that the request runs in - * @see MockEvent - */ - public MockEventRequest(Event event, PortletContext portletContext) { - super(portletContext); - this.event = event; - } - - /** - * Create a new MockEventRequest. - * @param event the event that this request wraps - * @param portalContext the PortletContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockEventRequest(Event event, PortalContext portalContext, PortletContext portletContext) { - super(portalContext, portletContext); - this.event = event; - } - - - @Override - protected String getLifecyclePhase() { - return EVENT_PHASE; - } - - @Override - public Event getEvent() { - return this.event; - } - - public void setMethod(String method) { - this.method = method; - } - - @Override - public String getMethod() { - return this.method; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java deleted file mode 100644 index 1114d0081b..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockEventResponse.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import javax.portlet.EventRequest; -import javax.portlet.EventResponse; - -/** - * Mock implementation of the {@link javax.portlet.EventResponse} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockEventResponse extends MockStateAwareResponse implements EventResponse { - - @Override - public void setRenderParameters(EventRequest request) { - setRenderParameters(request.getParameterMap()); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java deleted file mode 100644 index 3a45fcf209..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMimeResponse.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright 2002-2014 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.mock.web.portlet; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Locale; -import javax.portlet.CacheControl; -import javax.portlet.MimeResponse; -import javax.portlet.PortalContext; -import javax.portlet.PortletRequest; -import javax.portlet.PortletURL; -import javax.portlet.ResourceURL; - -import org.springframework.util.CollectionUtils; -import org.springframework.web.util.WebUtils; - -/** - * Mock implementation of the {@link javax.portlet.MimeResponse} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockMimeResponse extends MockPortletResponse implements MimeResponse { - - private PortletRequest request; - - private String contentType; - - private String characterEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING; - - private PrintWriter writer; - - private Locale locale = Locale.getDefault(); - - private int bufferSize = 4096; - - private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); - - private final CacheControl cacheControl = new MockCacheControl(); - - private boolean committed; - - private String includedUrl; - - private String forwardedUrl; - - - /** - * Create a new MockMimeResponse with a default {@link MockPortalContext}. - * @see org.springframework.mock.web.portlet.MockPortalContext - */ - public MockMimeResponse() { - super(); - } - - /** - * Create a new MockMimeResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - */ - public MockMimeResponse(PortalContext portalContext) { - super(portalContext); - } - - /** - * Create a new MockMimeResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - * @param request the corresponding render/resource request that this response - * is being generated for - */ - public MockMimeResponse(PortalContext portalContext, PortletRequest request) { - super(portalContext); - this.request = request; - } - - - //--------------------------------------------------------------------- - // RenderResponse methods - //--------------------------------------------------------------------- - - @Override - public void setContentType(String contentType) { - if (this.request != null) { - Enumeration supportedTypes = this.request.getResponseContentTypes(); - if (!CollectionUtils.contains(supportedTypes, contentType)) { - throw new IllegalArgumentException("Content type [" + contentType + "] not in supported list: " + - Collections.list(supportedTypes)); - } - } - this.contentType = contentType; - } - - @Override - public String getContentType() { - return this.contentType; - } - - public void setCharacterEncoding(String characterEncoding) { - this.characterEncoding = characterEncoding; - } - - @Override - public String getCharacterEncoding() { - return this.characterEncoding; - } - - @Override - public PrintWriter getWriter() throws UnsupportedEncodingException { - if (this.writer == null) { - Writer targetWriter = (this.characterEncoding != null ? - new OutputStreamWriter(this.outputStream, this.characterEncoding) : - new OutputStreamWriter(this.outputStream)); - this.writer = new PrintWriter(targetWriter); - } - return this.writer; - } - - public byte[] getContentAsByteArray() { - flushBuffer(); - return this.outputStream.toByteArray(); - } - - public String getContentAsString() throws UnsupportedEncodingException { - flushBuffer(); - return (this.characterEncoding != null ? - this.outputStream.toString(this.characterEncoding) : this.outputStream.toString()); - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - @Override - public Locale getLocale() { - return this.locale; - } - - @Override - public void setBufferSize(int bufferSize) { - this.bufferSize = bufferSize; - } - - @Override - public int getBufferSize() { - return this.bufferSize; - } - - @Override - public void flushBuffer() { - if (this.writer != null) { - this.writer.flush(); - } - try { - this.outputStream.flush(); - } - catch (IOException ex) { - throw new IllegalStateException("Could not flush OutputStream: " + ex.getMessage()); - } - this.committed = true; - } - - @Override - public void resetBuffer() { - if (this.committed) { - throw new IllegalStateException("Cannot reset buffer - response is already committed"); - } - this.outputStream.reset(); - } - - public void setCommitted(boolean committed) { - this.committed = committed; - } - - @Override - public boolean isCommitted() { - return this.committed; - } - - @Override - public void reset() { - resetBuffer(); - this.characterEncoding = null; - this.contentType = null; - this.locale = null; - } - - @Override - public OutputStream getPortletOutputStream() throws IOException { - return this.outputStream; - } - - @Override - public PortletURL createRenderURL() { - return new MockPortletURL(getPortalContext(), MockPortletURL.URL_TYPE_RENDER); - } - - @Override - public PortletURL createActionURL() { - return new MockPortletURL(getPortalContext(), MockPortletURL.URL_TYPE_ACTION); - } - - @Override - public ResourceURL createResourceURL() { - return new MockResourceURL(); - } - - @Override - public CacheControl getCacheControl() { - return this.cacheControl; - } - - - //--------------------------------------------------------------------- - // Methods for MockPortletRequestDispatcher - //--------------------------------------------------------------------- - - public void setIncludedUrl(String includedUrl) { - this.includedUrl = includedUrl; - } - - public String getIncludedUrl() { - return this.includedUrl; - } - - public void setForwardedUrl(String forwardedUrl) { - this.forwardedUrl = forwardedUrl; - } - - public String getForwardedUrl() { - return this.forwardedUrl; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java deleted file mode 100644 index e269a621e1..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockMultipartActionRequest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.springframework.util.Assert; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.portlet.multipart.MultipartActionRequest; - -/** - * Mock implementation of the - * {@link org.springframework.web.portlet.multipart.MultipartActionRequest} interface. - * - *

Useful for testing application controllers that access multipart uploads. - * The {@link org.springframework.mock.web.MockMultipartFile} can be used to - * populate these mock requests with files. - * - * @author Juergen Hoeller - * @author Arjen Poutsma - * @since 2.0 - * @see org.springframework.mock.web.MockMultipartFile - */ -public class MockMultipartActionRequest extends MockActionRequest implements MultipartActionRequest { - - private final MultiValueMap multipartFiles = - new LinkedMultiValueMap(); - - - /** - * Add a file to this request. The parameter name from the multipart - * form is taken from the {@link org.springframework.web.multipart.MultipartFile#getName()}. - * @param file multipart file to be added - */ - public void addFile(MultipartFile file) { - Assert.notNull(file, "MultipartFile must not be null"); - this.multipartFiles.add(file.getName(), file); - } - - @Override - public Iterator getFileNames() { - return this.multipartFiles.keySet().iterator(); - } - - @Override - public MultipartFile getFile(String name) { - return this.multipartFiles.getFirst(name); - } - - @Override - public List getFiles(String name) { - List multipartFiles = this.multipartFiles.get(name); - if (multipartFiles != null) { - return multipartFiles; - } - else { - return Collections.emptyList(); - } - } - - @Override - public Map getFileMap() { - return this.multipartFiles.toSingleValueMap(); - } - - @Override - public MultiValueMap getMultiFileMap() { - return new LinkedMultiValueMap(this.multipartFiles); - } - - @Override - public String getMultipartContentType(String paramOrFileName) { - MultipartFile file = getFile(paramOrFileName); - if (file != null) { - return file.getContentType(); - } - else { - return null; - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java deleted file mode 100644 index 824df6f70d..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortalContext.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.WindowState; - -/** - * Mock implementation of the {@link javax.portlet.PortalContext} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortalContext implements PortalContext { - - private final Map properties = new HashMap(); - - private final List portletModes; - - private final List windowStates; - - - /** - * Create a new MockPortalContext - * with default PortletModes (VIEW, EDIT, HELP) - * and default WindowStates (NORMAL, MAXIMIZED, MINIMIZED). - * @see javax.portlet.PortletMode - * @see javax.portlet.WindowState - */ - public MockPortalContext() { - this.portletModes = new ArrayList(3); - this.portletModes.add(PortletMode.VIEW); - this.portletModes.add(PortletMode.EDIT); - this.portletModes.add(PortletMode.HELP); - - this.windowStates = new ArrayList(3); - this.windowStates.add(WindowState.NORMAL); - this.windowStates.add(WindowState.MAXIMIZED); - this.windowStates.add(WindowState.MINIMIZED); - } - - /** - * Create a new MockPortalContext with the given PortletModes and WindowStates. - * @param supportedPortletModes the List of supported PortletMode instances - * @param supportedWindowStates the List of supported WindowState instances - * @see javax.portlet.PortletMode - * @see javax.portlet.WindowState - */ - public MockPortalContext(List supportedPortletModes, List supportedWindowStates) { - this.portletModes = new ArrayList(supportedPortletModes); - this.windowStates = new ArrayList(supportedWindowStates); - } - - - @Override - public String getPortalInfo() { - return "MockPortal/1.0"; - } - - public void setProperty(String name, String value) { - this.properties.put(name, value); - } - - @Override - public String getProperty(String name) { - return this.properties.get(name); - } - - @Override - public Enumeration getPropertyNames() { - return Collections.enumeration(this.properties.keySet()); - } - - @Override - public Enumeration getSupportedPortletModes() { - return Collections.enumeration(this.portletModes); - } - - @Override - public Enumeration getSupportedWindowStates() { - return Collections.enumeration(this.windowStates); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java deleted file mode 100644 index cf7f48bb17..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletConfig.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.Set; -import javax.portlet.PortletConfig; -import javax.portlet.PortletContext; -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.PortletConfig} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletConfig implements PortletConfig { - - private final PortletContext portletContext; - - private final String portletName; - - private final Map resourceBundles = new HashMap(); - - private final Map initParameters = new LinkedHashMap(); - - private final Set publicRenderParameterNames = new LinkedHashSet(); - - private String defaultNamespace = XMLConstants.NULL_NS_URI; - - private final Set publishingEventQNames = new LinkedHashSet(); - - private final Set processingEventQNames = new LinkedHashSet(); - - private final Set supportedLocales = new LinkedHashSet(); - - private final Map containerRuntimeOptions = new LinkedHashMap(); - - - /** - * Create a new MockPortletConfig with a default {@link MockPortletContext}. - */ - public MockPortletConfig() { - this(null, ""); - } - - /** - * Create a new MockPortletConfig with a default {@link MockPortletContext}. - * @param portletName the name of the portlet - */ - public MockPortletConfig(String portletName) { - this(null, portletName); - } - - /** - * Create a new MockPortletConfig. - * @param portletContext the PortletContext that the portlet runs in - */ - public MockPortletConfig(PortletContext portletContext) { - this(portletContext, ""); - } - - /** - * Create a new MockPortletConfig. - * @param portletContext the PortletContext that the portlet runs in - * @param portletName the name of the portlet - */ - public MockPortletConfig(PortletContext portletContext, String portletName) { - this.portletContext = (portletContext != null ? portletContext : new MockPortletContext()); - this.portletName = portletName; - } - - - @Override - public String getPortletName() { - return this.portletName; - } - - @Override - public PortletContext getPortletContext() { - return this.portletContext; - } - - public void setResourceBundle(Locale locale, ResourceBundle resourceBundle) { - Assert.notNull(locale, "Locale must not be null"); - this.resourceBundles.put(locale, resourceBundle); - } - - @Override - public ResourceBundle getResourceBundle(Locale locale) { - Assert.notNull(locale, "Locale must not be null"); - return this.resourceBundles.get(locale); - } - - public void addInitParameter(String name, String value) { - Assert.notNull(name, "Parameter name must not be null"); - this.initParameters.put(name, value); - } - - @Override - public String getInitParameter(String name) { - Assert.notNull(name, "Parameter name must not be null"); - return this.initParameters.get(name); - } - - @Override - public Enumeration getInitParameterNames() { - return Collections.enumeration(this.initParameters.keySet()); - } - - public void addPublicRenderParameterName(String name) { - this.publicRenderParameterNames.add(name); - } - - @Override - public Enumeration getPublicRenderParameterNames() { - return Collections.enumeration(this.publicRenderParameterNames); - } - - public void setDefaultNamespace(String defaultNamespace) { - this.defaultNamespace = defaultNamespace; - } - - @Override - public String getDefaultNamespace() { - return this.defaultNamespace; - } - - public void addPublishingEventQName(QName name) { - this.publishingEventQNames.add(name); - } - - @Override - public Enumeration getPublishingEventQNames() { - return Collections.enumeration(this.publishingEventQNames); - } - - public void addProcessingEventQName(QName name) { - this.processingEventQNames.add(name); - } - - @Override - public Enumeration getProcessingEventQNames() { - return Collections.enumeration(this.processingEventQNames); - } - - public void addSupportedLocale(Locale locale) { - this.supportedLocales.add(locale); - } - - @Override - public Enumeration getSupportedLocales() { - return Collections.enumeration(this.supportedLocales); - } - - public void addContainerRuntimeOption(String key, String value) { - this.containerRuntimeOptions.put(key, new String[] {value}); - } - - public void addContainerRuntimeOption(String key, String[] values) { - this.containerRuntimeOptions.put(key, values); - } - - @Override - public Map getContainerRuntimeOptions() { - return Collections.unmodifiableMap(this.containerRuntimeOptions); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java deleted file mode 100644 index bf1e6f0975..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright 2002-2013 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.mock.web.portlet; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import javax.activation.FileTypeMap; -import javax.portlet.PortletContext; -import javax.portlet.PortletRequestDispatcher; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.util.Assert; -import org.springframework.web.util.WebUtils; - -/** - * Mock implementation of the {@link javax.portlet.PortletContext} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletContext implements PortletContext { - - private static final String TEMP_DIR_SYSTEM_PROPERTY = "java.io.tmpdir"; - - - private final Log logger = LogFactory.getLog(getClass()); - - private final String resourceBasePath; - - private final ResourceLoader resourceLoader; - - private final Map attributes = new LinkedHashMap(); - - private final Map initParameters = new LinkedHashMap(); - - private String portletContextName = "MockPortletContext"; - - private Set containerRuntimeOptions = new LinkedHashSet(); - - - /** - * Create a new MockPortletContext with no base path and a - * DefaultResourceLoader (i.e. the classpath root as WAR root). - * @see org.springframework.core.io.DefaultResourceLoader - */ - public MockPortletContext() { - this("", null); - } - - /** - * Create a new MockPortletContext using a DefaultResourceLoader. - * @param resourceBasePath the WAR root directory (should not end with a slash) - * @see org.springframework.core.io.DefaultResourceLoader - */ - public MockPortletContext(String resourceBasePath) { - this(resourceBasePath, null); - } - - /** - * Create a new MockPortletContext, using the specified ResourceLoader - * and no base path. - * @param resourceLoader the ResourceLoader to use (or null for the default) - */ - public MockPortletContext(ResourceLoader resourceLoader) { - this("", resourceLoader); - } - - /** - * Create a new MockPortletContext. - * @param resourceBasePath the WAR root directory (should not end with a slash) - * @param resourceLoader the ResourceLoader to use (or null for the default) - */ - public MockPortletContext(String resourceBasePath, ResourceLoader resourceLoader) { - this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : ""); - this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader()); - - // Use JVM temp dir as PortletContext temp dir. - String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY); - if (tempDir != null) { - this.attributes.put(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File(tempDir)); - } - } - - /** - * Build a full resource location for the given path, - * prepending the resource base path of this MockPortletContext. - * @param path the path as specified - * @return the full resource path - */ - protected String getResourceLocation(String path) { - if (!path.startsWith("/")) { - path = "/" + path; - } - return this.resourceBasePath + path; - } - - - @Override - public String getServerInfo() { - return "MockPortal/1.0"; - } - - @Override - public PortletRequestDispatcher getRequestDispatcher(String path) { - if (!path.startsWith("/")) { - throw new IllegalArgumentException( - "PortletRequestDispatcher path at PortletContext level must start with '/'"); - } - return new MockPortletRequestDispatcher(path); - } - - @Override - public PortletRequestDispatcher getNamedDispatcher(String path) { - return null; - } - - @Override - public InputStream getResourceAsStream(String path) { - Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); - try { - return resource.getInputStream(); - } - catch (IOException ex) { - logger.info("Couldn't open InputStream for " + resource, ex); - return null; - } - } - - @Override - public int getMajorVersion() { - return 2; - } - - @Override - public int getMinorVersion() { - return 0; - } - - @Override - public String getMimeType(String filePath) { - return MimeTypeResolver.getMimeType(filePath); - } - - @Override - public String getRealPath(String path) { - Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); - try { - return resource.getFile().getAbsolutePath(); - } - catch (IOException ex) { - logger.info("Couldn't determine real path of resource " + resource, ex); - return null; - } - } - - @Override - public Set getResourcePaths(String path) { - Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); - try { - File file = resource.getFile(); - String[] fileList = file.list(); - String prefix = (path.endsWith("/") ? path : path + "/"); - Set resourcePaths = new HashSet(fileList.length); - for (String fileEntry : fileList) { - resourcePaths.add(prefix + fileEntry); - } - return resourcePaths; - } - catch (IOException ex) { - logger.info("Couldn't get resource paths for " + resource, ex); - return null; - } - } - - @Override - public URL getResource(String path) throws MalformedURLException { - Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); - try { - return resource.getURL(); - } - catch (IOException ex) { - logger.info("Couldn't get URL for " + resource, ex); - return null; - } - } - - @Override - public Object getAttribute(String name) { - return this.attributes.get(name); - } - - @Override - public Enumeration getAttributeNames() { - return Collections.enumeration(new LinkedHashSet(this.attributes.keySet())); - } - - @Override - public void setAttribute(String name, Object value) { - if (value != null) { - this.attributes.put(name, value); - } - else { - this.attributes.remove(name); - } - } - - @Override - public void removeAttribute(String name) { - this.attributes.remove(name); - } - - public void addInitParameter(String name, String value) { - Assert.notNull(name, "Parameter name must not be null"); - this.initParameters.put(name, value); - } - - @Override - public String getInitParameter(String name) { - Assert.notNull(name, "Parameter name must not be null"); - return this.initParameters.get(name); - } - - @Override - public Enumeration getInitParameterNames() { - return Collections.enumeration(this.initParameters.keySet()); - } - - @Override - public void log(String message) { - logger.info(message); - } - - @Override - public void log(String message, Throwable t) { - logger.info(message, t); - } - - public void setPortletContextName(String portletContextName) { - this.portletContextName = portletContextName; - } - - @Override - public String getPortletContextName() { - return this.portletContextName; - } - - public void addContainerRuntimeOption(String key) { - this.containerRuntimeOptions.add(key); - } - - @Override - public Enumeration getContainerRuntimeOptions() { - return Collections.enumeration(this.containerRuntimeOptions); - } - - - /** - * Inner factory class used to just introduce a Java Activation Framework - * dependency when actually asked to resolve a MIME type. - */ - private static class MimeTypeResolver { - - public static String getMimeType(String filePath) { - return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath); - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java deleted file mode 100644 index 3af2d6e97a..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletPreferences.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.IOException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import javax.portlet.PortletPreferences; -import javax.portlet.PreferencesValidator; -import javax.portlet.ReadOnlyException; -import javax.portlet.ValidatorException; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.PortletPreferences} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletPreferences implements PortletPreferences { - - private PreferencesValidator preferencesValidator; - - private final Map preferences = new LinkedHashMap(); - - private final Set readOnly = new HashSet(); - - - public void setReadOnly(String key, boolean readOnly) { - Assert.notNull(key, "Key must not be null"); - if (readOnly) { - this.readOnly.add(key); - } - else { - this.readOnly.remove(key); - } - } - - @Override - public boolean isReadOnly(String key) { - Assert.notNull(key, "Key must not be null"); - return this.readOnly.contains(key); - } - - @Override - public String getValue(String key, String def) { - Assert.notNull(key, "Key must not be null"); - String[] values = this.preferences.get(key); - return (values != null && values.length > 0 ? values[0] : def); - } - - @Override - public String[] getValues(String key, String[] def) { - Assert.notNull(key, "Key must not be null"); - String[] values = this.preferences.get(key); - return (values != null && values.length > 0 ? values : def); - } - - @Override - public void setValue(String key, String value) throws ReadOnlyException { - setValues(key, new String[] {value}); - } - - @Override - public void setValues(String key, String[] values) throws ReadOnlyException { - Assert.notNull(key, "Key must not be null"); - if (isReadOnly(key)) { - throw new ReadOnlyException("Preference '" + key + "' is read-only"); - } - this.preferences.put(key, values); - } - - @Override - public Enumeration getNames() { - return Collections.enumeration(this.preferences.keySet()); - } - - @Override - public Map getMap() { - return Collections.unmodifiableMap(this.preferences); - } - - @Override - public void reset(String key) throws ReadOnlyException { - Assert.notNull(key, "Key must not be null"); - if (isReadOnly(key)) { - throw new ReadOnlyException("Preference '" + key + "' is read-only"); - } - this.preferences.remove(key); - } - - public void setPreferencesValidator(PreferencesValidator preferencesValidator) { - this.preferencesValidator = preferencesValidator; - } - - @Override - public void store() throws IOException, ValidatorException { - if (this.preferencesValidator != null) { - this.preferencesValidator.validate(this); - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java deleted file mode 100644 index 649bafe6f6..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java +++ /dev/null @@ -1,569 +0,0 @@ -/* - * Copyright 2002-2013 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.mock.web.portlet; - -import java.security.Principal; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletPreferences; -import javax.portlet.PortletRequest; -import javax.portlet.PortletSession; -import javax.portlet.WindowState; -import javax.servlet.http.Cookie; - -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -/** - * Mock implementation of the {@link javax.portlet.PortletRequest} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletRequest implements PortletRequest { - - private boolean active = true; - - private final PortalContext portalContext; - - private final PortletContext portletContext; - - private PortletSession session; - - private WindowState windowState = WindowState.NORMAL; - - private PortletMode portletMode = PortletMode.VIEW; - - private PortletPreferences portletPreferences = new MockPortletPreferences(); - - private final Map> properties = new LinkedHashMap>(); - - private final Map attributes = new LinkedHashMap(); - - private final Map parameters = new LinkedHashMap(); - - private String authType = null; - - private String contextPath = ""; - - private String remoteUser = null; - - private Principal userPrincipal = null; - - private final Set userRoles = new HashSet(); - - private boolean secure = false; - - private boolean requestedSessionIdValid = true; - - private final List responseContentTypes = new LinkedList(); - - private final List locales = new LinkedList(); - - private String scheme = "http"; - - private String serverName = "localhost"; - - private int serverPort = 80; - - private String windowID; - - private Cookie[] cookies; - - private final Set publicParameterNames = new HashSet(); - - - /** - * Create a new MockPortletRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * - * @see MockPortalContext - * @see MockPortletContext - */ - public MockPortletRequest() { - this(null, null); - } - - /** - * Create a new MockPortletRequest with a default {@link MockPortalContext}. - * - * @param portletContext the PortletContext that the request runs in - * @see MockPortalContext - */ - public MockPortletRequest(PortletContext portletContext) { - this(null, portletContext); - } - - /** - * Create a new MockPortletRequest. - * - * @param portalContext the PortalContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockPortletRequest(PortalContext portalContext, PortletContext portletContext) { - this.portalContext = (portalContext != null ? portalContext : new MockPortalContext()); - this.portletContext = (portletContext != null ? portletContext : new MockPortletContext()); - this.responseContentTypes.add("text/html"); - this.locales.add(Locale.ENGLISH); - this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase()); - } - - // --------------------------------------------------------------------- - // Lifecycle methods - // --------------------------------------------------------------------- - - /** - * Return the Portlet 2.0 lifecycle id for the current phase. - */ - protected String getLifecyclePhase() { - return null; - } - - /** - * Return whether this request is still active (that is, not completed yet). - */ - public boolean isActive() { - return this.active; - } - - /** - * Mark this request as completed. - */ - public void close() { - this.active = false; - } - - /** - * Check whether this request is still active (that is, not completed yet), - * throwing an IllegalStateException if not active anymore. - */ - protected void checkActive() throws IllegalStateException { - if (!this.active) { - throw new IllegalStateException("Request is not active anymore"); - } - } - - // --------------------------------------------------------------------- - // PortletRequest methods - // --------------------------------------------------------------------- - - @Override - public boolean isWindowStateAllowed(WindowState windowState) { - return CollectionUtils.contains(this.portalContext.getSupportedWindowStates(), windowState); - } - - @Override - public boolean isPortletModeAllowed(PortletMode portletMode) { - return CollectionUtils.contains(this.portalContext.getSupportedPortletModes(), portletMode); - } - - public void setPortletMode(PortletMode portletMode) { - Assert.notNull(portletMode, "PortletMode must not be null"); - this.portletMode = portletMode; - } - - @Override - public PortletMode getPortletMode() { - return this.portletMode; - } - - public void setWindowState(WindowState windowState) { - Assert.notNull(windowState, "WindowState must not be null"); - this.windowState = windowState; - } - - @Override - public WindowState getWindowState() { - return this.windowState; - } - - public void setPreferences(PortletPreferences preferences) { - Assert.notNull(preferences, "PortletPreferences must not be null"); - this.portletPreferences = preferences; - } - - @Override - public PortletPreferences getPreferences() { - return this.portletPreferences; - } - - public void setSession(PortletSession session) { - this.session = session; - if (session instanceof MockPortletSession) { - MockPortletSession mockSession = ((MockPortletSession) session); - mockSession.access(); - } - } - - @Override - public PortletSession getPortletSession() { - return getPortletSession(true); - } - - @Override - public PortletSession getPortletSession(boolean create) { - checkActive(); - // Reset session if invalidated. - if (this.session instanceof MockPortletSession && ((MockPortletSession) this.session).isInvalid()) { - this.session = null; - } - // Create new session if necessary. - if (this.session == null && create) { - this.session = new MockPortletSession(this.portletContext); - } - return this.session; - } - - /** - * Set a single value for the specified property. - *

- * If there are already one or more values registered for the given property - * key, they will be replaced. - */ - public void setProperty(String key, String value) { - Assert.notNull(key, "Property key must not be null"); - List list = new LinkedList(); - list.add(value); - this.properties.put(key, list); - } - - /** - * Add a single value for the specified property. - *

- * If there are already one or more values registered for the given property - * key, the given value will be added to the end of the list. - */ - public void addProperty(String key, String value) { - Assert.notNull(key, "Property key must not be null"); - List oldList = this.properties.get(key); - if (oldList != null) { - oldList.add(value); - } - else { - List list = new LinkedList(); - list.add(value); - this.properties.put(key, list); - } - } - - @Override - public String getProperty(String key) { - Assert.notNull(key, "Property key must not be null"); - List list = this.properties.get(key); - return (list != null && list.size() > 0 ? list.get(0) : null); - } - - @Override - public Enumeration getProperties(String key) { - Assert.notNull(key, "property key must not be null"); - return Collections.enumeration(this.properties.get(key)); - } - - @Override - public Enumeration getPropertyNames() { - return Collections.enumeration(this.properties.keySet()); - } - - @Override - public PortalContext getPortalContext() { - return this.portalContext; - } - - public void setAuthType(String authType) { - this.authType = authType; - } - - @Override - public String getAuthType() { - return this.authType; - } - - public void setContextPath(String contextPath) { - this.contextPath = contextPath; - } - - @Override - public String getContextPath() { - return this.contextPath; - } - - public void setRemoteUser(String remoteUser) { - this.remoteUser = remoteUser; - } - - @Override - public String getRemoteUser() { - return this.remoteUser; - } - - public void setUserPrincipal(Principal userPrincipal) { - this.userPrincipal = userPrincipal; - } - - @Override - public Principal getUserPrincipal() { - return this.userPrincipal; - } - - public void addUserRole(String role) { - this.userRoles.add(role); - } - - @Override - public boolean isUserInRole(String role) { - return this.userRoles.contains(role); - } - - @Override - public Object getAttribute(String name) { - checkActive(); - return this.attributes.get(name); - } - - @Override - public Enumeration getAttributeNames() { - checkActive(); - return Collections.enumeration(new LinkedHashSet(this.attributes.keySet())); - } - - public void setParameters(Map parameters) { - Assert.notNull(parameters, "Parameters Map must not be null"); - this.parameters.clear(); - this.parameters.putAll(parameters); - } - - public void setParameter(String key, String value) { - Assert.notNull(key, "Parameter key must be null"); - Assert.notNull(value, "Parameter value must not be null"); - this.parameters.put(key, new String[] { value }); - } - - public void setParameter(String key, String[] values) { - Assert.notNull(key, "Parameter key must be null"); - Assert.notNull(values, "Parameter values must not be null"); - this.parameters.put(key, values); - } - - public void addParameter(String name, String value) { - addParameter(name, new String[] { value }); - } - - public void addParameter(String name, String[] values) { - String[] oldArr = this.parameters.get(name); - if (oldArr != null) { - String[] newArr = new String[oldArr.length + values.length]; - System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); - System.arraycopy(values, 0, newArr, oldArr.length, values.length); - this.parameters.put(name, newArr); - } - else { - this.parameters.put(name, values); - } - } - - @Override - public String getParameter(String name) { - String[] arr = this.parameters.get(name); - return (arr != null && arr.length > 0 ? arr[0] : null); - } - - @Override - public Enumeration getParameterNames() { - return Collections.enumeration(this.parameters.keySet()); - } - - @Override - public String[] getParameterValues(String name) { - return this.parameters.get(name); - } - - @Override - public Map getParameterMap() { - return Collections.unmodifiableMap(this.parameters); - } - - public void setSecure(boolean secure) { - this.secure = secure; - } - - @Override - public boolean isSecure() { - return this.secure; - } - - @Override - public void setAttribute(String name, Object value) { - checkActive(); - if (value != null) { - this.attributes.put(name, value); - } - else { - this.attributes.remove(name); - } - } - - @Override - public void removeAttribute(String name) { - checkActive(); - this.attributes.remove(name); - } - - @Override - public String getRequestedSessionId() { - PortletSession session = this.getPortletSession(); - return (session != null ? session.getId() : null); - } - - public void setRequestedSessionIdValid(boolean requestedSessionIdValid) { - this.requestedSessionIdValid = requestedSessionIdValid; - } - - @Override - public boolean isRequestedSessionIdValid() { - return this.requestedSessionIdValid; - } - - public void addResponseContentType(String responseContentType) { - this.responseContentTypes.add(responseContentType); - } - - public void addPreferredResponseContentType(String responseContentType) { - this.responseContentTypes.add(0, responseContentType); - } - - @Override - public String getResponseContentType() { - return this.responseContentTypes.get(0); - } - - @Override - public Enumeration getResponseContentTypes() { - return Collections.enumeration(this.responseContentTypes); - } - - public void addLocale(Locale locale) { - this.locales.add(locale); - } - - public void addPreferredLocale(Locale locale) { - this.locales.add(0, locale); - } - - @Override - public Locale getLocale() { - return this.locales.get(0); - } - - @Override - public Enumeration getLocales() { - return Collections.enumeration(this.locales); - } - - public void setScheme(String scheme) { - this.scheme = scheme; - } - - @Override - public String getScheme() { - return this.scheme; - } - - public void setServerName(String serverName) { - this.serverName = serverName; - } - - @Override - public String getServerName() { - return this.serverName; - } - - public void setServerPort(int serverPort) { - this.serverPort = serverPort; - } - - @Override - public int getServerPort() { - return this.serverPort; - } - - public void setWindowID(String windowID) { - this.windowID = windowID; - } - - @Override - public String getWindowID() { - return this.windowID; - } - - public void setCookies(Cookie... cookies) { - this.cookies = cookies; - } - - @Override - public Cookie[] getCookies() { - return this.cookies; - } - - @Override - public Map getPrivateParameterMap() { - if (!this.publicParameterNames.isEmpty()) { - Map filtered = new LinkedHashMap(); - for (String key : this.parameters.keySet()) { - if (!this.publicParameterNames.contains(key)) { - filtered.put(key, this.parameters.get(key)); - } - } - return filtered; - } - else { - return Collections.unmodifiableMap(this.parameters); - } - } - - @Override - public Map getPublicParameterMap() { - if (!this.publicParameterNames.isEmpty()) { - Map filtered = new LinkedHashMap(); - for (String key : this.parameters.keySet()) { - if (this.publicParameterNames.contains(key)) { - filtered.put(key, this.parameters.get(key)); - } - } - return filtered; - } - else { - return Collections.emptyMap(); - } - } - - public void registerPublicParameter(String name) { - this.publicParameterNames.add(name); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java deleted file mode 100644 index f4e0dc98fd..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequestDispatcher.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.IOException; -import javax.portlet.PortletException; -import javax.portlet.PortletRequest; -import javax.portlet.PortletRequestDispatcher; -import javax.portlet.PortletResponse; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.PortletRequestDispatcher} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletRequestDispatcher implements PortletRequestDispatcher { - - private final Log logger = LogFactory.getLog(getClass()); - - private final String url; - - - /** - * Create a new MockPortletRequestDispatcher for the given URL. - * @param url the URL to dispatch to. - */ - public MockPortletRequestDispatcher(String url) { - Assert.notNull(url, "URL must not be null"); - this.url = url; - } - - - @Override - public void include(RenderRequest request, RenderResponse response) throws PortletException, IOException { - include((PortletRequest) request, (PortletResponse) response); - } - - @Override - public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException { - Assert.notNull(request, "Request must not be null"); - Assert.notNull(response, "Response must not be null"); - if (!(response instanceof MockMimeResponse)) { - throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse"); - } - ((MockMimeResponse) response).setIncludedUrl(this.url); - if (logger.isDebugEnabled()) { - logger.debug("MockPortletRequestDispatcher: including URL [" + this.url + "]"); - } - } - - @Override - public void forward(PortletRequest request, PortletResponse response) throws PortletException, IOException { - Assert.notNull(request, "Request must not be null"); - Assert.notNull(response, "Response must not be null"); - if (!(response instanceof MockMimeResponse)) { - throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse"); - } - ((MockMimeResponse) response).setForwardedUrl(this.url); - if (logger.isDebugEnabled()) { - logger.debug("MockPortletRequestDispatcher: forwarding to URL [" + this.url + "]"); - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java deleted file mode 100644 index 513a6c8c9c..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletResponse.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import javax.portlet.PortalContext; -import javax.portlet.PortletResponse; -import javax.servlet.http.Cookie; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.DOMException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.PortletResponse} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletResponse implements PortletResponse { - - private final PortalContext portalContext; - - private final Map properties = new LinkedHashMap(); - - private String namespace = ""; - - private final Set cookies = new LinkedHashSet(); - - private final Map xmlProperties = new LinkedHashMap(); - - private Document xmlDocument; - - - /** - * Create a new MockPortletResponse with a default {@link MockPortalContext}. - * @see MockPortalContext - */ - public MockPortletResponse() { - this(null); - } - - /** - * Create a new MockPortletResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - */ - public MockPortletResponse(PortalContext portalContext) { - this.portalContext = (portalContext != null ? portalContext : new MockPortalContext()); - } - - /** - * Return the PortalContext that this MockPortletResponse runs in, - * defining the supported PortletModes and WindowStates. - */ - public PortalContext getPortalContext() { - return this.portalContext; - } - - - //--------------------------------------------------------------------- - // PortletResponse methods - //--------------------------------------------------------------------- - - @Override - public void addProperty(String key, String value) { - Assert.notNull(key, "Property key must not be null"); - String[] oldArr = this.properties.get(key); - if (oldArr != null) { - String[] newArr = new String[oldArr.length + 1]; - System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); - newArr[oldArr.length] = value; - this.properties.put(key, newArr); - } - else { - this.properties.put(key, new String[] {value}); - } - } - - @Override - public void setProperty(String key, String value) { - Assert.notNull(key, "Property key must not be null"); - this.properties.put(key, new String[] {value}); - } - - public Set getPropertyNames() { - return Collections.unmodifiableSet(this.properties.keySet()); - } - - public String getProperty(String key) { - Assert.notNull(key, "Property key must not be null"); - String[] arr = this.properties.get(key); - return (arr != null && arr.length > 0 ? arr[0] : null); - } - - public String[] getProperties(String key) { - Assert.notNull(key, "Property key must not be null"); - return this.properties.get(key); - } - - @Override - public String encodeURL(String path) { - return path; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - @Override - public String getNamespace() { - return this.namespace; - } - - @Override - public void addProperty(Cookie cookie) { - Assert.notNull(cookie, "Cookie must not be null"); - this.cookies.add(cookie); - } - - public Cookie[] getCookies() { - return this.cookies.toArray(new Cookie[this.cookies.size()]); - } - - public Cookie getCookie(String name) { - Assert.notNull(name, "Cookie name must not be null"); - for (Cookie cookie : this.cookies) { - if (name.equals(cookie.getName())) { - return cookie; - } - } - return null; - } - - @Override - public void addProperty(String key, Element value) { - Assert.notNull(key, "Property key must not be null"); - Element[] oldArr = this.xmlProperties.get(key); - if (oldArr != null) { - Element[] newArr = new Element[oldArr.length + 1]; - System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); - newArr[oldArr.length] = value; - this.xmlProperties.put(key, newArr); - } - else { - this.xmlProperties.put(key, new Element[] {value}); - } - } - - - public Set getXmlPropertyNames() { - return Collections.unmodifiableSet(this.xmlProperties.keySet()); - } - - public Element getXmlProperty(String key) { - Assert.notNull(key, "Property key must not be null"); - Element[] arr = this.xmlProperties.get(key); - return (arr != null && arr.length > 0 ? arr[0] : null); - } - - public Element[] getXmlProperties(String key) { - Assert.notNull(key, "Property key must not be null"); - return this.xmlProperties.get(key); - } - - @Override - public Element createElement(String tagName) throws DOMException { - if (this.xmlDocument == null) { - try { - this.xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - } - catch (ParserConfigurationException ex) { - throw new DOMException(DOMException.INVALID_STATE_ERR, ex.toString()); - } - } - return this.xmlDocument.createElement(tagName); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java deleted file mode 100644 index fac33bacc4..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright 2002-2013 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.mock.web.portlet; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import javax.portlet.PortletContext; -import javax.portlet.PortletSession; -import javax.servlet.http.HttpSessionBindingEvent; -import javax.servlet.http.HttpSessionBindingListener; - -import org.springframework.mock.web.MockHttpSession; - -/** - * Mock implementation of the {@link javax.portlet.PortletSession} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletSession implements PortletSession { - - private static int nextId = 1; - - - private final String id = Integer.toString(nextId++); - - private final long creationTime = System.currentTimeMillis(); - - private int maxInactiveInterval; - - private long lastAccessedTime = System.currentTimeMillis(); - - private final PortletContext portletContext; - - private final Map portletAttributes = new LinkedHashMap(); - - private final Map applicationAttributes = new LinkedHashMap(); - - private boolean invalid = false; - - private boolean isNew = true; - - - /** - * Create a new MockPortletSession with a default {@link MockPortletContext}. - * @see MockPortletContext - */ - public MockPortletSession() { - this(null); - } - - /** - * Create a new MockPortletSession. - * @param portletContext the PortletContext that the session runs in - */ - public MockPortletSession(PortletContext portletContext) { - this.portletContext = (portletContext != null ? portletContext : new MockPortletContext()); - } - - - @Override - public Object getAttribute(String name) { - return this.portletAttributes.get(name); - } - - @Override - public Object getAttribute(String name, int scope) { - if (scope == PortletSession.PORTLET_SCOPE) { - return this.portletAttributes.get(name); - } - else if (scope == PortletSession.APPLICATION_SCOPE) { - return this.applicationAttributes.get(name); - } - return null; - } - - @Override - public Enumeration getAttributeNames() { - return Collections.enumeration(new LinkedHashSet(this.portletAttributes.keySet())); - } - - @Override - public Enumeration getAttributeNames(int scope) { - if (scope == PortletSession.PORTLET_SCOPE) { - return Collections.enumeration(new LinkedHashSet(this.portletAttributes.keySet())); - } - else if (scope == PortletSession.APPLICATION_SCOPE) { - return Collections.enumeration(new LinkedHashSet(this.applicationAttributes.keySet())); - } - return null; - } - - @Override - public long getCreationTime() { - return this.creationTime; - } - - @Override - public String getId() { - return this.id; - } - - public void access() { - this.lastAccessedTime = System.currentTimeMillis(); - setNew(false); - } - - @Override - public long getLastAccessedTime() { - return this.lastAccessedTime; - } - - @Override - public int getMaxInactiveInterval() { - return this.maxInactiveInterval; - } - - /** - * Clear all of this session's attributes. - */ - public void clearAttributes() { - doClearAttributes(this.portletAttributes); - doClearAttributes(this.applicationAttributes); - } - - protected void doClearAttributes(Map attributes) { - for (Iterator> it = attributes.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); - String name = entry.getKey(); - Object value = entry.getValue(); - it.remove(); - if (value instanceof HttpSessionBindingListener) { - ((HttpSessionBindingListener) value).valueUnbound( - new HttpSessionBindingEvent(new MockHttpSession(), name, value)); - } - } - } - - @Override - public void invalidate() { - this.invalid = true; - clearAttributes(); - } - - public boolean isInvalid() { - return this.invalid; - } - - public void setNew(boolean value) { - this.isNew = value; - } - - @Override - public boolean isNew() { - return this.isNew; - } - - @Override - public void removeAttribute(String name) { - this.portletAttributes.remove(name); - } - - @Override - public void removeAttribute(String name, int scope) { - if (scope == PortletSession.PORTLET_SCOPE) { - this.portletAttributes.remove(name); - } - else if (scope == PortletSession.APPLICATION_SCOPE) { - this.applicationAttributes.remove(name); - } - } - - @Override - public void setAttribute(String name, Object value) { - if (value != null) { - this.portletAttributes.put(name, value); - } - else { - this.portletAttributes.remove(name); - } - } - - @Override - public void setAttribute(String name, Object value, int scope) { - if (scope == PortletSession.PORTLET_SCOPE) { - if (value != null) { - this.portletAttributes.put(name, value); - } - else { - this.portletAttributes.remove(name); - } - } - else if (scope == PortletSession.APPLICATION_SCOPE) { - if (value != null) { - this.applicationAttributes.put(name, value); - } - else { - this.applicationAttributes.remove(name); - } - } - } - - @Override - public void setMaxInactiveInterval(int interval) { - this.maxInactiveInterval = interval; - } - - @Override - public PortletContext getPortletContext() { - return this.portletContext; - } - - @Override - public Map getAttributeMap() { - return Collections.unmodifiableMap(this.portletAttributes); - } - - @Override - public Map getAttributeMap(int scope) { - if (scope == PortletSession.PORTLET_SCOPE) { - return Collections.unmodifiableMap(this.portletAttributes); - } - else if (scope == PortletSession.APPLICATION_SCOPE) { - return Collections.unmodifiableMap(this.applicationAttributes); - } - else { - return Collections.emptyMap(); - } - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java deleted file mode 100644 index c7eff5a528..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockPortletURL.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Map; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletModeException; -import javax.portlet.PortletURL; -import javax.portlet.WindowState; -import javax.portlet.WindowStateException; - -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -/** - * Mock implementation of the {@link javax.portlet.PortletURL} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockPortletURL extends MockBaseURL implements PortletURL { - - public static final String URL_TYPE_RENDER = "render"; - - public static final String URL_TYPE_ACTION = "action"; - - - private final PortalContext portalContext; - - private final String urlType; - - private WindowState windowState; - - private PortletMode portletMode; - - - /** - * Create a new MockPortletURL for the given URL type. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - * @param urlType the URL type, for example "render" or "action" - * @see #URL_TYPE_RENDER - * @see #URL_TYPE_ACTION - */ - public MockPortletURL(PortalContext portalContext, String urlType) { - Assert.notNull(portalContext, "PortalContext is required"); - this.portalContext = portalContext; - this.urlType = urlType; - } - - - //--------------------------------------------------------------------- - // PortletURL methods - //--------------------------------------------------------------------- - - @Override - public void setWindowState(WindowState windowState) throws WindowStateException { - if (!CollectionUtils.contains(this.portalContext.getSupportedWindowStates(), windowState)) { - throw new WindowStateException("WindowState not supported", windowState); - } - this.windowState = windowState; - } - - @Override - public WindowState getWindowState() { - return this.windowState; - } - - @Override - public void setPortletMode(PortletMode portletMode) throws PortletModeException { - if (!CollectionUtils.contains(this.portalContext.getSupportedPortletModes(), portletMode)) { - throw new PortletModeException("PortletMode not supported", portletMode); - } - this.portletMode = portletMode; - } - - @Override - public PortletMode getPortletMode() { - return this.portletMode; - } - - @Override - public void removePublicRenderParameter(String name) { - this.parameters.remove(name); - } - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(encodeParameter("urlType", this.urlType)); - if (this.windowState != null) { - sb.append(";").append(encodeParameter("windowState", this.windowState.toString())); - } - if (this.portletMode != null) { - sb.append(";").append(encodeParameter("portletMode", this.portletMode.toString())); - } - for (Map.Entry entry : this.parameters.entrySet()) { - sb.append(";").append(encodeParameter("param_" + entry.getKey(), entry.getValue())); - } - return (isSecure() ? "https:" : "http:") + - "//localhost/mockportlet?" + sb.toString(); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java deleted file mode 100644 index 8b9ed2e41a..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderRequest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; -import javax.portlet.PortletMode; -import javax.portlet.RenderRequest; -import javax.portlet.WindowState; - -/** - * Mock implementation of the {@link javax.portlet.RenderRequest} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockRenderRequest extends MockPortletRequest implements RenderRequest { - - /** - * Create a new MockRenderRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @see MockPortalContext - * @see MockPortletContext - */ - public MockRenderRequest() { - super(); - } - - /** - * Create a new MockRenderRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param portletMode the mode that the portlet runs in - */ - public MockRenderRequest(PortletMode portletMode) { - super(); - setPortletMode(portletMode); - } - - /** - * Create a new MockRenderRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param portletMode the mode that the portlet runs in - * @param windowState the window state to run the portlet in - */ - public MockRenderRequest(PortletMode portletMode, WindowState windowState) { - super(); - setPortletMode(portletMode); - setWindowState(windowState); - } - - /** - * Create a new MockRenderRequest with a default {@link MockPortalContext}. - * @param portletContext the PortletContext that the request runs in - */ - public MockRenderRequest(PortletContext portletContext) { - super(portletContext); - } - - /** - * Create a new MockRenderRequest. - * @param portalContext the PortletContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockRenderRequest(PortalContext portalContext, PortletContext portletContext) { - super(portalContext, portletContext); - } - - - @Override - protected String getLifecyclePhase() { - return RENDER_PHASE; - } - - @Override - public String getETag() { - return getProperty(RenderRequest.ETAG); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java deleted file mode 100644 index e359b0b52c..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockRenderResponse.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Collection; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; - -/** - * Mock implementation of the {@link javax.portlet.RenderResponse} interface. - * - * @author John A. Lewis - * @author Juergen Hoeller - * @since 2.0 - */ -public class MockRenderResponse extends MockMimeResponse implements RenderResponse { - - private String title; - - private Collection nextPossiblePortletModes; - - - /** - * Create a new MockRenderResponse with a default {@link MockPortalContext}. - * @see MockPortalContext - */ - public MockRenderResponse() { - super(); - } - - /** - * Create a new MockRenderResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - */ - public MockRenderResponse(PortalContext portalContext) { - super(portalContext); - } - - /** - * Create a new MockRenderResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - * @param request the corresponding render request that this response - * is generated for - */ - public MockRenderResponse(PortalContext portalContext, RenderRequest request) { - super(portalContext, request); - } - - - //--------------------------------------------------------------------- - // RenderResponse methods - //--------------------------------------------------------------------- - - @Override - public void setTitle(String title) { - this.title = title; - } - - public String getTitle() { - return this.title; - } - - @Override - public void setNextPossiblePortletModes(Collection portletModes) { - this.nextPossiblePortletModes = portletModes; - } - - public Collection getNextPossiblePortletModes() { - return this.nextPossiblePortletModes; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java deleted file mode 100644 index 5878e7b96e..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceRequest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.portlet.PortalContext; -import javax.portlet.PortletContext; -import javax.portlet.RenderRequest; -import javax.portlet.ResourceRequest; - -/** - * Mock implementation of the {@link javax.portlet.ResourceRequest} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockResourceRequest extends MockClientDataRequest implements ResourceRequest { - - private String resourceID; - - private String cacheability; - - private final Map privateRenderParameterMap = new LinkedHashMap(); - - - /** - * Create a new MockResourceRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @see org.springframework.mock.web.portlet.MockPortalContext - * @see org.springframework.mock.web.portlet.MockPortletContext - */ - public MockResourceRequest() { - super(); - } - - /** - * Create a new MockResourceRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param resourceID the resource id for this request - */ - public MockResourceRequest(String resourceID) { - super(); - this.resourceID = resourceID; - } - - /** - * Create a new MockResourceRequest with a default {@link MockPortalContext} - * and a default {@link MockPortletContext}. - * @param url the resource URL for this request - */ - public MockResourceRequest(MockResourceURL url) { - super(); - this.resourceID = url.getResourceID(); - this.cacheability = url.getCacheability(); - } - - /** - * Create a new MockResourceRequest with a default {@link MockPortalContext}. - * @param portletContext the PortletContext that the request runs in - */ - public MockResourceRequest(PortletContext portletContext) { - super(portletContext); - } - - /** - * Create a new MockResourceRequest. - * @param portalContext the PortalContext that the request runs in - * @param portletContext the PortletContext that the request runs in - */ - public MockResourceRequest(PortalContext portalContext, PortletContext portletContext) { - super(portalContext, portletContext); - } - - - @Override - protected String getLifecyclePhase() { - return RESOURCE_PHASE; - } - - public void setResourceID(String resourceID) { - this.resourceID = resourceID; - } - - @Override - public String getResourceID() { - return this.resourceID; - } - - public void setCacheability(String cacheLevel) { - this.cacheability = cacheLevel; - } - - @Override - public String getCacheability() { - return this.cacheability; - } - - @Override - public String getETag() { - return getProperty(RenderRequest.ETAG); - } - - public void addPrivateRenderParameter(String key, String value) { - this.privateRenderParameterMap.put(key, new String[] {value}); - } - - public void addPrivateRenderParameter(String key, String[] values) { - this.privateRenderParameterMap.put(key, values); - } - - @Override - public Map getPrivateRenderParameterMap() { - return Collections.unmodifiableMap(this.privateRenderParameterMap); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java deleted file mode 100644 index 4c7f45279b..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import javax.portlet.ResourceResponse; - -/** - * Mock implementation of the {@link javax.portlet.ResourceResponse} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockResourceResponse extends MockMimeResponse implements ResourceResponse { - - private int contentLength = 0; - - - @Override - public void setContentLength(int len) { - this.contentLength = len; - } - - public int getContentLength() { - return this.contentLength; - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java deleted file mode 100644 index b7aab871df..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockResourceURL.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.util.Map; -import javax.portlet.ResourceURL; - -/** - * Mock implementation of the {@link javax.portlet.ResourceURL} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockResourceURL extends MockBaseURL implements ResourceURL { - - private String resourceID; - - private String cacheability; - - - //--------------------------------------------------------------------- - // ResourceURL methods - //--------------------------------------------------------------------- - - @Override - public void setResourceID(String resourceID) { - this.resourceID = resourceID; - } - - public String getResourceID() { - return this.resourceID; - } - - @Override - public void setCacheability(String cacheLevel) { - this.cacheability = cacheLevel; - } - - @Override - public String getCacheability() { - return this.cacheability; - } - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(encodeParameter("resourceID", this.resourceID)); - if (this.cacheability != null) { - sb.append(";").append(encodeParameter("cacheability", this.cacheability)); - } - for (Map.Entry entry : this.parameters.entrySet()) { - sb.append(";").append(encodeParameter("param_" + entry.getKey(), entry.getValue())); - } - return (isSecure() ? "https:" : "http:") + - "//localhost/mockportlet?" + sb.toString(); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java deleted file mode 100644 index 007204ce98..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/MockStateAwareResponse.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2002-2012 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.mock.web.portlet; - -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.portlet.PortalContext; -import javax.portlet.PortletMode; -import javax.portlet.PortletModeException; -import javax.portlet.StateAwareResponse; -import javax.portlet.WindowState; -import javax.portlet.WindowStateException; -import javax.xml.namespace.QName; - -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -/** - * Mock implementation of the {@link javax.portlet.StateAwareResponse} interface. - * - * @author Juergen Hoeller - * @since 3.0 - */ -public class MockStateAwareResponse extends MockPortletResponse implements StateAwareResponse { - - private WindowState windowState; - - private PortletMode portletMode; - - private final Map renderParameters = new LinkedHashMap(); - - private final Map events = new HashMap(); - - - /** - * Create a new MockActionResponse with a default {@link MockPortalContext}. - * @see org.springframework.mock.web.portlet.MockPortalContext - */ - public MockStateAwareResponse() { - super(); - } - - /** - * Create a new MockActionResponse. - * @param portalContext the PortalContext defining the supported - * PortletModes and WindowStates - */ - public MockStateAwareResponse(PortalContext portalContext) { - super(portalContext); - } - - - @Override - public void setWindowState(WindowState windowState) throws WindowStateException { - if (!CollectionUtils.contains(getPortalContext().getSupportedWindowStates(), windowState)) { - throw new WindowStateException("WindowState not supported", windowState); - } - this.windowState = windowState; - } - - @Override - public WindowState getWindowState() { - return this.windowState; - } - - @Override - public void setPortletMode(PortletMode portletMode) throws PortletModeException { - if (!CollectionUtils.contains(getPortalContext().getSupportedPortletModes(), portletMode)) { - throw new PortletModeException("PortletMode not supported", portletMode); - } - this.portletMode = portletMode; - } - - @Override - public PortletMode getPortletMode() { - return this.portletMode; - } - - @Override - public void setRenderParameters(Map parameters) { - Assert.notNull(parameters, "Parameters Map must not be null"); - this.renderParameters.clear(); - this.renderParameters.putAll(parameters); - } - - @Override - public void setRenderParameter(String key, String value) { - Assert.notNull(key, "Parameter key must not be null"); - Assert.notNull(value, "Parameter value must not be null"); - this.renderParameters.put(key, new String[] {value}); - } - - @Override - public void setRenderParameter(String key, String[] values) { - Assert.notNull(key, "Parameter key must not be null"); - Assert.notNull(values, "Parameter values must not be null"); - this.renderParameters.put(key, values); - } - - public String getRenderParameter(String key) { - Assert.notNull(key, "Parameter key must not be null"); - String[] arr = this.renderParameters.get(key); - return (arr != null && arr.length > 0 ? arr[0] : null); - } - - public String[] getRenderParameterValues(String key) { - Assert.notNull(key, "Parameter key must not be null"); - return this.renderParameters.get(key); - } - - public Iterator getRenderParameterNames() { - return this.renderParameters.keySet().iterator(); - } - - @Override - public Map getRenderParameterMap() { - return Collections.unmodifiableMap(this.renderParameters); - } - - @Override - public void removePublicRenderParameter(String name) { - this.renderParameters.remove(name); - } - - @Override - public void setEvent(QName name, Serializable value) { - this.events.put(name, value); - } - - @Override - public void setEvent(String name, Serializable value) { - this.events.put(new QName(name), value); - } - - public Iterator getEventNames() { - return this.events.keySet().iterator(); - } - - public Serializable getEvent(QName name) { - return this.events.get(name); - } - - public Serializable getEvent(String name) { - return this.events.get(new QName(name)); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java deleted file mode 100644 index 716f71b0ef..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/ServletWrappingPortletContext.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2002-2016 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.mock.web.portlet; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Set; -import javax.portlet.PortletContext; -import javax.portlet.PortletRequestDispatcher; -import javax.servlet.ServletContext; - -import org.springframework.util.Assert; - -/** - * Mock implementation of the {@link javax.portlet.PortletContext} interface, - * wrapping an underlying {@link javax.servlet.ServletContext}. - * - * @author Juergen Hoeller - * @since 3.0 - * @see MockPortletContext - */ -public class ServletWrappingPortletContext implements PortletContext { - - private final ServletContext servletContext; - - - /** - * Create a new PortletContext wrapping the given ServletContext. - * @param servletContext the ServletContext to wrap - */ - public ServletWrappingPortletContext(ServletContext servletContext) { - Assert.notNull(servletContext, "ServletContext must not be null"); - this.servletContext = servletContext; - } - - /** - * Return the underlying ServletContext that this PortletContext wraps. - */ - public final ServletContext getServletContext() { - return this.servletContext; - } - - - @Override - public String getServerInfo() { - return this.servletContext.getServerInfo(); - } - - @Override - public PortletRequestDispatcher getRequestDispatcher(String path) { - return null; - } - - @Override - public PortletRequestDispatcher getNamedDispatcher(String name) { - return null; - } - - @Override - public InputStream getResourceAsStream(String path) { - return this.servletContext.getResourceAsStream(path); - } - - @Override - public int getMajorVersion() { - return 2; - } - - @Override - public int getMinorVersion() { - return 0; - } - - @Override - public String getMimeType(String file) { - return this.servletContext.getMimeType(file); - } - - @Override - public String getRealPath(String path) { - return this.servletContext.getRealPath(path); - } - - @Override - public Set getResourcePaths(String path) { - return this.servletContext.getResourcePaths(path); - } - - @Override - public URL getResource(String path) throws MalformedURLException { - return this.servletContext.getResource(path); - } - - @Override - public Object getAttribute(String name) { - return this.servletContext.getAttribute(name); - } - - @Override - public Enumeration getAttributeNames() { - return this.servletContext.getAttributeNames(); - } - - @Override - public String getInitParameter(String name) { - return this.servletContext.getInitParameter(name); - } - - @Override - public Enumeration getInitParameterNames() { - return this.servletContext.getInitParameterNames(); - } - - @Override - public void log(String msg) { - this.servletContext.log(msg); - } - - @Override - public void log(String message, Throwable throwable) { - this.servletContext.log(message, throwable); - } - - @Override - public void removeAttribute(String name) { - this.servletContext.removeAttribute(name); - } - - @Override - public void setAttribute(String name, Object object) { - this.servletContext.setAttribute(name, object); - } - - @Override - public String getPortletContextName() { - return this.servletContext.getServletContextName(); - } - - @Override - public Enumeration getContainerRuntimeOptions() { - return Collections.enumeration(Collections.emptySet()); - } - -} diff --git a/spring-test/src/main/java/org/springframework/mock/web/portlet/package-info.java b/spring-test/src/main/java/org/springframework/mock/web/portlet/package-info.java deleted file mode 100644 index 526481c681..0000000000 --- a/spring-test/src/main/java/org/springframework/mock/web/portlet/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * A comprehensive set of Portlet API 2.0 mock objects, - * targeted at usage with Spring's Web MVC framework. - * Useful for testing web contexts and controllers. - * - *

More convenient to use than dynamic mock objects - * (EasyMock) or - * existing Portlet API mock objects. - */ -package org.springframework.mock.web.portlet; diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java index 41aafefa42..e9b7231baf 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -27,8 +27,6 @@ import org.springframework.core.annotation.AliasFor; /** * Annotation which indicates that a method parameter should be bound to an HTTP cookie. * - *

Supported for annotated handler methods in Servlet and Portlet environments. - * *

The method parameter may be declared as type {@link javax.servlet.http.Cookie} * or as cookie value type (String, int, etc.). * @@ -39,9 +37,6 @@ import org.springframework.core.annotation.AliasFor; * @see RequestParam * @see RequestHeader * @see org.springframework.web.bind.annotation.RequestMapping - * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter - * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java index 98cbd6a895..943b81995c 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -24,8 +24,7 @@ import java.lang.annotation.Target; /** * Annotation for handling exceptions in specific handler classes and/or - * handler methods. Provides consistent style between Servlet and Portlet - * environments, with the semantics adapting to the concrete environment. + * handler methods. * *

Handler methods which are annotated with this annotation are allowed to * have very flexible signatures. They may have parameters of the following @@ -34,16 +33,10 @@ import java.lang.annotation.Target; *

  • An exception argument: declared as a general Exception or as a more * specific exception. This also serves as a mapping hint if the annotation * itself does not narrow the exception types through its {@link #value()}. - *
  • Request and/or response objects (Servlet API or Portlet API). + *
  • Request and/or response objects (typically from the Servlet API). * You may choose any specific request/response type, e.g. - * {@link javax.servlet.ServletRequest} / {@link javax.servlet.http.HttpServletRequest} - * or {@link javax.portlet.PortletRequest} / {@link javax.portlet.ActionRequest} / - * {@link javax.portlet.RenderRequest}. Note that in the Portlet case, - * an explicitly declared action/render argument is also used for mapping - * specific request types onto a handler method (in case of no other - * information given that differentiates between action and render requests). - *
  • Session object (Servlet API or Portlet API): either - * {@link javax.servlet.http.HttpSession} or {@link javax.portlet.PortletSession}. + * {@link javax.servlet.ServletRequest} / {@link javax.servlet.http.HttpServletRequest}. + *
  • Session object: typically {@link javax.servlet.http.HttpSession}. * An argument of this type will enforce the presence of a corresponding session. * As a consequence, such an argument will never be {@code null}. * Note that session access may not be thread-safe, in particular in a @@ -54,17 +47,17 @@ import java.lang.annotation.Target; *
  • {@link org.springframework.web.context.request.WebRequest} or * {@link org.springframework.web.context.request.NativeWebRequest}. * Allows for generic request parameter access as well as request/session - * attribute access, without ties to the native Servlet/Portlet API. + * attribute access, without ties to the native Servlet API. *
  • {@link java.util.Locale} for the current request locale * (determined by the most specific locale resolver available, * i.e. the configured {@link org.springframework.web.servlet.LocaleResolver} - * in a Servlet environment and the portal locale in a Portlet environment). + * in a Servlet environment). *
  • {@link java.io.InputStream} / {@link java.io.Reader} for access * to the request's content. This will be the raw InputStream/Reader as - * exposed by the Servlet/Portlet API. + * exposed by the Servlet API. *
  • {@link java.io.OutputStream} / {@link java.io.Writer} for generating * the response's content. This will be the raw OutputStream/Writer as - * exposed by the Servlet/Portlet API. + * exposed by the Servlet API. *
  • {@link org.springframework.ui.Model} as an alternative to returning * a model map from the handler method. Note that the provided model is not * pre-populated with regular model attributes and therefore always empty, @@ -73,7 +66,7 @@ import java.lang.annotation.Target; * *

    The following return types are supported for handler methods: *

    * *

    In Servlet environments, you can combine the {@code ExceptionHandler} annotation * with {@link ResponseStatus @ResponseStatus}, to define the response status * for the HTTP response. * - *

    Note: In Portlet environments, {@code ExceptionHandler} annotated methods - * will only be called during the render and resource phases - just like - * {@link org.springframework.web.portlet.HandlerExceptionResolver} beans would. - * Exceptions carried over from the action and event phases will be invoked during - * the render phase as well, with exception handler methods having to be present - * on the controller class that defines the applicable render method. - * * @author Arjen Poutsma * @author Juergen Hoeller * @since 3.0 * @see org.springframework.web.context.request.WebRequest - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver - * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestHeader.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestHeader.java index b7203f2fe2..a01ad44a2c 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestHeader.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestHeader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -40,8 +40,6 @@ import org.springframework.core.annotation.AliasFor; * @see RequestMapping * @see RequestParam * @see CookieValue - * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java index cda331c4b8..0e756a2c1e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java @@ -27,34 +27,17 @@ import org.springframework.core.annotation.AliasFor; /** * Annotation for mapping web requests onto specific handler classes and/or - * handler methods. Provides a consistent style between Servlet and Portlet - * environments, with the semantics adapting to the concrete environment. - * - *

    NOTE: The set of features supported for Servlets is a superset - * of the set of features supported for Portlets. The places where this applies - * are marked with the label "Servlet-only" in this source file. For Servlet - * environments there are some further distinctions depending on whether an - * application is configured with {@literal "@MVC 3.0"} or - * {@literal "@MVC 3.1"} support classes. The places where this applies are - * marked with {@literal "@MVC 3.1-only"} in this source file. For more - * details see the note on the new support classes added in Spring MVC 3.1 - * further below. + * handler methods. * *

    Handler methods which are annotated with this annotation are allowed to * have very flexible signatures. They may have parameters of the following * types, in arbitrary order (except for validation results, which need to * follow right after the corresponding command object, if desired): *