Author: ddewolf Date: Wed Dec 13 12:53:57 2006 New Revision: 486835 URL: http://svn.apache.org/viewvc?view=rev&rev=486835 Log: Adding TilesDispathServlet to allow direct invocation of a tile without a jsp or api invocation. This can be used to simplify deployment
Added: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java (with props) Modified: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp Modified: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java?view=diff&rev=486835&r1=486834&r2=486835 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java (original) +++ struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java Wed Dec 13 12:53:57 2006 @@ -136,7 +136,7 @@ private String getRequestBase(ServletRequest request) { // Included Path - String include = (String) request.getAttribute("javax.servlet.include.request_uri"); + String include = (String) request.getAttribute("javax.servlet.include.servlet_path"); if (include != null) { return include; } Added: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java?view=auto&rev=486835 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java (added) +++ struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java Wed Dec 13 12:53:57 2006 @@ -0,0 +1,77 @@ +/* + * $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.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tiles.TilesContainer; +import org.apache.tiles.TilesException; +import org.apache.tiles.access.TilesAccess; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Tiles dispatching servlet. Used to invoke + * a definition directly. + */ +public class TilesDispatchServlet extends HttpServlet { + + private static final Log LOG = + LogFactory.getLog(TilesDispatchServlet.class); + + protected void doGet(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + + TilesContainer container = TilesAccess.getContainer(getServletContext()); + try { + String definition = getDefinitionName(req); + if (LOG.isDebugEnabled()) { + LOG.info("Dispatching to tile '" + definition + "'"); + } + container.render(req, res, definition); + } catch (TilesException e) { + throw new ServletException("Error rendering tile.", e); + } + } + + protected String getDefinitionName(HttpServletRequest request) { + String path = (String) request.getAttribute("javax.servlet.include.servlet_path"); + if (path == null) { + path = request.getServletPath(); + } + + int start = path.startsWith("/") ? 1 : 0; + int end = path.endsWith(".tiles") ? path.indexOf(".tiles") : path.length(); + + return path.substring(start, end); + } + + protected void doPost(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + LOG.info("Tiles dispatch request received. Redirecting POST to GET."); + doGet(req, res); + } +} Propchange: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDispatchServlet.java ------------------------------------------------------------------------------ svn:keywords = Id Author Date Rev Modified: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml?view=diff&rev=486835&r1=486834&r2=486835 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml (original) +++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml Wed Dec 13 12:53:57 2006 @@ -83,6 +83,8 @@ <put name="header" value="/header.jsp"/> </definition> + <definition name="testdispatchservlet" extends="test.definition"/> + <definition name="preparer.definition.configured" extends="preparer.definition" preparer="org.apache.tiles.test.preparer.TestViewPreparer" /> </tiles-definitions> Modified: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml?view=diff&rev=486835&r1=486834&r2=486835 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml (original) +++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml Wed Dec 13 12:53:57 2006 @@ -24,11 +24,12 @@ --> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" - version="2.4"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" + version="2.4"> - <display-name>Tiles 2 Test Application</display-name> + <display-name>Tiles 2 Test Application</display-name> + <distributable/> <context-param> <param-name>org.apache.tiles.CONTEXT_FACTORY</param-name> @@ -58,35 +59,45 @@ <url-pattern>/testdecorationfilter.jsp</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping> - - <!-- Standard Action Servlet Configuration --> - <servlet> - <servlet-name>tiles</servlet-name> - <servlet-class>org.apache.tiles.servlet.TilesServlet</servlet-class> - <init-param> - <param-name>definitions-config</param-name> - <param-value>/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml</param-value> - </init-param> - <load-on-startup>2</load-on-startup> - </servlet> - - <!-- Standard Action Servlet Configuration --> - <servlet> - <servlet-name>layoutServlet</servlet-name> - <servlet-class>org.apache.tiles.test.servlet.IncludingServlet</servlet-class> - <init-param> - <param-name>include</param-name> - <param-value>/layout.jsp</param-value> - </init-param> - </servlet> - - <welcome-file-list> - <welcome-file>index.jsp</welcome-file> - </welcome-file-list> - - <servlet-mapping> - <servlet-name>layoutServlet</servlet-name> - <url-pattern>/servlets/layoutServlet</url-pattern> - </servlet-mapping> + + <!-- Standard Action Servlet Configuration --> + <servlet> + <servlet-name>tiles</servlet-name> + <servlet-class>org.apache.tiles.servlet.TilesServlet</servlet-class> + <init-param> + <param-name>definitions-config</param-name> + <param-value>/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml</param-value> + </init-param> + <load-on-startup>2</load-on-startup> + </servlet> + + <servlet> + <servlet-name>Tiles Dispatch Servlet</servlet-name> + <servlet-class>org.apache.tiles.web.TilesDispatchServlet</servlet-class> + </servlet> + + <!-- Standard Action Servlet Configuration --> + <servlet> + <servlet-name>layoutServlet</servlet-name> + <servlet-class>org.apache.tiles.test.servlet.IncludingServlet</servlet-class> + <init-param> + <param-name>include</param-name> + <param-value>/layout.jsp</param-value> + </init-param> + </servlet> + + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> + + <servlet-mapping> + <servlet-name>layoutServlet</servlet-name> + <url-pattern>/servlets/layoutServlet</url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name>Tiles Dispatch Servlet</servlet-name> + <url-pattern>*.tiles</url-pattern> + </servlet-mapping> </web-app> Modified: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp?view=diff&rev=486835&r1=486834&r2=486835 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp (original) +++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp Wed Dec 13 12:53:57 2006 @@ -44,6 +44,8 @@ <a href="testput_servlet.jsp">Test Put Tag using a servlet mapping as a template</a><br/> <a href="testimportattribute.jsp">Test importAttribute Tag</a><br/> <a href="testimportattribute_all.jsp">Test importAttribute Tag with no name</a><br/> + <a href="testdecorationfilter.jsp">Test Tiles Definition Filter</a><br/> + <a href="testdispatchservlet.tiles">Test Tiles Dispatch Servlet</a><br/> <h3>Mutable Container Tests</h3> <a href="testinitcontainer.jsp">Test Initialize Container</a><br/>