You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2007/12/03 21:25:46 UTC
svn commit: r600665 - in /tiles/framework/branches/TILES_2_0_X:
tiles-core/src/main/java/org/apache/tiles/servlet/context/
tiles-core/src/test/java/org/apache/tiles/servlet/context/
tiles-jsp/src/main/java/org/apache/tiles/jsp/context/ tiles-jsp/src/ma...
Author: apetrelli
Date: Mon Dec 3 12:25:44 2007
New Revision: 600665
URL: http://svn.apache.org/viewvc?rev=600665&view=rev
Log:
TILES-232
Merge from trunk to TILES_2_0_X branch.
Now, when an "include" operation is needed, a request attribute is set, so Tiles always included from that point.
Added:
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java (contents, props changed)
- copied, changed from r600658, tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java
tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp (contents, props changed)
- copied, changed from r600658, tiles/framework/trunk/tiles-test/src/main/webapp/errorInclude.jsp
Modified:
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java
tiles/framework/branches/TILES_2_0_X/tiles-core/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java
tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/java/org/apache/tiles/test/servlet/IncludingServlet.java
tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/WEB-INF/web.xml
Modified: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java Mon Dec 3 12:25:44 2007
@@ -179,7 +179,7 @@
/** {@inheritDoc} */
public void dispatch(String path) throws IOException {
- if (response.isCommitted()) {
+ if (response.isCommitted() || ServletUtil.isForceInclude(request)) {
include(path);
} else {
forward(path);
@@ -192,7 +192,7 @@
* @param path The path to forward to.
* @throws IOException If something goes wrong during the operation.
*/
- private void forward(String path) throws IOException {
+ protected void forward(String path) throws IOException {
RequestDispatcher rd = request.getRequestDispatcher(path);
try {
rd.forward(request, response);
@@ -206,6 +206,7 @@
/** {@inheritDoc} */
public void include(String path) throws IOException {
+ ServletUtil.setForceInclude(request, true);
RequestDispatcher rd = request.getRequestDispatcher(path);
try {
rd.include(request, response);
Copied: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java (from r600658, tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java)
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java?p2=tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java&p1=tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java&r1=600658&r2=600665&rev=600665&view=diff
==============================================================================
(empty)
Propchange: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: tiles/framework/branches/TILES_2_0_X/tiles-core/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-core/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-core/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java Mon Dec 3 12:25:44 2007
@@ -21,8 +21,13 @@
package org.apache.tiles.servlet.context;
+import java.io.IOException;
import java.util.Map;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.shale.test.mock.MockHttpServletRequest;
import org.apache.shale.test.mock.MockHttpServletResponse;
import org.apache.shale.test.mock.MockHttpSession;
@@ -38,15 +43,25 @@
public class ServletTilesRequestContextTest extends TestCase {
/**
+ * Test path to check forward and include.
+ */
+ private static final String TEST_PATH = "testPath.jsp";
+
+ /**
* The request context.
*/
private TilesRequestContext context;
+ /**
+ * The servlet context.
+ */
+ private MockServletContext servletContext;
+
/** {@inheritDoc} */
@Override
protected void setUp() throws Exception {
super.setUp();
- MockServletContext servletContext = new MockServletContext();
+ servletContext = new MockServletContext();
servletContext
.addInitParameter("initParameter1", "initParameterValue1");
MockHttpSession session = new MockHttpSession(servletContext);
@@ -170,6 +185,27 @@
}
/**
+ * Tests the forced inclusion in the request.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testForceInclude() throws IOException {
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse response = new CommitSupportMockHttpServletResponse();
+ MockServletTilesRequestContext context = new MockServletTilesRequestContext(
+ servletContext, request, response);
+ context.dispatch(TEST_PATH);
+ assertEquals("Forward has not been called", 1, context.getForwardCount());
+ assertEquals("Include has been called", 0, context.getIncludeCount());
+ assertFalse("Force include has been incorrectly set.", ServletUtil
+ .isForceInclude(request));
+ ServletUtil.setForceInclude(request, true);
+ context.dispatch(TEST_PATH);
+ assertEquals("Forward has been called", 1, context.getForwardCount());
+ assertEquals("Include has not been called", 1, context.getIncludeCount());
+ }
+
+ /**
* Tests a generic map.
*
* @param <K> The key type.
@@ -195,6 +231,79 @@
assertTrue("The map " + mapName
+ " does not return the correct value for 'containsValue'",
currentMap.containsValue(value));
+ }
+ }
+
+ /**
+ * Extends {@link MockHttpServletResponse} to override
+ * {@link MockHttpServletResponse#isCommitted()} method.
+ */
+ private static class CommitSupportMockHttpServletResponse extends
+ MockHttpServletResponse {
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isCommitted() {
+ return false;
+ }
+ }
+
+ /**
+ * Extends {@link ServletTilesRequestContext} to check forward and include.
+ */
+ private static class MockServletTilesRequestContext extends
+ ServletTilesRequestContext {
+
+ /**
+ * The number of times that forward has been called.
+ */
+ private int forwardCount = 0;
+
+ /**
+ * The number of times that include has been called.
+ */
+ private int includeCount = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param servletContext The servlet context.
+ * @param request The request.
+ * @param response The response.
+ */
+ public MockServletTilesRequestContext(ServletContext servletContext,
+ HttpServletRequest request, HttpServletResponse response) {
+ super(servletContext, request, response);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void forward(String path) throws IOException {
+ forwardCount++;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void include(String path) throws IOException {
+ includeCount++;
+ }
+
+ /**
+ * Returns the forward count.
+ *
+ * @return The forward count.
+ */
+ public int getForwardCount() {
+ return forwardCount;
+ }
+
+ /**
+ * Returns the include count.
+ *
+ * @return The include count.
+ */
+ public int getIncludeCount() {
+ return includeCount;
}
}
}
Modified: tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java Mon Dec 3 12:25:44 2007
@@ -84,6 +84,7 @@
/** {@inheritDoc} */
public void include(String path) throws IOException {
+ JspUtil.setForceInclude(pageContext, true);
try {
JspUtil.doInclude(pageContext, path, false);
} catch (JspException e) {
Modified: tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java Mon Dec 3 12:25:44 2007
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.servlet.context.ServletUtil;
import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
@@ -104,5 +105,30 @@
}
+ /**
+ * Returns true if forced include of the result is needed.
+ *
+ * @param context The page context.
+ * @return If <code>true</code> the include operation must be forced.
+ */
+ public static boolean isForceInclude(PageContext context) {
+ Boolean retValue = (Boolean) context.getAttribute(
+ ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME,
+ PageContext.REQUEST_SCOPE);
+ return retValue != null && retValue.booleanValue();
+ }
+ /**
+ * Sets the option that enables the forced include of the response.
+ *
+ * @param context The page context.
+ * @param forceInclude If <code>true</code> the include operation must be
+ * forced.
+ */
+ public static void setForceInclude(PageContext context, boolean forceInclude) {
+ Boolean retValue = Boolean.valueOf(forceInclude);
+ context.setAttribute(
+ ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME,
+ retValue, PageContext.REQUEST_SCOPE);
+ }
}
Modified: tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java Mon Dec 3 12:25:44 2007
@@ -61,6 +61,10 @@
/** {@inheritDoc} */
protected void render() throws JspException {
+ // FIXME This code should be changed once the overriding template
+ // facility will be available, so it can be managed by the Tiles
+ // container.
+ JspUtil.setForceInclude(pageContext, true);
JspUtil.doInclude(pageContext, template, flush);
}
}
Modified: tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/java/org/apache/tiles/test/servlet/IncludingServlet.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/java/org/apache/tiles/test/servlet/IncludingServlet.java?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/java/org/apache/tiles/test/servlet/IncludingServlet.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/java/org/apache/tiles/test/servlet/IncludingServlet.java Mon Dec 3 12:25:44 2007
@@ -28,6 +28,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.tiles.servlet.context.ServletUtil;
+
/**
* Sample servlet that includes a page specified by the <code>include</code>
* init parameter.
@@ -37,11 +39,17 @@
public class IncludingServlet extends HttpServlet {
/**
- * Init parameter value, that indicates the pate to include.
+ * Init parameter value, that indicates the path to include.
*/
private String include;
/**
+ * Init parameter value, that indicates the path to include in case of
+ * error.
+ */
+ private String errorInclude;
+
+ /**
* Initializes the servlet, reading the <code>include</code> init
* parameter.
*
@@ -53,6 +61,7 @@
super.init(config);
include = config.getInitParameter("include");
+ errorInclude = config.getInitParameter("errorInclude");
}
/**
@@ -65,6 +74,10 @@
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
- request.getRequestDispatcher(include).include(request, response);
+ if (ServletUtil.isForceInclude(request)) {
+ request.getRequestDispatcher(include).include(request, response);
+ } else {
+ request.getRequestDispatcher(errorInclude).include(request, response);
+ }
}
}
Modified: tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/WEB-INF/web.xml?rev=600665&r1=600664&r2=600665&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/WEB-INF/web.xml (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/WEB-INF/web.xml Mon Dec 3 12:25:44 2007
@@ -128,6 +128,10 @@
<param-name>include</param-name>
<param-value>/layout.jsp</param-value>
</init-param>
+ <init-param>
+ <param-name>errorInclude</param-name>
+ <param-value>/errorInclude.jsp</param-value>
+ </init-param>
</servlet>
<servlet>
<servlet-name>selectLocaleServlet</servlet-name>
Copied: tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp (from r600658, tiles/framework/trunk/tiles-test/src/main/webapp/errorInclude.jsp)
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp?p2=tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp&p1=tiles/framework/trunk/tiles-test/src/main/webapp/errorInclude.jsp&r1=600658&r2=600665&rev=600665&view=diff
==============================================================================
(empty)
Propchange: tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/branches/TILES_2_0_X/tiles-test/src/main/webapp/errorInclude.jsp
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL