Author: ddewolf
Date: Wed Dec 13 12:24:14 2006
New Revision: 486826

URL: http://svn.apache.org/viewvc?view=rev&rev=486826
Log:
Moving TilesAccess to API; Implementing decoration filter to reduce the amount 
of configuration required

Added:
    struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/
    
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
   (with props)
    struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/
    
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java
   (with props)
    struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/
    
struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java
   (contents, props changed)
      - copied, changed from r486806, 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/access/TilesAccessTest.java
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
   (with props)
    
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp  
 (with props)
Removed:
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/access/
Modified:
    struts/sandbox/trunk/tiles/tiles-api/pom.xml
    
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
    struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml

Modified: struts/sandbox/trunk/tiles/tiles-api/pom.xml
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/pom.xml?view=diff&rev=486826&r1=486825&r2=486826
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-api/pom.xml (original)
+++ struts/sandbox/trunk/tiles/tiles-api/pom.xml Wed Dec 13 12:24:14 2006
@@ -23,152 +23,167 @@
  */
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
 
-   <parent>
-      <groupId>org.apache.struts.tiles</groupId>
-      <artifactId>tiles-parent</artifactId>
-      <version>2.0-SNAPSHOT</version>
-   </parent>
-
-   <modelVersion>4.0.0</modelVersion>
-   <artifactId>tiles-api</artifactId>
-   <packaging>jar</packaging>
-   <name>Tiles - API </name>
-
-   <build>
-
-      <resources>
-         <resource>
-            <directory>src/main/resources</directory>
-         </resource>
-         <resource>
-            <directory>.</directory>
-            <includes>
-               <include>LICENSE.txt</include>
-               <include>NOTICE.txt</include>
-            </includes>
-            <targetPath>META-INF</targetPath>
-         </resource>
-      </resources>
-
-      <testResources>
-         <testResource>
-            <directory>src/test/java</directory>
-            <includes>
-               <include>**/*.xml</include>
-               <include>**/*.properties</include>
-            </includes>
-         </testResource>
-      </testResources>
-
-       <plugins>
-           <plugin>
-               <artifactId>maven-jar-plugin</artifactId>
-               <configuration>
-                   <archive>
-                       <manifest>
-                       </manifest>
-                   </archive>
-               </configuration>
-           </plugin>
-       </plugins>
+    <parent>
+        <groupId>org.apache.struts.tiles</groupId>
+        <artifactId>tiles-parent</artifactId>
+        <version>2.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>tiles-api</artifactId>
+    <packaging>jar</packaging>
+    <name>Tiles - API</name>
+
+    <build>
+
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+            <resource>
+                <directory>.</directory>
+                <includes>
+                    <include>LICENSE.txt</include>
+                    <include>NOTICE.txt</include>
+                </includes>
+                <targetPath>META-INF</targetPath>
+            </resource>
+        </resources>
+
+        <testResources>
+            <testResource>
+                <directory>src/test/java</directory>
+                <includes>
+                    <include>**/*.xml</include>
+                    <include>**/*.properties</include>
+                </includes>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
 
-   </build>
+    </build>
 
-        <profiles>
+    <profiles>
         <profile>
-               <!--
-                       Run the translator for Java 1.4 compatiblity
+            <!--
+                   Run the translator for Java 1.4 compatiblity
 
-                       Sample:
-                       $ cd tiles-core/
-                       $ mvn clean install -Papps,j4 
-Djava14.jar=$JAVA_HOME/../Classes/classes.jar
-
-                -->
-             <id>j4</id>
-             <build>
-               <plugins>
-                 <plugin>
-                   <groupId>org.codehaus.mojo</groupId>
-                   <artifactId>retrotranslator-maven-plugin</artifactId>
-                   <executions>
-                     <execution>
-                       <id>retrotranslate</id>
-                     </execution>
-                   </executions>
-                 </plugin>
-                 <plugin>
-                   <artifactId>maven-jar-plugin</artifactId>
-                   <executions>
-                     <execution>
-                       <id>create-j4-jar</id>
-                       <goals><goal>jar</goal></goals>
-                       <configuration>
-                         
<classesDirectory>${project.build.directory}/classes-retro</classesDirectory>
-                         <classifier>j4</classifier>
-                         <archive>
-                           <manifestEntries>
-                             
<Extension-Name>${project.artifactId}-j4</Extension-Name>
-                             
<Specification-Vendor>${project.organization.name}</Specification-Vendor>
-                             
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
-                             
<Implementation-Title>${project.description}</Implementation-Title>
-                             
<Implementation-Version>${project.version}</Implementation-Version>
-                             <Revision>${scm.revision}</Revision>
-                           </manifestEntries>
-                          </archive>
-                       </configuration>
-                     </execution>
-                   </executions>
-                 </plugin>
-               </plugins>
-             </build>
-              <dependencies>
-               <dependency>
-                 <groupId>sun.jdk</groupId>
-                 <artifactId>rt</artifactId>
-                 <version>1.4.0</version>
-                 <scope>system</scope>
-                 <!-- path to rt.jar (on OSX, it's classes.jar) -->
-                 <systemPath>${java14.jar}</systemPath>
-               </dependency>
-               <dependency>
-                 <groupId>net.sf.retrotranslator</groupId>
-                 <artifactId>retrotranslator-runtime</artifactId>
-                 <version>1.0.8</version>
-               </dependency>
-             </dependencies>
-           </profile>
+                   Sample:
+                   $ cd tiles-core/
+                   $ mvn clean install -Papps,j4 
-Djava14.jar=$JAVA_HOME/../Classes/classes.jar
+
+                -->
+            <id>j4</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>retrotranslator-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>retrotranslate</id>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-jar-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>create-j4-jar</id>
+                                <goals>
+                                    <goal>jar</goal>
+                                </goals>
+                                <configuration>
+                                    
<classesDirectory>${project.build.directory}/classes-retro</classesDirectory>
+                                    <classifier>j4</classifier>
+                                    <archive>
+                                        <manifestEntries>
+                                            
<Extension-Name>${project.artifactId}-j4</Extension-Name>
+                                            
<Specification-Vendor>${project.organization.name}</Specification-Vendor>
+                                            
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+                                            
<Implementation-Title>${project.description}</Implementation-Title>
+                                            
<Implementation-Version>${project.version}</Implementation-Version>
+                                            
<Revision>${scm.revision}</Revision>
+                                        </manifestEntries>
+                                    </archive>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+            <dependencies>
+                <dependency>
+                    <groupId>sun.jdk</groupId>
+                    <artifactId>rt</artifactId>
+                    <version>1.4.0</version>
+                    <scope>system</scope>
+                    <!-- path to rt.jar (on OSX, it's classes.jar) -->
+                    <systemPath>${java14.jar}</systemPath>
+                </dependency>
+                <dependency>
+                    <groupId>net.sf.retrotranslator</groupId>
+                    <artifactId>retrotranslator-runtime</artifactId>
+                    <version>1.0.8</version>
+                </dependency>
+            </dependencies>
+        </profile>
     </profiles>
 
     <dependencies>
 
-      <dependency>
-         <groupId>javax.servlet</groupId>
-         <artifactId>servlet-api</artifactId>
-         <version>2.4</version>
-         <scope>provided</scope>
-      </dependency>
-
-      <dependency>
-         <groupId>javax.servlet</groupId>
-         <artifactId>jsp-api</artifactId>
-         <version>2.0</version>
-         <scope>provided</scope>
-      </dependency>
-
-      <dependency>
-         <groupId>javax.portlet</groupId>
-         <artifactId>portlet-api</artifactId>
-         <version>1.0</version>
-         <scope>provided</scope>
-      </dependency>
-
-      <dependency>
-         <groupId>junit</groupId>
-         <artifactId>junit</artifactId>
-         <version>3.8.1</version>
-         <scope>test</scope>
-      </dependency>
-   </dependencies>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>jsp-api</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.portlet</groupId>
+            <artifactId>portlet-api</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.0.4</version>
+        </dependency>
+
+          <dependency>
+              <groupId>junit</groupId>
+              <artifactId>junit</artifactId>
+              <version>4.0</version>
+              <scope>test</scope>
+          </dependency>
+
+          <dependency>
+              <groupId>org.easymock</groupId>
+              <artifactId>easymock</artifactId>
+              <version>2.2</version>
+              <scope>test</scope>
+          </dependency>
+    </dependencies>
 </project>

Added: 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java?view=auto&rev=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
 Wed Dec 13 12:24:14 2006
@@ -0,0 +1,108 @@
+/*
+ * $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.access;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesException;
+
+import java.lang.reflect.Method;
+
+
+/**
+ * Provides static access to the tiles container.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TilesAccess {
+
+    private static final Log LOG =
+        LogFactory.getLog(TilesAccess.class);
+
+    public static final String CONTAINER_ATTRIBUTE =
+        "org.apache.tiles.CONTAINER";
+
+    private static final String CONTEXT_ATTRIBUTE =
+        "org.apache.tiles.APPLICATION_CONTEXT";
+
+    public static TilesContainer getContainer(Object context) {
+        return (TilesContainer) getAttribute(context, CONTAINER_ATTRIBUTE);
+    }
+
+    public static void setContainer(Object context, TilesContainer container)
+        throws TilesException {
+
+        if (container == null) {
+            if(LOG.isInfoEnabled()) {
+                LOG.info("Removing TilesContext for context: " + 
context.getClass().getName());
+            }
+            removeAttribute(context, CONTAINER_ATTRIBUTE);
+        }
+        if (container != null && LOG.isInfoEnabled()) {
+            LOG.info("Publishing TilesContext for context: " + 
context.getClass().getName());
+        }
+        setAttribute(context, CONTAINER_ATTRIBUTE, container);
+    }
+
+    public static TilesApplicationContext getApplicationContext(Object 
context) {
+        TilesContainer container = getContainer(context);
+        if (container != null) {
+            return container.getApplicationContext();
+        }
+        return (TilesApplicationContext) getAttribute(context, 
CONTEXT_ATTRIBUTE);
+    }
+
+    private static Object getAttribute(Object context, String attributeName) {
+        try {
+            Class contextClass = context.getClass();
+            Method attrMethod = contextClass.getMethod("getAttribute", 
String.class);
+            return attrMethod.invoke(context, attributeName);
+        } catch (Exception e) {
+            LOG.warn("Unable to retrieve container from specified context: '" 
+ context + "'", e);
+            return null;
+        }
+    }
+
+    private static void setAttribute(Object context, String name, Object value)
+        throws TilesException {
+        try {
+            Class contextClass = context.getClass();
+            Method attrMethod = contextClass.getMethod("setAttribute", 
String.class, Object.class);
+            attrMethod.invoke(context, name, value);
+        } catch (Exception e) {
+            throw new TilesException("Unable to set attribute for specified 
context: '" + context + "'");
+        }
+    }
+
+    private static void removeAttribute(Object context, String name)
+        throws TilesException {
+        try {
+            Class contextClass = context.getClass();
+            Method attrMethod = contextClass.getMethod("removeAttribute", 
String.class);
+            attrMethod.invoke(context, name);
+        } catch (Exception e) {
+            throw new TilesException("Unable to remove attribute for specified 
context: '" + context + "'");
+        }
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Added: 
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=auto&rev=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java
 Wed Dec 13 12:24:14 2006
@@ -0,0 +1,149 @@
+/*
+ * $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.ComponentAttribute;
+import org.apache.tiles.ComponentContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * Decoration Filter.  Intercepts all requests and decorates them
+ * with the configured definition.
+ *
+ * For example, given the following config:
+ * <xmp>
+    <filter>
+        <filter-name>Tiles Decoration Filter</filter-name>
+        <filter-class>org.apache.tiles.web.TilesDecorationFilter</filter-class>
+        <init-param>
+            <param-name>definition</param-name>
+            <param-value>test.definition</param-value>
+        </init-param>
+        <init-param>
+            <param-name>attribute-name</param-name>
+            <param-value>body</param-value>
+        </init-param>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>Tiles Decoration Filter</filter-name>
+        <url-pattern>/testdecorationfilter.jsp</url-pattern>
+        <dispatcher>REQUEST</dispatcher>
+    </filter-mapping>
+ * </xmp>
+ * The filter will intercept all requests to the indicated url pattern
+ * store the initial request path as the "body" component attribute
+ * and then render the "test.definition" definition.
+ *
+ */
+public class TilesDecorationFilter implements Filter {
+
+    private static final Log LOG =
+        LogFactory.getLog(TilesDecorationFilter.class);
+
+    /**
+     * Filter configuration.
+     */
+    private FilterConfig filterConfig;
+
+    /**
+     * The name of the component attribute used to
+     * pass on the request.
+     */
+    private String componentAttributeName = "content";
+
+    private String definitionName = "layout";
+
+
+    public FilterConfig getFilterConfig() {
+        return filterConfig;
+    }
+
+    public ServletContext getServletContext() {
+        return filterConfig.getServletContext();
+    }
+
+    public void init(FilterConfig config) throws ServletException {
+        filterConfig = config;
+        String temp = config.getInitParameter("attribute-name");
+        if(temp != null) {
+            componentAttributeName = temp;
+        }
+
+        temp = config.getInitParameter("definition");
+        if(temp != null) {
+            definitionName = temp;
+        }
+    }
+
+    public void destroy() {
+        filterConfig = null;
+    }
+
+
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain 
filterChain)
+        throws IOException, ServletException {
+        TilesContainer container = 
TilesAccess.getContainer(getServletContext());
+        prepareComponentAttributes(req, container.getComponentContext(req, 
res));
+        try {
+            container.render(req, res, definitionName);
+        } catch (TilesException e) {
+            throw new ServletException("Error wrapping jsp with tile 
definition.", e);
+        }
+    }
+
+    protected void prepareComponentAttributes(ServletRequest req, 
ComponentContext ctx) {
+        ComponentAttribute attr = new ComponentAttribute();
+        attr.setType(ComponentAttribute.TEMPLATE);
+        attr.setName(componentAttributeName);
+        attr.setValue(getRequestBase(req));
+        ctx.putAttribute(componentAttributeName, attr);
+    }
+
+
+    private String getRequestBase(ServletRequest request) {
+        // Included Path
+        String include = (String) 
request.getAttribute("javax.servlet.include.request_uri");
+        if (include != null) {
+            return include;
+        }
+
+        // As opposed to includes, if a forward occurs, it will update the 
servletPath property
+        // and include the original as the request attribute.
+        return ((HttpServletRequest) request).getServletPath();
+    }
+
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/web/TilesDecorationFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Copied: 
struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java
 (from r486806, 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/access/TilesAccessTest.java)
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java?view=diff&rev=486826&p1=struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/access/TilesAccessTest.java&r1=486806&p2=struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java&r2=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/access/TilesAccessTest.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java
 Wed Dec 13 12:24:14 2006
@@ -24,7 +24,6 @@
 import org.easymock.EasyMock;
 import org.apache.tiles.TilesContainer;
 import org.apache.tiles.TilesException;
-import org.apache.tiles.impl.BasicTilesContainer;
 
 import javax.servlet.ServletContext;
 
@@ -42,7 +41,7 @@
     }
 
     public void testSetContext() throws TilesException {
-        TilesContainer container = new BasicTilesContainer();
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
         context.setAttribute(TilesAccess.CONTAINER_ATTRIBUTE,container);
         EasyMock.replay(context);
         TilesAccess.setContainer(context, container);
@@ -50,7 +49,7 @@
     }
 
     public void testGetContext() throws TilesException {
-        TilesContainer container = new BasicTilesContainer();
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
         
EasyMock.expect(context.getAttribute(TilesAccess.CONTAINER_ATTRIBUTE)).andReturn(container);
         EasyMock.replay(context);
         assertEquals(container, TilesAccess.getContainer(context));

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-api/src/test/java/org/apache/tiles/access/TilesAccessTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java?view=auto&rev=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
 Wed Dec 13 12:24:14 2006
@@ -0,0 +1,120 @@
+/*
+ * $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.filter;
+
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.ComponentContext;
+import org.apache.tiles.ComponentAttribute;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * Processes Reloadable Tiles Definitions.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class TilesDecorationFilter implements Filter {
+
+    private static final Log LOG = 
LogFactory.getLog(TilesDecorationFilter.class);
+
+    /**
+     * The filter configuration object we are associated with.  If
+     * this value is null, this filter instance is not currently
+     * configured.
+     */
+    private FilterConfig filterConfig = null;
+
+    private ServletContext servletContext = null;
+
+    private String targetAttributeName = "body";
+
+    private String definition = "layout";
+
+
+    /**
+     * Checks whether Tiles Definitions need to be reloaded.
+     *
+     * @param request  The servlet request we are processing
+     * @param response The servlet response we are creating
+     * @param chain    The filter chain we are processing
+     * @throws java.io.IOException      if an input/output error occurs
+     * @throws javax.servlet.ServletException if a servlet error occurs
+     */
+    public void doFilter(ServletRequest request, ServletResponse response,
+                         FilterChain chain)
+        throws IOException, ServletException {
+
+        TilesContainer container = TilesAccess.getContainer(servletContext);
+        ComponentContext ctx = container.getComponentContext(request, 
response);
+
+        ComponentAttribute attr = new ComponentAttribute();
+        attr.setType(ComponentAttribute.TEMPLATE);
+        attr.setName(targetAttributeName);
+        attr.setValue(getTargetResource(request));
+        ctx.putAttribute(targetAttributeName, attr);
+
+        try {
+            container.render(request, response, definition);
+        } catch (TilesException e) {
+            throw new ServletException("Error wrapping jsp with tile 
definition.", e);
+        }
+    }
+
+    private String getTargetResource(ServletRequest request) {
+        HttpServletRequest req = (HttpServletRequest)request;
+        String includePath = (String)req.getAttribute("");
+        return includePath == null ? req.getServletPath() : includePath;
+
+    }
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        this.filterConfig = filterConfig;
+        String name = filterConfig.getInitParameter("target-attribute-name");
+        if(name != null) {
+            targetAttributeName = name;
+        }
+    }
+
+    /**
+     * Destroy method for this filter
+     */
+    public void destroy() {
+        this.filterConfig = null;
+        this.servletContext = null;
+        this.targetAttributeName = "body";
+    }
+
+
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesDecorationFilter.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java?view=diff&rev=486826&r1=486825&r2=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
 Wed Dec 13 12:24:14 2006
@@ -24,12 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.tiles.TilesContainer;
-import org.apache.tiles.access.TilesAccess;
-import org.apache.tiles.definition.DefinitionsFactory;
-import org.apache.tiles.definition.ReloadableDefinitionsFactory;
 import org.apache.tiles.definition.util.DefinitionsFactoryUtil;
-import org.apache.tiles.impl.BasicTilesContainer;
 import org.apache.tiles.servlet.TilesServlet;
 
 import javax.servlet.*;
@@ -113,7 +108,7 @@
         super.init(createServletConfig());
 
         if (debug) {
-            log("TilesFilter:Initializing filter");
+            log("TilesDecorationFilter:Initializing filter");
         }
     }
 

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=486826&r1=486825&r2=486826
==============================================================================
--- 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:24:14 2006
@@ -39,6 +39,25 @@
         <param-name>org.apache.tiles.CONTAINER_FACTORY.mutable</param-name>
         <param-value>true</param-value>
     </context-param>
+
+    <filter>
+        <filter-name>Tiles Decoration Filter</filter-name>
+        <filter-class>org.apache.tiles.web.TilesDecorationFilter</filter-class>
+        <init-param>
+            <param-name>definition</param-name>
+            <param-value>test.definition</param-value>
+        </init-param>
+        <init-param>
+            <param-name>attribute-name</param-name>
+            <param-value>body</param-value>
+        </init-param>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>Tiles Decoration Filter</filter-name>
+        <url-pattern>/testdecorationfilter.jsp</url-pattern>
+        <dispatcher>REQUEST</dispatcher>
+    </filter-mapping>
   
   <!-- Standard Action Servlet Configuration -->
   <servlet>

Added: 
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp?view=auto&rev=486826
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp 
(added)
+++ 
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp 
Wed Dec 13 12:24:14 2006
@@ -0,0 +1 @@
+<i>This Content should be wrapped with the standard layout.</i>
\ No newline at end of file

Propchange: 
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testdecorationfilter.jsp
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev


Reply via email to