mirror of
https://github.com/apache/struts.git
synced 2026-08-07 23:57:03 +00:00
WW-5141
- delete portlet code
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
# Struts 2 Portlet JUnit plugin
|
||||
The Portlet JUnit Plugin supports testing applications that use the Portlet Plugin.
|
||||
@@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-junit-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>DEPRECATED: Struts 2 Portlet JUnit Plugin - since 6.3.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.junit;
|
||||
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.mock.web.portlet.MockPortletContext;
|
||||
import org.apache.struts2.mock.web.portlet.MockPortletRequest;
|
||||
import org.apache.struts2.mock.web.portlet.MockPortletResponse;
|
||||
import org.apache.struts2.mock.web.portlet.MockPortletSession;
|
||||
import org.apache.struts2.mock.web.portlet.MockStateAwareResponse;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class StrutsPortletTestCase extends StrutsTestCase {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsPortletTestCase.class);
|
||||
|
||||
protected MockPortletSession portletSession;
|
||||
protected MockPortletRequest portletRequest;
|
||||
protected MockPortletResponse portletResponse;
|
||||
protected MockContext portletContext;
|
||||
|
||||
@Override
|
||||
protected void initActionContext(ActionContext actionContext) {
|
||||
super.initActionContext(actionContext);
|
||||
initPortletContext(actionContext);
|
||||
}
|
||||
|
||||
protected void initPortletContext(ActionContext actionContext) {
|
||||
LOG.debug("Initializing mock portlet environment");
|
||||
portletContext = new MockContext();
|
||||
portletContext.setMajorVersion(getMajorVersion());
|
||||
actionContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletContext);
|
||||
|
||||
portletRequest = new MockPortletRequest(portletContext);
|
||||
portletResponse = new MockStateAwareResponse();
|
||||
portletSession = new MockPortletSession();
|
||||
portletRequest.setSession(portletSession);
|
||||
actionContext.withSession(createSession());
|
||||
actionContext.put(PortletConstants.REQUEST, portletRequest);
|
||||
actionContext.put(PortletConstants.RESPONSE, portletResponse);
|
||||
actionContext.put(PortletConstants.MODE_NAMESPACE_MAP, new HashMap<PortletMode, String>());
|
||||
actionContext.put(PortletConstants.PHASE, PortletPhase.EVENT_PHASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to define version of your portlet environment
|
||||
*
|
||||
* @return portlet version
|
||||
*/
|
||||
protected int getMajorVersion() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to create your own session
|
||||
*
|
||||
* @return Map with session parameters
|
||||
*/
|
||||
private Map<String, Object> createSession() {
|
||||
return new HashMap<>(portletRequest.getPortletSession().getAttributeMap());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple workaround to define Portlet version
|
||||
*/
|
||||
class MockContext extends MockPortletContext {
|
||||
|
||||
private int majorVersion;
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
public void setMajorVersion(int majorVersion) {
|
||||
this.majorVersion = majorVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project name="Apache Struts">
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>${fluido-skin.version}</version>
|
||||
</skin>
|
||||
<bannerLeft>
|
||||
<name>Apache Software Foundation</name>
|
||||
<src>http://www.apache.org/images/asf-logo.gif</src>
|
||||
<href>http://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<name>Apache Struts</name>
|
||||
<src>http://struts.apache.org/img/struts-logo.svg</src>
|
||||
<href>http://struts.apache.org/</href>
|
||||
</bannerRight>
|
||||
<publishDate position="left"/>
|
||||
<version position="right"/>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Apache" href="http://www.apache.org/"/>
|
||||
<item name="Struts" href="http://struts.apache.org/"/>
|
||||
</links>
|
||||
|
||||
<menu ref="parent"/>
|
||||
<menu ref="reports"/>
|
||||
|
||||
<footer>
|
||||
<![CDATA[<div class="row span12">
|
||||
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project
|
||||
logos are trademarks of The Apache Software Foundation.
|
||||
</div>]]>
|
||||
</footer>
|
||||
</body>
|
||||
</project>
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.junit;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
public class StrutsPortletTestCaseTest extends StrutsPortletTestCase {
|
||||
|
||||
String KEY = "my-param";
|
||||
|
||||
public void testShouldPortletContextBeAvailable() throws Exception {
|
||||
// given
|
||||
assertNull(ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT));
|
||||
|
||||
// when
|
||||
ActionProxy proxy = getActionProxy("/test/testAction.action");
|
||||
String result = proxy.execute();
|
||||
|
||||
// then
|
||||
assertEquals(Action.SUCCESS, result);
|
||||
Object portletContext = ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
assertNotNull(portletContext);
|
||||
assertTrue(portletContext instanceof PortletContext);
|
||||
}
|
||||
|
||||
public void testShouldAdditionalContextParamsBeAvailable() throws Exception {
|
||||
// given
|
||||
assertNull(ActionContext.getContext().get(KEY));
|
||||
|
||||
// when
|
||||
ActionProxy proxy = getActionProxy("/test/testAction.action");
|
||||
String result = proxy.execute();
|
||||
|
||||
// then
|
||||
assertEquals(Action.SUCCESS, result);
|
||||
assertNotNull(ActionContext.getContext().get(KEY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyAdditionalParams(ActionContext context) {
|
||||
context.put(KEY, new Object());
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
|
||||
"https://struts.apache.org/dtds/struts-2.1.dtd">
|
||||
|
||||
<struts>
|
||||
<package name="test" namespace="/test" extends="struts-default">
|
||||
<action name="testAction" class="com.opensymphony.xwork2.ActionSupport">
|
||||
<result name="success" type="httpheader">
|
||||
<param name="status">200</param>
|
||||
</result>
|
||||
</action>
|
||||
</package>
|
||||
</struts>
|
||||
@@ -1,2 +0,0 @@
|
||||
# Struts 2 Portlet Mocks plugin
|
||||
This plugin is deprecated, and it will be removed soon, **please do not use it**!
|
||||
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>DEPRECATED: Struts 2 Portlet Mocks Plugin - since 6.0.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Portlet -->
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring.platformVersion>4.3.30.RELEASE</spring.platformVersion>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
-86
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-132
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> 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) {
|
||||
// NOTE: Changed since original Spring 4.3.x version.
|
||||
// Cannot call setRenderParameter(renderUrlParamName, location) here as it always results in an IllegalStateException - since a redirect has been called.
|
||||
// Due to this, we call super.setRenderParameter() directly, otherwise this method can never successfully be called.
|
||||
super.setRenderParameter(renderUrlParamName, location);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRedirectedUrl() {
|
||||
return this.redirectedUrl;
|
||||
}
|
||||
|
||||
}
|
||||
-161
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> parameters = new LinkedHashMap<String, String[]>();
|
||||
|
||||
private boolean secure = false;
|
||||
|
||||
private final Map<String, String[]> properties = new LinkedHashMap<String, String[]>();
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// 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<String, String[]> parameters) {
|
||||
Assert.notNull(parameters, "Parameters Map must not be null");
|
||||
this.parameters.clear();
|
||||
this.parameters.putAll(parameters);
|
||||
}
|
||||
|
||||
public Set<String> 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<String, String[]> 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<String, String[]> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-78
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-135
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-91
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-90
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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());
|
||||
}
|
||||
|
||||
}
|
||||
-259
@@ -1,259 +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
|
||||
*
|
||||
* https://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.apache.struts2.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();
|
||||
|
||||
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<String> 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();
|
||||
}
|
||||
if (this.outputStream != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
-101
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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.apache.struts2.mock.web.portlet.multipart.MultipartActionRequest;
|
||||
|
||||
/**
|
||||
* Mock implementation of the
|
||||
* {@link org.springframework.web.portlet.multipart.MultipartActionRequest} interface.
|
||||
*
|
||||
* <p>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<String, MultipartFile> multipartFiles =
|
||||
new LinkedMultiValueMap<String, MultipartFile>();
|
||||
|
||||
|
||||
/**
|
||||
* 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<String> getFileNames() {
|
||||
return this.multipartFiles.keySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultipartFile getFile(String name) {
|
||||
return this.multipartFiles.getFirst(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MultipartFile> getFiles(String name) {
|
||||
List<MultipartFile> multipartFiles = this.multipartFiles.get(name);
|
||||
if (multipartFiles != null) {
|
||||
return multipartFiles;
|
||||
}
|
||||
else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MultipartFile> getFileMap() {
|
||||
return this.multipartFiles.toSingleValueMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiValueMap<String, MultipartFile> getMultiFileMap() {
|
||||
return new LinkedMultiValueMap<String, MultipartFile>(this.multipartFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMultipartContentType(String paramOrFileName) {
|
||||
MultipartFile file = getFile(paramOrFileName);
|
||||
if (file != null) {
|
||||
return file.getContentType();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-106
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String> properties = new HashMap<String, String>();
|
||||
|
||||
private final List<PortletMode> portletModes;
|
||||
|
||||
private final List<WindowState> 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<PortletMode>(3);
|
||||
this.portletModes.add(PortletMode.VIEW);
|
||||
this.portletModes.add(PortletMode.EDIT);
|
||||
this.portletModes.add(PortletMode.HELP);
|
||||
|
||||
this.windowStates = new ArrayList<WindowState>(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<PortletMode> supportedPortletModes, List<WindowState> supportedWindowStates) {
|
||||
this.portletModes = new ArrayList<PortletMode>(supportedPortletModes);
|
||||
this.windowStates = new ArrayList<WindowState>(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<String> getPropertyNames() {
|
||||
return Collections.enumeration(this.properties.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<PortletMode> getSupportedPortletModes() {
|
||||
return Collections.enumeration(this.portletModes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<WindowState> getSupportedWindowStates() {
|
||||
return Collections.enumeration(this.windowStates);
|
||||
}
|
||||
|
||||
}
|
||||
-194
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<Locale, ResourceBundle> resourceBundles = new HashMap<Locale, ResourceBundle>();
|
||||
|
||||
private final Map<String, String> initParameters = new LinkedHashMap<String, String>();
|
||||
|
||||
private final Set<String> publicRenderParameterNames = new LinkedHashSet<String>();
|
||||
|
||||
private String defaultNamespace = XMLConstants.NULL_NS_URI;
|
||||
|
||||
private final Set<QName> publishingEventQNames = new LinkedHashSet<QName>();
|
||||
|
||||
private final Set<QName> processingEventQNames = new LinkedHashSet<QName>();
|
||||
|
||||
private final Set<Locale> supportedLocales = new LinkedHashSet<Locale>();
|
||||
|
||||
private final Map<String, String[]> containerRuntimeOptions = new LinkedHashMap<String, String[]>();
|
||||
|
||||
|
||||
/**
|
||||
* 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<String> getInitParameterNames() {
|
||||
return Collections.enumeration(this.initParameters.keySet());
|
||||
}
|
||||
|
||||
public void addPublicRenderParameterName(String name) {
|
||||
this.publicRenderParameterNames.add(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> 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<QName> getPublishingEventQNames() {
|
||||
return Collections.enumeration(this.publishingEventQNames);
|
||||
}
|
||||
|
||||
public void addProcessingEventQName(QName name) {
|
||||
this.processingEventQNames.add(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<QName> getProcessingEventQNames() {
|
||||
return Collections.enumeration(this.processingEventQNames);
|
||||
}
|
||||
|
||||
public void addSupportedLocale(Locale locale) {
|
||||
this.supportedLocales.add(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<Locale> 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<String, String[]> getContainerRuntimeOptions() {
|
||||
return Collections.unmodifiableMap(this.containerRuntimeOptions);
|
||||
}
|
||||
|
||||
}
|
||||
-285
@@ -1,285 +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
|
||||
*
|
||||
* https://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.apache.struts2.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.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<String, Object> attributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
private final Map<String, String> initParameters = new LinkedHashMap<String, String>();
|
||||
|
||||
private String portletContextName = "MockPortletContext";
|
||||
|
||||
private Set<String> containerRuntimeOptions = new LinkedHashSet<String>();
|
||||
|
||||
|
||||
/**
|
||||
* 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 null;
|
||||
}
|
||||
|
||||
@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<String> 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<String> resourcePaths = new HashSet<String>(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<String> getAttributeNames() {
|
||||
return Collections.enumeration(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<String> 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<String> getContainerRuntimeOptions() {
|
||||
return Collections.enumeration(this.containerRuntimeOptions);
|
||||
}
|
||||
|
||||
}
|
||||
-123
@@ -1,123 +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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> preferences = new LinkedHashMap<String, String[]>();
|
||||
|
||||
private final Set<String> readOnly = new HashSet<String>();
|
||||
|
||||
|
||||
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<String> getNames() {
|
||||
return Collections.enumeration(this.preferences.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-565
@@ -1,565 +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
|
||||
*
|
||||
* https://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.apache.struts2.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.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 jakarta.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<String, List<String>> properties = new LinkedHashMap<String, List<String>>();
|
||||
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
|
||||
|
||||
private final Map<String, String[]> parameters = new LinkedHashMap<String, String[]>();
|
||||
|
||||
private String authType = null;
|
||||
|
||||
private String contextPath = "";
|
||||
|
||||
private String remoteUser = null;
|
||||
|
||||
private Principal userPrincipal = null;
|
||||
|
||||
private final Set<String> userRoles = new HashSet<String>();
|
||||
|
||||
private boolean secure = false;
|
||||
|
||||
private boolean requestedSessionIdValid = true;
|
||||
|
||||
private final List<String> responseContentTypes = new LinkedList<String>();
|
||||
|
||||
private final List<Locale> locales = new LinkedList<Locale>();
|
||||
|
||||
private String scheme = "http";
|
||||
|
||||
private String serverName = "localhost";
|
||||
|
||||
private int serverPort = 80;
|
||||
|
||||
private String windowID;
|
||||
|
||||
private Cookie[] cookies;
|
||||
|
||||
private final Set<String> publicParameterNames = new HashSet<String>();
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <p>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<String> list = new LinkedList<String>();
|
||||
list.add(value);
|
||||
this.properties.put(key, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single value for the specified property.
|
||||
* <p>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<String> oldList = this.properties.get(key);
|
||||
if (oldList != null) {
|
||||
oldList.add(value);
|
||||
}
|
||||
else {
|
||||
List<String> list = new LinkedList<String>();
|
||||
list.add(value);
|
||||
this.properties.put(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key) {
|
||||
Assert.notNull(key, "Property key must not be null");
|
||||
List<String> list = this.properties.get(key);
|
||||
return (list != null && list.size() > 0 ? list.get(0) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getProperties(String key) {
|
||||
Assert.notNull(key, "property key must not be null");
|
||||
return Collections.enumeration(this.properties.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> 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<String> getAttributeNames() {
|
||||
checkActive();
|
||||
return Collections.enumeration(this.attributes.keySet());
|
||||
}
|
||||
|
||||
public void setParameters(Map<String, String[]> 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<String> getParameterNames() {
|
||||
return Collections.enumeration(this.parameters.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
return this.parameters.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> 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<String> 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<Locale> 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<String, String[]> getPrivateParameterMap() {
|
||||
if (!this.publicParameterNames.isEmpty()) {
|
||||
Map<String, String[]> filtered = new LinkedHashMap<String, String[]>();
|
||||
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<String, String[]> getPublicParameterMap() {
|
||||
if (!this.publicParameterNames.isEmpty()) {
|
||||
Map<String, String[]> filtered = new LinkedHashMap<String, String[]>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
-87
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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 + "]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-202
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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 jakarta.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<String, String[]> properties = new LinkedHashMap<String, String[]>();
|
||||
|
||||
private String namespace = "";
|
||||
|
||||
private final Set<Cookie> cookies = new LinkedHashSet<Cookie>();
|
||||
|
||||
private final Map<String, Element[]> xmlProperties = new LinkedHashMap<String, Element[]>();
|
||||
|
||||
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<String> 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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
-250
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.mock.web.portlet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletSession;
|
||||
import jakarta.servlet.http.HttpSessionBindingEvent;
|
||||
import jakarta.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<String, Object> portletAttributes = new HashMap<String, Object>();
|
||||
|
||||
private final Map<String, Object> applicationAttributes = new HashMap<String, Object>();
|
||||
|
||||
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<String> getAttributeNames() {
|
||||
return Collections.enumeration(this.portletAttributes.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames(int scope) {
|
||||
if (scope == PortletSession.PORTLET_SCOPE) {
|
||||
return Collections.enumeration(this.portletAttributes.keySet());
|
||||
}
|
||||
else if (scope == PortletSession.APPLICATION_SCOPE) {
|
||||
return Collections.enumeration(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<String, Object> attributes) {
|
||||
for (Iterator<Map.Entry<String, Object>> it = attributes.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<String, Object> 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.lastAccessedTime = System.currentTimeMillis();
|
||||
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<String, Object> getAttributeMap() {
|
||||
return Collections.unmodifiableMap(this.portletAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-121
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> entry : this.parameters.entrySet()) {
|
||||
sb.append(";").append(encodeParameter("param_" + entry.getKey(), entry.getValue()));
|
||||
}
|
||||
return (isSecure() ? "https:" : "http:") +
|
||||
"//localhost/mockportlet?" + sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
-94
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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);
|
||||
}
|
||||
|
||||
}
|
||||
-90
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<PortletMode> 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<PortletMode> portletModes) {
|
||||
this.nextPossiblePortletModes = portletModes;
|
||||
}
|
||||
|
||||
public Collection<PortletMode> getNextPossiblePortletModes() {
|
||||
return this.nextPossiblePortletModes;
|
||||
}
|
||||
|
||||
}
|
||||
-132
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> privateRenderParameterMap = new LinkedHashMap<String, String[]>();
|
||||
|
||||
|
||||
/**
|
||||
* 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<String, String[]> getPrivateRenderParameterMap() {
|
||||
return Collections.unmodifiableMap(this.privateRenderParameterMap);
|
||||
}
|
||||
|
||||
}
|
||||
-41
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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;
|
||||
}
|
||||
|
||||
}
|
||||
-73
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> entry : this.parameters.entrySet()) {
|
||||
sb.append(";").append(encodeParameter("param_" + entry.getKey(), entry.getValue()));
|
||||
}
|
||||
return (isSecure() ? "https:" : "http:") +
|
||||
"//localhost/mockportlet?" + sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
-165
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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<String, String[]> renderParameters = new LinkedHashMap<String, String[]>();
|
||||
|
||||
private final Map<QName, Serializable> events = new HashMap<QName, Serializable>();
|
||||
|
||||
|
||||
/**
|
||||
* 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<String, String[]> 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<String> getRenderParameterNames() {
|
||||
return this.renderParameters.keySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> 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<QName> 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));
|
||||
}
|
||||
|
||||
}
|
||||
-161
@@ -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
|
||||
*
|
||||
* https://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.apache.struts2.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 jakarta.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<String> 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<String> getAttributeNames() {
|
||||
return this.servletContext.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
return this.servletContext.getInitParameter(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> 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<String> getContainerRuntimeOptions() {
|
||||
return Collections.enumeration(Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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
|
||||
*
|
||||
* https://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.apache.struts2.mock.web.portlet.multipart;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
|
||||
import org.springframework.web.multipart.MultipartRequest;
|
||||
|
||||
/**
|
||||
* Interface which provides additional methods for dealing with multipart
|
||||
* content within a portlet request, allowing to access uploaded files.
|
||||
* Implementations also need to override the standard ActionRequest
|
||||
* methods for parameter access, making multipart parameters available.
|
||||
*
|
||||
* <p>A concrete implementation is {@link DefaultMultipartActionRequest}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
* @see PortletMultipartResolver
|
||||
* @see org.springframework.web.multipart.MultipartFile
|
||||
* @see javax.portlet.ActionRequest#getParameter
|
||||
* @see javax.portlet.ActionRequest#getParameterNames
|
||||
* @see javax.portlet.ActionRequest#getParameterMap
|
||||
*/
|
||||
public interface MultipartActionRequest extends ActionRequest, MultipartRequest {
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
/*
|
||||
* This package is a copy of the org.springframework.web.portlet.multipart package from Spring 4.3.x
|
||||
* (org.springframework, spring-webmvc-portlet, <a href="https://github.com/spring-projects/spring-framework/tree/4.3.x</a>)
|
||||
* which changes the package name to: org.apache.struts2.mock.web.portlet.multipart.
|
||||
*
|
||||
* The copyright and license notice above is reproduced from the original package's CommonsPortletMultipartResolver.java,
|
||||
* since it contained the widest year-range.
|
||||
*
|
||||
* The mock objects only have a dependency on one file from the package, MultipartActionRequest.java, so
|
||||
* it was required. The other files in the package were not retained in this copy (CommonsPortletMultipartResolver.java
|
||||
* in particular created additional dependencies that would require copying additional packages).
|
||||
*
|
||||
* With Spring 5 dropping Portlet MVC support completely [SPR-14129], copying this package should allow
|
||||
* individuals to continue using JUnit unit tests for their Struts 2 Portlet Plugin applications with
|
||||
* Spring 5.x.
|
||||
*/
|
||||
/**
|
||||
* Multipart resolution framework for handling file uploads.
|
||||
* Provides a PortletMultipartResolver strategy interface,
|
||||
* and a generic extension of the ActionRequest interface
|
||||
* for accessing multipart files in web application code.
|
||||
*/
|
||||
package org.apache.struts2.mock.web.portlet.multipart;
|
||||
-35
@@ -1,35 +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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
/*
|
||||
* This package is a copy of the org.springframework.mock.web.portlet package from Spring 4.3.x
|
||||
* (org.springframework, spring-test, <a href="https://github.com/spring-projects/spring-framework/tree/4.3.x</a>)
|
||||
* which changes the package name to: org.apache.struts2.mock.web.portlet.
|
||||
*
|
||||
* The copyright and license notice above is reproduced from the original package's ServletWrappingPortletContext.java,
|
||||
* since it contained the widest year-range.
|
||||
*
|
||||
* With Spring 5 dropping Portlet MVC support completely [SPR-14129], copying this package should allow
|
||||
* individuals to continue using JUnit unit tests for their Struts 2 Portlet Plugin applications with
|
||||
* Spring 5.x.
|
||||
*/
|
||||
/**
|
||||
* A comprehensive set of Portlet API mock objects, targeted at usage with Spring's web MVC framework.
|
||||
* Useful for testing web contexts and controllers.
|
||||
*
|
||||
* <p>More convenient to use than dynamic mock objects (<a href="http://easymock.org/">EasyMock</a>) or
|
||||
* existing Portlet API mock objects.
|
||||
*/
|
||||
package org.apache.struts2.mock.web.portlet;
|
||||
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project name="Apache Struts">
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>${fluido-skin.version}</version>
|
||||
</skin>
|
||||
<bannerLeft>
|
||||
<name>Apache Software Foundation</name>
|
||||
<src>http://www.apache.org/images/asf-logo.gif</src>
|
||||
<href>http://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<name>Apache Struts</name>
|
||||
<src>http://struts.apache.org/img/struts-logo.svg</src>
|
||||
<href>http://struts.apache.org/</href>
|
||||
</bannerRight>
|
||||
<publishDate position="left"/>
|
||||
<version position="right"/>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Apache" href="http://www.apache.org/"/>
|
||||
<item name="Struts" href="http://struts.apache.org/"/>
|
||||
</links>
|
||||
|
||||
<menu ref="parent"/>
|
||||
<menu ref="reports"/>
|
||||
|
||||
<footer>
|
||||
<![CDATA[<div class="row span12">
|
||||
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project
|
||||
logos are trademarks of The Apache Software Foundation.
|
||||
</div>]]>
|
||||
</footer>
|
||||
</body>
|
||||
</project>
|
||||
-1604
File diff suppressed because it is too large
Load Diff
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
|
||||
<property name="scopes">
|
||||
<map>
|
||||
<entry key="session">
|
||||
<bean class="org.springframework.context.support.SimpleThreadScope"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,2 +0,0 @@
|
||||
# Struts 2 Portlet Tiles plugin
|
||||
This plugin is deprecated, and it will be removed soon, **please do not use it**!
|
||||
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-tiles-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>DEPRECATED: Struts 2 Portlet Tiles Plugin - since 6.0.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-tiles-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.views.tiles;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
import org.apache.struts2.result.ServletDispatcherResult;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.api.TilesException;
|
||||
import org.apache.tiles.api.access.TilesAccess;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.portlet.RenderPortletRequest;
|
||||
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Dedicated Tile result to be used in Portlet environment
|
||||
*
|
||||
* WW-2749
|
||||
*/
|
||||
public class PortletTilesResult extends ServletDispatcherResult {
|
||||
|
||||
public static final String TILES_ACTION_NAME = "tilesDirect";
|
||||
|
||||
public PortletTilesResult() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PortletTilesResult(String location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
public void doExecute(String location, ActionInvocation invocation) throws Exception {
|
||||
if (PortletActionContext.getPhase().isAction() || PortletActionContext.getPhase().isEvent()) {
|
||||
executeActionResult(location, invocation);
|
||||
} else {
|
||||
executeRenderResult(location);
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeRenderResult(String location) throws TilesException {
|
||||
setLocation(location);
|
||||
|
||||
PortletContext portletContext = PortletActionContext.getPortletContext();
|
||||
RenderRequest request = PortletActionContext.getRenderRequest();
|
||||
RenderResponse response = PortletActionContext.getRenderResponse();
|
||||
|
||||
TilesContainer container = getCurrentContainer(request, portletContext);
|
||||
ApplicationContext applicationContext = container.getApplicationContext();
|
||||
Request currentRequest = new RenderPortletRequest(applicationContext, portletContext, request, response);
|
||||
|
||||
container.render(location, currentRequest);
|
||||
}
|
||||
|
||||
protected void executeActionResult(String location, ActionInvocation invocation) {
|
||||
ActionResponse res = PortletActionContext.getActionResponse();
|
||||
|
||||
res.setRenderParameter(PortletConstants.ACTION_PARAM, TILES_ACTION_NAME);
|
||||
|
||||
Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
|
||||
sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location);
|
||||
|
||||
res.setRenderParameter(PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode().toString());
|
||||
}
|
||||
|
||||
protected TilesContainer getCurrentContainer(javax.portlet.PortletRequest request, PortletContext context) {
|
||||
|
||||
TilesContainer container = (TilesContainer) request.getAttribute(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME);
|
||||
|
||||
if (container == null) {
|
||||
container = getContainer(context);
|
||||
request.setAttribute(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
protected TilesContainer getContainer(PortletContext context) {
|
||||
return getContainer(context, TilesAccess.CONTAINER_ATTRIBUTE);
|
||||
}
|
||||
|
||||
protected TilesContainer getContainer(PortletContext context, String key) {
|
||||
if (key == null) {
|
||||
key = TilesAccess.CONTAINER_ATTRIBUTE;
|
||||
}
|
||||
return (TilesContainer) context.getAttribute(key);
|
||||
}
|
||||
|
||||
}
|
||||
-344
@@ -1,344 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.AbstractClientRequest;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.attribute.Addable;
|
||||
import org.apache.tiles.request.collection.HeaderValuesMap;
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.collection.ScopeMap;
|
||||
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.apache.tiles.request.portlet.extractor.RequestScopeExtractor;
|
||||
import org.apache.tiles.request.portlet.extractor.SessionScopeExtractor;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Portlet-based TilesApplicationContext implementation.
|
||||
*/
|
||||
public class PortletRequest extends AbstractClientRequest {
|
||||
|
||||
/**
|
||||
* The native available scopes.
|
||||
*/
|
||||
private static final List<String> SCOPES = Collections.unmodifiableList(Arrays.asList(REQUEST_SCOPE, "portletSession", "session", APPLICATION_SCOPE));
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-value
|
||||
* combinations (immutable).</p>
|
||||
*/
|
||||
private Map<String, String> header = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-value
|
||||
* combinations (write-only).</p>
|
||||
*/
|
||||
private Addable<String> responseHeaders = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-values
|
||||
* combinations (immutable).</p>
|
||||
*/
|
||||
private Map<String, String[]> headerValues = null;
|
||||
|
||||
/**
|
||||
* The <code>PortletContext</code> for this application.
|
||||
*/
|
||||
protected PortletContext context;
|
||||
|
||||
/**
|
||||
* <p>The <code>PortletRequest</code> for this request.</p>
|
||||
*/
|
||||
protected javax.portlet.PortletRequest request;
|
||||
|
||||
/**
|
||||
* The delegate to get information about parameters.
|
||||
*/
|
||||
protected RequestDelegate requestDelegate;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> requestScope = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The <code>PortletResponse</code> for this request.</p>
|
||||
*/
|
||||
protected PortletResponse response;
|
||||
|
||||
/**
|
||||
* The delegate to get information from a response (output stream, writer, etc.).
|
||||
*/
|
||||
protected ResponseDelegate responseDelegate;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of session scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> sessionScope = null;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of portlet session scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> portletSessionScope = null;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of PortletTilesRequestContext.
|
||||
*
|
||||
* @param applicationContext The Tiles application context.
|
||||
* @param context The portlet context to use.
|
||||
* @param request The request object to use.
|
||||
* @param response The response object to use.
|
||||
* @param requestDelegate The request delegate.
|
||||
* @param responseDelegate The response delegate.
|
||||
*/
|
||||
public PortletRequest(ApplicationContext applicationContext,
|
||||
PortletContext context, javax.portlet.PortletRequest request,
|
||||
PortletResponse response, RequestDelegate requestDelegate, ResponseDelegate responseDelegate) {
|
||||
super(applicationContext);
|
||||
|
||||
// Save the specified Portlet API object references
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.requestDelegate = requestDelegate;
|
||||
this.responseDelegate = responseDelegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return the {@link PortletRequest} for this context.</p>
|
||||
*
|
||||
* @return The used portlet request.
|
||||
*/
|
||||
public javax.portlet.PortletRequest getRequest() {
|
||||
return (this.request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the portlet context.
|
||||
*
|
||||
* @return The portlet context.
|
||||
*/
|
||||
public PortletContext getPortletContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String> getHeader() {
|
||||
if ((header == null) && (request != null)) {
|
||||
header = new ReadOnlyEnumerationMap<>(new HeaderExtractor(request, null));
|
||||
}
|
||||
return (header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Addable<String> getResponseHeaders() {
|
||||
if ((responseHeaders == null) && (request != null)) {
|
||||
responseHeaders = new HeaderExtractor(null, response);
|
||||
}
|
||||
return (responseHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String[]> getHeaderValues() {
|
||||
if ((headerValues == null) && (request != null)) {
|
||||
headerValues = new HeaderValuesMap(new HeaderExtractor(request, response));
|
||||
}
|
||||
return (headerValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getRequestScope() {
|
||||
if ((requestScope == null) && (request != null)) {
|
||||
requestScope = new ScopeMap(new RequestScopeExtractor(request));
|
||||
}
|
||||
return (requestScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getSessionScope() {
|
||||
if ((sessionScope == null) && (request != null)) {
|
||||
sessionScope = new ScopeMap(new SessionScopeExtractor(request,
|
||||
PortletSession.APPLICATION_SCOPE));
|
||||
}
|
||||
return (sessionScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getPortletSessionScope() {
|
||||
if ((portletSessionScope == null) && (request != null)) {
|
||||
portletSessionScope = new ScopeMap(new SessionScopeExtractor(
|
||||
request, PortletSession.APPLICATION_SCOPE));
|
||||
}
|
||||
return (portletSessionScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAvailableScopes() {
|
||||
return SCOPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Locale getRequestLocale() {
|
||||
return request.getLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParam() {
|
||||
return requestDelegate.getParam();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> getParamValues() {
|
||||
return requestDelegate.getParamValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isUserInRole(String role) {
|
||||
return request.isUserInRole(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return responseDelegate.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getPrintWriter() throws IOException {
|
||||
return responseDelegate.getPrintWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getWriter() throws IOException {
|
||||
return responseDelegate.getWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResponseCommitted() {
|
||||
return responseDelegate.isResponseCommitted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String contentType) {
|
||||
responseDelegate.setContentType(contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void doForward(String path) throws IOException {
|
||||
if (responseDelegate.isResponseCommitted()) {
|
||||
doInclude(path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
PortletRequestDispatcher rd = getPortletContext()
|
||||
.getRequestDispatcher(path);
|
||||
|
||||
if (rd == null) {
|
||||
throw new IOException(
|
||||
"No portlet request dispatcher returned for path '"
|
||||
+ path + "'");
|
||||
}
|
||||
|
||||
rd.forward(request, response);
|
||||
} catch (PortletException e) {
|
||||
throw new IOException("PortletException while including path '"
|
||||
+ path + "'.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void doInclude(String path) throws IOException {
|
||||
try {
|
||||
PortletRequestDispatcher rd = getPortletContext()
|
||||
.getRequestDispatcher(path);
|
||||
|
||||
if (rd == null) {
|
||||
throw new IOException(
|
||||
"No portlet request dispatcher returned for path '"
|
||||
+ path + "'");
|
||||
}
|
||||
|
||||
rd.include(request, response);
|
||||
} catch (PortletException e) {
|
||||
throw new IOException("PortletException while including path '"
|
||||
+ path + "'.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getContext(String scope) {
|
||||
if (REQUEST_SCOPE.equals(scope)) {
|
||||
return getRequestScope();
|
||||
} else if ("session".equals(scope)) {
|
||||
return getSessionScope();
|
||||
} else if ("portletSession".equals(scope)) {
|
||||
return getPortletSessionScope();
|
||||
} else if (APPLICATION_SCOPE.equals(scope)) {
|
||||
return getApplicationScope();
|
||||
}
|
||||
throw new IllegalArgumentException(scope + " does not exist. Call getAvailableScopes() first to check.");
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
|
||||
/**
|
||||
* Portlet request for a {@link RenderRequest}.
|
||||
*/
|
||||
public class RenderPortletRequest extends PortletRequest {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param applicationContext The application context.
|
||||
* @param context The portlet context.
|
||||
* @param request The portlet request.
|
||||
* @param response The portlet response.
|
||||
*/
|
||||
public RenderPortletRequest(ApplicationContext applicationContext, PortletContext context, RenderRequest request, RenderResponse response) {
|
||||
super(applicationContext, context, request, response, new PortletRequestDelegate(request), new MimeResponseDelegate(response));
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import javax.portlet.MimeResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Response delegate in case of {@link MimeResponse}.
|
||||
*/
|
||||
public class MimeResponseDelegate implements ResponseDelegate {
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private final MimeResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param response The response.
|
||||
*/
|
||||
public MimeResponseDelegate(MimeResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return response.getPortletOutputStream();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public PrintWriter getPrintWriter() throws IOException {
|
||||
return response.getWriter();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Writer getWriter() throws IOException {
|
||||
return response.getWriter();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean isResponseCommitted() {
|
||||
return response.isCommitted();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setContentType(String contentType) {
|
||||
response.setContentType(contentType);
|
||||
}
|
||||
}
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Request delegate in case of simple Portlet request.
|
||||
*/
|
||||
public class PortletRequestDelegate implements RequestDelegate {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request
|
||||
* parameter name-value.</p>
|
||||
*/
|
||||
private Map<String, String> param = null;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request
|
||||
* parameter name-values.</p>
|
||||
*/
|
||||
private Map<String, String[]> paramValues = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
*/
|
||||
public PortletRequestDelegate(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String> getParam() {
|
||||
if ((param == null) && (request != null)) {
|
||||
param = new ReadOnlyEnumerationMap<>(new ParameterExtractor(request));
|
||||
}
|
||||
return (param);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String[]> getParamValues() {
|
||||
if ((paramValues == null) && (request != null)) {
|
||||
paramValues = request.getParameterMap();
|
||||
}
|
||||
return (paramValues);
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Exposes the parameters of a portlet request, if available.
|
||||
*/
|
||||
public interface RequestDelegate {
|
||||
|
||||
/**
|
||||
* The parameters, as single values.
|
||||
*
|
||||
* @return The parameters.
|
||||
*/
|
||||
Map<String, String> getParam();
|
||||
|
||||
/**
|
||||
* The parameters, with values as array of strings.
|
||||
*
|
||||
* @return The parameters.
|
||||
*/
|
||||
Map<String, String[]> getParamValues();
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Exposes features of a response, if they are available.
|
||||
*/
|
||||
public interface ResponseDelegate {
|
||||
|
||||
/**
|
||||
* Returns the output stream.
|
||||
*
|
||||
* @return The output stream.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
OutputStream getOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the print writer.
|
||||
*
|
||||
* @return The print writer.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
PrintWriter getPrintWriter() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the writer.
|
||||
*
|
||||
* @return The writer.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
Writer getWriter() throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the content type of the response.
|
||||
*
|
||||
* @param contentType The content type.
|
||||
*/
|
||||
void setContentType(String contentType);
|
||||
|
||||
/**
|
||||
* Checks if the response is committed.
|
||||
*
|
||||
* @return <code>true</code> if the response is committed.
|
||||
*/
|
||||
boolean isResponseCommitted();
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
/**
|
||||
* Delegations to map all the different types of request and responses.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from portlet application scope.
|
||||
*/
|
||||
public class ApplicationScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private final PortletContext context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The portlet context.
|
||||
*/
|
||||
public ApplicationScopeExtractor(PortletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
context.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
context.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return context.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
return context.getAttribute(key);
|
||||
}
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.EnumeratedValuesExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts and puts headers in portlet requests and responses.
|
||||
*/
|
||||
public class HeaderExtractor implements EnumeratedValuesExtractor {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private final PortletResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
* @param response The response.
|
||||
*/
|
||||
public HeaderExtractor(PortletRequest request, PortletResponse response) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getPropertyNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return request.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getValues(String key) {
|
||||
return request.getProperties(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String key, String value) {
|
||||
response.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasKeys;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts init parameters from a portlet context.
|
||||
*/
|
||||
public class InitParameterExtractor implements HasKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private final PortletContext context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The portlet context.
|
||||
*/
|
||||
public InitParameterExtractor(PortletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return context.getInitParameterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return context.getInitParameter(key);
|
||||
}
|
||||
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasKeys;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts parameters from a portlet request.
|
||||
*/
|
||||
public class ParameterExtractor implements HasKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
*/
|
||||
public ParameterExtractor(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getParameterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return request.getParameter(key);
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from request scope of a portlet request.
|
||||
*/
|
||||
public class RequestScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
*/
|
||||
public RequestScopeExtractor(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
request.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
request.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
return request.getAttribute(key);
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from the session scope of a portlet request.
|
||||
*/
|
||||
public class SessionScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* The subscope (application or portlet).
|
||||
*/
|
||||
private final int scope;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
* @param scope The subscope (application or portlet).
|
||||
*/
|
||||
public SessionScopeExtractor(PortletRequest request, int scope) {
|
||||
this.request = request;
|
||||
if (scope != PortletSession.APPLICATION_SCOPE && scope != PortletSession.PORTLET_SCOPE) {
|
||||
throw new IllegalArgumentException("The scope must be either APPLICATION_SCOPE or PORTLET_SCOPE");
|
||||
}
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
request.getPortletSession().setAttribute(name, value, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
session.removeAttribute(name, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
return session.getAttributeNames(scope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
return session.getAttribute(key, scope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasAddableKeys;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.StateAwareResponse;
|
||||
|
||||
/**
|
||||
* Extracts parameters from a request and allows putting render parameters in a state aware response.
|
||||
*/
|
||||
public class StateAwareParameterExtractor extends ParameterExtractor implements HasAddableKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet response.
|
||||
*/
|
||||
private final StateAwareResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
* @param response The portlet response.
|
||||
*/
|
||||
public StateAwareParameterExtractor(PortletRequest request, StateAwareResponse response) {
|
||||
super(request);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String key, String value) {
|
||||
response.setRenderParameter(key, value);
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
/**
|
||||
* Extractors to get scopes from Portlet requests.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
/**
|
||||
* Support of Tiles requests to portlets.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
@@ -1,174 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
@@ -1,5 +0,0 @@
|
||||
Apache Struts
|
||||
Copyright 2000-2011 The Apache Software Foundation
|
||||
|
||||
This product includes software developed by
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
|
||||
"https://struts.apache.org/dtds/struts-6.0.dtd">
|
||||
|
||||
<struts>
|
||||
|
||||
<package name="struts-portlet-tiles-default" extends="struts-portlet-default">
|
||||
|
||||
<result-types>
|
||||
<result-type name="tiles" class="org.apache.struts2.views.tiles.PortletTilesResult"/>
|
||||
</result-types>
|
||||
|
||||
<action name="tilesDirect" class="org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction">
|
||||
<result type="tiles" name="success">${location}</result>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
|
||||
</struts>
|
||||
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project name="Apache Struts">
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>${fluido-skin.version}</version>
|
||||
</skin>
|
||||
<bannerLeft>
|
||||
<name>Apache Software Foundation</name>
|
||||
<src>http://www.apache.org/images/asf-logo.gif</src>
|
||||
<href>http://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<name>Apache Struts</name>
|
||||
<src>http://struts.apache.org/img/struts-logo.svg</src>
|
||||
<href>http://struts.apache.org/</href>
|
||||
</bannerRight>
|
||||
<publishDate position="left"/>
|
||||
<version position="right"/>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Apache" href="http://www.apache.org/"/>
|
||||
<item name="Struts" href="http://struts.apache.org/"/>
|
||||
</links>
|
||||
|
||||
<menu ref="parent"/>
|
||||
<menu ref="reports"/>
|
||||
|
||||
<footer>
|
||||
<![CDATA[<div class="row span12">
|
||||
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project
|
||||
logos are trademarks of The Apache Software Foundation.
|
||||
</div>]]>
|
||||
</footer>
|
||||
</body>
|
||||
</project>
|
||||
-424
@@ -1,424 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.collection.HeaderValuesMap;
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.collection.ScopeMap;
|
||||
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletResponse;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link PortletRequest}.
|
||||
*/
|
||||
public class PortletRequestTest {
|
||||
|
||||
/**
|
||||
* The application context.
|
||||
*/
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext portletContext;
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private javax.portlet.PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
/**
|
||||
* The request to test.
|
||||
*/
|
||||
private PortletRequest req;
|
||||
|
||||
/**
|
||||
* The request delegate.
|
||||
*/
|
||||
private RequestDelegate requestDelegate;
|
||||
|
||||
/**
|
||||
* The response delegate.
|
||||
*/
|
||||
private ResponseDelegate responseDelegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
applicationContext = createMock(ApplicationContext.class);
|
||||
portletContext = createMock(PortletContext.class);
|
||||
request = createMock(javax.portlet.PortletRequest.class);
|
||||
response = createMock(PortletResponse.class);
|
||||
requestDelegate = createMock(RequestDelegate.class);
|
||||
responseDelegate = createMock(ResponseDelegate.class);
|
||||
req = new PortletRequest(applicationContext, portletContext, request,
|
||||
response, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoForward() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.forward(request, response);
|
||||
|
||||
replay(applicationContext, portletContext, request, response, rd);
|
||||
req.doForward("/my/path");
|
||||
verify(applicationContext, portletContext, request, response, rd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoForwardNoDispatcher() throws IOException {
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doForward("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoForwardPortletException() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.forward(request, response);
|
||||
expectLastCall().andThrow(new PortletException());
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doForward("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoForwardInclude() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(true);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
req.doForward("/my/path");
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoInclude() throws IOException, PortletException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
req.doInclude("/my/path");
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoIncludeNoDispatcher() throws IOException {
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doInclude("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoIncludePortletException() throws IOException, PortletException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
expectLastCall().andThrow(new PortletException());
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doInclude("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getHeader()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetHeader() {
|
||||
assertTrue(req.getHeader() instanceof ReadOnlyEnumerationMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getResponseHeaders()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetResponseHeaders() {
|
||||
assertTrue(req.getResponseHeaders() instanceof HeaderExtractor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getHeaderValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetHeaderValues() {
|
||||
assertTrue(req.getHeaderValues() instanceof HeaderValuesMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getParam()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParam() {
|
||||
Map<String, String> map = createMock(Map.class);
|
||||
|
||||
expect(requestDelegate.getParam()).andReturn(map);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(map, req.getParam());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getParamValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParamValues() {
|
||||
Map<String, String[]> paramMap = createMock(Map.class);
|
||||
|
||||
expect(requestDelegate.getParamValues()).andReturn(paramMap);
|
||||
|
||||
replay(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(paramMap, req.getParamValues());
|
||||
verify(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequestScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequestScope() {
|
||||
assertTrue(req.getRequestScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getSessionScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSessionScope() {
|
||||
assertTrue(req.getSessionScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getPortletSessionScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPortletSessionScope() {
|
||||
assertTrue(req.getPortletSessionScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getOutputStream()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetOutputStream() throws IOException {
|
||||
ServletOutputStream os = createMock(ServletOutputStream.class);
|
||||
|
||||
expect(responseDelegate.getOutputStream()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getOutputStream(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(responseDelegate.getWriter()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getWriter(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getPrintWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPrintWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(responseDelegate.getPrintWriter()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getPrintWriter(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#isResponseCommitted()}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsResponseCommitted() {
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(true);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertTrue(req.isResponseCommitted());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#setContentType(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetContentType() {
|
||||
responseDelegate.setContentType("text/html");
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
req.setContentType("text/html");
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequestLocale()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequestLocale() {
|
||||
Locale locale = Locale.ITALY;
|
||||
|
||||
expect(request.getLocale()).andReturn(locale);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(locale, req.getRequestLocale());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequest()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequest() {
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(request, req.getRequest());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#isUserInRole(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsUserInRole() {
|
||||
expect(request.isUserInRole("myrole")).andReturn(true);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertTrue(req.isUserInRole("myrole"));
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link RenderPortletRequest}.
|
||||
*/
|
||||
public class RenderPortletRequestTest {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link RenderPortletRequest#RenderPortletRequest(ApplicationContext, PortletContext,
|
||||
* RenderRequest, RenderResponse)}.
|
||||
*
|
||||
* @throws NoSuchFieldException If something goes wrong.
|
||||
* @throws SecurityException If something goes wrong.
|
||||
* @throws IllegalAccessException If something goes wrong.
|
||||
* @throws IllegalArgumentException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testRenderPortletRequest() throws NoSuchFieldException, IllegalAccessException {
|
||||
ApplicationContext applicationContext = createMock(ApplicationContext.class);
|
||||
PortletContext portletContext = createMock(PortletContext.class);
|
||||
RenderRequest request = createMock(RenderRequest.class);
|
||||
RenderResponse response = createMock(RenderResponse.class);
|
||||
|
||||
replay(applicationContext, portletContext, request, response);
|
||||
RenderPortletRequest req = new RenderPortletRequest(applicationContext,
|
||||
portletContext, request, response);
|
||||
Class<? extends RenderPortletRequest> clazz = req.getClass();
|
||||
Field field = clazz.getSuperclass().getDeclaredField("requestDelegate");
|
||||
assertTrue(field.get(req) instanceof PortletRequestDelegate);
|
||||
field = clazz.getSuperclass().getDeclaredField("responseDelegate");
|
||||
assertTrue(field.get(req) instanceof MimeResponseDelegate);
|
||||
verify(applicationContext, portletContext, request, response);
|
||||
}
|
||||
|
||||
}
|
||||
-132
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.MimeResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link MimeResponseDelegate}.
|
||||
*/
|
||||
public class MimeResponseDelegateTest {
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private MimeResponse response;
|
||||
|
||||
/**
|
||||
* The delegate to test.
|
||||
*/
|
||||
private MimeResponseDelegate delegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
response = createMock(MimeResponse.class);
|
||||
delegate = new MimeResponseDelegate(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getOutputStream()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetOutputStream() throws IOException {
|
||||
OutputStream os = createMock(OutputStream.class);
|
||||
|
||||
expect(response.getPortletOutputStream()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getOutputStream());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getPrintWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPrintWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(response.getWriter()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getPrintWriter());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(response.getWriter()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getWriter());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#isResponseCommitted()}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsResponseCommitted() {
|
||||
expect(response.isCommitted()).andReturn(true);
|
||||
|
||||
replay(response);
|
||||
assertTrue(delegate.isResponseCommitted());
|
||||
verify(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#setContentType(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetContentType() {
|
||||
response.setContentType("text/html");
|
||||
|
||||
replay(response);
|
||||
delegate.setContentType("text/html");
|
||||
verify(response);
|
||||
}
|
||||
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link PortletRequestDelegate}.
|
||||
*/
|
||||
public class PortletRequestDelegateTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The delegate to test.
|
||||
*/
|
||||
private PortletRequestDelegate delegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
delegate = new PortletRequestDelegate(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequestDelegate#getParam()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParam() {
|
||||
replay(request);
|
||||
assertTrue(delegate.getParam() instanceof ReadOnlyEnumerationMap);
|
||||
verify(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequestDelegate#getParamValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParamValues() {
|
||||
Map<String, String[]> params = createMock(Map.class);
|
||||
|
||||
expect(request.getParameterMap()).andReturn(params);
|
||||
|
||||
replay(request, params);
|
||||
assertEquals(params, delegate.getParamValues());
|
||||
verify(request, params);
|
||||
}
|
||||
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.ApplicationScopeExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link ApplicationScopeExtractor}.
|
||||
*/
|
||||
public class ApplicationScopeExtractorTest {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* The extractot to test.
|
||||
*/
|
||||
private ApplicationScopeExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = createMock(PortletContext.class);
|
||||
extractor = new ApplicationScopeExtractor(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#setValue(String, Object)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
context.setAttribute("attribute", "value");
|
||||
|
||||
replay(context);
|
||||
extractor.setValue("attribute", "value");
|
||||
verify(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#removeValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveValue() {
|
||||
context.removeAttribute("attribute");
|
||||
|
||||
replay(context);
|
||||
extractor.removeValue("attribute");
|
||||
verify(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
expect(context.getAttributeNames()).andReturn(keys);
|
||||
|
||||
replay(context, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(context, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(context.getAttribute("attribute")).andReturn("value");
|
||||
|
||||
replay(context);
|
||||
assertEquals("value", extractor.getValue("attribute"));
|
||||
verify(context);
|
||||
}
|
||||
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link HeaderExtractor}.
|
||||
*/
|
||||
public class HeaderExtractorTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private HeaderExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
response = createMock(PortletResponse.class);
|
||||
extractor = new HeaderExtractor(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getPropertyNames()).andReturn(keys);
|
||||
|
||||
replay(request, response, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, response, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getProperty("name")).andReturn("value");
|
||||
|
||||
replay(request, response);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getValues(String)}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetValues() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getProperties("name")).andReturn(keys);
|
||||
|
||||
replay(request, response, keys);
|
||||
assertEquals(keys, extractor.getValues("name"));
|
||||
verify(request, response, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#setValue(String, String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
response.setProperty("name", "value");
|
||||
|
||||
replay(request, response);
|
||||
extractor.setValue("name", "value");
|
||||
verify(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.InitParameterExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link InitParameterExtractor}.
|
||||
*/
|
||||
public class InitParameterExtractorTest {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private InitParameterExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = createMock(PortletContext.class);
|
||||
extractor = new InitParameterExtractor(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link InitParameterExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(context.getInitParameterNames()).andReturn(keys);
|
||||
|
||||
replay(context, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(context, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link InitParameterExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(context.getInitParameter("name")).andReturn("value");
|
||||
|
||||
replay(context);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(context);
|
||||
}
|
||||
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link ParameterExtractor}.
|
||||
*/
|
||||
public class ParameterExtractorTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private ParameterExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
extractor = new ParameterExtractor(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ParameterExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getParameterNames()).andReturn(keys);
|
||||
|
||||
replay(request, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ParameterExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getParameter("name")).andReturn("value");
|
||||
|
||||
replay(request);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request);
|
||||
}
|
||||
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.RequestScopeExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link RequestScopeExtractor}.
|
||||
*/
|
||||
public class RequestScopeExtractorTest {
|
||||
|
||||
/**
|
||||
* The request to test.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private RequestScopeExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
extractor = new RequestScopeExtractor(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link RequestScopeExtractor#setValue(String, Object)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
request.setAttribute("name", "value");
|
||||
|
||||
replay(request);
|
||||
extractor.setValue("name", "value");
|
||||
verify(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link RequestScopeExtractor#removeValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveValue() {
|
||||
request.removeAttribute("name");
|
||||
|
||||
replay(request);
|
||||
extractor.removeValue("name");
|
||||
verify(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link RequestScopeExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getAttributeNames()).andReturn(keys);
|
||||
|
||||
replay(request, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link RequestScopeExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getAttribute("name")).andReturn("value");
|
||||
|
||||
replay(request);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request);
|
||||
}
|
||||
|
||||
}
|
||||
-154
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.SessionScopeExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests {@link SessionScopeExtractor}.
|
||||
*/
|
||||
public class SessionScopeExtractorTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The session.
|
||||
*/
|
||||
private PortletSession session;
|
||||
|
||||
/**
|
||||
* The scope to test.
|
||||
*/
|
||||
private SessionScopeExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
session = createMock(PortletSession.class);
|
||||
extractor = new SessionScopeExtractor(request, PortletSession.PORTLET_SCOPE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link SessionScopeExtractor#SessionScopeExtractor(PortletRequest, int)}.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testIllegalScope() {
|
||||
replay(request, session);
|
||||
new SessionScopeExtractor(request, 0);
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#setValue(String, Object)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
expect(request.getPortletSession()).andReturn(session);
|
||||
session.setAttribute("name", "value", PortletSession.PORTLET_SCOPE);
|
||||
|
||||
replay(request, session);
|
||||
extractor.setValue("name", "value");
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#removeValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveValue() {
|
||||
expect(request.getPortletSession(false)).andReturn(session);
|
||||
session.removeAttribute("name", PortletSession.PORTLET_SCOPE);
|
||||
|
||||
replay(request, session);
|
||||
extractor.removeValue("name");
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getPortletSession(false)).andReturn(session);
|
||||
expect(session.getAttributeNames(PortletSession.PORTLET_SCOPE)).andReturn(keys);
|
||||
|
||||
replay(request, session, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, session, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#getKeys()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetKeysNoSession() {
|
||||
expect(request.getPortletSession(false)).andReturn(null);
|
||||
|
||||
replay(request, session);
|
||||
assertNull(extractor.getKeys());
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getPortletSession(false)).andReturn(session);
|
||||
expect(session.getAttribute("name", PortletSession.PORTLET_SCOPE)).andReturn("value");
|
||||
|
||||
replay(request, session);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link SessionScopeExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValueNoSession() {
|
||||
expect(request.getPortletSession(false)).andReturn(null);
|
||||
|
||||
replay(request, session);
|
||||
assertNull(extractor.getValue("name"));
|
||||
verify(request, session);
|
||||
}
|
||||
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.StateAwareParameterExtractor;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.StateAwareResponse;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
/**
|
||||
* Tests {@link StateAwareParameterExtractor}.
|
||||
*/
|
||||
public class StateAwareParameterExtractorTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link StateAwareParameterExtractor#setValue(String, String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
PortletRequest request = createMock(PortletRequest.class);
|
||||
StateAwareResponse response = createMock(StateAwareResponse.class);
|
||||
|
||||
response.setRenderParameter("name", "value");
|
||||
|
||||
replay(request, response);
|
||||
StateAwareParameterExtractor extractor = new StateAwareParameterExtractor(request, response);
|
||||
extractor.setValue("name", "value");
|
||||
verify(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
# Struts 2 Portlet plugin
|
||||
This plugin is deprecated, and it will be removed soon, **please do not use it**!
|
||||
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>DEPRECATED: Struts 2 Portlet Plugin - since 6.0.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-velocity-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- spring-core is required for javadoc of jdk8 -->
|
||||
<!-- It is indirectly referenced by struts2-junit-plugin. -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Portlet -->
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mockobjects</groupId>
|
||||
<artifactId>mockobjects-jdk1.3-j2ee1.3</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jmock</groupId>
|
||||
<artifactId>jmock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jmock</groupId>
|
||||
<artifactId>jmock-cglib</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mockobjects</groupId>
|
||||
<artifactId>mockobjects-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Mocks for unit testing (by Spring) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.components;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelper;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelperJSR286;
|
||||
import org.apache.struts2.url.QueryStringParser;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link UrlRenderer} interface that renders URLs for portlet environments.
|
||||
*
|
||||
* @see UrlRenderer
|
||||
*/
|
||||
public class PortletUrlRenderer implements UrlRenderer {
|
||||
|
||||
/**
|
||||
* The servlet renderer used when not executing in a portlet context.
|
||||
*/
|
||||
private ServletUrlRenderer servletRenderer = null;
|
||||
private PortletUrlHelper portletUrlHelper = null;
|
||||
|
||||
public PortletUrlRenderer() {
|
||||
this.servletRenderer = new ServletUrlRenderer();
|
||||
|
||||
if (PortletActionContext.isJSR268Supported()) {
|
||||
this.portletUrlHelper = new PortletUrlHelperJSR286();
|
||||
} else {
|
||||
this.portletUrlHelper = new PortletUrlHelper();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setActionMapper(ActionMapper actionMapper) {
|
||||
servletRenderer.setActionMapper(actionMapper);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setUrlHelper(UrlHelper urlHelper) {
|
||||
servletRenderer.setUrlHelper(urlHelper);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQueryStringParser(QueryStringParser queryStringParser) {
|
||||
this.servletRenderer.setQueryStringParser(queryStringParser);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void renderUrl(Writer writer, UrlProvider urlComponent) {
|
||||
if (PortletActionContext.getPortletContext() == null) {
|
||||
servletRenderer.renderUrl(writer, urlComponent);
|
||||
return;
|
||||
}
|
||||
String result;
|
||||
if (isPortletModeChange(urlComponent, PortletActionContext.getRequest().getPortletMode())
|
||||
&& StringUtils.isEmpty(urlComponent.getNamespace())) {
|
||||
String mode = urlComponent.getPortletMode();
|
||||
PortletMode portletMode = new PortletMode(mode);
|
||||
String action = urlComponent.getAction();
|
||||
if (StringUtils.isEmpty(action)) {
|
||||
action = PortletActionContext.getModeActionMap().get(portletMode).getName();
|
||||
}
|
||||
String modeNamespace = PortletActionContext.getModeNamespaceMap().get(portletMode);
|
||||
result = portletUrlHelper.buildUrl(action, modeNamespace, urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), mode, urlComponent.getWindowState());
|
||||
|
||||
} else {
|
||||
String namespace = urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest());
|
||||
urlComponent.setNamespace(namespace);
|
||||
if (onlyActionSpecified(urlComponent)) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getAction())) {
|
||||
String action = urlComponent.findString(urlComponent.getAction());
|
||||
result = portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
} else {
|
||||
result = portletUrlHelper.buildUrl(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
}
|
||||
} else if (onlyValueSpecified(urlComponent)) {
|
||||
result = portletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters());
|
||||
} else {
|
||||
result = createDefaultUrl(urlComponent);
|
||||
}
|
||||
}
|
||||
String anchor = urlComponent.getAnchor();
|
||||
if (StringUtils.isNotEmpty(anchor)) {
|
||||
result += '#' + urlComponent.findString(anchor);
|
||||
}
|
||||
|
||||
String var = urlComponent.getVar();
|
||||
|
||||
if (var != null) {
|
||||
urlComponent.putInContext(result);
|
||||
|
||||
// add to the request and page scopes as well
|
||||
urlComponent.getHttpServletRequest().setAttribute(var, result);
|
||||
} else {
|
||||
try {
|
||||
writer.write(result);
|
||||
} catch (IOException e) {
|
||||
throw new StrutsException("IOError: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean isPortletModeChange(UrlProvider urlComponent, PortletMode currentMode) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getPortletMode())) {
|
||||
PortletMode newPortletMode = new PortletMode(urlComponent.getPortletMode());
|
||||
return !(newPortletMode.equals(currentMode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String createDefaultUrl(UrlProvider urlComponent) {
|
||||
ActionInvocation ai = urlComponent.getStack().getActionContext().getActionInvocation();
|
||||
String action = ai.getProxy().getActionName();
|
||||
return portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
|
||||
urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
}
|
||||
|
||||
private boolean onlyValueSpecified(UrlProvider urlComponent) {
|
||||
return urlComponent.getValue() != null && urlComponent.getAction() == null;
|
||||
}
|
||||
|
||||
private boolean onlyActionSpecified(UrlProvider urlComponent) {
|
||||
return urlComponent.getValue() == null && urlComponent.getAction() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void renderFormUrl(Form formComponent) {
|
||||
if (PortletActionContext.getPortletContext() == null) {
|
||||
servletRenderer.renderFormUrl(formComponent);
|
||||
return;
|
||||
}
|
||||
String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(),
|
||||
formComponent.request);
|
||||
String action;
|
||||
if (formComponent.action != null) {
|
||||
action = formComponent.findString(formComponent.action);
|
||||
} else {
|
||||
ActionInvocation ai = formComponent.getStack().getActionContext().getActionInvocation();
|
||||
action = ai.getProxy().getActionName();
|
||||
}
|
||||
|
||||
String type = "action";
|
||||
if (StringUtils.isNotEmpty(formComponent.method)) {
|
||||
if ("GET".equalsIgnoreCase(formComponent.method.trim())) {
|
||||
type = "render";
|
||||
}
|
||||
}
|
||||
if (action != null) {
|
||||
String result = portletUrlHelper.buildUrl(action, namespace, null,
|
||||
formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState);
|
||||
formComponent.addParameter("action", result);
|
||||
|
||||
|
||||
// name/id: cut out anything between / and . should be the id and
|
||||
// name
|
||||
String id = formComponent.getId();
|
||||
if (id == null) {
|
||||
int slash = action.lastIndexOf('/');
|
||||
int dot = action.indexOf('.', slash);
|
||||
if (dot != -1) {
|
||||
id = action.substring(slash + 1, dot);
|
||||
} else {
|
||||
id = action.substring(slash + 1);
|
||||
}
|
||||
String escapedId = formComponent.escape(id);
|
||||
formComponent.addParameter("id", escapedId);
|
||||
formComponent.addParameter("escapedId", escapedId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeRenderUrl(UrlProvider urlComponent) {
|
||||
if (PortletActionContext.getPortletContext() == null) {
|
||||
servletRenderer.beforeRenderUrl(urlComponent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Portlet specific {@link java.util.Map} implementation representing the
|
||||
* {@link javax.portlet.PortletContext} of a Portlet.
|
||||
*
|
||||
*/
|
||||
public class PortletApplicationMap extends AbstractMap<String, Object> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2296107511063504414L;
|
||||
|
||||
private final PortletContext context;
|
||||
private Set<Entry<String, Object>> entries;
|
||||
|
||||
/**
|
||||
* Creates a new map object given the {@link PortletContext}.
|
||||
*
|
||||
* @param ctx The portlet context.
|
||||
*/
|
||||
public PortletApplicationMap(PortletContext ctx) {
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all entries from the Map and removes all attributes from the
|
||||
* portlet context.
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
entries = null;
|
||||
|
||||
Enumeration e = context.getAttributeNames();
|
||||
|
||||
while (e.hasMoreElements()) {
|
||||
context.removeAttribute(e.nextElement().toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Set of all portlet context attributes as well as context init
|
||||
* parameters.
|
||||
*
|
||||
* @return a Set of all portlet context attributes as well as context init
|
||||
* parameters.
|
||||
*/
|
||||
@Override
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
if (entries == null) {
|
||||
entries = new HashSet<Entry<String, Object>>();
|
||||
|
||||
// Add portlet context attributes
|
||||
Enumeration enumeration = context.getAttributeNames();
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final String key = enumeration.nextElement().toString();
|
||||
final Object value = context.getAttribute(key);
|
||||
entries.add(new Entry<String, Object>() {
|
||||
public boolean equals(Object obj) {
|
||||
Map.Entry entry = (Map.Entry) obj;
|
||||
|
||||
return ((key == null) ? (entry.getKey() == null) : key
|
||||
.equals(entry.getKey()))
|
||||
&& ((value == null) ? (entry.getValue() == null)
|
||||
: value.equals(entry.getValue()));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ((key == null) ? 0 : key.hashCode())
|
||||
^ ((value == null) ? 0 : value.hashCode());
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object setValue(Object obj) {
|
||||
context.setAttribute(key, obj);
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add portlet context init params
|
||||
enumeration = context.getInitParameterNames();
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final String key = enumeration.nextElement().toString();
|
||||
final Object value = context.getInitParameter(key);
|
||||
entries.add(new Entry<String, Object>() {
|
||||
public boolean equals(Object obj) {
|
||||
Map.Entry entry = (Map.Entry) obj;
|
||||
|
||||
return ((key == null) ? (entry.getKey() == null) : key
|
||||
.equals(entry.getKey()))
|
||||
&& ((value == null) ? (entry.getValue() == null)
|
||||
: value.equals(entry.getValue()));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ((key == null) ? 0 : key.hashCode())
|
||||
^ ((value == null) ? 0 : value.hashCode());
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object setValue(Object obj) {
|
||||
context.setAttribute(key, obj);
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the portlet context attribute or init parameter based on the
|
||||
* given key. If the entry is not found, <tt>null</tt> is returned.
|
||||
*
|
||||
* @param key
|
||||
* the entry key.
|
||||
* @return the portlet context attribute or init parameter or <tt>null</tt>
|
||||
* if the entry is not found.
|
||||
*/
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
// Try context attributes first, then init params
|
||||
// This gives the proper shadowing effects
|
||||
Object value = context.getAttribute(key.toString());
|
||||
|
||||
return (value == null) ? context.getInitParameter(key.toString()) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a portlet context attribute given a attribute name and value.
|
||||
*
|
||||
* @param key
|
||||
* the name of the attribute.
|
||||
* @param value
|
||||
* the value to set.
|
||||
* @return the attribute that was just set.
|
||||
*/
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
entries = null;
|
||||
context.setAttribute(key, value);
|
||||
|
||||
return get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified portlet context attribute.
|
||||
*
|
||||
* @param key
|
||||
* the attribute to remove.
|
||||
* @return the entry that was just removed.
|
||||
*/
|
||||
public Object remove(String key) {
|
||||
entries = null;
|
||||
|
||||
Object value = get(key);
|
||||
context.removeAttribute(key);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.portlet.dispatcher.DispatcherServlet;
|
||||
|
||||
public class PortletConstants {
|
||||
/**
|
||||
* Default action name to use when no default action has been configured in the portlet
|
||||
* init parameters.
|
||||
*/
|
||||
public static String DEFAULT_ACTION_NAME = "default";
|
||||
|
||||
/**
|
||||
* Action name parameter name
|
||||
*/
|
||||
public static String ACTION_PARAM = "struts.portlet.action";
|
||||
|
||||
/**
|
||||
* Key for parameter holding the last executed portlet mode.
|
||||
*/
|
||||
public static String MODE_PARAM = "struts.portlet.mode";
|
||||
|
||||
/**
|
||||
* Key used for looking up and storing the portlet phase
|
||||
*/
|
||||
public static String PHASE = "struts.portlet.phase";
|
||||
|
||||
/**
|
||||
* Key used for looking up and storing the
|
||||
* {@link javax.portlet.PortletRequest}
|
||||
*/
|
||||
public static String REQUEST = "struts.portlet.request";
|
||||
|
||||
/**
|
||||
* Key used for looking up and storing the
|
||||
* {@link javax.portlet.PortletResponse}
|
||||
*/
|
||||
public static String RESPONSE = "struts.portlet.response";
|
||||
|
||||
/**
|
||||
* Key used for looking up and storing the action that was invoked in the action or event phase.
|
||||
*/
|
||||
public static String EVENT_ACTION = "struts.portlet.eventAction";
|
||||
|
||||
/**
|
||||
* Key used for looking up and storing the
|
||||
* {@link javax.portlet.PortletConfig}
|
||||
*/
|
||||
public static String PORTLET_CONFIG = "struts.portlet.config";
|
||||
|
||||
/**
|
||||
* Name of the action used as error handler
|
||||
*/
|
||||
public static String ERROR_ACTION = "errorHandler";
|
||||
|
||||
/**
|
||||
* Key for the portlet namespace stored in the
|
||||
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
|
||||
*/
|
||||
public static String PORTLET_NAMESPACE = "struts.portlet.portletNamespace";
|
||||
|
||||
/**
|
||||
* Key for the mode-to-namespace map stored in the
|
||||
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
|
||||
*/
|
||||
public static String MODE_NAMESPACE_MAP = "struts.portlet.modeNamespaceMap";
|
||||
|
||||
/**
|
||||
* Key for the mode-to-default-action map stored in the
|
||||
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
|
||||
*/
|
||||
public static String DEFAULT_ACTION_MAP = "struts.portlet.modeActionMap";
|
||||
|
||||
/**
|
||||
* Key for the default action name for the portlet, stored in the
|
||||
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
|
||||
*/
|
||||
public static String DEFAULT_ACTION_FOR_MODE = "struts.portlet.defaultActionForMode";
|
||||
|
||||
/**
|
||||
* Key for request attribute indicating if the action has been reset.
|
||||
*/
|
||||
public static String ACTION_RESET = "struts.portlet.actionReset";
|
||||
|
||||
/**
|
||||
* Key for session attribute indicating the location of the render direct action.
|
||||
*/
|
||||
public static String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation";
|
||||
|
||||
/**
|
||||
* Namespace use for executing the renderDirect action. Necessary to get the namespaces on s:urls correct.
|
||||
*/
|
||||
public static String RENDER_DIRECT_NAMESPACE = "struts.portlet.renderDirectNamespace";
|
||||
|
||||
/**
|
||||
* Key for the dispatch instruction for the {@link DispatcherServlet}
|
||||
*/
|
||||
public static String DISPATCH_TO = "struts.portlet.dispatchTo";
|
||||
|
||||
/**
|
||||
* Session key where the value stack from the event phase is stored.
|
||||
*/
|
||||
public static String STACK_FROM_EVENT_PHASE = "struts.portlet.valueStackFromEventPhase";
|
||||
|
||||
/**
|
||||
* Default name of dispatcher servlet in web.xml
|
||||
*/
|
||||
public static String DEFAULT_DISPATCHER_SERVLET_NAME = "Struts2PortletDispatcherServlet";
|
||||
|
||||
/**
|
||||
* Key for the action mapping in the context
|
||||
*/
|
||||
public static String ACTION_MAPPING = ServletActionContext.ACTION_MAPPING;
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet;
|
||||
|
||||
/**
|
||||
* Defines phases of portlet processing per the portlet specification.
|
||||
*/
|
||||
public enum PortletPhase {
|
||||
|
||||
/**
|
||||
* Constant used for the render phase (
|
||||
* {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)})
|
||||
*/
|
||||
RENDER_PHASE,
|
||||
|
||||
/**
|
||||
* Constant used for the action phase (
|
||||
* {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)})
|
||||
*/
|
||||
ACTION_PHASE,
|
||||
|
||||
/**
|
||||
* Constant used for the event phase
|
||||
*/
|
||||
EVENT_PHASE,
|
||||
|
||||
/**
|
||||
* Constant used for the serve resource phase that was added with the 2.0 portlet specification.
|
||||
*/
|
||||
SERVE_RESOURCE_PHASE;
|
||||
|
||||
public boolean isRender() {
|
||||
return this.equals(RENDER_PHASE);
|
||||
}
|
||||
|
||||
public boolean isAction() {
|
||||
return this.equals(ACTION_PHASE);
|
||||
}
|
||||
|
||||
public boolean isEvent() {
|
||||
return this.equals(EVENT_PHASE);
|
||||
}
|
||||
|
||||
public boolean isResource() {
|
||||
return this.equals(SERVE_RESOURCE_PHASE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes.
|
||||
*
|
||||
*/
|
||||
public class PortletRequestMap extends AbstractMap<String, Object> {
|
||||
|
||||
private Set<Entry<String, Object>> entries = null;
|
||||
private PortletRequest request = null;
|
||||
|
||||
/**
|
||||
* Saves the request to use as the backing for getting and setting values
|
||||
*
|
||||
* @param request the portlet request.
|
||||
*/
|
||||
public PortletRequestMap(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all attributes from the request as well as clears entries in this
|
||||
* map.
|
||||
*/
|
||||
public void clear() {
|
||||
entries = null;
|
||||
Enumeration keys = request.getAttributeNames();
|
||||
ArrayList<String> keyStrings = new ArrayList<>();
|
||||
// Depending on the underlying collection, a ConcurrentModificationException may occur if we attempt
|
||||
// to remove attributes while iterating over the keys Enumeration. Instead use an interim collection to
|
||||
// gather all the keys and then remove them.
|
||||
while (keys.hasMoreElements()) {
|
||||
keyStrings.add((String) keys.nextElement());
|
||||
}
|
||||
for (String key : keyStrings){
|
||||
request.removeAttribute(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Set of attributes from the portlet request.
|
||||
*
|
||||
* @return a Set of attributes from the portlet request.
|
||||
*/
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
if (entries == null) {
|
||||
entries = new HashSet<Entry<String, Object>>();
|
||||
|
||||
Enumeration<String> enumeration = request.getAttributeNames();
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final String key = enumeration.nextElement();
|
||||
final Object value = request.getAttribute(key);
|
||||
entries.add(new Entry<String, Object>() {
|
||||
public boolean equals(Object obj) {
|
||||
Entry entry = (Entry) obj;
|
||||
|
||||
return ((key == null) ? (entry.getKey() == null) : key
|
||||
.equals(entry.getKey()))
|
||||
&& ((value == null) ? (entry.getValue() == null)
|
||||
: value.equals(entry.getValue()));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ((key == null) ? 0 : key.hashCode())
|
||||
^ ((value == null) ? 0 : value.hashCode());
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object setValue(Object obj) {
|
||||
request.setAttribute(key, obj);
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request attribute associated with the given key or
|
||||
* <tt>null</tt> if it doesn't exist.
|
||||
*
|
||||
* @param key the name of the request attribute.
|
||||
* @return the request attribute or <tt>null</tt> if it doesn't exist.
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
return request.getAttribute(key.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an attribute in the request.
|
||||
*
|
||||
* @param key the name of the request attribute.
|
||||
* @param value the value to set.
|
||||
* @return the object that was just set.
|
||||
*/
|
||||
public Object put(String key, Object value) {
|
||||
entries = null;
|
||||
request.setAttribute(key, value);
|
||||
|
||||
return get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified request attribute.
|
||||
*
|
||||
* @param key the name of the attribute to remove.
|
||||
* @return the value that was removed or <tt>null</tt> if the value was
|
||||
* not found (and hence, not removed).
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
entries = null;
|
||||
|
||||
Object value = get(key);
|
||||
request.removeAttribute(key.toString());
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A simple implementation of the {@link java.util.Map} interface to handle a collection of portlet session
|
||||
* attributes. The {@link #entrySet()} method enumerates over all session attributes and creates a Set of entries.
|
||||
* Note, this will occur lazily - only when the entry set is asked for.
|
||||
*
|
||||
*/
|
||||
public class PortletSessionMap extends AbstractMap<String, Object> {
|
||||
|
||||
private final PortletSession session;
|
||||
private Set<Entry<String, Object>> entries = null;
|
||||
|
||||
/**
|
||||
* Creates a new session map given a portlet request.
|
||||
*
|
||||
* @param request the portlet request object.
|
||||
*/
|
||||
public PortletSessionMap(PortletRequest request) {
|
||||
this.session = request.getPortletSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
synchronized (session) {
|
||||
if (entries == null) {
|
||||
entries = new HashSet<Entry<String, Object>>();
|
||||
|
||||
Enumeration enumeration = session.getAttributeNames();
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
final String key = enumeration.nextElement().toString();
|
||||
final Object value = session.getAttribute(key);
|
||||
entries.add(new Entry<String, Object>() {
|
||||
public boolean equals(Object obj) {
|
||||
Map.Entry entry = (Map.Entry) obj;
|
||||
|
||||
return ((key == null) ? (entry.getKey() == null)
|
||||
: key.equals(entry.getKey()))
|
||||
&& ((value == null) ? (entry.getValue() == null)
|
||||
: value.equals(entry.getValue()));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ((key == null) ? 0 : key.hashCode())
|
||||
^ ((value == null) ? 0 : value.hashCode());
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object setValue(Object obj) {
|
||||
session.setAttribute(key, obj);
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session attribute associated with the given key or
|
||||
* <tt>null</tt> if it doesn't exist.
|
||||
*
|
||||
* @param key the name of the session attribute.
|
||||
* @return the session attribute or <tt>null</tt> if it doesn't exist.
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
synchronized (session) {
|
||||
return session.getAttribute(key != null ? key.toString() : null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an attribute in the session.
|
||||
*
|
||||
* @param key the name of the session attribute.
|
||||
* @param value the value to set.
|
||||
* @return the object that was just set.
|
||||
*/
|
||||
public Object put(String key, Object value) {
|
||||
synchronized (session) {
|
||||
entries = null;
|
||||
session.setAttribute(key, value);
|
||||
|
||||
return get(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Map#clear()
|
||||
*/
|
||||
public void clear() {
|
||||
synchronized (session) {
|
||||
entries = null;
|
||||
session.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified session attribute.
|
||||
*
|
||||
* @param key the name of the attribute to remove.
|
||||
* @return the value that was removed or <tt>null</tt> if the value was
|
||||
* not found (and hence, not removed).
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
synchronized (session) {
|
||||
entries = null;
|
||||
|
||||
Object value = get(key);
|
||||
session.removeAttribute(key.toString());
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.action;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
/**
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public interface PortletContextAware {
|
||||
|
||||
void withPortletContext(PortletContext portletContext);
|
||||
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.action;
|
||||
|
||||
import javax.portlet.PortletPreferences;
|
||||
|
||||
|
||||
/**
|
||||
* All Actions that want to have access to the portlet preferences should
|
||||
* implement this interface. If running in a servlet environment, an
|
||||
* appropriate testing implementation will be provided.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public interface PortletPreferencesAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP request object in implementing classes.
|
||||
*
|
||||
* @param preferences the portlet preferences.
|
||||
*/
|
||||
void withPortletPreferences(PortletPreferences preferences);
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.action;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
|
||||
/**
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public interface PortletRequestAware {
|
||||
|
||||
void withPortletRequest(PortletRequest request);
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.action;
|
||||
|
||||
import javax.portlet.PortletResponse;
|
||||
|
||||
/**
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public interface PortletResponseAware {
|
||||
|
||||
void withPortletResponse(PortletResponse response);
|
||||
|
||||
}
|
||||
-233
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.context;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletConfig;
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletMode;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import javax.portlet.ResourceResponse;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
|
||||
import static org.apache.struts2.portlet.PortletConstants.MODE_NAMESPACE_MAP;
|
||||
import static org.apache.struts2.portlet.PortletConstants.PHASE;
|
||||
import static org.apache.struts2.portlet.PortletConstants.PORTLET_CONFIG;
|
||||
import static org.apache.struts2.portlet.PortletConstants.PORTLET_NAMESPACE;
|
||||
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
|
||||
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
|
||||
|
||||
/**
|
||||
* PortletActionContext. ActionContext thread local for the portlet environment.
|
||||
*
|
||||
* @version $Revision: 564279 $ $Date: 2007-08-09 19:00:49 +0200 (Thu, 09 Aug 2007) $
|
||||
*/
|
||||
public class PortletActionContext {
|
||||
|
||||
/**
|
||||
* Get the PortletConfig of the portlet that is executing.
|
||||
*
|
||||
* @return The PortletConfig of the executing portlet.
|
||||
*/
|
||||
public static PortletConfig getPortletConfig() {
|
||||
return (PortletConfig) getContext().get(PORTLET_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RenderRequest. Can only be invoked in the render phase.
|
||||
*
|
||||
* @return The current RenderRequest.
|
||||
* @throws IllegalStateException If the method is invoked in the wrong phase.
|
||||
*/
|
||||
public static RenderRequest getRenderRequest() {
|
||||
if (!getPhase().isRender()) {
|
||||
throw new IllegalStateException("RenderRequest cannot be obtained in event phase");
|
||||
}
|
||||
return (RenderRequest) getContext().get(REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RenderResponse. Can only be invoked in the render phase.
|
||||
*
|
||||
* @return The current RenderResponse.
|
||||
* @throws IllegalStateException If the method is invoked in the wrong phase.
|
||||
*/
|
||||
public static RenderResponse getRenderResponse() {
|
||||
if (!getPhase().isRender()) {
|
||||
throw new IllegalStateException("RenderResponse cannot be obtained in event phase");
|
||||
}
|
||||
return (RenderResponse) getContext().get(RESPONSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ActionRequest. Can only be invoked in the event phase.
|
||||
*
|
||||
* @return The current ActionRequest.
|
||||
* @throws IllegalStateException If the method is invoked in the wrong phase.
|
||||
*/
|
||||
public static ActionRequest getActionRequest() {
|
||||
if (!getPhase().isAction()) {
|
||||
throw new IllegalStateException("ActionRequest cannot be obtained in render phase");
|
||||
}
|
||||
return (ActionRequest) getContext().get(REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ActionRequest. Can only be invoked in the event phase.
|
||||
*
|
||||
* @return The current ActionRequest.
|
||||
* @throws IllegalStateException If the method is invoked in the wrong phase.
|
||||
*/
|
||||
public static ActionResponse getActionResponse() {
|
||||
if (!getPhase().isAction()) {
|
||||
throw new IllegalStateException("ActionResponse cannot be obtained in render phase");
|
||||
}
|
||||
return (ActionResponse) getContext().get(RESPONSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ResourceResponse. Can only be invoked in the resource phase.
|
||||
*
|
||||
* @return The current ResourceResponse.
|
||||
* @throws IllegalStateException If the method is invoked in the wrong phase.
|
||||
*/
|
||||
public static ResourceResponse getResourceResponse() {
|
||||
if (!getPhase().isResource()) {
|
||||
throw new IllegalStateException("ResourceResponse cannot be obtained in event phase");
|
||||
}
|
||||
return (ResourceResponse) getContext().get(RESPONSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action namespace of the portlet. Used to organize actions for multiple portlets in
|
||||
* the same portlet application.
|
||||
*
|
||||
* @return The portlet namespace as defined in <code>portlet.xml</code> and <code>struts.xml</code>
|
||||
*/
|
||||
public static String getPortletNamespace() {
|
||||
return (String) getContext().get(PORTLET_NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current PortletRequest.
|
||||
*
|
||||
* @return The current PortletRequest.
|
||||
*/
|
||||
public static PortletRequest getRequest() {
|
||||
return (PortletRequest) getContext().get(REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current PortletResponse
|
||||
*
|
||||
* @return The current PortletResponse.
|
||||
*/
|
||||
public static PortletResponse getResponse() {
|
||||
return (PortletResponse) getContext().get(RESPONSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phase that the portlet is executing in.
|
||||
*
|
||||
* @return {@link PortletPhase#RENDER_PHASE} in render phase, and
|
||||
* {@link PortletPhase#ACTION_PHASE} in the event phase.
|
||||
*/
|
||||
public static PortletPhase getPhase() {
|
||||
return (PortletPhase) getContext().get(PHASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current ActionContext.
|
||||
*/
|
||||
private static ActionContext getContext() {
|
||||
return ActionContext.getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the current request is a portlet request.
|
||||
*
|
||||
* @return <code>true</code> if the current request is a portlet request.
|
||||
*/
|
||||
public static boolean isPortletRequest() {
|
||||
return getRequest() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default action mapping for the current mode.
|
||||
*
|
||||
* @return The default action mapping for the current portlet mode.
|
||||
*/
|
||||
public static ActionMapping getDefaultActionForMode() {
|
||||
return (ActionMapping) getContext().get(DEFAULT_ACTION_FOR_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespace to mode mappings.
|
||||
*
|
||||
* @return The map of the namespaces for each mode.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<PortletMode,String> getModeNamespaceMap() {
|
||||
return (Map<PortletMode,String>) getContext().get(MODE_NAMESPACE_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mode to default action mappings.
|
||||
*
|
||||
* @return The map of default action mapping for each mode
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<PortletMode,ActionMapping> getModeActionMap() {
|
||||
return (Map<PortletMode,ActionMapping>) getContext().get(PortletConstants.DEFAULT_ACTION_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the portlet context.
|
||||
*
|
||||
* @return The portlet context.
|
||||
*/
|
||||
public static PortletContext getPortletContext() {
|
||||
return (PortletContext) getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether JSR286 features are supported.
|
||||
*
|
||||
* @return <code>true</code> if {@link javax.portlet.PortletContext#getMajorVersion()} returns a value greater than 1
|
||||
*/
|
||||
public static boolean isJSR268Supported() {
|
||||
PortletContext ctx = getPortletContext();
|
||||
if (ctx == null) {
|
||||
return false; // fallback to old behaviour, check WW-3763
|
||||
}
|
||||
return ctx.getMajorVersion() > 1;
|
||||
}
|
||||
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* When a portlet is targetted for an <code>event</code>, the portlet will receive two
|
||||
* portlet requests, one for the <code>event</code> phase, and then followed by a <code>render</code>
|
||||
* operation. When in the <code>event</code> phase, the action that is executed can't render
|
||||
* any output. This means that if an action in the XWork configuration is executed in the event
|
||||
* phase, and the action is set up with a result that should render something, the result can't
|
||||
* immediately be executed. The portlet needs to "wait" to the render phase to do the
|
||||
* rendering.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When the {@link org.apache.struts2.portlet.result.PortletResult} detects such a
|
||||
* scenario, instead of executing the actual view, it prepares a couple of render parameters
|
||||
* specifying this action and the location of the view, which then will be executed in the
|
||||
* following render request.
|
||||
* </p>
|
||||
*/
|
||||
public class DirectRenderFromEventAction implements SessionAware, Action, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1814807772308405785L;
|
||||
|
||||
private String location = null;
|
||||
|
||||
/**
|
||||
* Get the location of the view.
|
||||
*
|
||||
* @return Returns the location.
|
||||
*/
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always return success.
|
||||
*
|
||||
* @return SUCCESS
|
||||
*/
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
location = (String)session.get(PortletConstants.RENDER_DIRECT_LOCATION);
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.dispatcher;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.dispatcher.StrutsRequestWrapper;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DispatcherServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = -266147033645951967L;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String dispatchTo = (String) request.getAttribute(PortletConstants.DISPATCH_TO);
|
||||
HttpServletRequest wrapper = wrapRequestIfNecessary(request);
|
||||
if(StringUtils.isNotEmpty(dispatchTo)) {
|
||||
request.getRequestDispatcher(dispatchTo).include(wrapper, response);
|
||||
}
|
||||
}
|
||||
|
||||
private HttpServletRequest wrapRequestIfNecessary(HttpServletRequest request) {
|
||||
if(!(request instanceof StrutsRequestWrapper)) {
|
||||
return new StrutsRequestWrapper(request);
|
||||
}
|
||||
else {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-674
@@ -1,674 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import org.apache.commons.lang3.LocaleUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.ApplicationMap;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.dispatcher.DispatcherConstants;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
import org.apache.struts2.dispatcher.RequestMap;
|
||||
import org.apache.struts2.dispatcher.SessionMap;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
|
||||
import org.apache.struts2.portlet.PortletApplicationMap;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
import org.apache.struts2.portlet.PortletRequestMap;
|
||||
import org.apache.struts2.portlet.PortletSessionMap;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
import org.apache.struts2.portlet.servlet.PortletServletContext;
|
||||
import org.apache.struts2.portlet.servlet.PortletServletRequest;
|
||||
import org.apache.struts2.portlet.servlet.PortletServletResponse;
|
||||
import org.apache.struts2.dispatcher.AttributeMap;
|
||||
|
||||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.GenericPortlet;
|
||||
import javax.portlet.PortletConfig;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletMode;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import javax.portlet.WindowState;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.struts2.portlet.PortletConstants.ACTION_PARAM;
|
||||
import static org.apache.struts2.portlet.PortletConstants.ACTION_RESET;
|
||||
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
|
||||
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_NAME;
|
||||
import static org.apache.struts2.portlet.PortletConstants.MODE_NAMESPACE_MAP;
|
||||
import static org.apache.struts2.portlet.PortletConstants.MODE_PARAM;
|
||||
import static org.apache.struts2.portlet.PortletConstants.PORTLET_CONFIG;
|
||||
import static org.apache.struts2.portlet.PortletConstants.PORTLET_NAMESPACE;
|
||||
import static org.apache.struts2.portlet.PortletConstants.REQUEST;
|
||||
import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: javadoc -->
|
||||
* <p>
|
||||
* Struts JSR-168 portlet dispatcher. Similar to the WW2 Servlet dispatcher,
|
||||
* but adjusted to a portal environment. The portlet is configured through the <tt>portlet.xml</tt>
|
||||
* descriptor. Examples and descriptions follow below:
|
||||
* </p>
|
||||
* <!-- END SNIPPET: javadoc -->
|
||||
*
|
||||
* @author Nils-Helge Garli
|
||||
* @author Rainer Hermanns
|
||||
*
|
||||
* <p><b>Init parameters</b></p>
|
||||
* <!-- START SNIPPET: params -->
|
||||
* <table class="confluenceTable" summary="">
|
||||
* <tr>
|
||||
* <th class="confluenceTh">Name</th>
|
||||
* <th class="confluenceTh">Description</th>
|
||||
* <th class="confluenceTh">Default value</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">portletNamespace</td><td class="confluenceTd">The namespace for the portlet in the xwork configuration. This
|
||||
* namespace is prepended to all action lookups, and makes it possible to host multiple
|
||||
* portlets in the same portlet application. If this parameter is set, the complete namespace
|
||||
* will be <tt>/portletNamespace/modeNamespace/actionName</tt></td><td class="confluenceTd">The default namespace</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">viewNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>view</tt> portlet
|
||||
* mode</td><td class="confluenceTd">The default namespace</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">editNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>edit</tt> portlet
|
||||
* mode</td><td class="confluenceTd">The default namespace</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">helpNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>help</tt> portlet
|
||||
* mode</td><td class="confluenceTd">The default namespace</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">defaultViewAction</td><td class="confluenceTd">Default action to invoke in the <tt>view</tt> portlet mode if no action is
|
||||
* specified</td><td class="confluenceTd"><tt>default</tt></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">defaultEditAction</td><td class="confluenceTd">Default action to invoke in the <tt>edit</tt> portlet mode if no action is
|
||||
* specified</td><td class="confluenceTd"><tt>default</tt></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td class="confluenceTd">defaultHelpAction</td><td class="confluenceTd">Default action to invoke in the <tt>help</tt> portlet mode if no action is
|
||||
* specified</td><td class="confluenceTd"><tt>default</tt></td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <!-- END SNIPPET: params -->
|
||||
* <p><b>Example:</b></p>
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
*
|
||||
* <init-param>
|
||||
* <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
|
||||
* <name>viewNamespace</name>
|
||||
* <value>/view</value>
|
||||
* </init-param>
|
||||
* <init-param>
|
||||
* <!-- The default action to invoke in view mode -->
|
||||
* <name>defaultViewAction</name>
|
||||
* <value>index</value>
|
||||
* </init-param>
|
||||
* <init-param>
|
||||
* <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
|
||||
* <name>editNamespace</name>
|
||||
* <value>/edit</value>
|
||||
* </init-param>
|
||||
* <init-param>
|
||||
* <!-- The default action to invoke in view mode -->
|
||||
* <name>defaultEditAction</name>
|
||||
* <value>index</value>
|
||||
* </init-param>
|
||||
* <init-param>
|
||||
* <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
|
||||
* <name>helpNamespace</name>
|
||||
* <value>/help</value>
|
||||
* </init-param>
|
||||
* <init-param>
|
||||
* <!-- The default action to invoke in view mode -->
|
||||
* <name>defaultHelpAction</name>
|
||||
* <value>index</value>
|
||||
* </init-param>
|
||||
*
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*/
|
||||
public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(Jsr168Dispatcher.class);
|
||||
|
||||
protected String portletNamespace = null;
|
||||
|
||||
private ActionProxyFactory factory = null;
|
||||
private Map<PortletMode, String> modeMap = new HashMap<PortletMode, String>(3);
|
||||
private Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>(3);
|
||||
private Dispatcher dispatcherUtils;
|
||||
private ActionMapper actionMapper;
|
||||
private Container container;
|
||||
private ServletContext servletContext;
|
||||
|
||||
/**
|
||||
* Initialize the portlet with the init parameters from <tt>portlet.xml</tt>
|
||||
*
|
||||
* @param cfg portlet configuration
|
||||
* @throws PortletException in case of errors
|
||||
*/
|
||||
public void init(PortletConfig cfg) throws PortletException {
|
||||
super.init(cfg);
|
||||
LOG.debug("Initializing portlet {}", getPortletName());
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
for (Enumeration e = cfg.getInitParameterNames(); e.hasMoreElements(); ) {
|
||||
String name = (String) e.nextElement();
|
||||
String value = cfg.getInitParameter(name);
|
||||
params.put(name, value);
|
||||
}
|
||||
|
||||
servletContext = new PortletServletContext(cfg.getPortletContext());
|
||||
dispatcherUtils = new Dispatcher(servletContext, params);
|
||||
dispatcherUtils.init();
|
||||
|
||||
// For testability
|
||||
if (factory == null) {
|
||||
factory = dispatcherUtils.getContainer().getInstance(ActionProxyFactory.class);
|
||||
}
|
||||
portletNamespace = cfg.getInitParameter("portletNamespace");
|
||||
LOG.debug("PortletNamespace: {}", portletNamespace);
|
||||
|
||||
parseModeConfig(actionMap, cfg, PortletMode.VIEW, "viewNamespace",
|
||||
"defaultViewAction");
|
||||
parseModeConfig(actionMap, cfg, PortletMode.EDIT, "editNamespace",
|
||||
"defaultEditAction");
|
||||
parseModeConfig(actionMap, cfg, PortletMode.HELP, "helpNamespace",
|
||||
"defaultHelpAction");
|
||||
parseModeConfig(actionMap, cfg, new PortletMode("config"), "configNamespace",
|
||||
"defaultConfigAction");
|
||||
parseModeConfig(actionMap, cfg, new PortletMode("about"), "aboutNamespace",
|
||||
"defaultAboutAction");
|
||||
parseModeConfig(actionMap, cfg, new PortletMode("print"), "printNamespace",
|
||||
"defaultPrintAction");
|
||||
parseModeConfig(actionMap, cfg, new PortletMode("preview"), "previewNamespace",
|
||||
"defaultPreviewAction");
|
||||
parseModeConfig(actionMap, cfg, new PortletMode("edit_defaults"),
|
||||
"editDefaultsNamespace", "defaultEditDefaultsAction");
|
||||
if (StringUtils.isEmpty(portletNamespace)) {
|
||||
portletNamespace = "";
|
||||
}
|
||||
|
||||
container = dispatcherUtils.getContainer();
|
||||
actionMapper = container.getInstance(ActionMapper.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the mode to namespace mappings configured in portlet.xml
|
||||
*
|
||||
* @param actionMap The map with mode <-> default action mapping.
|
||||
* @param portletConfig The PortletConfig.
|
||||
* @param portletMode The PortletMode.
|
||||
* @param nameSpaceParam Name of the init parameter where the namespace for the mode
|
||||
* is configured.
|
||||
* @param defaultActionParam Name of the init parameter where the default action to
|
||||
* execute for the mode is configured.
|
||||
*/
|
||||
void parseModeConfig(Map<PortletMode, ActionMapping> actionMap, PortletConfig portletConfig,
|
||||
PortletMode portletMode, String nameSpaceParam,
|
||||
String defaultActionParam) {
|
||||
String namespace = portletConfig.getInitParameter(nameSpaceParam);
|
||||
if (StringUtils.isEmpty(namespace)) {
|
||||
namespace = "";
|
||||
}
|
||||
modeMap.put(portletMode, namespace);
|
||||
String defaultAction = portletConfig.getInitParameter(defaultActionParam);
|
||||
String method = null;
|
||||
if (StringUtils.isEmpty(defaultAction)) {
|
||||
defaultAction = DEFAULT_ACTION_NAME;
|
||||
}
|
||||
if (defaultAction.indexOf('!') >= 0) {
|
||||
method = defaultAction.substring(defaultAction.indexOf('!') + 1);
|
||||
defaultAction = defaultAction.substring(0, defaultAction.indexOf('!'));
|
||||
}
|
||||
StringBuilder fullPath = new StringBuilder();
|
||||
if (StringUtils.isNotEmpty(portletNamespace)) {
|
||||
fullPath.append(portletNamespace);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(namespace)) {
|
||||
fullPath.append(namespace).append("/");
|
||||
} else {
|
||||
fullPath.append("/");
|
||||
}
|
||||
fullPath.append(defaultAction);
|
||||
ActionMapping mapping = new ActionMapping();
|
||||
mapping.setName(getActionName(fullPath.toString()));
|
||||
mapping.setNamespace(getNamespace(fullPath.toString()));
|
||||
if (method != null) {
|
||||
mapping.setMethod(method);
|
||||
}
|
||||
actionMap.put(portletMode, mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service an action from the <tt>event</tt> phase.
|
||||
*
|
||||
* @param request action request
|
||||
* @param response action response
|
||||
* @throws PortletException in case of errors
|
||||
* @throws IOException in case of IO errors
|
||||
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
|
||||
* javax.portlet.ActionResponse)
|
||||
*/
|
||||
public void processAction(ActionRequest request, ActionResponse response)
|
||||
throws PortletException, IOException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering processAction in mode ", request.getPortletMode().toString());
|
||||
}
|
||||
resetActionContext();
|
||||
try {
|
||||
serviceAction(request, response, getRequestMap(request), getParameterMap(request),
|
||||
getSessionMap(request), getApplicationMap(),
|
||||
portletNamespace, PortletPhase.ACTION_PHASE);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Leaving processAction");
|
||||
} finally {
|
||||
ActionContext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Service an action from the <tt>render</tt> phase.
|
||||
*
|
||||
* @param request render request
|
||||
* @param response render response
|
||||
* @throws PortletException in case of errors
|
||||
* @throws IOException in case of IO errors
|
||||
* @see javax.portlet.Portlet#render(javax.portlet.RenderRequest,
|
||||
* javax.portlet.RenderResponse)
|
||||
*/
|
||||
public void render(RenderRequest request, RenderResponse response)
|
||||
throws PortletException, IOException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering render in mode ", request.getPortletMode().toString());
|
||||
}
|
||||
resetActionContext();
|
||||
response.setTitle(getTitle(request));
|
||||
if (!request.getWindowState().equals(WindowState.MINIMIZED)) {
|
||||
try {
|
||||
// Check to see if an event set the render to be included directly
|
||||
serviceAction(request, response, getRequestMap(request), getParameterMap(request),
|
||||
getSessionMap(request), getApplicationMap(),
|
||||
portletNamespace, PortletPhase.RENDER_PHASE);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Leaving render");
|
||||
} finally {
|
||||
resetActionContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the action context.
|
||||
*/
|
||||
void resetActionContext() {
|
||||
ActionContext.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges all application and portlet attributes into a single
|
||||
* <tt>HashMap</tt> to represent the entire <tt>Action</tt> context.
|
||||
*
|
||||
* @param requestMap a Map of all request attributes.
|
||||
* @param parameterMap a Map of all request parameters.
|
||||
* @param sessionMap a Map of all session attributes.
|
||||
* @param applicationMap a Map of all servlet context attributes.
|
||||
* @param request the PortletRequest object.
|
||||
* @param response the PortletResponse object.
|
||||
* @param servletRequest the HttpServletRequest object.
|
||||
* @param servletResponse the HttpServletResponse object.
|
||||
* @param servletContext the ServletContext object.
|
||||
* @param portletConfig the PortletConfig object.
|
||||
* @param phase The portlet phase (render or action, see
|
||||
* {@link PortletConstants})
|
||||
* @return a HashMap representing the <tt>Action</tt> context.
|
||||
* @throws IOException in case of IO errors
|
||||
*/
|
||||
public Map<String, Object> createContextMap(Map<String, Object> requestMap, Map<String, String[]> parameterMap,
|
||||
Map<String, Object> sessionMap, Map<String, Object> applicationMap,
|
||||
PortletRequest request, PortletResponse response, HttpServletRequest servletRequest,
|
||||
HttpServletResponse servletResponse, ServletContext servletContext,
|
||||
PortletConfig portletConfig, PortletPhase phase) throws IOException {
|
||||
|
||||
// TODO Must put http request/response objects into map for use with
|
||||
container.inject(servletRequest);
|
||||
|
||||
// ServletActionContext
|
||||
Map<String, Object> extraContext = ActionContext.of(new HashMap<>())
|
||||
.withServletRequest(servletRequest)
|
||||
.withServletResponse(servletResponse)
|
||||
.withServletContext(servletContext)
|
||||
.withParameters(HttpParameters.create(parameterMap).build())
|
||||
.withSession(sessionMap)
|
||||
.withApplication(applicationMap)
|
||||
.withLocale(getLocale(request))
|
||||
.with(StrutsStatics.STRUTS_PORTLET_CONTEXT, getPortletContext())
|
||||
.with(REQUEST, request)
|
||||
.with(RESPONSE, response)
|
||||
.with(PORTLET_CONFIG, portletConfig)
|
||||
.with(PORTLET_NAMESPACE, portletNamespace)
|
||||
.with(DEFAULT_ACTION_FOR_MODE, actionMap.get(request.getPortletMode()))
|
||||
// helpers to get access to request/session/application scope
|
||||
.with(DispatcherConstants.REQUEST, requestMap)
|
||||
.with(DispatcherConstants.SESSION, sessionMap)
|
||||
.with(DispatcherConstants.APPLICATION, applicationMap)
|
||||
.with(DispatcherConstants.PARAMETERS, parameterMap)
|
||||
.with(MODE_NAMESPACE_MAP, modeMap)
|
||||
.with(PortletConstants.DEFAULT_ACTION_MAP, actionMap)
|
||||
.with(PortletConstants.PHASE, phase)
|
||||
.getContextMap();
|
||||
|
||||
AttributeMap attrMap = new AttributeMap(extraContext);
|
||||
extraContext.put("attr", attrMap);
|
||||
|
||||
return extraContext;
|
||||
}
|
||||
|
||||
protected Locale getLocale(PortletRequest request) {
|
||||
String defaultLocale = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
|
||||
Locale locale;
|
||||
if (defaultLocale != null) {
|
||||
try {
|
||||
locale = LocaleUtils.toLocale(defaultLocale);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.warn(new ParameterizedMessage("Cannot convert 'struts.locale' = [{}] to proper locale, defaulting to request locale [{}]",
|
||||
defaultLocale, request.getLocale()), e);
|
||||
locale = request.getLocale();
|
||||
}
|
||||
} else {
|
||||
locale = request.getLocale();
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the action and executes it. This method first creates the action
|
||||
* context from the given parameters then loads an <tt>ActionProxy</tt>
|
||||
* from the given action name and namespace. After that, the action is
|
||||
* executed and output channels throught the response object.
|
||||
*
|
||||
* @param request the HttpServletRequest object.
|
||||
* @param response the HttpServletResponse object.
|
||||
* @param requestMap a Map of request attributes.
|
||||
* @param parameterMap a Map of request parameters.
|
||||
* @param sessionMap a Map of all session attributes.
|
||||
* @param applicationMap a Map of all application attributes.
|
||||
* @param portletNamespace the namespace or context of the action.
|
||||
* @param phase The portlet phase (render or action, see {@link PortletConstants})
|
||||
* @throws PortletException in case of errors
|
||||
*/
|
||||
public void serviceAction(PortletRequest request, PortletResponse response, Map<String, Object> requestMap, Map<String, String[]> parameterMap,
|
||||
Map<String, Object> sessionMap, Map<String, Object> applicationMap, String portletNamespace,
|
||||
PortletPhase phase) throws PortletException {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("serviceAction");
|
||||
Dispatcher.setInstance(dispatcherUtils);
|
||||
String actionName = null;
|
||||
String namespace;
|
||||
try {
|
||||
HttpServletRequest servletRequest = new PortletServletRequest(request, getPortletContext());
|
||||
HttpServletResponse servletResponse = createPortletServletResponse(response);
|
||||
if (phase.isAction()) {
|
||||
servletRequest = dispatcherUtils.wrapRequest(servletRequest);
|
||||
if (servletRequest instanceof MultiPartRequestWrapper) {
|
||||
// Multipart request. Request parameters are encoded in the multipart data,
|
||||
// so we need to manually add them to the parameter map.
|
||||
parameterMap.putAll(servletRequest.getParameterMap());
|
||||
}
|
||||
}
|
||||
container.inject(servletRequest);
|
||||
ActionMapping mapping = getActionMapping(request, servletRequest);
|
||||
actionName = mapping.getName();
|
||||
if ("renderDirect".equals(actionName)) {
|
||||
namespace = request.getParameter(PortletConstants.RENDER_DIRECT_NAMESPACE);
|
||||
} else {
|
||||
namespace = mapping.getNamespace();
|
||||
}
|
||||
Map<String, Object> extraContext = createContextMap(requestMap, parameterMap,
|
||||
sessionMap, applicationMap, request, response, servletRequest, servletResponse,
|
||||
servletContext, getPortletConfig(), phase);
|
||||
extraContext.put(PortletConstants.ACTION_MAPPING, mapping);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Creating action proxy for name = " + actionName + ", namespace = " + namespace);
|
||||
}
|
||||
ActionProxy proxy = factory.createActionProxy(namespace, actionName, mapping.getMethod(), extraContext);
|
||||
request.setAttribute("struts.valueStack", proxy.getInvocation().getStack());
|
||||
proxy.execute();
|
||||
} catch (ConfigurationException e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("Could not find action", e);
|
||||
}
|
||||
throw new PortletException("Could not find action " + actionName, e);
|
||||
} catch (Exception e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("Could not execute action", e);
|
||||
}
|
||||
throw new PortletException("Error executing action " + actionName, e);
|
||||
} finally {
|
||||
Dispatcher.setInstance(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of all application attributes. Copies all attributes from
|
||||
* the {@link PortletActionContext}into an {@link ApplicationMap}.
|
||||
*
|
||||
* @return a Map of all application attributes.
|
||||
*/
|
||||
protected Map<String, Object> getApplicationMap() {
|
||||
return new PortletApplicationMap(getPortletContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace of the action from the request. The namespace is the
|
||||
* same as the portlet mode. E.g, view mode is mapped to namespace
|
||||
* <code>view</code>, and edit mode is mapped to the namespace
|
||||
* <code>edit</code>
|
||||
*
|
||||
* @param portletRequest the PortletRequest object.
|
||||
* @param servletRequest the ServletRequest to use
|
||||
* @return the namespace of the action.
|
||||
*/
|
||||
protected ActionMapping getActionMapping(final PortletRequest portletRequest, final HttpServletRequest servletRequest) {
|
||||
ActionMapping mapping;
|
||||
String actionPath = getDefaultActionPath(portletRequest);
|
||||
if (resetAction(portletRequest)) {
|
||||
mapping = actionMap.get(portletRequest.getPortletMode());
|
||||
} else {
|
||||
actionPath = servletRequest.getParameter(ACTION_PARAM);
|
||||
if (StringUtils.isEmpty(actionPath)) {
|
||||
mapping = actionMap.get(portletRequest.getPortletMode());
|
||||
} else {
|
||||
|
||||
// Use the usual action mapper, but it is expecting an action extension
|
||||
// on the uri, so we add the default one, which should be ok as the
|
||||
// portlet is a portlet first, a servlet second
|
||||
mapping = actionMapper.getMapping(servletRequest, dispatcherUtils.getConfigurationManager());
|
||||
}
|
||||
}
|
||||
|
||||
if (mapping == null) {
|
||||
throw new StrutsException("Unable to locate action mapping for request, probably due to an invalid action path: " + actionPath);
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
|
||||
protected String getDefaultActionPath(PortletRequest portletRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespace part of the action path.
|
||||
*
|
||||
* @param actionPath Full path to action
|
||||
* @return The namespace part.
|
||||
*/
|
||||
String getNamespace(String actionPath) {
|
||||
int idx = actionPath.lastIndexOf('/');
|
||||
String namespace = "";
|
||||
if (idx >= 0) {
|
||||
namespace = actionPath.substring(0, idx);
|
||||
}
|
||||
return namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action name part of the action path.
|
||||
*
|
||||
* @param actionPath Full path to action
|
||||
* @return The action name.
|
||||
*/
|
||||
String getActionName(String actionPath) {
|
||||
int idx = actionPath.lastIndexOf('/');
|
||||
String action = actionPath;
|
||||
if (idx >= 0) {
|
||||
action = actionPath.substring(idx + 1);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of all request parameters. This implementation just calls
|
||||
* {@link PortletRequest#getParameterMap()}.
|
||||
*
|
||||
* @param request the PortletRequest object.
|
||||
* @return a Map of all request parameters.
|
||||
* @throws IOException if an exception occurs while retrieving the parameter
|
||||
* map.
|
||||
*/
|
||||
protected Map<String, String[]> getParameterMap(PortletRequest request) throws IOException {
|
||||
return new HashMap<String, String[]>(request.getParameterMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of all request attributes. The default implementation is to
|
||||
* wrap the request in a {@link RequestMap}. Override this method to
|
||||
* customize how request attributes are mapped.
|
||||
*
|
||||
* @param request the PortletRequest object.
|
||||
* @return a Map of all request attributes.
|
||||
*/
|
||||
protected Map<String, Object> getRequestMap(PortletRequest request) {
|
||||
return new PortletRequestMap(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of all session attributes. The default implementation is to
|
||||
* wrap the reqeust in a {@link SessionMap}. Override this method to
|
||||
* customize how session attributes are mapped.
|
||||
*
|
||||
* @param request the PortletRequest object.
|
||||
* @return a Map of all session attributes.
|
||||
*/
|
||||
protected Map<String, Object> getSessionMap(PortletRequest request) {
|
||||
return new PortletSessionMap(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to ease testing.
|
||||
*
|
||||
* @param factory action proxy factory
|
||||
*/
|
||||
protected void setActionProxyFactory(ActionProxyFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the action parameter is valid for the current portlet mode. If the portlet
|
||||
* mode has been changed with the portal widgets, the action name is invalid, since the
|
||||
* action name belongs to the previous executing portlet mode. If this method evaluates to
|
||||
* <code>true</code> the <code>default<Mode>Action</code> is used instead.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
* @return <code>true</code> if the action should be reset.
|
||||
*/
|
||||
private boolean resetAction(PortletRequest request) {
|
||||
boolean reset = false;
|
||||
Map paramMap = request.getParameterMap();
|
||||
String[] modeParam = (String[]) paramMap.get(MODE_PARAM);
|
||||
if (modeParam != null && modeParam.length == 1) {
|
||||
String originatingMode = modeParam[0];
|
||||
String currentMode = request.getPortletMode().toString();
|
||||
if (!currentMode.equals(originatingMode)) {
|
||||
reset = true;
|
||||
}
|
||||
}
|
||||
if (reset) {
|
||||
request.setAttribute(ACTION_RESET, Boolean.TRUE);
|
||||
} else {
|
||||
request.setAttribute(ACTION_RESET, Boolean.FALSE);
|
||||
}
|
||||
return reset;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (dispatcherUtils != null) {
|
||||
dispatcherUtils.cleanup();
|
||||
} else {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("Something is seriously wrong, DispatcherUtil is not initialized (null) ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actionMapper the actionMapper to set
|
||||
*/
|
||||
public void setActionMapper(ActionMapper actionMapper) {
|
||||
this.actionMapper = actionMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a PortletServletResponse matching the used Portlet API, to be overridden for JSR286 Dispatcher.
|
||||
*
|
||||
* @param response The Response used for building the wrapper.
|
||||
* @return The wrapper response for Servlet bound usage.
|
||||
*/
|
||||
protected PortletServletResponse createPortletServletResponse(PortletResponse response) {
|
||||
return new PortletServletResponse(response);
|
||||
}
|
||||
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
import org.apache.struts2.portlet.servlet.PortletServletResponse;
|
||||
import org.apache.struts2.portlet.servlet.PortletServletResponseJSR286;
|
||||
|
||||
import javax.portlet.EventRequest;
|
||||
import javax.portlet.EventResponse;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.portlet.ResourceResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Jsr286Dispatcher extends Jsr168Dispatcher {
|
||||
|
||||
private final static Logger LOG = LogManager.getLogger(Jsr286Dispatcher.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering processEvent");
|
||||
}
|
||||
resetActionContext();
|
||||
try {
|
||||
// We'll use the event name as the "action"
|
||||
serviceAction(request, response,
|
||||
getRequestMap(request), getParameterMap(request),
|
||||
getSessionMap(request), getApplicationMap(),
|
||||
portletNamespace, PortletPhase.EVENT_PHASE);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Leaving processEvent");
|
||||
} finally {
|
||||
ActionContext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serveResource(ResourceRequest request, ResourceResponse response)
|
||||
throws PortletException, IOException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering serveResource");
|
||||
}
|
||||
resetActionContext();
|
||||
try {
|
||||
serviceAction(request, response,
|
||||
getRequestMap(request), getParameterMap(request),
|
||||
getSessionMap(request), getApplicationMap(),
|
||||
portletNamespace, PortletPhase.SERVE_RESOURCE_PHASE);
|
||||
} finally {
|
||||
ActionContext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultActionPath(PortletRequest portletRequest) {
|
||||
if (portletRequest instanceof EventRequest) {
|
||||
return ((EventRequest) portletRequest).getEvent().getName();
|
||||
}
|
||||
return super.getDefaultActionPath(portletRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PortletServletResponse createPortletServletResponse(PortletResponse response) {
|
||||
return new PortletServletResponseJSR286(response);
|
||||
}
|
||||
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.action.PrincipalAware;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.action.PortletContextAware;
|
||||
import org.apache.struts2.portlet.action.PortletPreferencesAware;
|
||||
import org.apache.struts2.portlet.action.PortletRequestAware;
|
||||
import org.apache.struts2.portlet.action.PortletResponseAware;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
|
||||
public class PortletAwareInterceptor extends AbstractInterceptor implements StrutsStatics {
|
||||
|
||||
private static final long serialVersionUID = 2476509721059587700L;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(PortletAwareInterceptor.class);
|
||||
|
||||
/**
|
||||
* Sets action properties based on the interfaces an action implements. Things like application properties,
|
||||
* parameters, session attributes, etc are set based on the implementing interface.
|
||||
*
|
||||
* @param invocation an encapsulation of the action execution state.
|
||||
* @throws Exception if an error occurs when setting action properties.
|
||||
*/
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
final Object action = invocation.getAction();
|
||||
final ActionContext context = invocation.getInvocationContext();
|
||||
|
||||
if (action instanceof PortletRequestAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((PortletRequestAware) action).withPortletRequest(request);
|
||||
}
|
||||
|
||||
if (action instanceof PortletResponseAware) {
|
||||
PortletResponse response = (PortletResponse) context.get(PortletConstants.RESPONSE);
|
||||
((PortletResponseAware) action).withPortletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof PrincipalAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((PrincipalAware) action).withPrincipalProxy(new PortletPrincipalProxy(request));
|
||||
}
|
||||
|
||||
if (action instanceof PortletContextAware) {
|
||||
PortletContext portletContext = (PortletContext) context.get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
((PortletContextAware) action).withPortletContext(portletContext);
|
||||
}
|
||||
|
||||
if (action instanceof PortletPreferencesAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
|
||||
// Check if running in a servlet environment
|
||||
if (request == null) {
|
||||
LOG.warn("This portlet preferences implementation should only be used during development");
|
||||
((PortletPreferencesAware) action).withPortletPreferences(new ServletPortletPreferences(ActionContext.getContext().getSession()));
|
||||
} else {
|
||||
((PortletPreferencesAware) action).withPortletPreferences(request.getPreferences());
|
||||
}
|
||||
}
|
||||
|
||||
return invocation.invoke();
|
||||
}
|
||||
}
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.interceptor;
|
||||
|
||||
import org.apache.struts2.interceptor.PrincipalProxy;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.security.Principal;
|
||||
|
||||
/**
|
||||
* PrincipalProxy implementation for using PortletRequest Principal related methods.
|
||||
*/
|
||||
public class PortletPrincipalProxy implements PrincipalProxy {
|
||||
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* Constructs a proxy
|
||||
*
|
||||
* @param request The underlying request
|
||||
*/
|
||||
public PortletPrincipalProxy(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user is in the given role
|
||||
*
|
||||
* @param role The role
|
||||
* @return True if the user is in that role
|
||||
*/
|
||||
public boolean isUserInRole(String role) {
|
||||
return request.isUserInRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user principal
|
||||
*
|
||||
* @return The principal
|
||||
*/
|
||||
public Principal getUserPrincipal() {
|
||||
return request.getUserPrincipal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user id
|
||||
*
|
||||
* @return The user id
|
||||
*/
|
||||
public String getRemoteUser() {
|
||||
return request.getRemoteUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the request using https?
|
||||
*
|
||||
* @return True if using https
|
||||
*/
|
||||
public boolean isRequestSecure() {
|
||||
return request.isSecure();
|
||||
}
|
||||
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
|
||||
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.RenderRequest;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.struts2.portlet.PortletConstants.*;
|
||||
|
||||
public class PortletStateInterceptor extends AbstractInterceptor {
|
||||
|
||||
private final static Logger LOG = LogManager.getLogger(PortletStateInterceptor.class);
|
||||
|
||||
private static final long serialVersionUID = 6138452063353911784L;
|
||||
|
||||
@Override
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
PortletPhase phase = (PortletPhase) invocation.getInvocationContext().get(PortletConstants.PHASE);
|
||||
if (phase.isRender()) {
|
||||
restoreStack(invocation);
|
||||
return invocation.invoke();
|
||||
} else if (phase.isAction()) {
|
||||
try {
|
||||
return invocation.invoke();
|
||||
} finally {
|
||||
saveStack(invocation);
|
||||
}
|
||||
} else {
|
||||
return invocation.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void saveStack(ActionInvocation invocation) {
|
||||
Map session = invocation.getInvocationContext().getSession();
|
||||
session.put(STACK_FROM_EVENT_PHASE, invocation.getStack());
|
||||
ActionResponse actionResponse = (ActionResponse) invocation.getInvocationContext().get(RESPONSE);
|
||||
actionResponse.setRenderParameter(EVENT_ACTION, "true");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void restoreStack(ActionInvocation invocation) {
|
||||
RenderRequest request = (RenderRequest) invocation.getInvocationContext().get(REQUEST);
|
||||
if (StringUtils.isNotEmpty(request.getParameter(EVENT_ACTION))) {
|
||||
if(!isProperPrg(invocation)) {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Restoring value stack from event phase");
|
||||
ValueStack oldStack = (ValueStack) invocation.getInvocationContext().getSession().get(
|
||||
STACK_FROM_EVENT_PHASE);
|
||||
if (oldStack != null) {
|
||||
CompoundRoot oldRoot = oldStack.getRoot();
|
||||
ValueStack currentStack = invocation.getStack();
|
||||
CompoundRoot root = currentStack.getRoot();
|
||||
root.addAll(0, oldRoot);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Restored stack");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Won't restore stack from event phase since it's a proper PRG request");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isProperPrg(ActionInvocation invocation) {
|
||||
return !(invocation.getAction() instanceof DirectRenderFromEventAction);
|
||||
}
|
||||
|
||||
}
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.interceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.portlet.PortletPreferences;
|
||||
import javax.portlet.ReadOnlyException;
|
||||
import javax.portlet.ValidatorException;
|
||||
|
||||
/**
|
||||
* Simple portlet preferences implementation that uses a map in the Session
|
||||
* as storage.
|
||||
*/
|
||||
public class ServletPortletPreferences implements PortletPreferences {
|
||||
|
||||
private Map session;
|
||||
private String PREFERENCES_KEY = "_portlet-preferences";
|
||||
|
||||
public ServletPortletPreferences(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
Map map = (Map) session.get(PREFERENCES_KEY);
|
||||
if (map == null) {
|
||||
map = new HashMap();
|
||||
session.put(PREFERENCES_KEY, map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public Enumeration getNames() {
|
||||
return new Vector(getMap().keySet()).elements();
|
||||
}
|
||||
|
||||
public String getValue(String key, String def) {
|
||||
String val = (String) getMap().get(key);
|
||||
if (val == null) {
|
||||
val = def;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public String[] getValues(String key, String[] def) {
|
||||
String[] val = (String[]) getMap().get(key);
|
||||
if (val == null) {
|
||||
val = def;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public boolean isReadOnly(String arg0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reset(String arg0) throws ReadOnlyException {
|
||||
session.put(PREFERENCES_KEY, new HashMap());
|
||||
}
|
||||
|
||||
public void setValue(String key, String value) throws ReadOnlyException {
|
||||
getMap().put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(String key, String[] value) throws ReadOnlyException {
|
||||
getMap().put(key, value);
|
||||
}
|
||||
|
||||
public void store() throws IOException, ValidatorException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-263
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.result;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.result.ServletActionRedirectResult;
|
||||
import org.apache.struts2.url.QueryStringBuilder;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Portlet modification of the {@link ServletActionRedirectResult}.
|
||||
* <p>
|
||||
* <!-- START SNIPPET: description -->
|
||||
* <p>
|
||||
* This result uses the {@link ActionMapper} provided by the
|
||||
* <code>ActionMapperFactory</code> to instruct the render phase to invoke the
|
||||
* specified action and (optional) namespace. This is better than the
|
||||
* {@link PortletResult} because it does not require you to encode the URL
|
||||
* patterns processed by the {@link ActionMapper} in to your struts.xml
|
||||
* configuration files. This means you can change your URL patterns at any point
|
||||
* and your application will still work. It is strongly recommended that if you
|
||||
* are redirecting to another action, you use this result rather than the
|
||||
* standard redirect result.
|
||||
* <p>
|
||||
* See examples below for an example of how request parameters could be passed
|
||||
* in.
|
||||
* <p>
|
||||
* <!-- END SNIPPET: description -->
|
||||
* <p>
|
||||
* <b>This result type takes the following parameters:</b>
|
||||
* <p>
|
||||
* <!-- START SNIPPET: params -->
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li><b>actionName (default)</b> - the name of the action that will be
|
||||
* redirect to</li>
|
||||
*
|
||||
* <li><b>namespace</b> - used to determine which namespace the action is in
|
||||
* that we're redirecting to . If namespace is null, this defaults to the
|
||||
* current namespace</li>
|
||||
*
|
||||
* </ul>
|
||||
* <p>
|
||||
* <!-- END SNIPPET: params -->
|
||||
* <p>
|
||||
* <b>Example:</b>
|
||||
*
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
* <package name="public" extends="struts-default">
|
||||
* <action name="login" class="...">
|
||||
* <!-- Redirect to another namespace -->
|
||||
* <result type="redirect-action">
|
||||
* <param name="actionName">dashboard</param>
|
||||
* <param name="namespace">/secure</param>
|
||||
* </result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
* <package name="secure" extends="struts-default" namespace="/secure">
|
||||
* <-- Redirect to an action in the same namespace -->
|
||||
* <action name="dashboard" class="...">
|
||||
* <result>dashboard.jsp</result>
|
||||
* <result name="error" type="redirect-action">error</result>
|
||||
* </action>
|
||||
*
|
||||
* <action name="error" class="...">
|
||||
* <result>error.jsp</result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
* <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
|
||||
* <-- Pass parameters (reportType, width and height) -->
|
||||
* <!--
|
||||
* The redirect-action url generated will be :
|
||||
* /genReport/generateReport.action?reportType=pie&width=100&height=100
|
||||
* -->
|
||||
* <action name="gatherReportInfo" class="...">
|
||||
* <result name="showReportResult" type="redirect-action">
|
||||
* <param name="actionName">generateReport</param>
|
||||
* <param name="namespace">/genReport</param>
|
||||
* <param name="reportType">pie</param>
|
||||
* <param name="width">100</param>
|
||||
* <param name="height">100</param>
|
||||
* </result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
*
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*
|
||||
* @see ActionMapper
|
||||
*/
|
||||
public class PortletActionRedirectResult extends PortletResult {
|
||||
|
||||
private static final long serialVersionUID = -7627388936683562557L;
|
||||
|
||||
/**
|
||||
* The default parameter
|
||||
*/
|
||||
public static final String DEFAULT_PARAM = "actionName";
|
||||
|
||||
protected String actionName;
|
||||
protected String namespace;
|
||||
protected String method;
|
||||
|
||||
private final Map<String, Object> requestParameters = new LinkedHashMap<>();
|
||||
|
||||
private ActionMapper actionMapper;
|
||||
private QueryStringBuilder queryStringBuilder;
|
||||
|
||||
public PortletActionRedirectResult() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PortletActionRedirectResult(String actionName) {
|
||||
this(null, actionName, null);
|
||||
}
|
||||
|
||||
public PortletActionRedirectResult(String actionName, String method) {
|
||||
this(null, actionName, method);
|
||||
}
|
||||
|
||||
public PortletActionRedirectResult(String namespace, String actionName, String method) {
|
||||
super(null);
|
||||
this.namespace = namespace;
|
||||
this.actionName = actionName;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
protected List<String> prohibitedResultParam = Arrays.asList(DEFAULT_PARAM, "namespace", "method", "encode", "parse",
|
||||
"location", "prependServletContext");
|
||||
|
||||
@Inject
|
||||
public void setActionMapper(ActionMapper actionMapper) {
|
||||
this.actionMapper = actionMapper;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQueryStringBuilder(QueryStringBuilder queryStringBuilder) {
|
||||
this.queryStringBuilder = queryStringBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
|
||||
*/
|
||||
public void execute(ActionInvocation invocation) throws Exception {
|
||||
if (invocation == null) {
|
||||
throw new IllegalArgumentException("Invocation cannot be null!");
|
||||
}
|
||||
|
||||
actionName = conditionalParse(actionName, invocation);
|
||||
parseLocation = false;
|
||||
|
||||
String portletNamespace = (String) invocation.getInvocationContext().get(PortletConstants.PORTLET_NAMESPACE);
|
||||
if (portletMode != null) {
|
||||
Map<PortletMode, String> namespaceMap = getNamespaceMap(invocation);
|
||||
namespace = namespaceMap.get(portletMode);
|
||||
}
|
||||
if (namespace == null) {
|
||||
namespace = invocation.getProxy().getNamespace();
|
||||
} else {
|
||||
namespace = conditionalParse(namespace, invocation);
|
||||
}
|
||||
if (method == null) {
|
||||
method = "";
|
||||
} else {
|
||||
method = conditionalParse(method, invocation);
|
||||
}
|
||||
|
||||
String resultCode = invocation.getResultCode();
|
||||
if (resultCode != null) {
|
||||
ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(resultCode);
|
||||
Map<String, String> resultConfigParams = resultConfig.getParams();
|
||||
for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
|
||||
if (!prohibitedResultParam.contains(e.getKey())) {
|
||||
requestParameters.put(e.getKey(), e.getValue() == null ? "" : conditionalParse(e.getValue(), invocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ActionMapping actionMapping = new ActionMapping(actionName, (portletNamespace == null ? namespace : portletNamespace + namespace), method, null);
|
||||
StringBuilder tmpLocation = new StringBuilder(actionMapper.getUriFromActionMapping(actionMapping));
|
||||
queryStringBuilder.build(requestParameters, tmpLocation, "&");
|
||||
|
||||
setLocation(tmpLocation.toString());
|
||||
|
||||
super.execute(invocation);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<PortletMode, String> getNamespaceMap(ActionInvocation invocation) {
|
||||
return (Map<PortletMode, String>) invocation.getInvocationContext().get(PortletConstants.MODE_NAMESPACE_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the action name
|
||||
*
|
||||
* @param actionName The name
|
||||
*/
|
||||
public void setActionName(String actionName) {
|
||||
this.actionName = actionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace
|
||||
*
|
||||
* @param namespace The namespace
|
||||
*/
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method
|
||||
*
|
||||
* @param method The method
|
||||
*/
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a request parameter to be added to the redirect url
|
||||
*
|
||||
* @param key The parameter name
|
||||
* @param value The parameter value
|
||||
* @return the portlet action redirect result
|
||||
*/
|
||||
public PortletActionRedirectResult addParameter(String key, Object value) {
|
||||
requestParameters.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.result;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.result.StrutsResultSupport;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.PortletPhase;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletMode;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.RenderResponse;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Result type that includes a JSP to render.
|
||||
*
|
||||
*/
|
||||
public class PortletResult extends StrutsResultSupport {
|
||||
|
||||
private static final long serialVersionUID = 434251393926178567L;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(PortletResult.class);
|
||||
|
||||
private boolean useDispatcherServlet;
|
||||
|
||||
private String dispatcherServletName = PortletConstants.DEFAULT_DISPATCHER_SERVLET_NAME;
|
||||
|
||||
|
||||
private String contentType = "text/html";
|
||||
|
||||
private String title;
|
||||
|
||||
protected PortletMode portletMode;
|
||||
|
||||
PortletResultHelper resultHelper;
|
||||
|
||||
public PortletResult() {
|
||||
super();
|
||||
determineResultHelper();
|
||||
}
|
||||
|
||||
public PortletResult(String location) {
|
||||
super(location);
|
||||
determineResultHelper();
|
||||
}
|
||||
|
||||
private void determineResultHelper() {
|
||||
if (PortletActionContext.isJSR268Supported()) {
|
||||
this.resultHelper = new PortletResultHelperJSR286();
|
||||
} else {
|
||||
this.resultHelper = new PortletResultHelperJSR168();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the result. Obtains the
|
||||
* {@link javax.portlet.PortletRequestDispatcher}from the
|
||||
* {@link PortletActionContext}and includes the JSP.
|
||||
*
|
||||
* @param finalLocation the final location
|
||||
* @param actionInvocation the action invocation
|
||||
*
|
||||
* @throws Exception in case of any errors
|
||||
*
|
||||
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
|
||||
*/
|
||||
public void doExecute(String finalLocation, ActionInvocation actionInvocation) throws Exception {
|
||||
|
||||
PortletPhase phase = PortletActionContext.getPhase();
|
||||
if (phase.isRender() || phase.isResource()) {
|
||||
executeMimeResult(finalLocation);
|
||||
} else if (phase.isAction() || phase.isEvent()) {
|
||||
executeActionResult(finalLocation, actionInvocation);
|
||||
} else {
|
||||
executeRegularServletResult(finalLocation, actionInvocation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the regular servlet result.
|
||||
*
|
||||
* @param finalLocation the final location
|
||||
* @param actionInvocation the action invocation
|
||||
*
|
||||
* @throws ServletException in case of any Servlet errors
|
||||
* @throws IOException in case of any IO errors
|
||||
*/
|
||||
private void executeRegularServletResult(String finalLocation, ActionInvocation actionInvocation)
|
||||
throws ServletException, IOException {
|
||||
ServletContext ctx = ServletActionContext.getServletContext();
|
||||
HttpServletRequest req = ServletActionContext.getRequest();
|
||||
HttpServletResponse res = ServletActionContext.getResponse();
|
||||
try {
|
||||
ctx.getRequestDispatcher(finalLocation).include(req, res);
|
||||
} catch (ServletException e) {
|
||||
LOG.error("ServletException including " + finalLocation, e);
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException while including result '" + finalLocation + "'", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action result.
|
||||
*
|
||||
* @param finalLocation the final location
|
||||
* @param invocation the action invocation
|
||||
*
|
||||
* @throws Exception in case of any errors
|
||||
*/
|
||||
protected void executeActionResult(String finalLocation, ActionInvocation invocation) throws Exception {
|
||||
String location = finalLocation;
|
||||
String namespace = invocation.getProxy().getNamespace();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Executing result in {} phase", (PortletActionContext.getPhase().isEvent()) ? "Event" : "Action");
|
||||
LOG.debug("Setting event render parameter location : {}", location);
|
||||
LOG.debug("Setting event render parameter namespace: {}", namespace);
|
||||
}
|
||||
Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
|
||||
if (location.indexOf('?') != -1) {
|
||||
convertQueryParamsToRenderParams(location.substring(location.indexOf('?') + 1));
|
||||
location = location.substring(0, location.indexOf('?'));
|
||||
}
|
||||
PortletResponse response = PortletActionContext.getResponse();
|
||||
if (location.endsWith(".action")) {
|
||||
// View is rendered with a view action...luckily...
|
||||
location = location.substring(0, location.lastIndexOf("."));
|
||||
resultHelper.setRenderParameter(response, PortletConstants.ACTION_PARAM, location);
|
||||
} else {
|
||||
// View is rendered outside an action...uh oh...
|
||||
resultHelper.setRenderParameter(response, PortletConstants.ACTION_PARAM, "renderDirect");
|
||||
sessionMap.put(PortletConstants.RENDER_DIRECT_LOCATION, location);
|
||||
}
|
||||
resultHelper.setRenderParameter(response, PortletConstants.RENDER_DIRECT_NAMESPACE, namespace);
|
||||
if(portletMode != null) {
|
||||
resultHelper.setPortletMode(response, portletMode);
|
||||
resultHelper.setRenderParameter(response, PortletConstants.MODE_PARAM, portletMode.toString());
|
||||
}
|
||||
else {
|
||||
resultHelper.setRenderParameter(response, PortletConstants.MODE_PARAM, PortletActionContext.getRequest().getPortletMode()
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the query params to render params.
|
||||
*
|
||||
* @param queryParams query parameter
|
||||
*/
|
||||
protected void convertQueryParamsToRenderParams(String queryParams) {
|
||||
StringTokenizer tok = new StringTokenizer(queryParams, "&");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String token = tok.nextToken();
|
||||
String key = token.substring(0, token.indexOf('='));
|
||||
String value = token.substring(token.indexOf('=') + 1);
|
||||
resultHelper.setRenderParameter(PortletActionContext.getResponse(), key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the render result.
|
||||
*
|
||||
* @param finalLocation the final location
|
||||
*
|
||||
* @throws PortletException in case of any Portlet errors
|
||||
* @throws IOException in case of any IO errors
|
||||
*/
|
||||
protected void executeMimeResult(final String finalLocation) throws PortletException, IOException {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Executing mime result");
|
||||
PortletContext ctx = PortletActionContext.getPortletContext();
|
||||
PortletRequest req = PortletActionContext.getRequest();
|
||||
PortletResponse res = PortletActionContext.getResponse();
|
||||
|
||||
if (StringUtils.isNotEmpty(title) && res instanceof RenderResponse) {
|
||||
((RenderResponse)res).setTitle(title);
|
||||
}
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Location: " + finalLocation);
|
||||
PortletRequestDispatcher dispatcher;
|
||||
if (useDispatcherServlet) {
|
||||
req.setAttribute(PortletConstants.DISPATCH_TO, finalLocation);
|
||||
dispatcher = ctx.getNamedDispatcher(dispatcherServletName);
|
||||
if(dispatcher == null) {
|
||||
throw new PortletException("Could not locate dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml file");
|
||||
}
|
||||
} else {
|
||||
dispatcher = ctx.getRequestDispatcher(finalLocation);
|
||||
if (dispatcher == null) {
|
||||
throw new PortletException("Could not locate dispatcher for '" + finalLocation + "'");
|
||||
}
|
||||
}
|
||||
resultHelper.include( dispatcher, contentType, req, res );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content type.
|
||||
*
|
||||
* @param contentType
|
||||
* The content type to set.
|
||||
*/
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title.
|
||||
*
|
||||
* @param title
|
||||
* The title to set.
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setPortletMode(String portletMode) {
|
||||
if(portletMode != null) {
|
||||
this.portletMode = new PortletMode(portletMode);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject("struts.portlet.useDispatcherServlet")
|
||||
public void setUseDispatcherServlet(String useDispatcherServlet) {
|
||||
this.useDispatcherServlet = "true".equalsIgnoreCase(useDispatcherServlet);
|
||||
}
|
||||
|
||||
@Inject("struts.portlet.dispatcherServletName")
|
||||
public void setDispatcherServletName(String dispatcherServletName) {
|
||||
this.dispatcherServletName = dispatcherServletName;
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.result;
|
||||
|
||||
import javax.portlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* PortletResultHelper abstracts Portlet API result functions specific to the used API spec version.
|
||||
*
|
||||
* @author Rene Gielen
|
||||
*/
|
||||
|
||||
public interface PortletResultHelper {
|
||||
|
||||
/**
|
||||
* Set a render parameter, abstracted from the used Portlet API version
|
||||
*
|
||||
* @param response The response to set the parameter on.
|
||||
* @param key The parameter key to set.
|
||||
* @param value The parameter value to set.
|
||||
*/
|
||||
void setRenderParameter( PortletResponse response, String key, String value );
|
||||
|
||||
/**
|
||||
* Set a portlet mode, abstracted from the used Portlet API version
|
||||
*
|
||||
* @param response The response to set the portlet mode on.
|
||||
* @param portletMode The portlet mode to set.
|
||||
*
|
||||
* @throws PortletModeException in case of errors during setting of portlet mode
|
||||
*/
|
||||
void setPortletMode( PortletResponse response, PortletMode portletMode ) throws PortletModeException;
|
||||
|
||||
/**
|
||||
* Call a dispatcher's include method, abstracted from the used Portlet API version.
|
||||
*
|
||||
* @param dispatcher The dispatcher to call the include method on.
|
||||
* @param contentType The content type to set for the response.
|
||||
* @param request The request to use for including
|
||||
* @param response The response to use for including
|
||||
*
|
||||
* @throws IOException in case of any I/O errors
|
||||
* @throws PortletException in case of any portlet errors
|
||||
*/
|
||||
void include( PortletRequestDispatcher dispatcher, String contentType, PortletRequest request,
|
||||
PortletResponse response ) throws IOException, PortletException;
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.result;
|
||||
|
||||
import javax.portlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* PortletResultHelperJSR168 implements PortletResultHelper for Portlet 1.0 API (JSR168).
|
||||
*
|
||||
* @author Rene Gielen
|
||||
*/
|
||||
public class PortletResultHelperJSR168 implements PortletResultHelper {
|
||||
|
||||
/**
|
||||
* Set a render parameter, abstracted from the used Portlet API version. This implementation assumes that the given
|
||||
* response must be a {@link javax.portlet.ActionResponse}, as JSR168 implies.
|
||||
*
|
||||
* @param response The response to set the parameter on.
|
||||
* @param key The parameter key to set.
|
||||
* @param value The parameter value to set.
|
||||
*/
|
||||
public void setRenderParameter( PortletResponse response, String key, String value ) {
|
||||
((ActionResponse) response).setRenderParameter(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a portlet mode, abstracted from the used Portlet API version. This implementation assumes that the given
|
||||
* response must be a {@link javax.portlet.ActionResponse}, as JSR168 implies.
|
||||
*
|
||||
* @param response The response to set the portlet mode on.
|
||||
* @param portletMode The portlet mode to set.
|
||||
*/
|
||||
public void setPortletMode( PortletResponse response, PortletMode portletMode ) throws PortletModeException {
|
||||
((ActionResponse) response).setPortletMode(portletMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a dispatcher's include method, abstracted from the used Portlet API version. This implementation assumes
|
||||
* that the given the request must be a {@link javax.portlet.RenderRequest} and the response must be a {@link
|
||||
* javax.portlet.RenderResponse}, as JSR168 implies.
|
||||
*
|
||||
* @param dispatcher The dispatcher to call the include method on.
|
||||
* @param contentType The content type to set for the response.
|
||||
* @param request The request to use for including
|
||||
* @param response The response to use for including
|
||||
*/
|
||||
public void include( PortletRequestDispatcher dispatcher, String contentType, PortletRequest request,
|
||||
PortletResponse response ) throws IOException, PortletException {
|
||||
RenderRequest req = (RenderRequest) request;
|
||||
RenderResponse res = (RenderResponse) response;
|
||||
res.setContentType(contentType);
|
||||
dispatcher.include(req, res);
|
||||
}
|
||||
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.struts2.portlet.result;
|
||||
|
||||
import javax.portlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* PortletResultHelperJSR286 implements PortletResultHelper for Portlet 2.0 API (JSR286).
|
||||
*
|
||||
* @author Rene Gielen
|
||||
*/
|
||||
public class PortletResultHelperJSR286 implements PortletResultHelper {
|
||||
|
||||
/**
|
||||
* Set a render parameter, abstracted from the used Portlet API version. This implementation assumes that the given
|
||||
* response is a {@link javax.portlet.StateAwareResponse}, as JSR286 implies.
|
||||
*
|
||||
* @param response The response to set the parameter on.
|
||||
* @param key The parameter key to set.
|
||||
* @param value The parameter value to set.
|
||||
*/
|
||||
public void setRenderParameter( PortletResponse response, String key, String value ) {
|
||||
((StateAwareResponse) response).setRenderParameter(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a portlet mode, abstracted from the used Portlet API version. This implementation assumes that the given
|
||||
* response is a {@link javax.portlet.StateAwareResponse}, as JSR286 implies.
|
||||
*
|
||||
* @param response The response to set the portlet mode on.
|
||||
* @param portletMode The portlet mode to set.
|
||||
*/
|
||||
public void setPortletMode( PortletResponse response, PortletMode portletMode ) throws PortletModeException {
|
||||
((StateAwareResponse) response).setPortletMode(portletMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a dispatcher's include method, abstracted from the used Portlet API version. This implementation assumes
|
||||
* that the response is a {@link javax.portlet.MimeResponse}, as JSR286 implies.
|
||||
*
|
||||
* @param dispatcher The dispatcher to call the include method on.
|
||||
* @param contentType The content type to set for the response.
|
||||
* @param request The request to use for including
|
||||
* @param response The response to use for including
|
||||
*/
|
||||
public void include( PortletRequestDispatcher dispatcher, String contentType, PortletRequest request,
|
||||
PortletResponse response ) throws IOException, PortletException {
|
||||
MimeResponse res = (MimeResponse) response;
|
||||
res.setContentType(contentType);
|
||||
dispatcher.include(request, res);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user