mirror of
https://github.com/apache/struts.git
synced 2026-08-09 16:46:55 +00:00
Compare commits
3 Commits
main
...
STRUTS_6_3_0_RC1
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d72886b26 | |||
| 93519c9ff8 | |||
| f7c522ab5a |
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-rest-showcase</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
<name>Struts 2 Rest Showcase Webapp</name>
|
||||
<description>Struts 2 Rest Showcase Example</description>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-showcase</artifactId>
|
||||
@@ -68,12 +68,6 @@
|
||||
<artifactId>struts2-json-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-assembly</artifactId>
|
||||
|
||||
+5
-5
@@ -24,12 +24,12 @@
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts-master</artifactId>
|
||||
<version>14</version>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-bom</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Struts 2 Bill of Materials</name>
|
||||
@@ -44,7 +44,7 @@
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<struts-version.version>6.3.0-SNAPSHOT</struts-version.version>
|
||||
<struts-version.version>6.3.0-RC1</struts-version.version>
|
||||
<maven.site.skip>true</maven.site.skip>
|
||||
<maven.site.deploy.skip>true</maven.site.deploy.skip>
|
||||
</properties>
|
||||
@@ -190,7 +190,7 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<scm>
|
||||
<tag>HEAD</tag>
|
||||
<tag>STRUTS_6_3_0_RC1</tag>
|
||||
<connection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</connection>
|
||||
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</developerConnection>
|
||||
<url>https://github.com/apache/struts/</url>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-admin-bundle</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-demo-bundle</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
<artifactId>struts2-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-async-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-cdi-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-config-browser-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-dwr-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-embeddedjsp-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-gxp-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jasperreports-plugin</artifactId>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-javatemplates-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jfreechart-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-json-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-oval-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-pell-multipart-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plexus-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-tiles-plugin</artifactId>
|
||||
@@ -40,10 +40,6 @@
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-request-portlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
@@ -55,9 +51,9 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ 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.TilesContainer;
|
||||
import org.apache.tiles.TilesException;
|
||||
import org.apache.tiles.access.TilesAccess;
|
||||
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;
|
||||
|
||||
+344
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $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
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $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;
|
||||
+424
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* 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 javax.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
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-rest-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-sitemesh-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-spring-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-testng-plugin</artifactId>
|
||||
|
||||
+68
-40
@@ -24,53 +24,51 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0-SNAPSHOT</version>
|
||||
<version>6.3.0-RC1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-tiles-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Struts 2 Tiles Plugin</name>
|
||||
|
||||
<!-- mvn -P build-autotags exec:java -->
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>build-autotags</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.apache.struts2.tiles.BuildAutotags</mainClass>
|
||||
<arguments>
|
||||
<!-- Output folder -->
|
||||
<argument>${project.build.directory}</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-servlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-request-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-request-jsp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-request-servlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-ognl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-el</artifactId>
|
||||
<groupId>commons-digester</groupId>
|
||||
<artifactId>commons-digester</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
@@ -82,8 +80,38 @@
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity.tools</groupId>
|
||||
<artifactId>velocity-tools-view</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity.tools</groupId>
|
||||
<artifactId>velocity-tools-view-jsp</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-jcl</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* 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.tiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.tiles.autotag.freemarker.FMTemplateGeneratorFactory;
|
||||
import org.apache.tiles.autotag.generate.TemplateGenerator;
|
||||
import org.apache.tiles.autotag.generate.TemplateGeneratorBuilder;
|
||||
import org.apache.tiles.autotag.jsp.JspTemplateGeneratorFactory;
|
||||
import org.apache.tiles.autotag.model.TemplateSuite;
|
||||
import org.apache.tiles.autotag.velocity.VelocityTemplateGeneratorFactory;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
/**
|
||||
* Helper class for building/generating the classes and resources used in the
|
||||
* plugin.
|
||||
*/
|
||||
public class BuildAutotags {
|
||||
|
||||
public BuildAutotags() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
BuildAutotags me = new BuildAutotags();
|
||||
|
||||
// Jsp classes
|
||||
me.buildJsp(args[0]);
|
||||
|
||||
// Freemarker classes
|
||||
me.buildFreemarker(args[0]);
|
||||
|
||||
// Velocity classes
|
||||
me.buildVelocity(args[0]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build JSP tag classes and .tld file.
|
||||
*
|
||||
* To build, change template-suite.xml as required and then run this program.
|
||||
* Copy the classes and .tld from the target autotag folder into the packageName
|
||||
* location, .tld to src/main/resources/META-INF/tld/tiles-jsp.tld
|
||||
*
|
||||
* @param outputDir the output dir
|
||||
*/
|
||||
public void buildJsp(String outputDir) {
|
||||
|
||||
// Default values
|
||||
String taglibURI = "http://tiles.apache.org/tags-tiles";
|
||||
String packageName = "org.apache.tiles.web.jsp.taglib";
|
||||
String requestClass = "org.apache.tiles.request.Request";
|
||||
String runtime = "org.apache.tiles.request.jsp.autotag.JspAutotagRuntime";
|
||||
// outputDir = "/target"
|
||||
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put("taglibURI", taglibURI);
|
||||
|
||||
try {
|
||||
|
||||
TemplateSuite suite;
|
||||
|
||||
InputStream stream = getClass().getResourceAsStream("/META-INF/template-suite.xml");
|
||||
|
||||
try {
|
||||
XStream xstream = new XStream(new DomDriver());
|
||||
xstream.allowTypes(new Class[] { org.apache.tiles.autotag.model.TemplateClass.class,
|
||||
org.apache.tiles.autotag.model.TemplateSuite.class,
|
||||
org.apache.tiles.autotag.model.TemplateParameter.class });
|
||||
suite = (TemplateSuite) xstream.fromXML(stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
Properties props = new Properties();
|
||||
InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
|
||||
props.load(propsStream);
|
||||
propsStream.close();
|
||||
|
||||
File classesOutputDirectory = new File(outputDir + "/generated-sources/autotag/classes");
|
||||
File resourcesOutputDirectory = new File(outputDir + "/generated-sources/autotag");
|
||||
|
||||
TemplateGenerator generator = new JspTemplateGeneratorFactory(classesOutputDirectory,
|
||||
resourcesOutputDirectory, new VelocityEngine(props), TemplateGeneratorBuilder.createNewInstance())
|
||||
.createTemplateGenerator();
|
||||
|
||||
generator.generate(packageName, suite, parameters, runtime, requestClass);
|
||||
|
||||
} catch (Exception e) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Freemarker classes.
|
||||
*
|
||||
* To build, change template-suite.xml as required and then run this program.
|
||||
* Copy the classes from the target autotag folder into the packageName
|
||||
* location.
|
||||
*
|
||||
* @param outputDir the output dir
|
||||
*/
|
||||
public void buildFreemarker(String outputDir) {
|
||||
|
||||
// Default values
|
||||
String packageName = "org.apache.tiles.freemarker.template";
|
||||
String requestClass = "org.apache.tiles.request.Request";
|
||||
String runtime = "org.apache.tiles.request.freemarker.autotag.FreemarkerAutotagRuntime";
|
||||
// outputDir = "/target"
|
||||
|
||||
try {
|
||||
|
||||
TemplateSuite suite;
|
||||
|
||||
InputStream stream = getClass().getResourceAsStream("/META-INF/template-suite.xml");
|
||||
|
||||
try {
|
||||
XStream xstream = new XStream(new DomDriver());
|
||||
xstream.allowTypes(new Class[] { org.apache.tiles.autotag.model.TemplateClass.class,
|
||||
org.apache.tiles.autotag.model.TemplateSuite.class,
|
||||
org.apache.tiles.autotag.model.TemplateParameter.class });
|
||||
suite = (TemplateSuite) xstream.fromXML(stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
Properties props = new Properties();
|
||||
InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
|
||||
props.load(propsStream);
|
||||
propsStream.close();
|
||||
|
||||
File classesOutputDirectory = new File(outputDir + "/generated-sources/autotag/classes");
|
||||
|
||||
TemplateGenerator generator = new FMTemplateGeneratorFactory(classesOutputDirectory,
|
||||
new VelocityEngine(props), TemplateGeneratorBuilder.createNewInstance()).createTemplateGenerator();
|
||||
|
||||
generator.generate(packageName, suite, null, runtime, requestClass);
|
||||
|
||||
} catch (Exception e) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the velocity classes and velocity.properties.
|
||||
*
|
||||
* To build, change template-suite.xml as required and then run this program.
|
||||
* Copy the classes from the target autotag folder into the packageName
|
||||
* location, and velocity.properties to
|
||||
* src/main/resources/META-INF/velocity.properties
|
||||
*
|
||||
* @param outputDir the output dir
|
||||
*/
|
||||
public void buildVelocity(String outputDir) {
|
||||
|
||||
// Default values
|
||||
String packageName = "org.apache.tiles.velocity.template";
|
||||
String requestClass = "org.apache.tiles.request.Request";
|
||||
String runtime = "org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime";
|
||||
// outputDir = "/target"
|
||||
|
||||
try {
|
||||
|
||||
TemplateSuite suite;
|
||||
|
||||
InputStream stream = getClass().getResourceAsStream("/META-INF/template-suite.xml");
|
||||
|
||||
try {
|
||||
XStream xstream = new XStream(new DomDriver());
|
||||
xstream.allowTypes(new Class[] { org.apache.tiles.autotag.model.TemplateClass.class,
|
||||
org.apache.tiles.autotag.model.TemplateSuite.class,
|
||||
org.apache.tiles.autotag.model.TemplateParameter.class });
|
||||
suite = (TemplateSuite) xstream.fromXML(stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
Properties props = new Properties();
|
||||
InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
|
||||
props.load(propsStream);
|
||||
propsStream.close();
|
||||
|
||||
File classesOutputDirectory = new File(outputDir + "/generated-sources/autotag/classes");
|
||||
File resourcesOutputDirectory = new File(outputDir + "/generated-sources/autotag");
|
||||
|
||||
TemplateGenerator generator = new VelocityTemplateGeneratorFactory(classesOutputDirectory,
|
||||
resourcesOutputDirectory, new VelocityEngine(props), TemplateGeneratorBuilder.createNewInstance())
|
||||
.createTemplateGenerator();
|
||||
|
||||
generator.generate(packageName, suite, null, runtime, requestClass);
|
||||
|
||||
} catch (Exception e) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.tiles.evaluator.AbstractAttributeEvaluator;
|
||||
import org.apache.tiles.core.evaluator.AbstractAttributeEvaluator;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import ognl.OgnlException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.tiles.evaluator.AbstractAttributeEvaluator;
|
||||
import org.apache.tiles.evaluator.EvaluationException;
|
||||
import org.apache.tiles.core.evaluator.AbstractAttributeEvaluator;
|
||||
import org.apache.tiles.core.evaluator.EvaluationException;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
|
||||
|
||||
+3
-3
@@ -33,9 +33,9 @@ import org.apache.struts2.views.freemarker.FreemarkerManager;
|
||||
import org.apache.struts2.views.freemarker.FreemarkerResult;
|
||||
import org.apache.struts2.views.freemarker.StrutsBeanWrapper;
|
||||
import org.apache.tiles.freemarker.template.TilesFMModelRepository;
|
||||
import org.apache.tiles.impl.InvalidTemplateException;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.render.Renderer;
|
||||
import org.apache.tiles.core.impl.InvalidTemplateException;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -44,7 +44,7 @@ import java.io.IOException;
|
||||
|
||||
public class StrutsFreeMarkerAttributeRenderer implements Renderer {
|
||||
|
||||
private static Logger LOG = LogManager.getLogger(StrutsFreeMarkerAttributeRenderer.class);
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsFreeMarkerAttributeRenderer.class);
|
||||
|
||||
@Override
|
||||
public void render(String path, Request request) throws IOException {
|
||||
@@ -75,7 +75,7 @@ public class StrutsFreeMarkerAttributeRenderer implements Renderer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending how Tiles definition was defined, request can an instance of JspRequest (for JSPs)
|
||||
* Depending on how Tiles definition was defined, request can an instance of JspRequest (for JSPs)
|
||||
* or a ServletRequest (FreeMarker)
|
||||
*/
|
||||
protected ActionContext readActionContext(Request request) {
|
||||
|
||||
@@ -23,8 +23,8 @@ import com.opensymphony.xwork2.ObjectFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.tiles.preparer.ViewPreparer;
|
||||
import org.apache.tiles.preparer.factory.BasicPreparerFactory;
|
||||
import org.apache.tiles.api.preparer.ViewPreparer;
|
||||
import org.apache.tiles.core.prepare.factory.BasicPreparerFactory;
|
||||
|
||||
/**
|
||||
* This is a basic ViewPreparer factory that uses {@link ObjectFactory} to create the ViewPreparer
|
||||
|
||||
+5
-5
@@ -25,10 +25,10 @@ import org.apache.struts2.tiles.annotation.TilesDefinition;
|
||||
import org.apache.struts2.tiles.annotation.TilesDefinitions;
|
||||
import org.apache.struts2.tiles.annotation.TilesPutAttribute;
|
||||
import org.apache.struts2.tiles.annotation.TilesPutListAttribute;
|
||||
import org.apache.tiles.Attribute;
|
||||
import org.apache.tiles.Definition;
|
||||
import org.apache.tiles.Expression;
|
||||
import org.apache.tiles.ListAttribute;
|
||||
import org.apache.tiles.api.Attribute;
|
||||
import org.apache.tiles.api.Definition;
|
||||
import org.apache.tiles.api.Expression;
|
||||
import org.apache.tiles.api.ListAttribute;
|
||||
|
||||
/**
|
||||
* Processes tiles annotations to create {@link Definition}s and
|
||||
@@ -123,7 +123,7 @@ public class StrutsTilesAnnotationProcessor {
|
||||
String templateType = getValueOrNull(tilesDef.templateType());
|
||||
if (templateType != null) {
|
||||
attribute.setRenderer(templateType);
|
||||
} else if (getValueOrNull(tilesDef.extend()) != null && templateType == null) {
|
||||
} else if (getValueOrNull(tilesDef.extend()) != null) {
|
||||
attribute.setRenderer(null);
|
||||
}
|
||||
return attribute;
|
||||
|
||||
+22
-22
@@ -24,25 +24,31 @@ import ognl.OgnlRuntime;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.TilesContainer;
|
||||
import org.apache.tiles.definition.DefinitionsFactory;
|
||||
import org.apache.tiles.definition.pattern.DefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
|
||||
import org.apache.tiles.definition.pattern.PrefixedPatternDefinitionResolver;
|
||||
import org.apache.tiles.definition.pattern.regexp.RegexpDefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.ApplicationResource;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.render.BasicRendererFactory;
|
||||
import org.apache.tiles.request.render.ChainedDelegateRenderer;
|
||||
import org.apache.tiles.core.definition.DefinitionsFactory;
|
||||
import org.apache.tiles.core.definition.pattern.DefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.core.definition.pattern.PatternDefinitionResolver;
|
||||
import org.apache.tiles.core.definition.pattern.PrefixedPatternDefinitionResolver;
|
||||
import org.apache.tiles.core.definition.pattern.regexp.RegexpDefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.core.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
|
||||
import org.apache.tiles.core.evaluator.AttributeEvaluatorFactory;
|
||||
import org.apache.tiles.core.evaluator.BasicAttributeEvaluatorFactory;
|
||||
import org.apache.tiles.core.evaluator.impl.DirectAttributeEvaluator;
|
||||
import org.apache.tiles.core.factory.BasicTilesContainerFactory;
|
||||
import org.apache.tiles.core.factory.TilesContainerFactoryException;
|
||||
import org.apache.tiles.core.impl.mgmt.CachingTilesContainer;
|
||||
import org.apache.tiles.core.locale.LocaleResolver;
|
||||
import org.apache.tiles.core.prepare.factory.PreparerFactory;
|
||||
import org.apache.tiles.el.ELAttributeEvaluator;
|
||||
import org.apache.tiles.el.JspExpressionFactoryFactory;
|
||||
import org.apache.tiles.el.ScopeELResolver;
|
||||
import org.apache.tiles.el.TilesContextBeanELResolver;
|
||||
import org.apache.tiles.el.TilesContextELResolver;
|
||||
import org.apache.tiles.evaluator.AttributeEvaluatorFactory;
|
||||
import org.apache.tiles.evaluator.BasicAttributeEvaluatorFactory;
|
||||
import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator;
|
||||
import org.apache.tiles.factory.BasicTilesContainerFactory;
|
||||
import org.apache.tiles.factory.TilesContainerFactoryException;
|
||||
import org.apache.tiles.impl.mgmt.CachingTilesContainer;
|
||||
import org.apache.tiles.locale.LocaleResolver;
|
||||
import org.apache.tiles.ognl.AnyScopePropertyAccessor;
|
||||
import org.apache.tiles.ognl.DelegatePropertyAccessor;
|
||||
import org.apache.tiles.ognl.NestedObjectDelegatePropertyAccessor;
|
||||
@@ -51,12 +57,6 @@ import org.apache.tiles.ognl.PropertyAccessorDelegateFactory;
|
||||
import org.apache.tiles.ognl.ScopePropertyAccessor;
|
||||
import org.apache.tiles.ognl.TilesApplicationContextNestedObjectExtractor;
|
||||
import org.apache.tiles.ognl.TilesContextPropertyAccessorDelegateFactory;
|
||||
import org.apache.tiles.preparer.factory.PreparerFactory;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.ApplicationResource;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.render.BasicRendererFactory;
|
||||
import org.apache.tiles.request.render.ChainedDelegateRenderer;
|
||||
import org.apache.tiles.request.render.Renderer;
|
||||
|
||||
import javax.el.ArrayELResolver;
|
||||
@@ -81,7 +81,7 @@ import java.util.Set;
|
||||
* - S2 ro access Struts' ValueStack
|
||||
* - OGNL
|
||||
* - EL
|
||||
*
|
||||
* <p>
|
||||
* If you need additional features create your own listener and factory,
|
||||
* you can base on code from Tiles' CompleteAutoloadTilesContainerFactory
|
||||
*/
|
||||
@@ -270,4 +270,4 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ package org.apache.struts2.tiles;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.definition.DefinitionsFactory;
|
||||
import org.apache.tiles.factory.AbstractTilesContainerFactory;
|
||||
import org.apache.tiles.core.definition.DefinitionsFactory;
|
||||
import org.apache.tiles.core.factory.AbstractTilesContainerFactory;
|
||||
import org.apache.tiles.core.startup.AbstractTilesInitializer;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.servlet.ServletApplicationContext;
|
||||
import org.apache.tiles.startup.AbstractTilesInitializer;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.apache.struts2.tiles;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.startup.TilesInitializer;
|
||||
import org.apache.tiles.core.startup.TilesInitializer;
|
||||
import org.apache.tiles.web.startup.AbstractTilesListener;
|
||||
|
||||
/**
|
||||
@@ -37,4 +37,4 @@ public class StrutsTilesListener extends AbstractTilesListener {
|
||||
LOG.info("Starting Struts Tiles 3 integration ...");
|
||||
return new StrutsTilesInitializer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.tiles.locale.LocaleResolver;
|
||||
import org.apache.tiles.core.locale.LocaleResolver;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.Locale;
|
||||
|
||||
public class StrutsTilesLocaleResolver implements LocaleResolver {
|
||||
|
||||
private static Logger LOG = LogManager.getLogger(StrutsTilesLocaleResolver.class);
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsTilesLocaleResolver.class);
|
||||
|
||||
@Override
|
||||
public Locale resolveLocale(Request request) {
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ import com.opensymphony.xwork2.util.finder.ResourceFinder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.request.ApplicationResource;
|
||||
import org.apache.tiles.request.locale.URLApplicationResource;
|
||||
import org.apache.tiles.request.servlet.ServletApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@@ -29,58 +29,41 @@ import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.result.ServletDispatcherResult;
|
||||
import org.apache.struts2.tiles.StrutsTilesAnnotationProcessor;
|
||||
import org.apache.struts2.tiles.annotation.TilesDefinition;
|
||||
import org.apache.tiles.Definition;
|
||||
import org.apache.tiles.TilesContainer;
|
||||
import org.apache.tiles.TilesException;
|
||||
import org.apache.tiles.api.Definition;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.api.TilesException;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import org.apache.tiles.access.TilesAccess;
|
||||
import org.apache.tiles.mgmt.MutableTilesContainer;
|
||||
import org.apache.tiles.api.access.TilesAccess;
|
||||
import org.apache.tiles.api.mgmt.MutableTilesContainer;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.servlet.ServletRequest;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
* Renders a view using struts-tiles.
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <!-- START SNIPPET: webxml -->
|
||||
* In your web.xml file, you need to add a TilesListener.
|
||||
*
|
||||
* Renders a view using struts-tiles. In your web.xml file, you need to add a TilesListener.
|
||||
* <p>
|
||||
* <listener>
|
||||
* <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
|
||||
* </listener>
|
||||
* <!-- END SNIPPET: webxml -->
|
||||
*
|
||||
* <!-- START SNIPPET: strutsxml -->
|
||||
* <p>
|
||||
* In struts.xml, use type="tiles" on your <result>.
|
||||
*
|
||||
* <p>
|
||||
* <action name="editUser" class="userAction" method="edit">
|
||||
* <result name="success" type="tiles">userForm</result>
|
||||
* <result name="input" type="tiles">userList</result>
|
||||
* </action>
|
||||
* <!-- END SNIPPET: strutsxml -->
|
||||
*
|
||||
*
|
||||
* <!-- START SNIPPET: packageconfig -->
|
||||
*
|
||||
* <p>
|
||||
* Making this result type the default for the current package.
|
||||
*
|
||||
* <p>
|
||||
* <result-types>
|
||||
* <result-type name="tiles"
|
||||
* class="org.apache.struts2.views.tiles.TilesResult" default="true" />
|
||||
* </result-types>
|
||||
* <!-- END SNIPPET: packageconfig -->
|
||||
*
|
||||
*
|
||||
* <!-- START SNIPPET: tilesconfig -->
|
||||
* <p>
|
||||
* You have to configure tiles itself. Therefore you can add <code>tiles.xml</code> either
|
||||
* to resources or WEB-INF. You may also use annotations like {@link TilesDefinition}.
|
||||
*
|
||||
* <!-- END SNIPPET: tilesconfig -->
|
||||
*
|
||||
*/
|
||||
public class TilesResult extends ServletDispatcherResult {
|
||||
|
||||
@@ -114,8 +97,7 @@ public class TilesResult extends ServletDispatcherResult {
|
||||
if (StringUtils.isEmpty(location)) {
|
||||
LOG.trace("location not set -> action must have one @TilesDefinition");
|
||||
tilesDefinition = annotationProcessor.findAnnotation(action, null);
|
||||
String tileName = StringUtils.isNotEmpty(tilesDefinition.name()) ? tilesDefinition.name() : actionName;
|
||||
location = tileName;
|
||||
location = StringUtils.isNotEmpty(tilesDefinition.name()) ? tilesDefinition.name() : actionName;
|
||||
LOG.debug("using new location name '{}' and @TilesDefinition '{}'", location, tilesDefinition);
|
||||
}
|
||||
setLocation(location);
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Common implementation of attribute definition.
|
||||
*/
|
||||
public class Attribute {
|
||||
|
||||
/**
|
||||
* The name of the template renderer.
|
||||
*/
|
||||
private static final String TEMPLATE_RENDERER = "template";
|
||||
|
||||
/**
|
||||
* The roles that can render this attribute.
|
||||
*
|
||||
* @since 2.0.6
|
||||
*/
|
||||
private Set<String> roles = null;
|
||||
|
||||
/**
|
||||
* The value of the attribute.
|
||||
*/
|
||||
private Object value = null;
|
||||
|
||||
/**
|
||||
* The expression to evaluate. Ignored if {@link #value} is not <code>null</code>.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
private Expression expressionObject = null;
|
||||
|
||||
/**
|
||||
* The renderer name of the attribute. Default names are <code>string</code>,
|
||||
* <code>template</code>, <code>definition</code>, <code>object</code>.
|
||||
*/
|
||||
private String renderer = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Attribute() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param value Object to store.
|
||||
*/
|
||||
public Attribute(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param attribute The attribute to copy from.
|
||||
*/
|
||||
public Attribute(Attribute attribute) {
|
||||
this.roles = attribute.roles;
|
||||
this.value = attribute.getValue();
|
||||
if (attribute.expressionObject != null) {
|
||||
this.expressionObject = new Expression(attribute.expressionObject);
|
||||
} else {
|
||||
this.expressionObject = null;
|
||||
}
|
||||
this.renderer = attribute.renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param value Object to store.
|
||||
* @param role Asociated role.
|
||||
*/
|
||||
public Attribute(Object value, String role) {
|
||||
this.value = value;
|
||||
setRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param value Object to store. If specified, the <code>expression</code>
|
||||
* parameter will be ignored.
|
||||
* @param expression The expression to be evaluated. Ignored if the
|
||||
* <code>value</code> is not null.
|
||||
* @param role Associated role.
|
||||
* @param rendererName The renderer name.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public Attribute(Object value, Expression expression, String role, String rendererName) {
|
||||
this.value = value;
|
||||
this.expressionObject = expression;
|
||||
this.renderer = rendererName;
|
||||
setRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a template attribute, starting from the name of the template.
|
||||
*
|
||||
* @param template The template that will be rendered.
|
||||
* @return The template attribute.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static Attribute createTemplateAttribute(String template) {
|
||||
Attribute attribute = new Attribute();
|
||||
attribute.setValue(template);
|
||||
attribute.setRenderer(TEMPLATE_RENDERER);
|
||||
return attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a template attribute, starting from the name of the template.
|
||||
*
|
||||
* @param template The template that will be rendered.
|
||||
* @param templateExpression The template expression that will be evaluated
|
||||
* to a template.
|
||||
* @param templateType The type, or renderer, of the template. If null, the
|
||||
* default <code>template</code> will be used.
|
||||
* @param role The comma-separated roles for which the template is
|
||||
* authorized to be rendered.
|
||||
* @return The template attribute.
|
||||
* @since 2.2.2
|
||||
*/
|
||||
public static Attribute createTemplateAttribute(String template,
|
||||
String templateExpression, String templateType, String role) {
|
||||
Attribute templateAttribute = createTemplateAttribute(template);
|
||||
templateAttribute.setRole(role);
|
||||
if (templateType != null) {
|
||||
templateAttribute.setRenderer(templateType);
|
||||
}
|
||||
templateAttribute
|
||||
.setExpressionObject(Expression
|
||||
.createExpressionFromDescribedExpression(templateExpression));
|
||||
return templateAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get role.
|
||||
*
|
||||
* @return the name of the required role(s)
|
||||
*/
|
||||
public String getRole() {
|
||||
String retValue = null;
|
||||
|
||||
if (roles != null && !roles.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator<String> roleIt = roles.iterator();
|
||||
if (roleIt.hasNext()) {
|
||||
builder.append(roleIt.next());
|
||||
while (roleIt.hasNext()) {
|
||||
builder.append(",");
|
||||
builder.append(roleIt.next());
|
||||
}
|
||||
retValue = builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the roles that can render this attribute.
|
||||
*
|
||||
* @return The enabled roles.
|
||||
* @since 2.0.6
|
||||
*/
|
||||
public Set<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set role.
|
||||
*
|
||||
* @param role Associated role.
|
||||
*/
|
||||
public void setRole(String role) {
|
||||
if (role != null && role.trim().length() > 0) {
|
||||
roles = TextParseUtil.commaDelimitedStringToSet(role);
|
||||
} else {
|
||||
roles = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the roles that can render this attribute.
|
||||
*
|
||||
* @param roles The enabled roles.
|
||||
* @since 2.0.6
|
||||
*/
|
||||
public void setRoles(Set<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value.
|
||||
*
|
||||
* @param value New value.
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The expression to evaluate. Ignored if {@link #value} is not
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @return The expression to be evaluated.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public Expression getExpressionObject() {
|
||||
return expressionObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets The expression to evaluate. Ignored if {@link #value} is not
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @param expressionObject The expression to be evaluated.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public void setExpressionObject(Expression expressionObject) {
|
||||
this.expressionObject = expressionObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the renderer name to use.
|
||||
*
|
||||
* @return The renderer name.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public String getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the renderer name to use.
|
||||
*
|
||||
* @param rendererName The renderer.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void setRenderer(String rendererName) {
|
||||
this.renderer = rendererName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits an attribute, i.e. overwrites null properties with the ones
|
||||
* provided by the attribute.
|
||||
*
|
||||
* @param attribute The attribute to inherit.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public void inherit(Attribute attribute) {
|
||||
if (value == null) {
|
||||
value = attribute.getValue();
|
||||
}
|
||||
Expression targetExpressionObject = attribute.getExpressionObject();
|
||||
if (targetExpressionObject != null
|
||||
&& (expressionObject == null || expressionObject
|
||||
.getExpression() == null)) {
|
||||
expressionObject = new Expression(targetExpressionObject);
|
||||
}
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
roles = attribute.getRoles();
|
||||
}
|
||||
if (renderer == null) {
|
||||
renderer = attribute.getRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null && value == null) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Attribute)) {
|
||||
return false;
|
||||
}
|
||||
Attribute attribute = (Attribute) obj;
|
||||
return Objects.equals(value, attribute.value)
|
||||
&& Objects.equals(renderer, attribute.renderer)
|
||||
&& Objects.equals(roles, attribute.roles)
|
||||
&& Objects.equals(expressionObject, attribute.expressionObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user can use this attribute.
|
||||
*
|
||||
* @param request The request context.
|
||||
* @return <code>true</code> if the current user can see this attribute.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public boolean isPermitted(Request request) {
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean retValue = false;
|
||||
|
||||
for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext()
|
||||
&& !retValue; ) {
|
||||
retValue = request.isUserInRole(roleIt.next());
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(value) + Objects.hashCode(renderer)
|
||||
+ Objects.hashCode(roles) + Objects.hashCode(expressionObject);
|
||||
}
|
||||
|
||||
public Attribute copy() {
|
||||
return new Attribute(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Encapsulation of the current state of execution.
|
||||
*
|
||||
* @since Tiles 2.0
|
||||
*/
|
||||
public interface AttributeContext {
|
||||
|
||||
/**
|
||||
* Returns the attribute that will be used to render a template.
|
||||
*
|
||||
* @return The template attribute.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
Attribute getTemplateAttribute();
|
||||
|
||||
/**
|
||||
* Sets the template attribute, that will be used to render the template
|
||||
* page.
|
||||
*
|
||||
* @param templateAttribute The template attribute.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
void setTemplateAttribute(Attribute templateAttribute);
|
||||
|
||||
/**
|
||||
* Get associated preparer instance.
|
||||
*
|
||||
* @return The preparer name.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
String getPreparer();
|
||||
|
||||
/**
|
||||
* Set associated preparer instance.
|
||||
*
|
||||
* @param url The preparer name.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void setPreparer(String url);
|
||||
|
||||
/**
|
||||
* Add all attributes to the context.
|
||||
*
|
||||
* @param newAttributes the attributes to be added.
|
||||
*/
|
||||
void addAll(Map<String, Attribute> newAttributes);
|
||||
|
||||
/**
|
||||
* Copies the cascaded attributes to this attribute context.
|
||||
*
|
||||
* @param parent The parent context to be used.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void inheritCascadedAttributes(AttributeContext parent);
|
||||
|
||||
/**
|
||||
* Copies all missing attributes from the <code>parent</code> attribute
|
||||
* context to this one.
|
||||
*
|
||||
* @param parent The attribute context to copy attributes from.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void inherit(AttributeContext parent);
|
||||
|
||||
/**
|
||||
* Retrieve the named attribute, either cascaded or not.
|
||||
*
|
||||
* @param name key name for the attribute.
|
||||
* @return Attribute associated with the given name.
|
||||
*/
|
||||
Attribute getAttribute(String name);
|
||||
|
||||
/**
|
||||
* Retrieve the attribute that has been defined in this context (i.e. not
|
||||
* cascaded).
|
||||
*
|
||||
* @param name key name for the attribute.
|
||||
* @return Attribute The local attribute associated with the given name, if
|
||||
* present, or <code>null</code> otherwise.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Attribute getLocalAttribute(String name);
|
||||
|
||||
/**
|
||||
* Retrieve the attribute that has been cascaded at upper levels.
|
||||
*
|
||||
* @param name key name for the attribute.
|
||||
* @return Attribute The cascaded attribute associated with the given name,
|
||||
* if present, or <code>null</code> otherwise.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Attribute getCascadedAttribute(String name);
|
||||
|
||||
/**
|
||||
* Returns the names of the local attributes, i.e. the one that have not
|
||||
* been cascaded.
|
||||
*
|
||||
* @return The local attribute names.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Set<String> getLocalAttributeNames();
|
||||
|
||||
/**
|
||||
* Returns the names of the cascaded attributes.
|
||||
*
|
||||
* @return The cascaded attribute names.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Set<String> getCascadedAttributeNames();
|
||||
|
||||
/**
|
||||
* Add the specified attribute. The attribute value will be available only
|
||||
* in the current context, i.e. it is like calling
|
||||
* {@link AttributeContext#putAttribute(String, Attribute, boolean)} with
|
||||
* <code>cascade = false</code>.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
*/
|
||||
void putAttribute(String name, Attribute value);
|
||||
|
||||
/**
|
||||
* Add the specified attribute.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @param cascade If <code>true</code>, the attribute value will be
|
||||
* available in all nested contexts. If <code>false</code>, it will be
|
||||
* available only in the current context.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void putAttribute(String name, Attribute value, boolean cascade);
|
||||
|
||||
/**
|
||||
* Clear the attributes.
|
||||
*/
|
||||
void clear();
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Basic implementation for <code>AttributeContext</code>.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class BasicAttributeContext implements AttributeContext, Serializable {
|
||||
|
||||
/**
|
||||
* The template attribute, to render a template.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected Attribute templateAttribute;
|
||||
|
||||
/**
|
||||
* Associated ViewPreparer URL or classname, if defined.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
protected String preparer = null;
|
||||
|
||||
/**
|
||||
* Template attributes.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
protected Map<String, Attribute> attributes = null;
|
||||
|
||||
/**
|
||||
* Cascaded template attributes.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
protected Map<String, Attribute> cascadedAttributes = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public BasicAttributeContext() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Create a context and set specified attributes.
|
||||
*
|
||||
* @param attributes Attributes to initialize context.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public BasicAttributeContext(Map<String, Attribute> attributes) {
|
||||
if (attributes != null) {
|
||||
this.attributes = deepCopyAttributeMap(attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param context The constructor to copy.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public BasicAttributeContext(AttributeContext context) {
|
||||
if (context instanceof BasicAttributeContext) {
|
||||
copyBasicAttributeContext((BasicAttributeContext) context);
|
||||
} else {
|
||||
Attribute parentTemplateAttribute = context.getTemplateAttribute();
|
||||
if (parentTemplateAttribute != null) {
|
||||
this.templateAttribute = new Attribute(parentTemplateAttribute);
|
||||
}
|
||||
this.preparer = context.getPreparer();
|
||||
this.attributes = new HashMap<>();
|
||||
Set<String> parentAttributeNames = context.getLocalAttributeNames();
|
||||
if (parentAttributeNames != null) {
|
||||
for (String name : parentAttributeNames) {
|
||||
attributes.put(name, new Attribute(context.getLocalAttribute(name)));
|
||||
}
|
||||
}
|
||||
inheritCascadedAttributes(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param context The constructor to copy.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public BasicAttributeContext(BasicAttributeContext context) {
|
||||
copyBasicAttributeContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Attribute getTemplateAttribute() {
|
||||
return templateAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setTemplateAttribute(Attribute templateAttribute) {
|
||||
this.templateAttribute = templateAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getPreparer() {
|
||||
return preparer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setPreparer(String url) {
|
||||
this.preparer = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void inheritCascadedAttributes(AttributeContext context) {
|
||||
if (context instanceof BasicAttributeContext) {
|
||||
if (((BasicAttributeContext) context).cascadedAttributes != null && !((BasicAttributeContext) context).cascadedAttributes.isEmpty()) {
|
||||
cascadedAttributes = deepCopyAttributeMap(((BasicAttributeContext) context).cascadedAttributes);
|
||||
}
|
||||
} else {
|
||||
this.cascadedAttributes = new HashMap<>();
|
||||
Set<String> parentAttributeNames = context.getCascadedAttributeNames();
|
||||
if (parentAttributeNames != null) {
|
||||
for (String name : parentAttributeNames) {
|
||||
cascadedAttributes.put(name, new Attribute(context
|
||||
.getCascadedAttribute(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void inherit(AttributeContext parent) {
|
||||
if (parent instanceof BasicAttributeContext) {
|
||||
inherit((BasicAttributeContext) parent);
|
||||
} else {
|
||||
// Inheriting template, roles and preparer.
|
||||
Attribute parentTemplateAttribute = parent.getTemplateAttribute();
|
||||
inheritParentTemplateAttribute(parentTemplateAttribute);
|
||||
if (preparer == null) {
|
||||
preparer = parent.getPreparer();
|
||||
}
|
||||
|
||||
// Inheriting attributes.
|
||||
Set<String> names = parent.getCascadedAttributeNames();
|
||||
if (names != null && !names.isEmpty()) {
|
||||
for (String name : names) {
|
||||
Attribute attribute = parent.getCascadedAttribute(name);
|
||||
Attribute destAttribute = getCascadedAttribute(name);
|
||||
if (destAttribute == null) {
|
||||
putAttribute(name, attribute, true);
|
||||
} else if (attribute instanceof ListAttribute
|
||||
&& destAttribute instanceof ListAttribute
|
||||
&& ((ListAttribute) destAttribute).isInherit()) {
|
||||
((ListAttribute) destAttribute).inherit((ListAttribute) attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
names = parent.getLocalAttributeNames();
|
||||
if (names != null && !names.isEmpty()) {
|
||||
for (String name : names) {
|
||||
Attribute attribute = parent.getLocalAttribute(name);
|
||||
Attribute destAttribute = getLocalAttribute(name);
|
||||
if (destAttribute == null) {
|
||||
putAttribute(name, attribute, false);
|
||||
} else if (attribute instanceof ListAttribute
|
||||
&& destAttribute instanceof ListAttribute
|
||||
&& ((ListAttribute) destAttribute).isInherit()) {
|
||||
((ListAttribute) destAttribute).inherit((ListAttribute) attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits the attribute context, inheriting, i.e. copying if not present,
|
||||
* the attributes.
|
||||
*
|
||||
* @param parent The attribute context to inherit.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void inherit(BasicAttributeContext parent) {
|
||||
// Set template, roles and preparer if not set.
|
||||
inheritParentTemplateAttribute(parent.getTemplateAttribute());
|
||||
if (preparer == null) {
|
||||
preparer = parent.preparer;
|
||||
}
|
||||
|
||||
// Sets attributes.
|
||||
cascadedAttributes = addMissingAttributes(parent.cascadedAttributes,
|
||||
cascadedAttributes);
|
||||
attributes = addMissingAttributes(parent.attributes, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all attributes to this context.
|
||||
* Copies all the mappings from the specified attribute map to this context.
|
||||
* New attribute mappings will replace any mappings that this context had for any of the keys
|
||||
* currently in the specified attribute map.
|
||||
*
|
||||
* @param newAttributes Attributes to add.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void addAll(Map<String, Attribute> newAttributes) {
|
||||
if (newAttributes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attributes == null) {
|
||||
attributes = new HashMap<>(newAttributes);
|
||||
return;
|
||||
}
|
||||
|
||||
attributes.putAll(newAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Attribute getAttribute(String name) {
|
||||
Attribute retValue = null;
|
||||
if (attributes != null) {
|
||||
retValue = attributes.get(name);
|
||||
}
|
||||
|
||||
if (retValue == null && cascadedAttributes != null) {
|
||||
retValue = cascadedAttributes.get(name);
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Attribute getLocalAttribute(String name) {
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Attribute getCascadedAttribute(String name) {
|
||||
if (cascadedAttributes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cascadedAttributes.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<String> getLocalAttributeNames() {
|
||||
if (attributes != null && !attributes.isEmpty()) {
|
||||
return attributes.keySet();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Set<String> getCascadedAttributeNames() {
|
||||
if (cascadedAttributes != null && !cascadedAttributes.isEmpty()) {
|
||||
return cascadedAttributes.keySet();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void putAttribute(String name, Attribute value) {
|
||||
if (attributes == null) {
|
||||
attributes = new HashMap<>();
|
||||
}
|
||||
|
||||
attributes.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void putAttribute(String name, Attribute value, boolean cascade) {
|
||||
Map<String, Attribute> mapToUse;
|
||||
if (cascade) {
|
||||
if (cascadedAttributes == null) {
|
||||
cascadedAttributes = new HashMap<>();
|
||||
}
|
||||
mapToUse = cascadedAttributes;
|
||||
} else {
|
||||
if (attributes == null) {
|
||||
attributes = new HashMap<>();
|
||||
}
|
||||
mapToUse = attributes;
|
||||
}
|
||||
mapToUse.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void clear() {
|
||||
templateAttribute = null;
|
||||
preparer = null;
|
||||
attributes.clear();
|
||||
cascadedAttributes.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof BasicAttributeContext)) {
|
||||
return false;
|
||||
}
|
||||
BasicAttributeContext bac = (BasicAttributeContext) obj;
|
||||
return Objects.equals(templateAttribute, bac.templateAttribute)
|
||||
&& Objects.equals(preparer, bac.preparer)
|
||||
&& Objects.equals(attributes, bac.attributes)
|
||||
&& Objects.equals(cascadedAttributes, bac.cascadedAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(templateAttribute) + Objects.hashCode(preparer)
|
||||
+ Objects.hashCode(attributes)
|
||||
+ Objects.hashCode(cascadedAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits the parent template attribute.
|
||||
*
|
||||
* @param parentTemplateAttribute The parent template attribute.
|
||||
*/
|
||||
private void inheritParentTemplateAttribute(
|
||||
Attribute parentTemplateAttribute) {
|
||||
if (parentTemplateAttribute != null) {
|
||||
if (templateAttribute == null) {
|
||||
templateAttribute = new Attribute(parentTemplateAttribute);
|
||||
} else {
|
||||
templateAttribute.inherit(parentTemplateAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a BasicAttributeContext in an easier way.
|
||||
*
|
||||
* @param context The context to copy.
|
||||
*/
|
||||
private void copyBasicAttributeContext(BasicAttributeContext context) {
|
||||
Attribute parentTemplateAttribute = context.getTemplateAttribute();
|
||||
if (parentTemplateAttribute != null) {
|
||||
this.templateAttribute = new Attribute(parentTemplateAttribute);
|
||||
}
|
||||
preparer = context.preparer;
|
||||
if (context.attributes != null && !context.attributes.isEmpty()) {
|
||||
attributes = deepCopyAttributeMap(context.attributes);
|
||||
}
|
||||
if (context.cascadedAttributes != null && !context.cascadedAttributes.isEmpty()) {
|
||||
cascadedAttributes = deepCopyAttributeMap(context.cascadedAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds missing attributes to the destination map.
|
||||
*
|
||||
* @param source The source attribute map.
|
||||
* @param destination The destination attribute map.
|
||||
* @return The destination attribute map if not null, a new one otherwise.
|
||||
*/
|
||||
private Map<String, Attribute> addMissingAttributes(Map<String, Attribute> source, Map<String, Attribute> destination) {
|
||||
if (source != null && !source.isEmpty()) {
|
||||
if (destination == null) {
|
||||
destination = new HashMap<>();
|
||||
}
|
||||
for (Map.Entry<String, Attribute> entry : source.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Attribute destAttribute = destination.get(key);
|
||||
if (destAttribute == null) {
|
||||
destination.put(key, entry.getValue());
|
||||
} else if (destAttribute instanceof ListAttribute
|
||||
&& entry.getValue() instanceof ListAttribute
|
||||
&& ((ListAttribute) destAttribute).isInherit()) {
|
||||
((ListAttribute) destAttribute)
|
||||
.inherit((ListAttribute) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep copies the attribute map, by creating clones (using copy
|
||||
* constructors) of the attributes.
|
||||
*
|
||||
* @param attributes The attribute map to copy.
|
||||
* @return The copied map.
|
||||
*/
|
||||
private Map<String, Attribute> deepCopyAttributeMap(Map<String, Attribute> attributes) {
|
||||
Map<String, Attribute> retValue = new HashMap<>(attributes.size());
|
||||
for (Map.Entry<String, Attribute> entry : attributes.entrySet()) {
|
||||
Attribute toCopy = entry.getValue();
|
||||
if (toCopy != null) {
|
||||
retValue.put(entry.getKey(), toCopy.copy());
|
||||
}
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A definition, i.e. a template with (completely or not) filled attributes.
|
||||
* Attributes of a template can be defined with the help of this class.<br>
|
||||
* It can be used as a data transfer object used for registering new
|
||||
* definitions with the Container.
|
||||
*
|
||||
* @since Tiles 2.0
|
||||
*/
|
||||
public class Definition extends BasicAttributeContext {
|
||||
/**
|
||||
* Extends attribute value.
|
||||
*/
|
||||
protected String inherit;
|
||||
/**
|
||||
* Definition name.
|
||||
*/
|
||||
protected String name = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Definition() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Constructor.
|
||||
* Create a new definition initialized with parent definition.
|
||||
* Do a shallow copy : attributes are shared between copies, but not the Map
|
||||
* containing attributes.
|
||||
*
|
||||
* @param definition The definition to copy.
|
||||
*/
|
||||
public Definition(Definition definition) {
|
||||
super(definition);
|
||||
this.name = definition.name;
|
||||
this.inherit = definition.inherit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name The name of the definition.
|
||||
* @param templateAttribute The template attribute of the definition.
|
||||
* @param attributes The attribute map of the definition.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public Definition(String name, Attribute templateAttribute,
|
||||
Map<String, Attribute> attributes) {
|
||||
super(attributes);
|
||||
this.name = name;
|
||||
this.templateAttribute = templateAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access method for the name property.
|
||||
*
|
||||
* @return the current value of the name property
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the name property.
|
||||
*
|
||||
* @param aName the new value of the name property
|
||||
*/
|
||||
public void setName(String aName) {
|
||||
name = aName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extends.
|
||||
*
|
||||
* @param name Name of the extended definition.
|
||||
*/
|
||||
public void setExtends(String name) {
|
||||
inherit = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extends.
|
||||
*
|
||||
* @return Name of the extended definition.
|
||||
*/
|
||||
public String getExtends() {
|
||||
return inherit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Definition)) {
|
||||
return false;
|
||||
}
|
||||
Definition def = (Definition) obj;
|
||||
return Objects.equals(name, def.name) && Objects.equals(inherit, def.inherit) && super.equals(def);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name) + Objects.hashCode(inherit) + super.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extends flag.
|
||||
*
|
||||
* @return <code>true</code> if this definition extends another.
|
||||
*/
|
||||
public boolean isExtending() {
|
||||
return inherit != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the attributes.
|
||||
*
|
||||
* @return A string representation of the content of this definition.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{name="
|
||||
+ name
|
||||
+ ", template="
|
||||
+ (templateAttribute != null ? templateAttribute.getValue() : "<null>")
|
||||
+ ", role="
|
||||
+ (templateAttribute != null ? templateAttribute.getRoles() : "<null>")
|
||||
+ ", preparerInstance="
|
||||
+ preparer
|
||||
+ ", attributes="
|
||||
+ attributes
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* It is an expression, along with the expression language (e.g. EL, MVEL, OGNL)
|
||||
* it is expressed with.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class Expression {
|
||||
|
||||
/**
|
||||
* The expression itself.
|
||||
*/
|
||||
private final String expression;
|
||||
|
||||
/**
|
||||
* The language of the expression.
|
||||
*/
|
||||
private final String language;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param expression The expression itself.
|
||||
* @param language The language of the expression.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public Expression(String expression, String language) {
|
||||
this.expression = expression;
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, using the default (i.e. <code>null</code>) language.
|
||||
*
|
||||
* @param expression The expression itself.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public Expression(String expression) {
|
||||
this(expression, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param toCopy The expression to copy.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public Expression(Expression toCopy) {
|
||||
this.expression = toCopy.expression;
|
||||
this.language = toCopy.language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Expression object from a string in the form
|
||||
* <code>LANGUAGE:EXPRESSION</code>.
|
||||
*
|
||||
* @param describedExpression The expression in the form
|
||||
* <code>LANGUAGE:EXPRESSION</code>. The LANGUAGE part should be expressed
|
||||
* only with letters and numbers.
|
||||
* @return The created object, or <code>null</code> if the expression is null.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public static Expression createExpressionFromDescribedExpression(String describedExpression) {
|
||||
if (describedExpression != null) {
|
||||
String language = null;
|
||||
String expression = describedExpression;
|
||||
if (describedExpression.matches("[a-zA-Z0-9]+:.+")) {
|
||||
language = describedExpression.substring(0, describedExpression.indexOf(':'));
|
||||
expression = describedExpression.substring(describedExpression.indexOf(':') + 1);
|
||||
}
|
||||
return new Expression(expression, language);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Expression object from the expression and its language.
|
||||
*
|
||||
* @param expression The expression itself.
|
||||
* @param language The language of the expression.
|
||||
* @return The created object, or <code>null</code> if the expression is null.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public static Expression createExpression(String expression, String language) {
|
||||
if (expression != null) {
|
||||
return new Expression(expression, language);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression string.
|
||||
*
|
||||
* @return The expression itself.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language in which the expression is expressed.
|
||||
*
|
||||
* @return The expression language.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Expression)) {
|
||||
return false;
|
||||
}
|
||||
Expression exp = (Expression) obj;
|
||||
return Objects.equals(expression, exp.expression) && Objects.equals(language, exp.language);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(expression) + Objects.hashCode(language);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return (language == null ? "DEFAULT" : language) + ":" + expression;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An attribute as a <code>List</code>.
|
||||
* This attribute associates a name with a list. The list can be found by the
|
||||
* property name.
|
||||
* Elements in list are retrieved using List methods.
|
||||
* This class is used to read configuration files.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class ListAttribute extends Attribute {
|
||||
|
||||
/**
|
||||
* If true, the attribute will put the elements of the attribute with the
|
||||
* same name of the parent definition before the ones specified here. By
|
||||
* default, it is 'false'.
|
||||
*/
|
||||
private boolean inherit = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public ListAttribute() {
|
||||
setValue(new ArrayList<Object>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param toCopy The list attribute to copy.
|
||||
* @since 2.1.3
|
||||
*/
|
||||
public ListAttribute(ListAttribute toCopy) {
|
||||
super(toCopy);
|
||||
List<Attribute> attributesToCopy = toCopy.getValue();
|
||||
if (attributesToCopy != null) {
|
||||
List<Attribute> attributes = new ArrayList<>(attributesToCopy.size());
|
||||
for (Attribute attribute : attributesToCopy) {
|
||||
if (attribute != null) {
|
||||
attributes.add(attribute.copy());
|
||||
} else {
|
||||
attributes.add(null);
|
||||
}
|
||||
}
|
||||
setValue(attributes);
|
||||
}
|
||||
this.inherit = toCopy.inherit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of the attributes that are elements of this attribute.
|
||||
*
|
||||
* @param attributes The attributes.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public void setValue(List<Attribute> attributes) {
|
||||
super.setValue(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of the attributes that are elements of this attribute.
|
||||
*
|
||||
* @return The attributes.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Attribute> getValue() {
|
||||
return (List<Attribute>) super.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element in list.
|
||||
* We use a property to avoid rewriting a new class.
|
||||
*
|
||||
* @param element XmlAttribute to add.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void add(Attribute element) {
|
||||
getValue().add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, the attribute will put the elements of the attribute with the
|
||||
* same name of the parent definition before the ones specified here. By
|
||||
* default, it is 'false'
|
||||
*
|
||||
* @param inherit The "inherit" value.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void setInherit(boolean inherit) {
|
||||
this.inherit = inherit;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, the attribute will put the elements of the attribute with the
|
||||
* same name of the parent definition before the ones specified here. By
|
||||
* default, it is 'false'
|
||||
*
|
||||
* @return inherit The "inherit" value.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public boolean isInherit() {
|
||||
return inherit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits elements present in a "parent" list attribute. The elements will
|
||||
* be put before the ones already present.
|
||||
*
|
||||
* @param parent The parent list attribute.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public void inherit(ListAttribute parent) {
|
||||
List<Attribute> tempList = new ArrayList<>();
|
||||
tempList.addAll(parent.getValue());
|
||||
tempList.addAll(getValue());
|
||||
setValue(tempList);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof ListAttribute)) {
|
||||
return false;
|
||||
}
|
||||
ListAttribute attribute = (ListAttribute) obj;
|
||||
return super.equals(attribute) && this.inherit == attribute.inherit;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + Boolean.valueOf(inherit).hashCode();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public ListAttribute copy() {
|
||||
return new ListAttribute(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
/**
|
||||
* Indicates that a keyed container has not been found.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class NoSuchContainerException extends TilesException {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The detail message.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public NoSuchContainerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An encapsulation of the Tiles framework. This interface is
|
||||
* used to expose tiles features to frameworks which leverage
|
||||
* it as a plugin. It can alternately be used by web applications
|
||||
* which would like a programmatic interface.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface TilesContainer {
|
||||
|
||||
/**
|
||||
* Retrieve the container's context.
|
||||
*
|
||||
* @return current application context
|
||||
*/
|
||||
ApplicationContext getApplicationContext();
|
||||
|
||||
/**
|
||||
* Retrieve the attribute context of the current request.
|
||||
* @param request The request.
|
||||
* @return map of the attributes in the current attribute context.
|
||||
*/
|
||||
AttributeContext getAttributeContext(Request request);
|
||||
|
||||
/**
|
||||
* Starts a new context, where attribute values are stored independently of others.<br>
|
||||
* When the use of the contexts is finished, call{@link TilesContainer#endContext(Request)}
|
||||
*
|
||||
* @param request The request.
|
||||
* @return The newly created context.
|
||||
*/
|
||||
AttributeContext startContext(Request request);
|
||||
|
||||
/**
|
||||
* Ends a context, where attribute values are stored independently of others.<br>
|
||||
* It must be called after a {@link TilesContainer#startContext(Request)} call.
|
||||
*
|
||||
* @param request The request.
|
||||
*/
|
||||
void endContext(Request request);
|
||||
|
||||
/**
|
||||
* Renders the current context, as it is.
|
||||
* @param request The request.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void renderContext(Request request);
|
||||
|
||||
/**
|
||||
* Executes a preparer.
|
||||
*
|
||||
* @param preparer The name of the preparer to execute.
|
||||
* @param request The request.
|
||||
*/
|
||||
void prepare(String preparer, Request request);
|
||||
|
||||
/**
|
||||
* Render the given tiles request.
|
||||
*
|
||||
* @param definition the current definition.
|
||||
* @param request The request.
|
||||
*/
|
||||
void render(String definition, Request request);
|
||||
|
||||
/**
|
||||
* Renders the specified definition.
|
||||
* @param definition The definition to render.
|
||||
* @param request The request context.
|
||||
*/
|
||||
void render(Definition definition, Request request);
|
||||
|
||||
/**
|
||||
* Render the given Attribute.
|
||||
*
|
||||
* @param attribute The attribute to render.
|
||||
* @param request The request.
|
||||
* @throws IOException If something goes wrong during writing to the output.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
void render(Attribute attribute, Request request)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Evaluates the given attribute.
|
||||
*
|
||||
* @param attribute The attribute to evaluate.
|
||||
* @param request The request.
|
||||
* @return The evaluated object.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Object evaluate(Attribute attribute, Request request);
|
||||
|
||||
/**
|
||||
* Returns a definition specifying its name.
|
||||
*
|
||||
* @param definitionName The name of the definition to find.
|
||||
* @param request The request context.
|
||||
* @return The definition, if found.
|
||||
*/
|
||||
Definition getDefinition(String definitionName,
|
||||
Request request);
|
||||
|
||||
/**
|
||||
* Determine whether the definition exists.
|
||||
*
|
||||
* @param definition the name of the definition.
|
||||
* @param request The request.
|
||||
* @return true if the definition is found.
|
||||
*/
|
||||
boolean isValidDefinition(String definition, Request request);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Wraps a Tiles container to allow easy decoration.
|
||||
*/
|
||||
public class TilesContainerWrapper implements TilesContainer {
|
||||
|
||||
/**
|
||||
* The container to wrap.
|
||||
*/
|
||||
protected TilesContainer container;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param container The container to wrap.
|
||||
*/
|
||||
public TilesContainerWrapper(TilesContainer container) {
|
||||
this.container = container;
|
||||
if (container == null) {
|
||||
throw new NullPointerException("The wrapped container must be not null");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endContext(Request request) {
|
||||
container.endContext(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evaluate(Attribute attribute, Request request) {
|
||||
return container.evaluate(attribute, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationContext getApplicationContext() {
|
||||
return container.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContext getAttributeContext(Request request) {
|
||||
return container.getAttributeContext(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Definition getDefinition(String definitionName, Request request) {
|
||||
return container.getDefinition(definitionName, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidDefinition(String definition, Request request) {
|
||||
return container.isValidDefinition(definition, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(String preparer, Request request) {
|
||||
container.prepare(preparer, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(String definition, Request request) {
|
||||
container.render(definition, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Definition definition, Request request) {
|
||||
container.render(definition, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Attribute attribute, Request request) throws IOException {
|
||||
container.render(attribute, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderContext(Request request) {
|
||||
container.renderContext(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContext startContext(Request request) {
|
||||
return container.startContext(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
/**
|
||||
* Root class for all Tiles-exceptions.
|
||||
*/
|
||||
public class TilesException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public TilesException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The error or warning message.
|
||||
*/
|
||||
public TilesException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>TilesException</code> wrapping an existing exception.
|
||||
* <p/>
|
||||
* <p>The existing exception will be embedded in the new
|
||||
* one, and its message will become the default message for
|
||||
* the TilesException.</p>
|
||||
*
|
||||
* @param e The cause to be wrapped.
|
||||
*/
|
||||
public TilesException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>TilesException</code> from an existing exception.
|
||||
* <p/>
|
||||
* <p>The existing exception will be embedded in the new
|
||||
* one, but the new exception will have its own message.</p>
|
||||
*
|
||||
* @param message The detail message.
|
||||
* @param e The cause to be wrapped.
|
||||
*/
|
||||
public TilesException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.api.access;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.api.NoSuchContainerException;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides static access to the Tiles container.
|
||||
*/
|
||||
public final class TilesAccess {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(TilesAccess.class);
|
||||
|
||||
/**
|
||||
* Name of the attribute used to store the current used container.
|
||||
*/
|
||||
public static final String CURRENT_CONTAINER_ATTRIBUTE_NAME =
|
||||
"org.apache.tiles.servlet.context.ServletTilesRequestContext.CURRENT_CONTAINER_KEY";
|
||||
|
||||
/**
|
||||
* Constructor, private to avoid instantiation.
|
||||
*/
|
||||
private TilesAccess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the attribute to use when getting and setting the container
|
||||
* object in a context.
|
||||
*/
|
||||
public static final String CONTAINER_ATTRIBUTE =
|
||||
"org.apache.tiles.CONTAINER";
|
||||
|
||||
/**
|
||||
* Configures the container to be used in the application.
|
||||
*
|
||||
* @param context The Tiles application context object to use.
|
||||
* @param container The container object to set.
|
||||
* @param key The key under which the container will be stored.
|
||||
* @since 2.1.2
|
||||
*/
|
||||
public static void setContainer(ApplicationContext context, TilesContainer container, String key) {
|
||||
if (key == null) {
|
||||
key = CONTAINER_ATTRIBUTE;
|
||||
}
|
||||
|
||||
if (container == null) {
|
||||
LOG.info("Removing TilesContext for context: {}", context.getClass().getName());
|
||||
context.getApplicationScope().remove(key);
|
||||
} else {
|
||||
LOG.info("Publishing TilesContext for context: {}", context.getClass().getName());
|
||||
context.getApplicationScope().put(key, container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default the container to be used in the application.
|
||||
*
|
||||
* @param context The Tiles application context object to use.
|
||||
* @return The default container object.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static TilesContainer getContainer(ApplicationContext context) {
|
||||
return getContainer(context, CONTAINER_ATTRIBUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the container to be used in the application registered under a specific key.
|
||||
*
|
||||
* @param context The Tiles application context object to use.
|
||||
* @param key The key under which the container will be stored.
|
||||
* @return The container object.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static TilesContainer getContainer(ApplicationContext context,
|
||||
String key) {
|
||||
if (key == null) {
|
||||
key = CONTAINER_ATTRIBUTE;
|
||||
}
|
||||
|
||||
return (TilesContainer) context.getApplicationScope().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current container to use in web pages.
|
||||
*
|
||||
* @param request The request to use.
|
||||
* @param key The key under which the container is stored.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static void setCurrentContainer(Request request,
|
||||
String key) {
|
||||
ApplicationContext applicationContext = request.getApplicationContext();
|
||||
TilesContainer container = getContainer(applicationContext, key);
|
||||
if (container != null) {
|
||||
request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
|
||||
} else {
|
||||
throw new NoSuchContainerException("The container with the key '"
|
||||
+ key + "' cannot be found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current container to use in web pages.
|
||||
*
|
||||
* @param request The request to use.
|
||||
* @param container The container to use as the current container.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static void setCurrentContainer(Request request, TilesContainer container) {
|
||||
if (container != null) {
|
||||
request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
|
||||
} else {
|
||||
throw new NullPointerException("The container cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current container that has been set, or the default one.
|
||||
*
|
||||
* @param request The request to use.
|
||||
* @return The current Tiles container to use in web pages.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static TilesContainer getCurrentContainer(Request request) {
|
||||
ApplicationContext context = request.getApplicationContext();
|
||||
Map<String, Object> requestScope = request.getContext("request");
|
||||
TilesContainer container = (TilesContainer) requestScope.get(CURRENT_CONTAINER_ATTRIBUTE_NAME);
|
||||
if (container == null) {
|
||||
container = getContainer(context);
|
||||
requestScope.put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* Tiles access package. Utility classes to access Tiles funcionality from an application.
|
||||
*/
|
||||
package org.apache.tiles.api.access;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.api.mgmt;
|
||||
|
||||
import org.apache.tiles.api.Definition;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
/**
|
||||
* Defines a mutable version of the TilesContainer.
|
||||
*
|
||||
* @since Tiles 2.0
|
||||
*/
|
||||
public interface MutableTilesContainer extends TilesContainer {
|
||||
|
||||
/**
|
||||
* Register a new definition with the container.
|
||||
*
|
||||
* @param definition The definition to register.
|
||||
* @param request TODO
|
||||
*/
|
||||
void register(Definition definition, Request request);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* Classes and interfaces to be used when it is needed to create Tiles definitions
|
||||
* during the execution of the application.
|
||||
*/
|
||||
package org.apache.tiles.api.mgmt;
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* The Tiles taglib and framework allows building web pages by assembling reusable
|
||||
pieces of pages, called Tiles. A Tiles is usually a simple JSP page.
|
||||
|
||||
<div class="section">
|
||||
<h2>Introduction</h2>
|
||||
|
||||
<p>The Tiles framework allows building pages by assembling reusable Tiles.
|
||||
As an example, the page in the next figure can be build by assembling a
|
||||
header, a footer, a menu and a body.</p>
|
||||
|
||||
<p><img src="doc-files/image001.gif" height="169" width="145" alt="doc-files/image001"></p>
|
||||
|
||||
<p>Each Tiles (header, menu, body, ...) is a JSP page and can itself be build
|
||||
by assembling other Tiles.</p>
|
||||
|
||||
<p>Using Tiles can be compared as using Java methods: You need to define the Tiles (the method body), and then you
|
||||
can "call" this body anywhere you want, passing it some parameters. In Tiles, parameters are called
|
||||
"attributes" in order to avoid confusion with the request parameters.</p>
|
||||
|
||||
<p>The Tiles body can be a simple JSP page, a Struts action or any URI pointing
|
||||
to a resource inside the current web site.</p>
|
||||
|
||||
<p>Inserting the body, or calling it, is done with the tag <tiles:insert
|
||||
...> anywhere in a JSP page. Insertion can also be done by specifying
|
||||
a <em>definition name </em>as the path of a Struts forward or as input,
|
||||
forward or include attributes of a Struts action.</p>
|
||||
|
||||
<p>Tiles bodies are used to create layouts, reusable parts, ... Tiles insertions
|
||||
are used to insert Tiles. The same Tiles can be reused several times in
|
||||
the same site, or even in the same page.</p>
|
||||
|
||||
<p>Insertion of a Tiles body can be associated to a logical name in what Tiles calls a "definition". A
|
||||
definition contains a logical name, a page used as body and some attribute values. The definition declaration
|
||||
doesn't insert the associated Tiles body. It just associates it with the name. A definition name can be used
|
||||
anywhere insertion of a Tiles body can occur. The associated Tiles body is then inserted with associated
|
||||
attributes.</p>
|
||||
|
||||
<p>The definition declarations can be done in JSP pages or in one or more
|
||||
centralized files. A definition can extend another one, overload some attributes,
|
||||
add new attributes ... This allows the declaration of a "master" definition
|
||||
declaring the common layout, header, menu and footer. All other definitions
|
||||
extend this master layout thereby making it possible to change the entire
|
||||
site look & feel simply by changing the master definition. </p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>Simple Examples</h2>
|
||||
|
||||
<div class="subsection1">
|
||||
<h3>Insert a JSP page</h3>
|
||||
<pre><tiles:insert <strong>page</strong>="/layouts/commonLayout.jsp" flush="true" />
|
||||
</pre>
|
||||
<p>This example inserts the specified page in place of the tag. The page attribute is any valid URL pointing to
|
||||
a resource inside the current site.</p>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<a name="doc.InsertPageWithAttributes"></a>
|
||||
|
||||
<h3>Insert a Tiles passing some attributes</h3>
|
||||
<pre>
|
||||
<tiles:insert page="/layouts/classicLayout.jsp" flush=&quot;true">
|
||||
<tiles:put name="title" value="Page Title" />
|
||||
<tiles:put name="header" value="/common/header.jsp" />
|
||||
<tiles:put name="footer" value="/common/footer.jsp" />
|
||||
<tiles:put name="menu" value="/common/menu.jsp" />
|
||||
<tiles:put name="body" value="/tiles/mainBody.jsp" />
|
||||
</tiles:insert>
|
||||
</pre>
|
||||
<p>This example inserts the specified page, passing it the attributes. Attributes
|
||||
are stored in a Tiles context which is passed to the inserted pag and
|
||||
can then be accesssed by their names.</p>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<h3>Retrieve an attribute value as String</h3>
|
||||
<pre>
|
||||
<tiles:getAsString name="title" />
|
||||
</pre>
|
||||
<p>This example retrieves the value of the attribute "title" and prints it as a String in the current
|
||||
output stream. The method toString() is applied on the attribute value, allowing to pass any kind of object
|
||||
as value.</p>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<h3>Insert Tiles referenced by an attribute</h3>
|
||||
<pre>
|
||||
<tiles:insert attribute='menu' />
|
||||
</pre>
|
||||
<p>This inserts the Tiles referenced by the attribute "menu" value. The
|
||||
specified attribute value is first retrieved from current Tiles's context,
|
||||
and then the value is used as a page target to insert.</p>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<h3>Classic Layout </h3>
|
||||
|
||||
<p>This example is a layout assembling a page in the classic header-footer-menu-body
|
||||
fashion.</p>
|
||||
<pre>
|
||||
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<link rel="stylesheet" href="<%=request.getContextPath()%>/layouts/stylesheet.css"
|
||||
type="text/css"/>
|
||||
<title><tiles:getAsString name="title"/></title>
|
||||
</HEAD>
|
||||
<body>
|
||||
<table border="0" width="100%" cellspacing="5">
|
||||
<tr>
|
||||
<td colspan="2"><tiles:insert attribute="header" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="140" valign="top">
|
||||
<tiles:insert attribute='menu' />
|
||||
</td>
|
||||
<td valign="top" align="left">
|
||||
<tiles:insert attribute='body' />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<tiles:insert attribute="footer" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</pre>
|
||||
<p>The layout is declared in a JSP page (ex: /layouts/classicLayout.jsp).
|
||||
It can be used in conjunction with the tag described in "<a href="#doc.InsertPageWithAttributes">Insert
|
||||
a page passing some attributes</a>". </p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2>Definitions</h2>
|
||||
|
||||
<p>A definition associates a logical name with the URL of a Tiles to be inserted
|
||||
and some attribute values. A definition doesn't insert the Tiles. This is
|
||||
done later using the definition name. A definition name can be inserted
|
||||
as often as you want in your site, making it easy to reuse a Tiles. </p>
|
||||
|
||||
<p>A definition can extend another definition and overload some attributes
|
||||
or add new ones. This makes easy factorization of definitions differing
|
||||
by some attributes. For example, you can define a master definition declaring
|
||||
the main header, menu, footer, and a default title. Then let each of your
|
||||
page definitions extend this master definition and overload the title and
|
||||
the body.</p>
|
||||
|
||||
<p>Definitions can be declared in a JSP page, or in one or more centralized
|
||||
files. To enable the definitions from centralized files, you need to initialize
|
||||
the "definitions factory&&quot; which will parse the definitions from the files
|
||||
and provide them to the Tiles framework.</p>
|
||||
|
||||
<div class="subsection1">
|
||||
<h3>Enabling Definition Factory</h3>
|
||||
|
||||
<p>To enable Tiles definitions described in one or more files, you need to write these files and to initialize the
|
||||
definition factory. </p>
|
||||
|
||||
<p>Initialization is different depending on the Struts version you use,
|
||||
or if you do not use Struts at all.</p>
|
||||
|
||||
<div class="subsection2">
|
||||
<h4>Struts1.1</h4>
|
||||
|
||||
<p>Use the Tiles plug-in to enable Tiles definitions. This plug-in creates
|
||||
the definition factory and passese it a configuration object populated
|
||||
with parameters. Parameters can be specified in the web.xml file or
|
||||
as plug-in parameters. The plug-in first reads parameters from web.xml,
|
||||
and then overloads them with the ones found in the plug-in. All parameters
|
||||
are optional and can be omitted. The plug-in should be declared in each
|
||||
struts-config file:</p>
|
||||
<pre>
|
||||
<plug-in className=&&quot;org.apache.struts.tiles.TilesPlugin&&quot; >
|
||||
<set-property property=&&quot;definitions-config&&quot;
|
||||
value=&&quot;/WEB-INF/tiles-defs.xml,
|
||||
/WEB-INF/tiles-tests-defs.xml,/WEB-INF/tiles-tutorial-defs.xml,
|
||||
/WEB-INF/tiles-examples-defs.xml&&quot; />
|
||||
<set-property property=&&quot;moduleAware&&quot; value=&&quot;true&&quot; />
|
||||
<set-property
|
||||
property=&&quot;org.apache.tiles.definition.digester.DigesterDefinitionsReader.PARSER_VALIDATE&&quot;
|
||||
value=&&quot;true&&quot; />
|
||||
</plug-in>
|
||||
</pre>
|
||||
<ul>
|
||||
<li>definitions-config: (optional)
|
||||
<ul>
|
||||
<li>Specify configuration file names. There can be several comma separated file names (default: ?? )
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>org.apache.tiles.definition.digester.DigesterDefinitionsReader.PARSER_VALIDATE: (optional)
|
||||
<ul>
|
||||
<li>Specify if XML parser should validate the Tiles configuration
|
||||
file
|
||||
<ul>
|
||||
<li>true : validate. DTD should be specified in file header (default)</li>
|
||||
<li>false : no validation</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>moduleAware: (optional)
|
||||
<ul>
|
||||
<li>Specify if the Tiles definition factory is module aware. If true (default),
|
||||
there will be one factory for each Struts module.
|
||||
If false, there will be one common factory for all module. In this later case,
|
||||
it is still needed to declare one plugin per module. The factory will be
|
||||
initialized with parameters found in the first initialized plugin (generally the
|
||||
one associated with the default module).
|
||||
<ul>
|
||||
<li>true : Tiles framework is module aware</li>
|
||||
<li>false :Tiles framework has one single factoy shared among modules (default)</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>tilesUtilImplClassname: (optional - for advanced user)
|
||||
<ul>
|
||||
<li>Specify The classname of the TilesUtil implementation to use. The specified class should
|
||||
be a subclass of TilesUtilStrutsImpl. This option disable the moduleAware option.
|
||||
<br>Specifying &&"TilesUtilStrutsImpl&&" is equivalent to moduleAware =
|
||||
false.
|
||||
<br>Specifying &&"TilesUtilStrutsModuleImpl&&" is equivalent to moduleAware
|
||||
= true.
|
||||
This option is taken into account only once, when it is first encountered. To avoid problems,
|
||||
it is advice to specify the same values in all TilesPlugin declaration.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<p>The TilesPlugin class creates one definition factory for each struts module.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If the flag moduleAware is false, only one shared factory is created for all modules.
|
||||
In this later case, the factory is initialized with parameters found in the first plugin.
|
||||
The plugins should be declared in all modules, and the moduleAware flag should be
|
||||
the same for the entire application.</p>
|
||||
|
||||
<p>
|
||||
Paths found in Tiles definitions are relative to the main context.</p>
|
||||
|
||||
<p>You don't need to specify a TilesRequestProcessor, this is automatically
|
||||
done by the plug-in. If, however, you want to specify your own RequestProcessor,
|
||||
it should extend the TilesRequestProcessor. The plug-in checks this
|
||||
constraint.</p>
|
||||
</div>
|
||||
<div class="subsection2">
|
||||
<h4>Struts1.0.x</h4>
|
||||
|
||||
<p>You need to use a special servlet extending the Struts servlet. This is specified in the web.xml file of your
|
||||
application:</p>
|
||||
<pre>
|
||||
<servlet>
|
||||
<servlet-name>action</servlet-name>
|
||||
<servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
|
||||
<!-- Tiles Servlet parameter
|
||||
Specify configuration file names. There can be several comma
|
||||
separated file names
|
||||
-->
|
||||
<init-param>
|
||||
<param-name>definitions-config</param-name>
|
||||
<param-value>/WEB-INF/tiles-defs.xml</param-value>
|
||||
</init-param>
|
||||
<!-- Tiles Servlet parameter
|
||||
Specify if XML parser should validate the Tiles configuration file(s).
|
||||
true : validate. DTD should be specified in file header.
|
||||
false : no validation
|
||||
-->
|
||||
<init-param>
|
||||
<param-name>org.apache.tiles.definition.digester.DigesterDefinitionsReader.PARSER_VALIDATE</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
...
|
||||
</servlet>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="subsection2">
|
||||
<h4>Without Struts</h4>
|
||||
|
||||
<p>Tiles can be used without Struts. To initialize the definition factory, you can use the provided servlet. Declare
|
||||
it in the web.xml file of your application:</p>
|
||||
<pre>
|
||||
<servlet>
|
||||
<servlet-name>action</servlet-name>
|
||||
<servlet-class>org.apache.struts.tiles.TilesServlet</servlet-class>
|
||||
|
||||
|
||||
<init-param>
|
||||
<param-name>definitions-config</param-name>
|
||||
<param-value>/WEB-INF/tiles-defs.xml</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>org.apache.tiles.definition.digester.DigesterDefinitionsReader.PARSER_VALIDATE</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
...
|
||||
</pre>
|
||||
<p>The parameters are the same as for Struts1.1 or 1.0.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<h3>Definition File Syntax</h3>
|
||||
|
||||
<p>The definition file syntax can be found in the
|
||||
<a href="http://tiles.apache.org/dtds/tiles-config_2_0.dtd">tiles-config_2_0.dtd file</a>.
|
||||
</p>
|
||||
|
||||
<p>Following is a simple example:</p>
|
||||
<pre>
|
||||
<!DOCTYPE tiles-definitions PUBLIC
|
||||
&&quot;-//Apache Software Foundation//DTD Tiles Configuration//EN&&quot;
|
||||
&&quot;http://tiles.apache.org/dtds/tiles-config_2_0.dtd&&quot;>
|
||||
|
||||
<!-- Definitions for Tiles documentation -->
|
||||
<tiles-definitions>
|
||||
|
||||
<!-- ========================================================== -->
|
||||
<!-- Master definition -->
|
||||
<!-- ========================================================== -->
|
||||
<!-- Main page layout used as a root for other page definitions -->
|
||||
|
||||
<definition name=&&quot;site.mainLayout&&quot;
|
||||
template=&&quot;/layouts/classicLayout.jsp&&quot;>
|
||||
<put name=&&quot;title&&quot; value=&&quot;Tiles Blank Site&&quot; />
|
||||
<put name=&&quot;header&&quot; value=&&quot;/tiles/common/header.jsp&&quot; />
|
||||
<put name=&&quot;menu&&quot; value=&&quot;site.menu.bar&&quot; />
|
||||
<put name=&&quot;footer&&quot; value=&&quot;/tiles/common/footer.jsp&&quot; />
|
||||
<put name=&&quot;body&&quot; value=&&quot;/tiles/body.jsp&&quot; />
|
||||
</definition>
|
||||
|
||||
<!-- ========================================================== -->
|
||||
<!-- Index page definition -->
|
||||
<!-- ========================================================== -->
|
||||
<!-- This definition inherits from the main definition.
|
||||
It overloads the page title and the body used.
|
||||
Use the same mechanism to define new pages sharing common
|
||||
properties (here header, menu, footer, layout)
|
||||
-->
|
||||
|
||||
<definition name=&&quot;site.index.page&&quot;
|
||||
extends=&&quot;site.mainLayout&&quot; >
|
||||
<put name=&&quot;title&&quot; value=&&quot;Tiles Blank Site Index&&quot; />
|
||||
<put name=&&quot;body&&quot; value=&&quot;/tiles/body.jsp&&quot; />
|
||||
</definition>
|
||||
|
||||
</tiles-definition>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="subsection1">
|
||||
<h3>Debugging</h3>
|
||||
|
||||
<p>To debug a page made of Tiles, you can use following advices:</p>
|
||||
<ul>
|
||||
<li>Check each Tiles separatly. Try to access nested Tiles directly to test
|
||||
if thes work properly.
|
||||
</li>
|
||||
<li>Enable Tiles logging. See the commons-logging package help.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
*/
|
||||
package org.apache.tiles.api;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.api.preparer;
|
||||
|
||||
import org.apache.tiles.api.TilesException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Thrown when an exception occurs while processing
|
||||
* a prepare request.
|
||||
* </p>
|
||||
*
|
||||
* @since Tiles 2.0
|
||||
*/
|
||||
public class PreparerException extends TilesException {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public PreparerException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param e The cause exception.
|
||||
*/
|
||||
public PreparerException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The message to include.
|
||||
*/
|
||||
public PreparerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The message to include.
|
||||
* @param e The cause exception.
|
||||
*/
|
||||
public PreparerException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.api.preparer;
|
||||
|
||||
import org.apache.tiles.api.AttributeContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Executed prior to rendering a view.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A view preparer is typically used to provide last minute
|
||||
* translations of the data within the attribute context.
|
||||
* A preparer is not intended to replace the controller within an
|
||||
* MVC architecture.
|
||||
* </p>
|
||||
*
|
||||
* See
|
||||
* <ul>
|
||||
* <li><insert></li>
|
||||
* <li><definition></li>
|
||||
* </ul>>
|
||||
*/
|
||||
public interface ViewPreparer {
|
||||
|
||||
/**
|
||||
* Method associated to a tile and called immediately before the tile
|
||||
* is included.
|
||||
*
|
||||
* @param tilesContext Current tiles application context.
|
||||
* @param attributeContext Current tile context.
|
||||
* @throws PreparerException If something goes wrong during execution.
|
||||
*/
|
||||
void execute(Request tilesContext,
|
||||
AttributeContext attributeContext);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* "View preparers" are objects that allows the "preparation" of a Tiles artifact
|
||||
* (definition, template or attribute) before it is rendered.<br>
|
||||
* It is useful, for example, when a view item should be built and stored in a
|
||||
* particular context (e.g. a menu) and then rendered.
|
||||
*/
|
||||
package org.apache.tiles.api.preparer;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.autotag.core;
|
||||
|
||||
/**
|
||||
* Generic exception for Autotag.
|
||||
*/
|
||||
public class AutotagRuntimeException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public AutotagRuntimeException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The message of the exception.
|
||||
*/
|
||||
public AutotagRuntimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param cause The cause.
|
||||
*/
|
||||
public AutotagRuntimeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param message The message of the exception.
|
||||
* @param cause The cause.
|
||||
*/
|
||||
public AutotagRuntimeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.autotag.core.runtime;
|
||||
|
||||
import org.apache.tiles.autotag.core.runtime.util.NullWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Base class for the abstraction of the body.
|
||||
*/
|
||||
public abstract class AbstractModelBody implements ModelBody {
|
||||
|
||||
// precompiled the pattern to avoid compiling on every method call
|
||||
private static final Pattern PATTERN = Pattern.compile("^\\s*$");
|
||||
|
||||
/**
|
||||
* The default writer to use.
|
||||
*/
|
||||
private final Writer defaultWriter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param defaultWriter The default writer to use.
|
||||
*/
|
||||
public AbstractModelBody(Writer defaultWriter) {
|
||||
this.defaultWriter = defaultWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() throws IOException {
|
||||
evaluate(defaultWriter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String evaluateAsString() throws IOException {
|
||||
StringWriter writer = new StringWriter();
|
||||
try {
|
||||
evaluate(writer);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
String body = writer.toString();
|
||||
if (body != null) {
|
||||
body = PATTERN.matcher(body).replaceAll("");
|
||||
if (body.length() == 0) {
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateWithoutWriting() throws IOException {
|
||||
try (NullWriter writer = new NullWriter()) {
|
||||
evaluate(writer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.autotag.core.runtime;
|
||||
|
||||
/**
|
||||
* Builder interface for creating requests.
|
||||
* The implementations are expected to provide a default constructor,
|
||||
* and to implement another interface that can be used to provide the
|
||||
* parameters needed to build the actual request object.
|
||||
*/
|
||||
public interface AutotagRuntime<R> {
|
||||
/**
|
||||
* Creates a new Request instance.
|
||||
*
|
||||
* @return The Request.
|
||||
*/
|
||||
R createRequest();
|
||||
|
||||
/**
|
||||
* Creates a new ModelBody instance to match the request.
|
||||
*
|
||||
* @return The ModelBody.
|
||||
*/
|
||||
ModelBody createModelBody();
|
||||
|
||||
/**
|
||||
* Extracts a parameter from the tag.
|
||||
* @param name The name of the parameter.
|
||||
* @param defaultValue The default value if none is specified.
|
||||
* @return The value of the parameter.
|
||||
*/
|
||||
<T> T getParameter(String name, Class<T> type, T defaultValue);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.autotag.core.runtime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Abstracts a tag/directive body.
|
||||
*/
|
||||
public interface ModelBody {
|
||||
|
||||
/**
|
||||
* Evaluates a body and returns it as a string.
|
||||
*
|
||||
* @return The body, as a string.
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
String evaluateAsString() throws IOException;
|
||||
|
||||
/**
|
||||
* Evaluates a body, but discards result.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
void evaluateWithoutWriting() throws IOException;
|
||||
|
||||
/**
|
||||
* Evaluates the body and writes in the default writer.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
void evaluate() throws IOException;
|
||||
|
||||
/**
|
||||
* Evaluates the body and writes the result in the writer.
|
||||
*
|
||||
* @param writer The writer to write the result into.
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
void evaluate(Writer writer) throws IOException;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.autotag.core.runtime.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Specifies behaviour for a parameter of the "execute" method of a template class.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface Parameter {
|
||||
|
||||
/**
|
||||
* Indicates to use the parameter name itself for the exported name.
|
||||
*/
|
||||
String SAME_NAME = "USE THE SAME NAME";
|
||||
|
||||
/**
|
||||
* Returns the name of the exported property name.
|
||||
*/
|
||||
String name() default SAME_NAME;
|
||||
|
||||
/**
|
||||
* Indicates that this parameter is required.
|
||||
*/
|
||||
boolean required() default false;
|
||||
|
||||
/**
|
||||
* Indicates the default value, as it will be written in Java code.
|
||||
*/
|
||||
String defaultValue() default "null";
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* Annotations to be used in template classes.
|
||||
*/
|
||||
package org.apache.tiles.autotag.core.runtime.annotation;
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* Runtime part for all Autotag generated code.
|
||||
*/
|
||||
package org.apache.tiles.autotag.core.runtime;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user