Author: apetrelli
Date: Thu Feb 26 13:03:05 2009
New Revision: 748125

URL: http://svn.apache.org/viewvc?rev=748125&view=rev
Log:
TILESSB-7
Created all VModels, now they need to be attached to Tiles2Tool.

Added:
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
   (with props)
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java
   (with props)
Modified:
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Tiles2Tool.java
    
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/VelocityUtil.java

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,43 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.AddAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class AddAttributeVModel implements Executable, BodyExecutable {
+
+    private AddAttributeModel model;
+
+    public AddAttributeVModel(AddAttributeModel model) {
+        this.model = model;
+    }
+
+    public void 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"));
+
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            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"));
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request));
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,30 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.AddListAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class AddListAttributeVModel implements BodyExecutable {
+
+    private AddListAttributeModel model;
+    
+    public AddListAttributeVModel(AddListAttributeModel model) {
+        this.model = model;
+    }
+    
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        model.end(ServletUtil.getComposeStack(request));
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        model.start(ServletUtil.getComposeStack(request), (String) 
params.get("role"));
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/AddListAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,34 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.velocity.context.Context;
+
+
+
+public interface BodyExecutable {
+
+    /**
+     * Returns a string representation of attribute value. If the attribute is
+     * <code>null</code> or if the attribute value is <code>null</code>,
+     * <code>null</code> is returned
+     * @param request TODO
+     * @param response TODO
+     * @param velocityContext TODO
+     */
+    public abstract void start(HttpServletRequest request, HttpServletResponse 
response, Context velocityContext, Map<String, Object> params);
+
+    /**
+     * Returns a string representation of attribute value. If the attribute is
+     * <code>null</code> or if the attribute value is <code>null</code>,
+     * <code>null</code> is returned
+     * @param request TODO
+     * @param response TODO
+     * @param velocityContext TODO
+     */
+    public abstract void end(HttpServletRequest request, HttpServletResponse 
response, Context velocityContext);
+
+}
\ No newline at end of file

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/BodyExecutable.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,81 @@
+package org.apache.tiles.velocity;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.velocity.context.Context;
+
+public class ContextHolder {
+
+    private Context velocityContext;
+    private HttpServletRequest request;
+    private HttpServletResponse response;
+    private ServletContext application;
+
+    /**
+     * Sets the current {...@link HttpServletRequest}. This is required for 
this
+     * tool to operate and will throw a NullPointerException if this is not set
+     * or is set to {...@code null}.
+     */
+    public void setRequest(HttpServletRequest request) {
+        if (request == null) {
+            throw new NullPointerException("request should not be null");
+        }
+        this.request = request;
+    }
+
+    /**
+     * Sets the current {...@link HttpServletResponse}. This is required for 
this
+     * tool to operate and will throw a NullPointerException if this is not set
+     * or is set to {...@code null}.
+     */
+    public void setResponse(HttpServletResponse response) {
+        if (response == null) {
+            throw new NullPointerException("response should not be null");
+        }
+        this.response = response;
+    }
+
+    /**
+     * Sets the {...@link ServletContext}. This is required for this tool to
+     * operate and will throw a NullPointerException if this is not set or is
+     * set to {...@code null}.
+     */
+    public void setServletContext(ServletContext application) {
+        if (application == null) {
+            throw new NullPointerException("servlet context should not be 
null");
+        }
+        this.application = application;
+    }
+
+    /**
+     * Initializes this tool.
+     * 
+     * @param context the current {...@link Context}
+     * @throws IllegalArgumentException if the param is not a {...@link 
Context}
+     */
+    public void setVelocityContext(Context context) {
+        if (context == null) {
+            throw new NullPointerException(
+                    "velocity context should not be null");
+        }
+        this.velocityContext = context;
+    }
+
+    protected HttpServletRequest getRequest() {
+        return request;
+    }
+
+    protected HttpServletResponse getResponse() {
+        return response;
+    }
+
+    protected ServletContext getServletContext() {
+        return application;
+    }
+
+    protected Context getVelocityContext() {
+        return velocityContext;
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ContextHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,56 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.mgmt.MutableTilesContainer;
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.DefinitionModel;
+import org.apache.velocity.context.Context;
+
+public class DefinitionVModel implements Executable, BodyExecutable {
+
+    private DefinitionModel model;
+
+    private ServletContext servletContext;
+
+    public DefinitionVModel(DefinitionModel model, ServletContext 
servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        model.execute((MutableTilesContainer) ServletUtil.getCurrentContainer(
+                request, servletContext), ServletUtil.getComposeStack(request),
+                (String) params.get("name"), (String) params.get("template"),
+                (String) params.get("role"), (String) params.get("extends"),
+                (String) params.get("preparer"), velocityContext, request,
+                response);
+
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = VelocityUtil.getParameterStack(
+                velocityContext).pop();
+        model.end((MutableTilesContainer) ServletUtil.getCurrentContainer(
+                request, servletContext), ServletUtil
+                .getComposeStack(request), (String) params.get("name"),
+                velocityContext, request, response);
+
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request), (String) params
+                .get("name"), (String) params.get("template"), (String) params
+                .get("role"), (String) params.get("extends"), (String) params
+                .get("preparer"));
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/DefinitionVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,24 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.velocity.context.Context;
+
+
+
+public interface Executable {
+
+    /**
+     * Returns a string representation of attribute value. If the attribute is
+     * <code>null</code> or if the attribute value is <code>null</code>,
+     * <code>null</code> is returned
+     * @param request TODO
+     * @param response TODO
+     * @param velocityContext TODO
+     */
+    void execute(HttpServletRequest request, HttpServletResponse response, 
Context velocityContext, Map<String, Object> params);
+
+}
\ No newline at end of file

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Executable.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,70 @@
+package org.apache.tiles.velocity;
+
+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.tiles.Attribute;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.GetAsStringModel;
+import org.apache.velocity.context.Context;
+
+public class GetAsStringVModel implements Executable, BodyExecutable {
+
+    private GetAsStringModel model;
+
+    private ServletContext servletContext;
+    
+    public GetAsStringVModel(GetAsStringModel model, ServletContext 
servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+    
+    public void execute(HttpServletRequest request, HttpServletResponse 
response, Context velocityContext, Map<String, Object> params) {
+        TilesContainer container = ServletUtil.getCurrentContainer(request,
+                servletContext);
+        try {
+            model.execute(container, response.getWriter(), VelocityUtil
+                    .toSimpleBoolean((Boolean) params.get("ignore"), false),
+                    (String) params.get("preparer"), (String) 
params.get("role"),
+                    params.get("defaultValue"), (String) params
+                            .get("defaultValueRole"), (String) params
+                            .get("defaultValueType"), (String) 
params.get("name"),
+                    (Attribute) params.get("value"), velocityContext, request,
+                    response);
+        } catch (IOException e) {
+            throw new TilesVelocityException("Cannot execute getAsString", e);
+        }
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse 
response, Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request), ServletUtil
+                .getCurrentContainer(request, servletContext), VelocityUtil
+                .toSimpleBoolean((Boolean) params.get("ignore"), false),
+                (String) params.get("preparer"), (String) params.get("role"),
+                params.get("defaultValue"), (String) params
+                        .get("defaultValueRole"), (String) params
+                        .get("defaultValueType"), (String) params.get("name"),
+                (Attribute) params.get("value"), velocityContext, request,
+                response);
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response, 
Context velocityContext) {
+        Map<String, Object> params = VelocityUtil.getParameterStack(
+                velocityContext).pop();
+        try {
+            model.end(ServletUtil.getComposeStack(request), ServletUtil
+                    .getCurrentContainer(request, servletContext), response
+                    .getWriter(), VelocityUtil.toSimpleBoolean((Boolean) params
+                    .get("ignore"), false), velocityContext, request, 
response);
+        } catch (IOException e) {
+            throw new TilesVelocityException("Cannot end getAsString", e);
+        }
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/GetAsStringVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,40 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.ImportAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class ImportAttributeVModel implements Executable {
+
+    private ImportAttributeModel model;
+
+    private ServletContext servletContext;
+
+    public ImportAttributeVModel(ImportAttributeModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        Map<String, Object> attributes = model.getImportedAttributes(
+                ServletUtil.getCurrentContainer(request, servletContext),
+                (String) params.get("name"), (String) params.get("toName"),
+                VelocityUtil.toSimpleBoolean((Boolean) params.get("ignore"),
+                        false), velocityContext, request, response);
+        String scope = (String) params.get("scope");
+        for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+            VelocityUtil.setAttribute(velocityContext, request, servletContext,
+                    entry.getKey(), entry.getValue(), scope);
+        }
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/ImportAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,66 @@
+package org.apache.tiles.velocity;
+
+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.tiles.Attribute;
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.InsertAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class InsertAttributeVModel implements Executable, BodyExecutable {
+
+    private InsertAttributeModel model;
+    
+    public InsertAttributeVModel(InsertAttributeModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    private ServletContext servletContext;
+    
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = 
VelocityUtil.getParameterStack(velocityContext).pop();
+        try {
+            model.end(ServletUtil.getComposeStack(request), 
ServletUtil.getCurrentContainer(request, servletContext),
+                    VelocityUtil.toSimpleBoolean((Boolean) 
params.get("ignore"), false),
+                    velocityContext, request, response);
+        } catch (IOException e) {
+            throw new TilesVelocityException("Cannot end insertAttribute", e);
+        }
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request), 
ServletUtil.getCurrentContainer(request, servletContext),
+                VelocityUtil.toSimpleBoolean((Boolean) params.get("ignore"), 
false),
+                (String) params.get("preparer"), (String) params.get("role"),
+                params.get("defaultValue"), (String) 
params.get("defaultValueRole"),
+                (String) params.get("defaultValueType"), (String) 
params.get("name"),
+                (Attribute) params.get("value"), velocityContext, request, 
response);
+        
+    }
+
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        try {
+            model.execute(ServletUtil.getCurrentContainer(request, 
servletContext),
+                    VelocityUtil.toSimpleBoolean((Boolean) 
params.get("ignore"), false),
+                    (String) params.get("preparer"), (String) 
params.get("role"),
+                    params.get("defaultValue"), (String) 
params.get("defaultValueRole"),
+                    (String) params.get("defaultValueType"), (String) 
params.get("name"),
+                    (Attribute) params.get("value"), velocityContext, request, 
response);
+        } catch (IOException e) {
+            throw new TilesVelocityException("Cannot execute insertAttribute", 
e);
+        }
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,49 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.InsertDefinitionModel;
+import org.apache.velocity.context.Context;
+
+public class InsertDefinitionVModel implements Executable, BodyExecutable {
+
+    private InsertDefinitionModel model;
+
+    private ServletContext servletContext;
+
+    public InsertDefinitionVModel(InsertDefinitionModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        model.execute(ServletUtil.getCurrentContainer(request, servletContext),
+                (String) params.get("name"), (String) params.get("template"),
+                (String) params.get("role"), (String) params.get("preparer"),
+                velocityContext, request, response);
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = 
VelocityUtil.getParameterStack(velocityContext).pop();
+        model.execute(ServletUtil.getCurrentContainer(request, servletContext),
+                (String) params.get("name"), (String) params.get("template"),
+                (String) params.get("role"), (String) params.get("preparer"),
+                velocityContext, request, response);
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertDefinitionVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,51 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.InsertTemplateModel;
+import org.apache.velocity.context.Context;
+
+public class InsertTemplateVModel implements Executable, BodyExecutable {
+
+    private InsertTemplateModel model;
+
+    private ServletContext servletContext;
+
+    public InsertTemplateVModel(InsertTemplateModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        model.execute(ServletUtil.getCurrentContainer(request, servletContext),
+                (String) params.get("template"), (String) params.get("role"),
+                (String) params.get("preparer"), velocityContext, request,
+                response);
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = VelocityUtil.getParameterStack(
+                velocityContext).pop();
+        model.end(ServletUtil.getCurrentContainer(request, servletContext),
+                (String) params.get("template"), (String) params.get("role"),
+                (String) params.get("preparer"), velocityContext, request,
+                response);
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getCurrentContainer(request, servletContext),
+                velocityContext, request, response);
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/InsertTemplateVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,52 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.PutAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class PutAttributeVModel implements Executable, BodyExecutable {
+
+    private PutAttributeModel model;
+
+    private ServletContext servletContext;
+    
+    public PutAttributeVModel(PutAttributeModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+    
+    public void execute(HttpServletRequest request,
+            HttpServletResponse response, Context velocityContext,
+            Map<String, Object> params) {
+        model.execute(ServletUtil.getCurrentContainer(request, 
servletContext), ServletUtil.getComposeStack(request),
+                (String) params.get("name"), params.get("value"),
+                (String) params.get("expression"), null, (String) 
params.get("role"),
+                (String) params.get("type"), 
VelocityUtil.toSimpleBoolean((Boolean) params.get("value"), false),
+                velocityContext, request, response);
+        
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = VelocityUtil.getParameterStack(
+                velocityContext).pop();
+        model.end(ServletUtil.getCurrentContainer(request, servletContext), 
ServletUtil.getComposeStack(request),
+                (String) params.get("name"), params.get("value"),
+                (String) params.get("expression"), null, (String) 
params.get("role"),
+                (String) params.get("type"), 
VelocityUtil.toSimpleBoolean((Boolean) params.get("value"), false),
+                velocityContext, request, response);
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request));
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,43 @@
+package org.apache.tiles.velocity;
+
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.apache.tiles.template.PutListAttributeModel;
+import org.apache.velocity.context.Context;
+
+public class PutListAttributeVModel implements BodyExecutable {
+
+    private PutListAttributeModel model;
+
+    private ServletContext servletContext;
+
+    public PutListAttributeVModel(PutListAttributeModel model,
+            ServletContext servletContext) {
+        this.model = model;
+        this.servletContext = servletContext;
+    }
+
+    public void end(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext) {
+        Map<String, Object> params = VelocityUtil.getParameterStack(
+                velocityContext).pop();
+        model.end(ServletUtil.getCurrentContainer(request, servletContext),
+                ServletUtil.getComposeStack(request), (String) params
+                        .get("name"), VelocityUtil.toSimpleBoolean(
+                        (Boolean) params.get("cascade"), false),
+                velocityContext, request, response);
+    }
+
+    public void start(HttpServletRequest request, HttpServletResponse response,
+            Context velocityContext, Map<String, Object> params) {
+        VelocityUtil.getParameterStack(velocityContext).push(params);
+        model.start(ServletUtil.getComposeStack(request), (String) params
+                .get("role"), VelocityUtil.toSimpleBoolean((Boolean) params
+                .get("inherit"), false));
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/PutListAttributeVModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Tiles2Tool.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Tiles2Tool.java?rev=748125&r1=748124&r2=748125&view=diff
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Tiles2Tool.java
 (original)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/Tiles2Tool.java
 Thu Feb 26 13:03:05 2009
@@ -27,62 +27,33 @@
 import org.apache.tiles.AttributeContext;
 import org.apache.tiles.TilesContainer;
 import org.apache.tiles.servlet.context.ServletUtil;
-import org.apache.tiles.template.AttributeResolver;
-import org.apache.tiles.template.DefaultAttributeResolver;
-import org.apache.tiles.template.GetAsStringModel;
-import org.apache.velocity.context.Context;
-import org.apache.velocity.tools.view.ImportSupport;
 
 /**
  * 
  * @author SergeyZ
  * 
  */
-public class Tiles2Tool extends ImportSupport {
+public class Tiles2Tool extends ContextHolder {
 
-    private Context velocityContext;
+    private static final String TILES_VELOCITY_REPOSITORY_KEY = 
"org.apache.tiles.velocity.TilesVelocityRepository";
     
-    private GetAsStringModel getAsStringModel;
+    private BodyExecutable currentBodyExecutable;
     
-    public Tiles2Tool() {
-        AttributeResolver attributeResolver = new DefaultAttributeResolver();
-        getAsStringModel = new GetAsStringModel(attributeResolver);
-    }
+    private TilesVelocityRepository repository;
 
     /**
-     * Initializes this tool.
-     *
-     * @param context the current {...@link Context}
-     * @throws IllegalArgumentException if the param is not a {...@link 
Context}
-     */
-    public void setVelocityContext(Context context)
-    {
-        if (context == null)
-        {
-            throw new NullPointerException("velocity context should not be 
null");
-        }
-        this.velocityContext = context;
-    }
-    
-    /**
      * Returns a string representation of attribute value. If the attribute is
      * <code>null</code> or if the attribute value is <code>null</code>,
      * <code>null</code> is returned
      * 
      * @throws IOException If something goes wrong.
      */
-    public void getAsString_start(Map<String, Object> params) throws 
IOException {
-        getAsStringModel.start(ServletUtil.getComposeStack(request),
-                ServletUtil.getCurrentContainer(request, application),
-                VelocityUtil.toSimpleBoolean((Boolean) params.get("ignore"),
-                        false), (String) params.get("preparer"),
-                (String) params.get("role"), params.get("defaultValue"),
-                (String) params.get("defaultValueRole"), (String) params
-                        .get("defaultValueType"), (String) params.get("name"),
-                (Attribute) params.get("value"), velocityContext, request,
-                response);
+    public Tiles2Tool getAsString(Map<String, Object> params)
+            throws IOException {
+        execute(getRepository().getGetAsString(), params);
+        return this;
     }
-    
+
     /**
      * Returns a string representation of attribute value. If the attribute is
      * <code>null</code> or if the attribute value is <code>null</code>,
@@ -90,24 +61,58 @@
      * 
      * @throws IOException If something goes wrong.
      */
-    public void getAsString(Map<String, Object> params) throws IOException {
-        TilesContainer container = ServletUtil.getCurrentContainer(request, 
application);
-        getAsStringModel.execute(container, response.getWriter(), VelocityUtil
-                .toSimpleBoolean((Boolean) params.get("ignore"), false),
-                (String) params.get("preparer"), (String) params.get("role"),
-                params.get("defaultValue"), (String) params
-                        .get("defaultValueRole"), (String) params
-                        .get("defaultValueType"), (String) params.get("name"),
-                (Attribute) params.get("value"), velocityContext, request,
-                response);
+    public Tiles2Tool getAsString() throws IOException {
+        currentBodyExecutable = getRepository().getGetAsString();
+        return this;
+    }
+    
+    public Tiles2Tool start(Map<String, Object> params) {
+        if (currentBodyExecutable == null) {
+            throw new NullPointerException("The current model to start has not 
been set");
+        }
+        currentBodyExecutable.start(getRequest(), getResponse(), 
getVelocityContext(), params);
+        return this;
+    }
+    
+    public Tiles2Tool end() {
+        if (currentBodyExecutable == null) {
+            throw new NullPointerException("The current model to start has not 
been set");
+        }
+        currentBodyExecutable.end(getRequest(), getResponse(), 
getVelocityContext());
+        return this;
     }
 
     public Attribute getAttribute(String key) {
-        TilesContainer container = ServletUtil.getCurrentContainer(request,
-                application);
+        TilesContainer container = ServletUtil.getCurrentContainer(
+                getRequest(), getServletContext());
         AttributeContext attributeContext = container.getAttributeContext(
-                velocityContext, request, response);
+                getVelocityContext(), getRequest(), getResponse());
         Attribute attribute = attributeContext.getAttribute(key);
         return attribute;
     }
+    
+    public Tiles2Tool setCurrentContainer(String containerKey) {
+        ServletUtil.setCurrentContainer(getRequest(), getServletContext(),
+                containerKey);
+        return this;
+    }
+
+    private TilesVelocityRepository getRepository() {
+        if (repository != null) {
+            return repository;
+        }
+
+        repository = (TilesVelocityRepository) getServletContext()
+                .getAttribute(TILES_VELOCITY_REPOSITORY_KEY);
+        if (repository == null) {
+            repository = new TilesVelocityRepository(getServletContext());
+            getServletContext().setAttribute(TILES_VELOCITY_REPOSITORY_KEY,
+                    repository);
+        }
+        return repository;
+    }
+    
+    private void execute(Executable executable, Map<String, Object> params) {
+        executable.execute(getRequest(), getResponse(), getVelocityContext(), 
params);
+    }
 }

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,26 @@
+package org.apache.tiles.velocity;
+
+import org.apache.tiles.TilesException;
+
+public class TilesVelocityException extends TilesException {
+
+    public TilesVelocityException() {
+        // TODO Auto-generated constructor stub
+    }
+
+    public TilesVelocityException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+
+    public TilesVelocityException(Exception e) {
+        super(e);
+        // TODO Auto-generated constructor stub
+    }
+
+    public TilesVelocityException(String message, Exception e) {
+        super(message, e);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java?rev=748125&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java
 Thu Feb 26 13:03:05 2009
@@ -0,0 +1,22 @@
+package org.apache.tiles.velocity;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tiles.template.AttributeResolver;
+import org.apache.tiles.template.DefaultAttributeResolver;
+import org.apache.tiles.template.GetAsStringModel;
+
+public class TilesVelocityRepository {
+
+    private GetAsStringVModel getAsString;
+    
+    public TilesVelocityRepository(ServletContext servletContext) {
+        AttributeResolver attributeResolver = new DefaultAttributeResolver();
+        getAsString = new GetAsStringVModel(new GetAsStringModel(
+                attributeResolver), servletContext);
+    }
+    
+    public GetAsStringVModel getGetAsString() {
+        return getAsString;
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/TilesVelocityRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/VelocityUtil.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/VelocityUtil.java?rev=748125&r1=748124&r2=748125&view=diff
==============================================================================
--- 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/VelocityUtil.java
 (original)
+++ 
tiles/sandbox/trunk/tiles-velocity/src/main/java/org/apache/tiles/velocity/VelocityUtil.java
 Thu Feb 26 13:03:05 2009
@@ -1,14 +1,49 @@
 package org.apache.tiles.velocity;
 
+import java.util.Map;
+import java.util.Stack;
+
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
 
-import org.apache.tiles.template.GetAsStringModel;
+import org.apache.velocity.context.Context;
 
 public class VelocityUtil {
-
-    private final static String TEMPLATE_PREFIX="org.apache.tiles.template.";
+    
+    private final static String PARAMETER_MAP_STACK_KEY = 
"org.apache.tiles.velocity.PARAMETER_MAP_STACK"; 
+    
+    private VelocityUtil() {
+    }
     
     public static boolean toSimpleBoolean(Boolean obj, boolean defaultValue) {
         return obj != null ? obj : defaultValue;
     }
+    
+    @SuppressWarnings("unchecked")
+    public static Stack<Map<String, Object>> getParameterStack(Context 
context) {
+        Stack<Map<String, Object>> stack = (Stack<Map<String, Object>>) context
+                .get(PARAMETER_MAP_STACK_KEY);
+        if (stack == null) {
+            stack = new Stack<Map<String,Object>>();
+            context.put(PARAMETER_MAP_STACK_KEY, stack);
+        }
+        return stack;
+    }
+
+    public static void setAttribute(Context velocityContext,
+            HttpServletRequest request, ServletContext servletContext,
+            String name, Object obj, String scope) {
+        if (scope == null) {
+            scope = "page";
+        }
+        if ("page".equals(scope)) {
+            velocityContext.put(name, obj);
+        } else if ("request".equals(scope)) {
+            request.setAttribute(name, obj);
+        } else if ("session".equals(scope)) {
+            request.getSession().setAttribute(name, obj);
+        } else if ("application".equals("scope")) {
+            servletContext.setAttribute(name, obj);
+        }
+    }
 }


Reply via email to