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 2009/11/15 14:56:43 UTC

svn commit: r836360 - in /tiles/sandbox/trunk/tiles3: tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/ tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/ tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ tiles-t...

Author: apetrelli
Date: Sun Nov 15 13:56:42 2009
New Revision: 836360

URL: http://svn.apache.org/viewvc?rev=836360&view=rev
Log:
TILESSB-14
Moved dependency on the compose stack in the template.

Added:
    tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java   (with props)
Modified:
    tiles/sandbox/trunk/tiles3/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/AddAttributeFMModel.java
    tiles/sandbox/trunk/tiles3/tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/AddAttributeFMModelTest.java
    tiles/sandbox/trunk/tiles3/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
    tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/AddAttributeModel.java
    tiles/sandbox/trunk/tiles3/tiles-template/src/test/java/org/apache/tiles/template/AddAttributeModelTest.java
    tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/AddAttributeVModel.java
    tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/TilesVelocityRepository.java
    tiles/sandbox/trunk/tiles3/tiles-velocity/src/test/java/org/apache/tiles/velocity/template/AddAttributeVModelTest.java

Modified: tiles/sandbox/trunk/tiles3/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/AddAttributeFMModel.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/AddAttributeFMModel.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/AddAttributeFMModel.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/AddAttributeFMModel.java Sun Nov 15 13:56:42 2009
@@ -24,8 +24,10 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.tiles.ArrayStack;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.freemarker.context.FreeMarkerTilesRequestContext;
 import org.apache.tiles.freemarker.context.FreeMarkerUtil;
+import org.apache.tiles.request.Request;
 import org.apache.tiles.template.AddAttributeModel;
 
 import freemarker.core.Environment;
@@ -36,8 +38,8 @@
 
 /**
  * Wraps {@link AddAttributeModel} to be used in FreeMarker. For the list of
- * parameters, see {@link AddAttributeModel#start(ArrayStack)} and
- * {@link AddAttributeModel#end(ArrayStack, Object, String, String, String, String)}.
+ * parameters, see {@link AddAttributeModel#start(Request)} and
+ * {@link AddAttributeModel#end(Object, String, String, String, String, Request)}.
  *
  * @version $Rev$ $Date$
  * @since 2.2.0
@@ -63,12 +65,15 @@
     @SuppressWarnings("unchecked")
     public void execute(Environment env, Map params, TemplateModel[] loopVars,
             TemplateDirectiveBody body) throws TemplateException, IOException {
-        ArrayStack<Object> composeStack = FreeMarkerUtil.getComposeStack(env);
-        model.start(composeStack);
+        TilesContainer container = FreeMarkerUtil.getCurrentContainer(env);
+        Request request = FreeMarkerTilesRequestContext
+                .createServletFreemarkerRequest(container
+                        .getApplicationContext(), env);
+        model.start(request);
         String bodyString = FreeMarkerUtil.renderAsString(body);
-        Map<String, TemplateModel> parms = (Map<String, TemplateModel>) params;
-        model.end(composeStack, FreeMarkerUtil.getAsObject(parms.get("value")),
-                FreeMarkerUtil.getAsString(parms.get("expression")), bodyString,
-                FreeMarkerUtil.getAsString(parms.get("role")), FreeMarkerUtil.getAsString(parms.get("type")));
+        Map<String, TemplateModel> parms = params;
+        model.end(FreeMarkerUtil.getAsObject(parms.get("value")), FreeMarkerUtil.getAsString(parms.get("expression")),
+                bodyString, FreeMarkerUtil.getAsString(parms.get("role")),
+                FreeMarkerUtil.getAsString(parms.get("type")), request);
     }
 }

Modified: tiles/sandbox/trunk/tiles3/tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/AddAttributeFMModelTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/AddAttributeFMModelTest.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/AddAttributeFMModelTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-freemarker/src/test/java/org/apache/tiles/freemarker/template/AddAttributeFMModelTest.java Sun Nov 15 13:56:42 2009
@@ -30,10 +30,15 @@
 import java.util.Locale;
 import java.util.Map;
 
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.tiles.ArrayStack;
-import org.apache.tiles.freemarker.context.FreeMarkerUtil;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.access.TilesAccess;
+import org.apache.tiles.freemarker.context.FreeMarkerTilesRequestContext;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.servlet.context.ServletUtil;
 import org.apache.tiles.template.AddAttributeModel;
 import org.junit.Before;
 import org.junit.Test;
@@ -41,6 +46,7 @@
 import freemarker.core.Environment;
 import freemarker.ext.servlet.FreemarkerServlet;
 import freemarker.ext.servlet.HttpRequestHashModel;
+import freemarker.ext.servlet.ServletContextHashModel;
 import freemarker.template.DefaultObjectWrapper;
 import freemarker.template.ObjectWrapper;
 import freemarker.template.Template;
@@ -86,10 +92,10 @@
     private ObjectWrapper objectWrapper;
 
     /**
-     * @throws java.lang.Exception If something goes wrong.
+     * Sets up the model.
      */
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         template = createMock(Template.class);
         model = createMock(TemplateHashModel.class);
         expect(template.getMacros()).andReturn(new HashMap<Object, Object>());
@@ -109,13 +115,25 @@
         AddAttributeModel tModel = createMock(AddAttributeModel.class);
         AddAttributeFMModel fmModel = new AddAttributeFMModel(tModel);
         HttpServletRequest request = createMock(HttpServletRequest.class);
+        TilesContainer container = createMock(TilesContainer.class);
 
         HttpRequestHashModel requestModel = new HttpRequestHashModel(request, objectWrapper);
-        expect(model.get(FreemarkerServlet.KEY_REQUEST)).andReturn(requestModel);
+        GenericServlet servlet = createMock(GenericServlet.class);
+        ServletContext servletContext = createMock(ServletContext.class);
+        ApplicationContext applicationContext = createMock(ApplicationContext.class);
+
+        expect(container.getApplicationContext()).andReturn(applicationContext);
+        expect(servlet.getServletContext()).andReturn(servletContext).anyTimes();
+        expect(servletContext.getAttribute(TilesAccess.CONTAINER_ATTRIBUTE)).andReturn(container);
+        replay(servlet, servletContext);
+        ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, objectWrapper);
+        expect(model.get(FreemarkerServlet.KEY_REQUEST)).andReturn(requestModel).anyTimes();
+        expect(model.get(FreemarkerServlet.KEY_APPLICATION)).andReturn(servletContextModel).anyTimes();
         initEnvironment();
+        expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(null);
+        request.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
 
         TemplateDirectiveBody body = createMock(TemplateDirectiveBody.class);
-        ArrayStack<Object> composeStack = new ArrayStack<Object>();
         Map<String, Object> params = new HashMap<String, Object>();
         Integer value = new Integer(1);
         params.put("value", objectWrapper.wrap(value));
@@ -123,15 +141,15 @@
         params.put("role", objectWrapper.wrap("myRole"));
         params.put("type", objectWrapper.wrap("myType"));
 
-        expect(request.getAttribute(FreeMarkerUtil.COMPOSE_STACK_ATTRIBUTE_NAME)).andReturn(composeStack);
-        tModel.start(composeStack);
-        tModel.end(composeStack, value, "myExpression", "",
-                "myRole", "myType");
+        tModel.start(isA(FreeMarkerTilesRequestContext.class));
+        tModel.end(eq(value), eq("myExpression"), eq(""), eq("myRole"),
+                eq("myType"), isA(FreeMarkerTilesRequestContext.class));
         body.render(isA(StringWriter.class));
 
-        replay(request, tModel, body);
+        replay(request, tModel, body, container, applicationContext);
         fmModel.execute(env, params, null, body);
-        verify(template, model, request, tModel, body);
+        verify(servlet, servletContext, template, model, request, tModel, body,
+                container, applicationContext);
     }
 
     /**

Modified: tiles/sandbox/trunk/tiles3/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java Sun Nov 15 13:56:42 2009
@@ -25,36 +25,47 @@
 
 import javax.servlet.jsp.JspContext;
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.SimpleTagSupport;
 
+import org.apache.tiles.TilesContainer;
 import org.apache.tiles.jsp.JspUtil;
+import org.apache.tiles.jsp.context.JspTilesRequestContext;
+import org.apache.tiles.request.Request;
 import org.apache.tiles.template.AddAttributeModel;
 
 /**
- * <p><strong>Adds an attribute in enclosing attribute container tag.</strong></p>
- * <p>Enclosing attribute container tag can be :
+ * <p>
+ * <strong>Adds an attribute in enclosing attribute container tag.</strong>
+ * </p>
+ * <p>
+ * Enclosing attribute container tag can be :
  * <ul>
  * <li>&lt;putListAttribute&gt;</li>
  * <li>&lt;putAttribute&gt;</li>
  * </ul>
- * Exception is thrown if no appropriate tag can be found.</p>
- * <p>Put tag can have following atributes :
+ * Exception is thrown if no appropriate tag can be found.
+ * </p>
+ * <p>
+ * Put tag can have following atributes :
  * <ul>
  * <li>name : Name of the attribute</li>
  * <li>value : value to put as attribute</li>
  * <li>type : value type. Only valid if value is a String and is set by
- * value="something" or by a bean.
- * Possible type are : string (value is used as direct string),
- * template (value is used as a page url to insert),
- * definition (value is used as a definition name to insert)</li>
+ * value="something" or by a bean. Possible type are : string (value is used as
+ * direct string), template (value is used as a page url to insert), definition
+ * (value is used as a definition name to insert)</li>
  * <li>role : Role to check when 'insert' will be called. If enclosing tag is
  * &lt;insert&gt;, role is checked immediately. If enclosing tag is
  * &lt;definition&gt;, role will be checked when this definition will be
  * inserted.</li>
- * </ul></p>
- * <p>Value can also come from tag body. Tag body is taken into account only if
+ * </ul>
+ * </p>
+ * <p>
+ * Value can also come from tag body. Tag body is taken into account only if
  * value is not set by one of the tag attributes. In this case Attribute type is
- * "string", unless tag body define another type.</p>
+ * "string", unless tag body define another type.
+ * </p>
  *
  * @version $Rev$ $Date$
  */
@@ -88,8 +99,8 @@
     private String type = null;
 
     /**
-     * Returns the role to check. If the user is in the specified role, the tag is
-     * taken into account; otherwise, the tag is ignored (skipped).
+     * Returns the role to check. If the user is in the specified role, the tag
+     * is taken into account; otherwise, the tag is ignored (skipped).
      *
      * @return The role to check.
      */
@@ -155,8 +166,8 @@
      * <li>String : Content is printed directly.</li>
      * <li>template : Content is included from specified URL. Value is used as
      * an URL.</li>
-     * <li>definition : Value denote a definition defined in factory (xml
-     * file). Definition will be searched in the inserted tile, in a
+     * <li>definition : Value denote a definition defined in factory (xml file).
+     * Definition will be searched in the inserted tile, in a
      * <code>&lt;insert attribute="attributeName"&gt;</code> tag, where
      * 'attributeName' is the name used for this tag.</li>
      * </ul>
@@ -175,8 +186,8 @@
      * <li>String : Content is printed directly.</li>
      * <li>template : Content is included from specified URL. Value is used as
      * an URL.</li>
-     * <li>definition : Value denote a definition defined in factory (xml
-     * file). Definition will be searched in the inserted tile, in a
+     * <li>definition : Value denote a definition defined in factory (xml file).
+     * Definition will be searched in the inserted tile, in a
      * <code>&lt;insert attribute="attributeName"&gt;</code> tag, where
      * 'attributeName' is the name used for this tag.</li>
      * </ul>
@@ -191,9 +202,14 @@
     @Override
     public void doTag() throws JspException, IOException {
         JspContext pageContext = getJspContext();
-        model.start(JspUtil.getComposeStack(pageContext));
+        TilesContainer currentContainer = JspUtil
+                .getCurrentContainer(pageContext);
+        Request request = JspTilesRequestContext.createServletJspRequest(
+                currentContainer.getApplicationContext(),
+                (PageContext) pageContext);
+        model.start(request);
         String body = JspUtil.evaluateFragmentAsString(getJspBody());
-        model.end(JspUtil.getComposeStack(pageContext), value, expression,
-                body, role, type);
+        model.end(value, expression, body,
+                role, type, request);
     }
 }

Modified: tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/AddAttributeModel.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/AddAttributeModel.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/AddAttributeModel.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/AddAttributeModel.java Sun Nov 15 13:56:42 2009
@@ -25,6 +25,7 @@
 import org.apache.tiles.Attribute;
 import org.apache.tiles.Expression;
 import org.apache.tiles.ListAttribute;
+import org.apache.tiles.request.Request;
 
 /**
  * <p>
@@ -45,19 +46,18 @@
 
     /**
      * Starts the operation..
+     * @param request TODO
      *
-     * @param composeStack The composing stack.
      * @since 2.2.0
      */
-    public void start(ArrayStack<Object> composeStack) {
+    public void start(Request request) {
         Attribute attribute = new Attribute();
-        composeStack.push(attribute);
+        ArrayStack<Object> composeStack2 = TilesTemplateUtil.getComposeStack(request);
+        composeStack2.push(attribute);
     }
 
     /**
      * Ends the operation.
-     *
-     * @param composeStack The composing stack.
      * @param value The value of the attribute. Use this parameter, or
      * expression, or body.
      * @param expression The expression to calculate the value from. Use this
@@ -67,19 +67,20 @@
      * @param role A comma-separated list of roles. If present, the attribute
      * will be rendered only if the current user belongs to one of the roles.
      * @param type The type (renderer) of the attribute.
+     * @param request TODO
+     *
      * @since 2.2.0
      */
-    public void end(ArrayStack<Object> composeStack, Object value,
-            String expression, String body, String role, String type) {
-        Attribute attribute = (Attribute) composeStack.pop();
-        addAttributeToList(attribute, composeStack, value, expression, body,
+    public void end(Object value, String expression,
+            String body, String role, String type, Request request) {
+        ArrayStack<Object> composeStack2 = TilesTemplateUtil.getComposeStack(request);
+        Attribute attribute = (Attribute) composeStack2.pop();
+        addAttributeToList(attribute, composeStack2, value, expression, body,
                 role, type);
     }
 
     /**
      * Executes the operation.
-     *
-     * @param composeStack The composing stack.
      * @param value The value of the attribute. Use this parameter, or
      * expression, or body.
      * @param expression The expression to calculate the value from. Use this
@@ -89,11 +90,14 @@
      * @param role A comma-separated list of roles. If present, the attribute
      * will be rendered only if the current user belongs to one of the roles.
      * @param type The type (renderer) of the attribute.
+     * @param request TODO
+     *
      * @since 2.2.0
      */
-    public void execute(ArrayStack<Object> composeStack, Object value,
-            String expression, String body, String role, String type) {
-        addAttributeToList(new Attribute(), composeStack, value, expression,
+    public void execute(Object value, String expression,
+            String body, String role, String type, Request request) {
+        ArrayStack<Object> composeStack2 = TilesTemplateUtil.getComposeStack(request);
+        addAttributeToList(new Attribute(), composeStack2, value, expression,
                 body, role, type);
     }
 

Added: tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java?rev=836360&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java (added)
+++ tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java Sun Nov 15 13:56:42 2009
@@ -0,0 +1,37 @@
+package org.apache.tiles.template;
+
+import java.util.Map;
+
+import org.apache.tiles.ArrayStack;
+import org.apache.tiles.request.Request;
+
+public final class TilesTemplateUtil {
+
+    /**
+     * The name of the attribute that holds the compose stack.
+     */
+    public static final String COMPOSE_STACK_ATTRIBUTE_NAME = "org.apache.tiles.template.COMPOSE_STACK";
+
+    private TilesTemplateUtil() {
+    }
+
+
+    /**
+     * Returns the current compose stack, or creates a new one if not present.
+     *
+     * @param env The current FreeMarker environment.
+     * @return The compose stack.
+     * @since 2.2.0
+     */
+    @SuppressWarnings("unchecked")
+    public static ArrayStack<Object> getComposeStack(Request request) {
+        Map<String, Object> requestScope = request.getRequestScope();
+        ArrayStack<Object> composeStack = (ArrayStack<Object>) requestScope
+                .get(COMPOSE_STACK_ATTRIBUTE_NAME);
+        if (composeStack == null) {
+            composeStack = new ArrayStack<Object>();
+            requestScope.put(COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
+        }
+        return composeStack;
+    }
+}

Propchange: tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles3/tiles-template/src/main/java/org/apache/tiles/template/TilesTemplateUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/sandbox/trunk/tiles3/tiles-template/src/test/java/org/apache/tiles/template/AddAttributeModelTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-template/src/test/java/org/apache/tiles/template/AddAttributeModelTest.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-template/src/test/java/org/apache/tiles/template/AddAttributeModelTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-template/src/test/java/org/apache/tiles/template/AddAttributeModelTest.java Sun Nov 15 13:56:42 2009
@@ -24,11 +24,14 @@
 import static org.easymock.classextension.EasyMock.*;
 import static org.junit.Assert.*;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.tiles.ArrayStack;
 import org.apache.tiles.Attribute;
 import org.apache.tiles.ListAttribute;
+import org.apache.tiles.request.Request;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -51,77 +54,92 @@
     }
 
     /**
-     * Test method for {@link org.apache.tiles.template.AddAttributeModel#start(java.util.Stack)}.
+     * Test method for {@link org.apache.tiles.template.AddAttributeModel#start(Request)}.
      */
     @SuppressWarnings("unchecked")
     @Test
     public void testStart() {
         ArrayStack<Object> composeStack = createMock(ArrayStack.class);
+        Request request = createMock(Request.class);
         Attribute attribute = new Attribute();
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+        requestScope.put(TilesTemplateUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
 
         expect(composeStack.push(isA(Attribute.class))).andReturn(attribute);
+        expect(request.getRequestScope()).andReturn(requestScope);
 
-        replay(composeStack);
-        model.start(composeStack);
-        verify(composeStack);
+        replay(composeStack, request);
+        model.start(request);
+        verify(composeStack, request);
     }
 
     /**
      * Test method for
      * {@link org.apache.tiles.template.AddAttributeModel
-     * #end(java.util.Stack, java.lang.Object, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}
+     * #end(java.lang.Object, java.lang.String, java.lang.String, java.lang.String, java.lang.String, Request)}
      * .
      */
-    @SuppressWarnings("unchecked")
     @Test
     public void testEnd() {
         ArrayStack<Object> composeStack = new ArrayStack<Object>();
+        Request request = createMock(Request.class);
         ListAttribute listAttribute = new ListAttribute();
         Attribute attribute = new Attribute();
         composeStack.push(listAttribute);
         composeStack.push(attribute);
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+        requestScope.put(TilesTemplateUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
+
+        expect(request.getRequestScope()).andReturn(requestScope).times(2);
 
-        model.end(composeStack, "myValue", "myExpression", "myBody", "myRole",
-                "myType");
-        assertEquals(1, ((List<Attribute>) listAttribute.getValue()).size());
+        replay(request);
+        model.end("myValue", "myExpression", "myBody", "myRole", "myType",
+                request);
+        assertEquals(1, listAttribute.getValue().size());
         assertEquals("myValue", attribute.getValue());
         assertEquals("myExpression", attribute.getExpressionObject()
                 .getExpression());
         assertEquals("myRole", attribute.getRole());
         assertEquals("myType", attribute.getRenderer());
 
-        composeStack = new ArrayStack<Object>();
+        composeStack.clear();
         listAttribute = new ListAttribute();
         attribute = new Attribute();
         composeStack.push(listAttribute);
         composeStack.push(attribute);
 
-        model.end(composeStack, null, "myExpression", "myBody", "myRole",
-                "myType");
-        assertEquals(1, ((List<Attribute>) listAttribute.getValue()).size());
+        model.end(null, "myExpression", "myBody", "myRole", "myType",
+                request);
+        assertEquals(1, listAttribute.getValue().size());
         assertEquals("myBody", attribute.getValue());
         assertEquals("myExpression", attribute.getExpressionObject()
                 .getExpression());
         assertEquals("myRole", attribute.getRole());
         assertEquals("myType", attribute.getRenderer());
+        verify(request);
     }
 
     /**
      * Test method for {@link org.apache.tiles.template.AddAttributeModel
-     * #execute(java.util.Stack, java.lang.Object, java.lang.String, java.lang.String,
-     * java.lang.String, java.lang.String)}.
+     * #execute(java.lang.Object, java.lang.String, java.lang.String, java.lang.String,
+     * java.lang.String, Request)}.
      */
-    @SuppressWarnings("unchecked")
     @Test
     public void testExecute() {
+        Request request = createMock(Request.class);
         ArrayStack<Object> composeStack = new ArrayStack<Object>();
         ListAttribute listAttribute = new ListAttribute();
         Attribute attribute;
         composeStack.push(listAttribute);
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+        requestScope.put(TilesTemplateUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
+
+        expect(request.getRequestScope()).andReturn(requestScope).times(2);
 
-        model.execute(composeStack, "myValue", "myExpression", "myBody",
-                "myRole", "myType");
-        List<Attribute> attributes = (List<Attribute>) listAttribute.getValue();
+        replay(request);
+        model.execute("myValue", "myExpression", "myBody", "myRole",
+                "myType", request);
+        List<Attribute> attributes = listAttribute.getValue();
         assertEquals(1, attributes.size());
         attribute = attributes.iterator().next();
         assertEquals("myValue", attribute.getValue());
@@ -129,15 +147,15 @@
         assertEquals("myRole", attribute.getRole());
         assertEquals("myType", attribute.getRenderer());
 
-        composeStack = new ArrayStack<Object>();
+        composeStack.clear();
         listAttribute = new ListAttribute();
         attribute = new Attribute();
         composeStack.push(listAttribute);
         composeStack.push(attribute);
 
-        model.execute(composeStack, null, "myExpression", "myBody", "myRole",
-                "myType");
-        attributes = (List<Attribute>) listAttribute.getValue();
+        model.execute(null, "myExpression", "myBody", "myRole", "myType",
+                request);
+        attributes = listAttribute.getValue();
         assertEquals(1, attributes.size());
         attribute = attributes.iterator().next();
         assertEquals("myBody", attribute.getValue());
@@ -145,6 +163,7 @@
                 .getExpression());
         assertEquals("myRole", attribute.getRole());
         assertEquals("myType", attribute.getRenderer());
+        verify(request);
     }
 
 }

Modified: tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/AddAttributeVModel.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/AddAttributeVModel.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/AddAttributeVModel.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/AddAttributeVModel.java Sun Nov 15 13:56:42 2009
@@ -23,20 +23,24 @@
 
 import java.util.Map;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.request.Request;
 import org.apache.tiles.servlet.context.ServletUtil;
 import org.apache.tiles.template.AddAttributeModel;
+import org.apache.tiles.velocity.context.VelocityTilesRequestContext;
 import org.apache.tiles.velocity.context.VelocityUtil;
 import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.Renderable;
 
 /**
  * Wraps {@link AddAttributeModel} to be used in Velocity. For the list of
- * parameters, see {@link AddAttributeModel#start(java.util.Stack)},
- * {@link AddAttributeModel#end(java.util.Stack, Object, String, String, String, String)}
- * and {@link AddAttributeModel#execute(java.util.Stack, Object, String, String, String, String)}
+ * parameters, see {@link AddAttributeModel#start(Request)},
+ * {@link AddAttributeModel#end(Object, String, String, String, String, Request)}
+ * and {@link AddAttributeModel#execute(Object, String, String, String, String, Request)}
  *
  * @version $Rev$ $Date$
  * @since 2.2.0
@@ -49,22 +53,35 @@
     private AddAttributeModel model;
 
     /**
+     * The Servlet context.
+     */
+    private ServletContext servletContext;
+
+    /**
      * Constructor.
      *
      * @param model The template model.
+     * @param servletContext TODO
      * @since 2.2.0
      */
-    public AddAttributeVModel(AddAttributeModel model) {
+    public AddAttributeVModel(AddAttributeModel model, ServletContext servletContext) {
         this.model = model;
+        this.servletContext = servletContext;
     }
 
     /** {@inheritDoc} */
     public Renderable execute(HttpServletRequest request,
             HttpServletResponse response, Context velocityContext,
             Map<String, Object> params) {
-        model.execute(ServletUtil.getComposeStack(request),
-                params.get("value"), (String) params.get("expression"), null,
-                (String) params.get("role"), (String) params.get("type"));
+        TilesContainer container = ServletUtil.getCurrentContainer(
+                request, servletContext);
+        Request currentRequest = VelocityTilesRequestContext
+                .createVelocityRequest(container
+                        .getApplicationContext(), request, response,
+                        velocityContext, null);
+        model.execute(params.get("value"),
+                (String) params.get("expression"), null, (String) params.get("role"),
+                (String) params.get("type"), currentRequest);
         return VelocityUtil.EMPTY_RENDERABLE;
     }
 
@@ -73,9 +90,15 @@
             Context velocityContext) {
         Map<String, Object> params = VelocityUtil.getParameterStack(
                 velocityContext).pop();
-        model.end(ServletUtil.getComposeStack(request), params.get("value"),
-                (String) params.get("expression"), null, (String) params
-                        .get("role"), (String) params.get("type"));
+        TilesContainer container = ServletUtil.getCurrentContainer(
+                request, servletContext);
+        Request currentRequest = VelocityTilesRequestContext
+                .createVelocityRequest(container
+                        .getApplicationContext(), request, response,
+                        velocityContext, null);
+        model.end(params.get("value"), (String) params.get("expression"),
+                null, (String) params
+                        .get("role"), (String) params.get("type"), currentRequest);
         return VelocityUtil.EMPTY_RENDERABLE;
     }
 
@@ -83,6 +106,12 @@
     public void start(HttpServletRequest request, HttpServletResponse response,
             Context velocityContext, Map<String, Object> params) {
         VelocityUtil.getParameterStack(velocityContext).push(params);
-        model.start(ServletUtil.getComposeStack(request));
+        TilesContainer container = ServletUtil.getCurrentContainer(
+                request, servletContext);
+        Request currentRequest = VelocityTilesRequestContext
+                .createVelocityRequest(container
+                        .getApplicationContext(), request, response,
+                        velocityContext, null);
+        model.start(currentRequest);
     }
 }

Modified: tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/TilesVelocityRepository.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/TilesVelocityRepository.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/TilesVelocityRepository.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-velocity/src/main/java/org/apache/tiles/velocity/template/TilesVelocityRepository.java Sun Nov 15 13:56:42 2009
@@ -103,7 +103,7 @@
     public TilesVelocityRepository(ServletContext servletContext) {
         AttributeResolver attributeResolver = new DefaultAttributeResolver();
 
-        addAttribute = new AddAttributeVModel(new AddAttributeModel());
+        addAttribute = new AddAttributeVModel(new AddAttributeModel(), servletContext);
         addListAttribute = new AddListAttributeVModel(
                 new AddListAttributeModel());
         definition = new DefinitionVModel(new DefinitionModel(), servletContext);

Modified: tiles/sandbox/trunk/tiles3/tiles-velocity/src/test/java/org/apache/tiles/velocity/template/AddAttributeVModelTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-velocity/src/test/java/org/apache/tiles/velocity/template/AddAttributeVModelTest.java?rev=836360&r1=836359&r2=836360&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-velocity/src/test/java/org/apache/tiles/velocity/template/AddAttributeVModelTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-velocity/src/test/java/org/apache/tiles/velocity/template/AddAttributeVModelTest.java Sun Nov 15 13:56:42 2009
@@ -28,12 +28,16 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tiles.ArrayStack;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.request.ApplicationContext;
 import org.apache.tiles.servlet.context.ServletUtil;
 import org.apache.tiles.template.AddAttributeModel;
+import org.apache.tiles.velocity.context.VelocityTilesRequestContext;
 import org.apache.tiles.velocity.context.VelocityUtil;
 import org.apache.velocity.context.Context;
 import org.junit.Before;
@@ -55,6 +59,11 @@
     private AddAttributeVModel model;
 
     /**
+     * The servlet context.
+     */
+    private ServletContext servletContext;
+
+    /**
      * The template model.
      */
     private AddAttributeModel tModel;
@@ -65,7 +74,8 @@
     @Before
     public void setUp() {
         tModel = createMock(AddAttributeModel.class);
-        model = new AddAttributeVModel(tModel);
+        servletContext = createMock(ServletContext.class);
+        model = new AddAttributeVModel(tModel, servletContext);
     }
 
     /**
@@ -78,16 +88,18 @@
         HttpServletRequest request = createMock(HttpServletRequest.class);
         HttpServletResponse response = createMock(HttpServletResponse.class);
         Context velocityContext = createMock(Context.class);
+        TilesContainer container = createMock(TilesContainer.class);
         Map<String, Object> params = createParams();
-        ArrayStack<Object> composeStack = new ArrayStack<Object>();
+        ApplicationContext applicationContext = createMock(ApplicationContext.class);
 
-        expect(request.getAttribute(ServletUtil.COMPOSE_STACK_ATTRIBUTE_NAME))
-                .andReturn(composeStack);
-        tModel.execute(composeStack, "myValue", "myExpression", null, "myRole", "myType");
+        expect(container.getApplicationContext()).andReturn(applicationContext);
+        expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(container);
+        tModel.execute(eq("myValue"), eq("myExpression"), (String) isNull(),
+                eq("myRole"), eq("myType"), isA(VelocityTilesRequestContext.class));
 
-        replay(tModel, request, response, velocityContext);
+        replay(tModel, request, response, velocityContext, servletContext, container, applicationContext);
         assertEquals(VelocityUtil.EMPTY_RENDERABLE, model.execute(request, response, velocityContext, params));
-        verify(tModel, request, response, velocityContext);
+        verify(tModel, request, response, velocityContext, servletContext, container, applicationContext);
     }
 
     /**
@@ -101,19 +113,20 @@
         HttpServletResponse response = createMock(HttpServletResponse.class);
         Context velocityContext = createMock(Context.class);
         Map<String, Object> params = createParams();
-        ArrayStack<Object> composeStack = new ArrayStack<Object>();
         ArrayStack<Map<String, Object>> parameterMapStack = new ArrayStack<Map<String, Object>>();
+        TilesContainer container = createMock(TilesContainer.class);
+        ApplicationContext applicationContext = createMock(ApplicationContext.class);
 
-        expect(request.getAttribute(ServletUtil.COMPOSE_STACK_ATTRIBUTE_NAME))
-                .andReturn(composeStack);
+        expect(container.getApplicationContext()).andReturn(applicationContext);
+        expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(container);
         expect(velocityContext.get(PARAMETER_MAP_STACK_KEY)).andReturn(parameterMapStack);
-        tModel.start(composeStack);
+        tModel.start(isA(VelocityTilesRequestContext.class));
 
-        replay(tModel, request, response, velocityContext);
+        replay(tModel, request, response, velocityContext, servletContext, container, applicationContext);
         model.start(request, response, velocityContext, params);
         assertEquals(1, parameterMapStack.size());
         assertEquals(params, parameterMapStack.peek());
-        verify(tModel, request, response, velocityContext);
+        verify(tModel, request, response, velocityContext, servletContext, container, applicationContext);
     }
 
     /**
@@ -127,20 +140,21 @@
         HttpServletResponse response = createMock(HttpServletResponse.class);
         Context velocityContext = createMock(Context.class);
         Map<String, Object> params = createParams();
-        ArrayStack<Object> composeStack = new ArrayStack<Object>();
         ArrayStack<Map<String, Object>> parameterMapStack = new ArrayStack<Map<String, Object>>();
         parameterMapStack.push(params);
+        TilesContainer container = createMock(TilesContainer.class);
+        ApplicationContext applicationContext = createMock(ApplicationContext.class);
 
-        expect(request.getAttribute(ServletUtil.COMPOSE_STACK_ATTRIBUTE_NAME))
-                .andReturn(composeStack);
+        expect(container.getApplicationContext()).andReturn(applicationContext);
+        expect(request.getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME)).andReturn(container);
         expect(velocityContext.get(PARAMETER_MAP_STACK_KEY)).andReturn(parameterMapStack);
-        tModel.end(composeStack, "myValue", "myExpression",
-                null, "myRole", "myType");
+        tModel.end(eq("myValue"), eq("myExpression"), (String) isNull(),
+                eq("myRole"), eq("myType"), isA(VelocityTilesRequestContext.class));
 
-        replay(tModel, request, response, velocityContext);
+        replay(tModel, request, response, velocityContext, container, applicationContext);
         assertEquals(VelocityUtil.EMPTY_RENDERABLE, model.end(request, response, velocityContext));
         assertTrue(parameterMapStack.isEmpty());
-        verify(tModel, request, response, velocityContext);
+        verify(tModel, request, response, velocityContext, container, applicationContext);
     }
 
     /**