You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2022/11/27 08:25:04 UTC
[struts] 21/23: Make plugin standalone with all generated resources for velocity.
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-5233-tiles
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 0568c2d3e98b582dbfe7b686c994fae04cb672d1
Author: Greg Huber <gh...@apache.org>
AuthorDate: Tue Oct 18 14:35:55 2022 +0100
Make plugin standalone with all generated resources for velocity.
---
plugins/tiles/pom.xml | 6 +
.../org/apache/struts2/tiles/BuildAutotags.java | 60 +++++-
.../velocity/VelocityDirectiveGenerator.java | 67 ++++++
.../velocity/VelocityPropertiesGenerator.java | 64 ++++++
.../velocity/VelocityTemplateGeneratorFactory.java | 87 ++++++++
.../tiles/autotag/velocity/package-info.java | 24 +++
.../servlet/ExternalWriterHttpServletResponse.java | 58 ++++++
.../tiles/request/velocity/VelocityRequest.java | 169 ++++++++++++++++
.../tiles/request/velocity/VelocityScopeMap.java | 87 ++++++++
.../velocity/autotag/VelocityAutotagRuntime.java | 102 ++++++++++
.../velocity/autotag/VelocityModelBody.java | 61 ++++++
.../request/velocity/autotag/VelocityUtil.java | 67 ++++++
.../request/velocity/autotag/package-info.java | 22 ++
.../velocity/extractor/VelocityScopeExtractor.java | 99 +++++++++
.../request/velocity/extractor/package-info.java | 22 ++
.../tiles/request/velocity/package-info.java | 22 ++
.../render/ApplicationContextJeeConfig.java | 77 +++++++
.../request/velocity/render/VelocityRenderer.java | 75 +++++++
.../velocity/render/VelocityRendererBuilder.java | 91 +++++++++
.../request/velocity/render/package-info.java | 22 ++
.../tiles/velocity/TilesVelocityException.java | 71 +++++++
.../org/apache/tiles/velocity/package-info.java | 22 ++
.../AbstractDefaultToStringRenderable.java | 119 +++++++++++
.../velocity/template/AddAttributeDirective.java | 78 +++++++
.../template/AddListAttributeDirective.java | 73 +++++++
.../tiles/velocity/template/ContextHolder.java | 154 ++++++++++++++
.../velocity/template/DefinitionDirective.java | 76 +++++++
.../velocity/template/GetAsStringDirective.java | 81 ++++++++
.../template/ImportAttributeDirective.java | 74 +++++++
.../template/InsertAttributeDirective.java | 94 +++++++++
.../template/InsertDefinitionDirective.java | 99 +++++++++
.../velocity/template/InsertTemplateDirective.java | 98 +++++++++
.../velocity/template/PutAttributeDirective.java | 101 ++++++++++
.../template/PutListAttributeDirective.java | 76 +++++++
.../template/SetCurrentContainerDirective.java | 64 ++++++
.../velocity/template/VelocityStyleTilesTool.java | 224 +++++++++++++++++++++
.../tiles/velocity/template/package-info.java | 22 ++
.../main/resources/META-INF/velocity.properties | 30 +++
.../org/apache/tiles/autotag/velocity.properties | 13 --
.../tiles/autotag/velocity/velocityDirective.vm | 76 +++++++
.../tiles/autotag/velocity/velocityProperties.vm | 21 ++
plugins/tiles/src/main/resources/tools.xml | 24 +++
.../velocity/VelocityDirectiveGeneratorTest.java | 139 +++++++++++++
.../velocity/VelocityPropertiesGeneratorTest.java | 125 ++++++++++++
.../VelocityTemplateGeneratorFactoryTest.java | 60 ++++++
.../autotag/velocity/test/DoStuffDirective.javat | 70 +++++++
.../velocity/test/DoStuffNoBodyDirective.javat | 68 +++++++
.../src/test/resources/velocity.properties.test | 21 ++
48 files changed, 3441 insertions(+), 14 deletions(-)
diff --git a/plugins/tiles/pom.xml b/plugins/tiles/pom.xml
index 627f3c317..55759a642 100644
--- a/plugins/tiles/pom.xml
+++ b/plugins/tiles/pom.xml
@@ -94,6 +94,12 @@
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity-tools</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/BuildAutotags.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/BuildAutotags.java
index de2eaee1e..c29ea67ef 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/BuildAutotags.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/BuildAutotags.java
@@ -29,6 +29,7 @@ import org.apache.tiles.autotag.generate.TemplateGenerator;
import org.apache.tiles.autotag.generate.TemplateGeneratorBuilder;
import org.apache.tiles.autotag.jsp.JspTemplateGeneratorFactory;
import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.tiles.autotag.velocity.VelocityTemplateGeneratorFactory;
import org.apache.velocity.app.VelocityEngine;
import com.thoughtworks.xstream.XStream;
@@ -58,6 +59,9 @@ public class BuildAutotags {
// Freemarker classes
me.buildFreemarker(args[0]);
+ // Freemarker classes
+ me.buildVelocity(args[0]);
+
}
/**
@@ -118,7 +122,7 @@ public class BuildAutotags {
}
/**
- * Builds the freemarker.
+ * Builds the Freemarker classes.
*
* To build, change template-suite.xml as required and then run this program.
* Copy the classes from the target autotag folder into the packageName
@@ -168,4 +172,58 @@ public class BuildAutotags {
}
+ /**
+ * Builds the velocity classes.
+ *
+ * To build, change template-suite.xml as required and then run this program.
+ * Copy the classes from the target autotag folder into the packageName
+ * location, and velocity.properties to
+ * src/main/resources/META-INF/velocity.properties
+ *
+ * @param outputDir the output dir
+ */
+ public void buildVelocity(String outputDir) {
+
+ // Default values
+ String packageName = "org.apache.tiles.velocity.template";
+ String requestClass = "org.apache.tiles.request.Request";
+ String runtime = "org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime";
+ // outputDir = "/target"
+
+ try {
+
+ TemplateSuite suite;
+
+ InputStream stream = getClass().getResourceAsStream("/META-INF/template-suite.xml");
+
+ try {
+ XStream xstream = new XStream(new DomDriver());
+ xstream.allowTypes(new Class[] { org.apache.tiles.autotag.model.TemplateClass.class,
+ org.apache.tiles.autotag.model.TemplateSuite.class,
+ org.apache.tiles.autotag.model.TemplateParameter.class });
+ suite = (TemplateSuite) xstream.fromXML(stream);
+ } finally {
+ stream.close();
+ }
+
+ Properties props = new Properties();
+ InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
+ props.load(propsStream);
+ propsStream.close();
+
+ File classesOutputDirectory = new File(outputDir + "/generated-sources/autotag/classes");
+ File resourcesOutputDirectory = new File(outputDir + "/generated-sources/autotag");
+
+ TemplateGenerator generator = new VelocityTemplateGeneratorFactory(classesOutputDirectory,
+ resourcesOutputDirectory, new VelocityEngine(props), TemplateGeneratorBuilder.createNewInstance())
+ .createTemplateGenerator();
+
+ generator.generate(packageName, suite, null, runtime, requestClass);
+
+ } catch (Exception e) {
+ // ignored
+ }
+
+ }
+
}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
new file mode 100644
index 000000000..b59b70843
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
@@ -0,0 +1,67 @@
+/*
+ * $Id: VelocityDirectiveGenerator.java 1349964 2012-06-13 17:18:51Z nlebas $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.tiles.autotag.generate.AbstractTemplateClassGenerator;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * Generates a Velocity directive using a template class.
+ *
+ * @version $Rev: 1349964 $ $Date: 2012-06-13 13:18:51 -0400 (Wed, 13 Jun 2012) $
+ */
+public class VelocityDirectiveGenerator extends AbstractTemplateClassGenerator {
+
+ /**
+ * Constructor.
+ *
+ * @param velocityEngine The Velocity engine.
+ */
+ public VelocityDirectiveGenerator(VelocityEngine velocityEngine) {
+ super(velocityEngine);
+ }
+
+ @Override
+ protected String getDirectoryName(File directory, String packageName,
+ TemplateSuite suite, TemplateClass clazz, Map<String, String> parameters,
+ String runtimeClass, String requestClass) {
+ return packageName.replaceAll("\\.", "/");
+ }
+
+ @Override
+ protected String getFilename(File directory, String packageName,
+ TemplateSuite suite, TemplateClass clazz, Map<String, String> parameters,
+ String runtimeClass, String requestClass) {
+ return clazz.getTagClassPrefix() + "Directive.java";
+ }
+
+ @Override
+ protected String getTemplatePath(File directory, String packageName,
+ TemplateSuite suite, TemplateClass clazz, Map<String, String> parameters,
+ String runtimeClass, String requestClass) {
+ return "/org/apache/tiles/autotag/velocity/velocityDirective.vm";
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
new file mode 100644
index 000000000..bf340c41f
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
@@ -0,0 +1,64 @@
+/*
+ * $Id: VelocityPropertiesGenerator.java 1045345 2010-12-13 19:58:23Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.tiles.autotag.generate.AbstractTemplateSuiteGenerator;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * Generates a Velocity properties containing the list of generated user directives for future use.
+ *
+ * @version $Rev: 1045345 $ $Date: 2010-12-13 14:58:23 -0500 (Mon, 13 Dec 2010) $
+ */
+public class VelocityPropertiesGenerator extends AbstractTemplateSuiteGenerator {
+
+ /**
+ * Constructor.
+ *
+ * @param velocityEngine The Velocity engine.
+ */
+ public VelocityPropertiesGenerator(VelocityEngine velocityEngine) {
+ super(velocityEngine);
+ }
+
+ @Override
+ protected String getTemplatePath(File directory, String packageName,
+ TemplateSuite suite, Map<String, String> parameters) {
+ return "/org/apache/tiles/autotag/velocity/velocityProperties.vm";
+ }
+
+ @Override
+ protected String getFilename(File directory, String packageName,
+ TemplateSuite suite, Map<String, String> parameters) {
+ return "velocity.properties";
+ }
+
+ @Override
+ protected String getDirectoryName(File directory, String packageName,
+ TemplateSuite suite, Map<String, String> parameters) {
+ return "META-INF/";
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactory.java b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactory.java
new file mode 100644
index 000000000..6ed64cf47
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactory.java
@@ -0,0 +1,87 @@
+/*
+ * $Id: VelocityTemplateGeneratorFactory.java 1045345 2010-12-13 19:58:23Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import java.io.File;
+
+import org.apache.tiles.autotag.generate.TemplateGenerator;
+import org.apache.tiles.autotag.generate.TemplateGeneratorBuilder;
+import org.apache.tiles.autotag.generate.TemplateGeneratorFactory;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * Creates a template generator that generates code to build Velocity code
+ * around template classes.
+ *
+ * @version $Rev: 1045345 $ $Date: 2010-12-13 14:58:23 -0500 (Mon, 13 Dec 2010) $
+ */
+public class VelocityTemplateGeneratorFactory implements
+ TemplateGeneratorFactory {
+
+ /**
+ * Location of the file.
+ */
+ private File classesOutputDirectory;
+
+ /**
+ * Location of the file.
+ */
+ private File resourcesOutputDirectory;
+
+ /**
+ * The Velocity engine.
+ */
+ private VelocityEngine velocityEngine;
+
+ /**
+ * The template generator builder.
+ */
+ private TemplateGeneratorBuilder templateGeneratorBuilder;
+
+ /**
+ * Constructor.
+ *
+ * @param classesOutputDirectory The directory where classes will be generated.
+ * @param resourcesOutputDirectory The directory where velocity.properties will be written.
+ * @param velocityEngine The Velocity engine.
+ * @param templateGeneratorBuilder The template generator builder.
+ */
+ public VelocityTemplateGeneratorFactory(File classesOutputDirectory,
+ File resourcesOutputDirectory, VelocityEngine velocityEngine,
+ TemplateGeneratorBuilder templateGeneratorBuilder) {
+ this.classesOutputDirectory = classesOutputDirectory;
+ this.resourcesOutputDirectory = resourcesOutputDirectory;
+ this.velocityEngine = velocityEngine;
+ this.templateGeneratorBuilder = templateGeneratorBuilder;
+ }
+
+ @Override
+ public TemplateGenerator createTemplateGenerator() {
+ return templateGeneratorBuilder
+ .setClassesOutputDirectory(classesOutputDirectory)
+ .setResourcesOutputDirectory(resourcesOutputDirectory)
+ .addResourcesTemplateSuiteGenerator(
+ new VelocityPropertiesGenerator(velocityEngine))
+ .addClassesTemplateClassGenerator(
+ new VelocityDirectiveGenerator(velocityEngine)).build();
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/package-info.java
new file mode 100644
index 000000000..15e00360f
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/autotag/velocity/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * $Id: package-info.java 1045345 2010-12-13 19:58:23Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Autotag support for Velocity.
+ */
+package org.apache.tiles.autotag.velocity;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/servlet/ExternalWriterHttpServletResponse.java b/plugins/tiles/src/main/java/org/apache/tiles/request/servlet/ExternalWriterHttpServletResponse.java
new file mode 100644
index 000000000..492530e7e
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/servlet/ExternalWriterHttpServletResponse.java
@@ -0,0 +1,58 @@
+/*
+ * $Id: ExternalWriterHttpServletResponse.java 1306435 2012-03-28 15:39:11Z nlebas $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.request.servlet;
+
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * Wraps an HTTP response and overrides its print writer.
+ *
+ * @version $Rev: 1306435 $ $Date: 2012-03-29 02:39:11 +1100 (Thu, 29 Mar 2012) $
+ */
+public class ExternalWriterHttpServletResponse extends
+ HttpServletResponseWrapper {
+
+ /**
+ * The print writer to use, instead of the response's one.
+ */
+ private PrintWriter writer;
+
+ /**
+ * Constructor.
+ *
+ * @param response The response to wrap.
+ * @param writer The print writer to use, instead of the response's one.
+ */
+ public ExternalWriterHttpServletResponse(HttpServletResponse response, PrintWriter writer) {
+ super(response);
+ this.writer = writer;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public PrintWriter getWriter() {
+ return writer;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityRequest.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityRequest.java
new file mode 100644
index 000000000..328d67c9e
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityRequest.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.request.velocity;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.request.AbstractViewRequest;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.DispatchRequest;
+import org.apache.tiles.request.servlet.ExternalWriterHttpServletResponse;
+import org.apache.tiles.request.servlet.ServletRequest;
+import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.velocity.context.Context;
+
+/**
+ * The implementation of the Tiles request context specific for Velocity.
+ */
+public class VelocityRequest extends AbstractViewRequest {
+
+ /**
+ * The native available scopes, in fact only "page".
+ */
+ private final List<String> scopes;
+
+ /**
+ * The Velocity current context.
+ */
+ private final Context ctx;
+
+ /**
+ * The writer to use to render the response. It may be null, if not necessary.
+ */
+ private Writer writer;
+
+ /**
+ * The map of the page scope.
+ */
+ private Map<String, Object> pageScope;
+
+ /**
+ * Factory method to create a Velocity request.
+ *
+ * @param applicationContext The application context.
+ * @param request The request.
+ * @param response The response.
+ * @param velocityContext The Velocity context.
+ * @param writer The writer to write into.
+ * @return The request.
+ */
+ public static VelocityRequest createVelocityRequest(ApplicationContext applicationContext,
+ HttpServletRequest request, HttpServletResponse response, Context velocityContext, Writer writer) {
+ DispatchRequest servletRequest = new ServletRequest(applicationContext, request, response);
+ VelocityRequest velocityRequest = new VelocityRequest(servletRequest, velocityContext, writer);
+ return velocityRequest;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param enclosedRequest The request that exposes non-Velocity specific
+ * properties
+ * @param ctx The Velocity current context.
+ * @param writer The writer to use to render the response. It may be
+ * null, if not necessary.
+ */
+ public VelocityRequest(DispatchRequest enclosedRequest, Context ctx, Writer writer) {
+ super(enclosedRequest);
+ List<String> scopes = new ArrayList<String>();
+ scopes.addAll(enclosedRequest.getAvailableScopes());
+ scopes.add("page");
+ this.scopes = Collections.unmodifiableList(scopes);
+ this.ctx = ctx;
+ this.writer = writer;
+ }
+
+ @Override
+ public List<String> getAvailableScopes() {
+ return scopes;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInclude(String path) throws IOException {
+ ServletRequest servletRequest = org.apache.tiles.request.servlet.ServletUtil.getServletRequest(this);
+ HttpServletRequest request = servletRequest.getRequest();
+ HttpServletResponse response = servletRequest.getResponse();
+ RequestDispatcher rd = request.getRequestDispatcher(path);
+
+ if (rd == null) {
+ throw new IOException("No request dispatcher returned for path '" + path + "'");
+ }
+
+ PrintWriter printWriter = getPrintWriter();
+ try {
+ rd.include(request, new ExternalWriterHttpServletResponse(response, printWriter));
+ } catch (ServletException ex) {
+ throw ServletUtil.wrapServletException(ex, "ServletException including path '" + path + "'.");
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public PrintWriter getPrintWriter() {
+ if (writer == null) {
+ throw new IllegalStateException(
+ "A writer-less Tiles request has been created, cannot return a PrintWriter");
+ }
+ if (writer instanceof PrintWriter) {
+ return (PrintWriter) writer;
+ }
+ return new PrintWriter(writer);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Writer getWriter() {
+ if (writer == null) {
+ throw new IllegalStateException(
+ "A writer-less Tiles request has been created, cannot return a PrintWriter");
+ }
+ return writer;
+ }
+
+ /**
+ * Returns the page scope.
+ *
+ * @return The page scope.
+ */
+ public Map<String, Object> getPageScope() {
+ if (pageScope == null) {
+ pageScope = new VelocityScopeMap(ctx);
+ }
+ return pageScope;
+ }
+
+ @Override
+ public Map<String, Object> getContext(String scope) {
+ return "page".equals(scope) ? getPageScope() : super.getContext(scope);
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityScopeMap.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityScopeMap.java
new file mode 100644
index 000000000..36e7c21be
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/VelocityScopeMap.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity;
+
+import static org.apache.tiles.request.collection.CollectionUtil.key;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tiles.request.collection.ScopeMap;
+import org.apache.tiles.request.velocity.extractor.VelocityScopeExtractor;
+import org.apache.velocity.context.Context;
+
+/**
+ * <p>
+ * Private implementation of <code>Map</code> for servlet request attributes.
+ * </p>
+ *
+ */
+
+final class VelocityScopeMap extends ScopeMap {
+
+ /**
+ * The request object to use.
+ */
+ private Context request = null;
+
+ /**
+ * Constructor.
+ *
+ * @param request The request object to use.
+ */
+ public VelocityScopeMap(Context request) {
+ super(new VelocityScopeExtractor(request));
+ this.request = request;
+ }
+
+ @Override
+ public Object remove(Object key) {
+ return request.remove(key(key));
+ }
+
+ @Override
+ public Object put(String key, Object value) {
+ return request.put(key, value);
+ }
+
+ /** {@inheritDoc} */
+ public boolean containsKey(Object key) {
+ return request.containsKey(key(key));
+ }
+
+ /** {@inheritDoc} */
+ public boolean isEmpty() {
+ return size() < 1;
+ }
+
+ /** {@inheritDoc} */
+ public Set<String> keySet() {
+ Set<String> set = new HashSet<String>();
+ for (Object key : request.getKeys()) {
+ set.add((String) key);
+ }
+ return (set);
+ }
+
+ /** {@inheritDoc} */
+ public int size() {
+ return request.getKeys().length;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityAutotagRuntime.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityAutotagRuntime.java
new file mode 100644
index 000000000..32e00e745
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityAutotagRuntime.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.autotag;
+
+import java.io.Writer;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.tiles.request.velocity.VelocityRequest;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.ASTBlock;
+import org.apache.velocity.runtime.parser.node.ASTMap;
+import org.apache.velocity.runtime.parser.node.Node;
+import org.apache.velocity.tools.view.ViewContext;
+
+/**
+ * A Runtime for implementing Velocity Directives.
+ */
+public class VelocityAutotagRuntime extends Directive implements AutotagRuntime<Request> {
+ private InternalContextAdapter context;
+ private Writer writer;
+ private Node node;
+ private Map<String, Object> params;
+
+ @Override
+ public Request createRequest() {
+ ViewContext viewContext = (ViewContext) context.getInternalUserContext();
+ HttpServletRequest request = viewContext.getRequest();
+ HttpServletResponse response = viewContext.getResponse();
+ ServletContext servletContext = viewContext.getServletContext();
+ return VelocityRequest.createVelocityRequest(ServletUtil.getApplicationContext(servletContext), request,
+ response, context, writer);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ModelBody createModelBody() {
+ ASTBlock block = (ASTBlock) node.jjtGetChild(1);
+ return new VelocityModelBody(context, block, writer);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getParameter(String name, Class<T> type, T defaultValue) {
+ if (params == null) {
+ ASTMap astMap = (ASTMap) node.jjtGetChild(0);
+ params = (Map<String, Object>) astMap.value(context);
+ }
+ T result = (T) params.get(name);
+ if (result == null) {
+ result = defaultValue;
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int getType() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) {
+ this.context = context;
+ this.writer = writer;
+ this.node = node;
+ return false;
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityModelBody.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityModelBody.java
new file mode 100644
index 000000000..1022175f6
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityModelBody.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.autotag;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.AbstractModelBody;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.parser.node.ASTBlock;
+
+/**
+ * Body abstraction for a Velocity directive body.
+ */
+public class VelocityModelBody extends AbstractModelBody {
+
+ /**
+ * The real body.
+ */
+ private ASTBlock body;
+
+ /**
+ * The Velocity context.
+ */
+ private InternalContextAdapter context;
+
+ /**
+ * Constructor.
+ *
+ * @param context The Velocity context.
+ * @param body The real body.
+ * @param defaultWriter The default writer.
+ */
+ public VelocityModelBody(InternalContextAdapter context, ASTBlock body, Writer defaultWriter) {
+ super(defaultWriter);
+ this.context = context;
+ this.body = body;
+ }
+
+ @Override
+ public void evaluate(Writer writer) throws IOException {
+ body.render(context, writer);
+ }
+
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityUtil.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityUtil.java
new file mode 100644
index 000000000..bca193836
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/VelocityUtil.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.autotag;
+
+import java.util.Map;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.parser.node.ASTMap;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * Utilities for Velocity usage in Tiles.
+ */
+public final class VelocityUtil {
+
+ /**
+ * Private constructor to avoid instantiation.
+ */
+ private VelocityUtil() {
+ }
+
+ /**
+ * Extracts the parameters from the directives, by getting the child at position
+ * 0 supposing it is a map.
+ *
+ * @param context The Velocity context.
+ * @param node The node to use.
+ * @return The extracted parameters.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String, Object> getParameters(InternalContextAdapter context, Node node) {
+ ASTMap astMap = (ASTMap) node.jjtGetChild(0);
+ Map<String, Object> params = (Map<String, Object>) astMap.value(context);
+ return params;
+ }
+
+ /**
+ * Returns the "value" parameter if it is not null, otherwise returns
+ * "defaultValue".
+ *
+ * @param value The value to return, if it is not null.
+ * @param defaultValue The value to return, if <code>value</code> is null.
+ * @return The value, defaulted if necessary.
+ */
+ public static Object getObject(Object value, Object defaultValue) {
+ if (value == null) {
+ value = defaultValue;
+ }
+ return value;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/package-info.java
new file mode 100644
index 000000000..456abb238
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/autotag/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Runtime part of Autotag support for Velocity.
+ */
+package org.apache.tiles.request.velocity.autotag;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/VelocityScopeExtractor.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/VelocityScopeExtractor.java
new file mode 100644
index 000000000..1481c3844
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/VelocityScopeExtractor.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.extractor;
+
+import java.util.Enumeration;
+
+import org.apache.tiles.request.attribute.AttributeExtractor;
+import org.apache.velocity.context.Context;
+
+/**
+ * Extracts attributes from Velocity context..
+ */
+public class VelocityScopeExtractor implements AttributeExtractor {
+
+ /**
+ * The Velocity context.
+ */
+ private Context context;
+
+ /**
+ * Constructor.
+ *
+ * @param context The Velocity context.
+ */
+ public VelocityScopeExtractor(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public void removeValue(String name) {
+ context.remove(name);
+ }
+
+ @Override
+ public Enumeration<String> getKeys() {
+ return new KeyEnumeration(context.getKeys());
+ }
+
+ @Override
+ public Object getValue(String key) {
+ return context.get(key);
+ }
+
+ @Override
+ public void setValue(String key, Object value) {
+ context.put(key, value);
+ }
+
+ /**
+ * Enumerates an array.
+ */
+ private static class KeyEnumeration implements Enumeration<String> {
+
+ /**
+ * The current index.
+ */
+ private int index = 0;
+
+ /**
+ * The array to enumerate.
+ */
+ private Object[] keys;
+
+ /**
+ * Constructor.
+ *
+ * @param keys The array to enumerate.
+ */
+ public KeyEnumeration(Object[] keys) {
+ this.keys = keys;
+ }
+
+ @Override
+ public boolean hasMoreElements() {
+ return index < keys.length;
+ }
+
+ @Override
+ public String nextElement() {
+ return (String) keys[index++];
+ }
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/package-info.java
new file mode 100644
index 000000000..d0c099c58
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/extractor/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Extractors to get info about Velocity-specific objects.
+ */
+package org.apache.tiles.request.velocity.extractor;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/package-info.java
new file mode 100644
index 000000000..2a3e45f0a
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Tiles request support for Velocity.
+ */
+package org.apache.tiles.request.velocity;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/ApplicationContextJeeConfig.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/ApplicationContextJeeConfig.java
new file mode 100644
index 000000000..9810ce3d9
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/ApplicationContextJeeConfig.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.render;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.velocity.tools.view.JeeConfig;
+
+/**
+ * Implements JeeConfig to use parameters set through
+ */
+public class ApplicationContextJeeConfig implements JeeConfig {
+
+ /**
+ * The application context.
+ */
+ private ApplicationContext applicationContext;
+
+ /**
+ * The initialization parameters for VelocityView.
+ */
+ private Map<String, String> params;
+
+ /**
+ * Constructor.
+ *
+ * @param applicationContext The application context.
+ * @param params Configuration parameters.
+ */
+ public ApplicationContextJeeConfig(ApplicationContext applicationContext, Map<String, String> params) {
+ this.applicationContext = applicationContext;
+ this.params = new HashMap<String, String>(params);
+ }
+
+ public String getInitParameter(String name) {
+ return params.get(name);
+ }
+
+ public String findInitParameter(String key) {
+ return params.get(key);
+ }
+
+ public Enumeration<String> getInitParameterNames() {
+ return Collections.enumeration(params.keySet());
+ }
+
+ public String getName() {
+ return "Application Context JEE Config";
+ }
+
+ public ServletContext getServletContext() {
+ return ServletUtil.getServletContext(applicationContext);
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRenderer.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRenderer.java
new file mode 100644
index 000000000..780a28569
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRenderer.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.request.velocity.render;
+
+import java.io.IOException;
+
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.render.CannotRenderException;
+import org.apache.tiles.request.render.Renderer;
+import org.apache.tiles.request.servlet.ServletRequest;
+import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.tools.view.VelocityView;
+
+/**
+ * Attribute renderer for rendering Velocity templates as attributes. It is
+ * available only to Servlet-based environment. It uses VelocityView to render
+ * the response. To initialize it correctly, call #setParameter(String, String)
+ * for all the parameters that you want to set, and then call #commit().
+ */
+public class VelocityRenderer implements Renderer {
+
+ /**
+ * The VelocityView object to use.
+ */
+ private VelocityView velocityView;
+
+ /**
+ * Constructor.
+ *
+ * @param velocityView The Velocity view manager.
+ */
+ public VelocityRenderer(VelocityView velocityView) {
+ this.velocityView = velocityView;
+ }
+
+ @Override
+ public void render(String path, Request request) throws IOException {
+ if (path == null) {
+ throw new CannotRenderException("Cannot dispatch a null path");
+ }
+
+ ServletRequest servletRequest = ServletUtil.getServletRequest(request);
+ // then get a context
+ Context context = velocityView.createContext(servletRequest.getRequest(), servletRequest.getResponse());
+
+ // get the template
+ Template template = velocityView.getTemplate((String) path);
+
+ // merge the template and context into the writer
+ velocityView.merge(template, context, request.getWriter());
+ }
+
+ public boolean isRenderable(String path, Request request) {
+ return path != null && path.startsWith("/") && path.endsWith(".vm");
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRendererBuilder.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRendererBuilder.java
new file mode 100644
index 000000000..6f028ea01
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/VelocityRendererBuilder.java
@@ -0,0 +1,91 @@
+/*
+ * $Id: VelocityRendererBuilder.java 1066512 2011-02-02 16:13:31Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.request.velocity.render;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.velocity.tools.view.VelocityView;
+
+/**
+ * Builds a VelocityRenderer.
+ */
+public final class VelocityRendererBuilder {
+
+ /**
+ * The initialization parameters for VelocityView.
+ */
+ private Map<String, String> params = new HashMap<String, String>();
+
+ /**
+ * The application context.
+ */
+ private ApplicationContext applicationContext;
+
+ /**
+ * Constructor.
+ */
+ private VelocityRendererBuilder() {
+ }
+
+ /**
+ * Returns a new instance of the builder.
+ *
+ * @return A new builder.
+ */
+ public static VelocityRendererBuilder createInstance() {
+ return new VelocityRendererBuilder();
+ }
+
+ /**
+ * Sets a parameter for the internal servlet.
+ *
+ * @param key The name of the parameter.
+ * @param value The value of the parameter.
+ * @return This builder.
+ */
+ public VelocityRendererBuilder setParameter(String key, String value) {
+ params.put(key, value);
+ return this;
+ }
+
+ /**
+ * Sets the application context.
+ *
+ * @param applicationContext The application context.
+ * @return This builder.
+ */
+ public VelocityRendererBuilder setApplicationContext(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ return this;
+ }
+
+ /**
+ * Creates the Velocity renderer.
+ *
+ * @return The Velocity renderer.
+ */
+ public VelocityRenderer build() {
+ VelocityView velocityView = new VelocityView(new ApplicationContextJeeConfig(applicationContext, params));
+ return new VelocityRenderer(velocityView);
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/package-info.java
new file mode 100644
index 000000000..bb0b2d39d
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/request/velocity/render/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Renderering support for Velocity.
+ */
+package org.apache.tiles.request.velocity.render;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
new file mode 100644
index 000000000..165bce373
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/TilesVelocityException.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.velocity;
+
+import org.apache.tiles.api.TilesException;
+
+/**
+ * Exception connected to the usage of Velocity and Tiles.
+ *
+ * @since 2.2.0
+ */
+public class TilesVelocityException extends TilesException {
+
+ private static final long serialVersionUID = -7013866521398042363L;
+
+ /**
+ * Constructor.
+ *
+ * @since 2.2.0
+ */
+ public TilesVelocityException() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message The message of the exception.
+ * @since 2.2.0
+ */
+ public TilesVelocityException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param e The cause of the exception.
+ * @since 2.2.0
+ */
+ public TilesVelocityException(Throwable e) {
+ super(e);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message The message of the exception.
+ * @param e The cause of the exception.
+ * @since 2.2.0
+ */
+ public TilesVelocityException(String message, Throwable e) {
+ super(message, e);
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/package-info.java
new file mode 100644
index 000000000..084432124
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Classes to support Velocity under a servlet environment in Tiles.
+ */
+package org.apache.tiles.velocity;
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AbstractDefaultToStringRenderable.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AbstractDefaultToStringRenderable.java
new file mode 100644
index 000000000..3628833bb
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AbstractDefaultToStringRenderable.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.velocity.TilesVelocityException;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.Renderable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Renderable that provides a default implementation of Renderable#toString()
+ * and allows access to parameters and context objects.
+ *
+ * @since 2.2.0
+ */
+public abstract class AbstractDefaultToStringRenderable implements Renderable {
+
+ /**
+ * The Velocity context.
+ *
+ * @since 2.2.0
+ */
+ protected final Context velocityContext;
+
+ /**
+ * The parameters used in the current tool call.
+ *
+ * @since 2.2.0
+ */
+ protected final Map<String, Object> params;
+
+ /**
+ * The HTTP response.
+ *
+ * @since 2.2.0
+ */
+ protected final HttpServletResponse response;
+
+ /**
+ * The HTTP request.
+ *
+ * @since 2.2.0
+ */
+ protected final HttpServletRequest request;
+
+ /**
+ * The logging object.
+ */
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ /**
+ * Constructor.
+ *
+ * @param velocityContext The Velocity context.
+ * @param params The parameters used in the current tool call.
+ * @param response The HTTP response.
+ * @param request The HTTP request.
+ * @since 2.2.0
+ */
+ public AbstractDefaultToStringRenderable(Context velocityContext, Map<String, Object> params,
+ HttpServletResponse response, HttpServletRequest request) {
+ this.velocityContext = velocityContext;
+ this.params = params;
+ this.response = response;
+ this.request = request;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ StringWriter writer = new StringWriter();
+ try {
+ render(null, writer);
+ } catch (MethodInvocationException e) {
+ throw new TilesVelocityException("Cannot invoke method when rendering", e);
+ } catch (ParseErrorException e) {
+ throw new TilesVelocityException("Cannot parse when rendering", e);
+ } catch (ResourceNotFoundException e) {
+ throw new TilesVelocityException("Cannot find resource when rendering", e);
+ } catch (IOException e) {
+ throw new TilesVelocityException("I/O exception when rendering", e);
+ } finally {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ log.error("Error when closing a StringWriter, the impossible happened!", e);
+ }
+ }
+ return writer.toString();
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddAttributeDirective.java
new file mode 100644
index 000000000..49f6c3112
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddAttributeDirective.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Add an element to the surrounding list. Equivalent to 'putAttribute', but for
+ * list element.
+ * </p>
+ *
+ * <p>
+ * Add an element to the surrounding list. This tag can only be used inside
+ * 'putListAttribute' or 'addListAttribute' tags. Value can come from a direct
+ * assignment (value="aValue")
+ * </p>
+ */
+public class AddAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.AddAttributeModel model = new org.apache.tiles.template.AddAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_addAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("value", java.lang.Object.class, null),
+ runtime.getParameter("expression", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("type", java.lang.String.class, null), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddListAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddListAttributeDirective.java
new file mode 100644
index 000000000..b42b120b0
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/AddListAttributeDirective.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Declare a list that will be pass as an attribute.
+ * </p>
+ * <p>
+ * Declare a list that will be pass as an attribute . List elements are added
+ * using the tag 'addAttribute' or 'addListAttribute'. This tag can only be used
+ * inside 'insertTemplate', 'insertDefinition' or 'definition' tag.
+ * </p>
+ */
+public class AddListAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.AddListAttributeModel model = new org.apache.tiles.template.AddListAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_addListAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("role", java.lang.String.class, null), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ContextHolder.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ContextHolder.java
new file mode 100644
index 000000000..ad43f3941
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ContextHolder.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.velocity.template;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.velocity.context.Context;
+
+/**
+ * An object that holds the current state of Velocity in a Servlet environment.
+ *
+ * @since 2.2.0
+ */
+public class ContextHolder {
+
+ /**
+ * The Velocity context.
+ */
+ private Context velocityContext;
+
+ /**
+ * The HTTP request.
+ */
+ private HttpServletRequest request;
+
+ /**
+ * The HTTP response.
+ */
+ private HttpServletResponse response;
+
+ /**
+ * The servlet context.
+ */
+ 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}.
+ *
+ * @param request The HTTP request.
+ * @since 2.2.0
+ */
+ 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}.
+ *
+ * @param response The HTTP response.
+ * @since 2.2.0
+ */
+ 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}.
+ *
+ * @param application The Servlet context.
+ * @since 2.2.0
+ */
+ public void setServletContext(ServletContext application) {
+ if (application == null) {
+ throw new NullPointerException("servlet context should not be null");
+ }
+ this.application = application;
+ }
+
+ /**
+ * Sets the Velocity {@link Context}. This is required for this tool to operate
+ * and will throw a NullPointerException if this is not set or is set to
+ * {@code null}.
+ *
+ * @param context The Velocity context.
+ * @since 2.2.0
+ */
+ public void setVelocityContext(Context context) {
+ if (context == null) {
+ throw new NullPointerException("velocity context should not be null");
+ }
+ this.velocityContext = context;
+ }
+
+ /**
+ * Returns the HTTP request.
+ *
+ * @return The HTTP request.
+ * @since 2.2.0
+ */
+ protected HttpServletRequest getRequest() {
+ return request;
+ }
+
+ /**
+ * Returns the HTTP response.
+ *
+ * @return The HTTP response.
+ * @since 2.2.0
+ */
+ protected HttpServletResponse getResponse() {
+ return response;
+ }
+
+ /**
+ * Returns the Servlet context.
+ *
+ * @return The Servlet context..
+ * @since 2.2.0
+ */
+ protected ServletContext getServletContext() {
+ return application;
+ }
+
+ /**
+ * Returns the Velocity context..
+ *
+ * @return The Velocity context.
+ * @since 2.2.0
+ */
+ protected Context getVelocityContext() {
+ return velocityContext;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/DefinitionDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/DefinitionDirective.java
new file mode 100644
index 000000000..90373e332
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/DefinitionDirective.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Create a definition at runtime.
+ * </p>
+ * <p>
+ * Create a new definition at runtime. Newly created definition will be
+ * available across the entire request.
+ * </p>
+ */
+public class DefinitionDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.DefinitionModel model = new org.apache.tiles.template.DefinitionModel();
+
+ @Override
+ public String getName() {
+ return "tiles_definition";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("template", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("extends", java.lang.String.class, null),
+ runtime.getParameter("preparer", java.lang.String.class, null), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/GetAsStringDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/GetAsStringDirective.java
new file mode 100644
index 000000000..24109ab3f
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/GetAsStringDirective.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Render the value of the specified template attribute to the current Writer
+ * </p>
+ *
+ * <p>
+ * Retrieve the value of the specified template attribute property, and render
+ * it to the current Writer as a String. The usual toString() conversions is
+ * applied on found value.
+ * </p>
+ */
+public class GetAsStringDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.GetAsStringModel model = new org.apache.tiles.template.GetAsStringModel();
+
+ @Override
+ public String getName() {
+ return "tiles_getAsString";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("ignore", java.lang.Boolean.class, false),
+ runtime.getParameter("preparer", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("defaultValue", java.lang.Object.class, null),
+ runtime.getParameter("defaultValueRole", java.lang.String.class, null),
+ runtime.getParameter("defaultValueType", java.lang.String.class, null),
+ runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("value", org.apache.tiles.api.Attribute.class, null), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ImportAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ImportAttributeDirective.java
new file mode 100644
index 000000000..7fa6f4f9f
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/ImportAttributeDirective.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Import attribute(s) in specified context.
+ * </p>
+ * <p>
+ * Import attribute(s) to requested scope. Attribute name and scope are
+ * optional. If not specified, all attributes are imported in page scope. Once
+ * imported, an attribute can be used as any other beans from jsp contexts.
+ * </p>
+ */
+public class ImportAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.ImportAttributeModel model = new org.apache.tiles.template.ImportAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_importAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return LINE;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ model.execute(runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("scope", java.lang.String.class, null),
+ runtime.getParameter("toName", java.lang.String.class, null),
+ runtime.getParameter("ignore", java.lang.Boolean.class, false), request
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertAttributeDirective.java
new file mode 100644
index 000000000..4a980cd1d
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertAttributeDirective.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Inserts the value of an attribute into the page.
+ * </p>
+ * <p>
+ * This tag can be flexibly used to insert the value of an attribute into a
+ * page. As in other usages in Tiles, every attribute can be determined to have
+ * a "type", either set explicitly when it was defined, or "computed". If the
+ * type is not explicit, then if the attribute value is a valid definition, it
+ * will be inserted as such. Otherwise, if it begins with a "/" character, it
+ * will be treated as a "template". Finally, if it has not otherwise been
+ * assigned a type, it will be treated as a String and included without any
+ * special handling.
+ * </p>
+ *
+ * <p>
+ * Example :
+ * </p>
+ *
+ * <pre>
+ * <tiles:insertAttribute name="body" />
+ * </pre>
+ */
+public class InsertAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.InsertAttributeModel model = new org.apache.tiles.template.InsertAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_insertAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("ignore", java.lang.Boolean.class, false),
+ runtime.getParameter("preparer", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("defaultValue", java.lang.Object.class, null),
+ runtime.getParameter("defaultValueRole", java.lang.String.class, null),
+ runtime.getParameter("defaultValueType", java.lang.String.class, null),
+ runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("value", org.apache.tiles.api.Attribute.class, null),
+ runtime.getParameter("flush", java.lang.Boolean.class, false), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertDefinitionDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertDefinitionDirective.java
new file mode 100644
index 000000000..51a098882
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertDefinitionDirective.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Insert a definition.
+ * </p>
+ * <p>
+ * Insert a definition with the possibility to override and specify parameters
+ * (called attributes). A definition can be seen as a (partially or totally)
+ * filled template that can override or complete attribute values.
+ * <tiles:insertDefinition> allows to define these attributes and pass
+ * them to the inserted jsp page, called template. Attributes are defined using
+ * nested tag <tiles:putAttribute> or <tiles:putListAttribute>.
+ * </p>
+ * <p>
+ * You must specify name tag attribute, for inserting a definition from
+ * definitions factory.
+ * </p>
+ * <p>
+ * Example :
+ * </p>
+ *
+ * <pre>
+ * <tiles:insertDefinition name=".my.tiles.defininition flush="true">
+ * <tiles:putAttribute name="title" value="My first page" />
+ * <tiles:putAttribute name="header" value="/common/header.jsp" />
+ * <tiles:putAttribute name="footer" value="/common/footer.jsp" />
+ * <tiles:putAttribute name="menu" value="/basic/menu.jsp" />
+ * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" />
+ * </tiles:insertDefinition>
+ * </pre>
+ */
+public class InsertDefinitionDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.InsertDefinitionModel model = new org.apache.tiles.template.InsertDefinitionModel();
+
+ @Override
+ public String getName() {
+ return "tiles_insertDefinition";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("template", java.lang.String.class, null),
+ runtime.getParameter("templateType", java.lang.String.class, null),
+ runtime.getParameter("templateExpression", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("preparer", java.lang.String.class, null),
+ runtime.getParameter("flush", java.lang.Boolean.class, false), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertTemplateDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertTemplateDirective.java
new file mode 100644
index 000000000..1ce0e53df
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/InsertTemplateDirective.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Insert a template.
+ * </p>
+ * <p>
+ * Insert a template with the possibility to pass parameters (called
+ * attributes). A template can be seen as a procedure that can take parameters
+ * or attributes. <tiles:insertTemplate> allows to define these attributes
+ * and pass them to the inserted jsp page, called template. Attributes are
+ * defined using nested tag <tiles:putAttribute> or
+ * <tiles:putListAttribute>.
+ * </p>
+ * <p>
+ * You must specify template attribute, for inserting a template
+ * </p>
+ *
+ * <p>
+ * Example :
+ * </p>
+ *
+ * <pre>
+ * <tiles:insertTemplate template="/basic/myLayout.jsp" flush="true">
+ * <tiles:putAttribute name="title" value="My first page" />
+ * <tiles:putAttribute name="header" value="/common/header.jsp" />
+ * <tiles:putAttribute name="footer" value="/common/footer.jsp" />
+ * <tiles:putAttribute name="menu" value="/basic/menu.jsp" />
+ * <tiles:putAttribute name="body" value="/basic/helloBody.jsp" />
+ * </tiles:insertTemplate>
+ * </pre>
+ */
+public class InsertTemplateDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.InsertTemplateModel model = new org.apache.tiles.template.InsertTemplateModel();
+
+ @Override
+ public String getName() {
+ return "tiles_insertTemplate";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("template", java.lang.String.class, null),
+ runtime.getParameter("templateType", java.lang.String.class, null),
+ runtime.getParameter("templateExpression", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("preparer", java.lang.String.class, null),
+ runtime.getParameter("flush", java.lang.Boolean.class, false), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutAttributeDirective.java
new file mode 100644
index 000000000..acac9b1fa
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutAttributeDirective.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Put an attribute in enclosing attribute container tag.
+ * </p>
+ * <p>
+ * Enclosing attribute container tag can be :
+ * <ul>
+ * <li><initContainer></li>
+ * <li><definition></li>
+ * <li><insertAttribute></li>
+ * <li><insertDefinition></li>
+ * <li><putListAttribute></li>
+ * </ul>
+ * (or any other tag which implements the PutAttributeTagParent interface.
+ * 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. 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), object (value is used as it is)</li>
+ * <li>role : Role to check when 'insertAttribute' will be called.</li>
+ * </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>
+ */
+public class PutAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.PutAttributeModel model = new org.apache.tiles.template.PutAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_putAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("value", java.lang.Object.class, null),
+ runtime.getParameter("expression", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("type", java.lang.String.class, null),
+ runtime.getParameter("cascade", java.lang.Boolean.class, false), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutListAttributeDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutListAttributeDirective.java
new file mode 100644
index 000000000..c55dd9274
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/PutListAttributeDirective.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * <p>
+ * Declare a list that will be pass as attribute to tile.
+ * </p>
+ * <p>
+ * Declare a list that will be pass as attribute to tile. List elements are
+ * added using the tags 'addAttribute' or 'addListAttribute'. This tag can only
+ * be used inside 'insertTemplate', 'insertDefinition', 'definition' tags.
+ * </p>
+ */
+public class PutListAttributeDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.PutListAttributeModel model = new org.apache.tiles.template.PutListAttributeModel();
+
+ @Override
+ public String getName() {
+ return "tiles_putListAttribute";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(runtime.getParameter("name", java.lang.String.class, null),
+ runtime.getParameter("role", java.lang.String.class, null),
+ runtime.getParameter("inherit", java.lang.Boolean.class, false),
+ runtime.getParameter("cascade", java.lang.Boolean.class, false), request, modelBody
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/SetCurrentContainerDirective.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/SetCurrentContainerDirective.java
new file mode 100644
index 000000000..d7ff03e80
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/SetCurrentContainerDirective.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * Selects a container to be used as the "current" container.
+ */
+public class SetCurrentContainerDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.template.SetCurrentContainerModel model = new org.apache.tiles.template.SetCurrentContainerModel();
+
+ @Override
+ public String getName() {
+ return "tiles_setCurrentContainer";
+ }
+
+ @Override
+ public int getType() {
+ return LINE;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
+ AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.request.Request request = runtime.createRequest();
+ model.execute(runtime.getParameter("containerKey", java.lang.String.class, null), request
+
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/VelocityStyleTilesTool.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/VelocityStyleTilesTool.java
new file mode 100644
index 000000000..e9c3852ac
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/VelocityStyleTilesTool.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.velocity.template;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tiles.api.Attribute;
+import org.apache.tiles.api.AttributeContext;
+import org.apache.tiles.api.TilesContainer;
+import org.apache.tiles.api.access.TilesAccess;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.tiles.request.velocity.VelocityRequest;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.Renderable;
+
+/**
+ * Tiles Tool to be used "the classic way".
+ *
+ * @since 2.2.0
+ */
+public class VelocityStyleTilesTool extends ContextHolder {
+
+ /**
+ * Returns an attribute.
+ *
+ * @param key The name of the attribute to get.
+ * @return The Attribute.
+ * @since 2.2.0
+ */
+ public Attribute get(String key) {
+ Request velocityRequest = createVelocityRequest(getServletContext(), null);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ AttributeContext attributeContext = container.getAttributeContext(velocityRequest);
+ Attribute attribute = attributeContext.getAttribute(key);
+ return attribute;
+ }
+
+ /**
+ * Creates a new empty attribute.
+ *
+ * @return The created attribute.
+ * @since 2.2.0
+ */
+ public Attribute createAttribute() {
+ return new Attribute();
+ }
+
+ /**
+ * Creates an attribute that is a copy of the one passed as a parameter.
+ *
+ * @param attribute The attribute to copy.
+ * @return The copied attribute.
+ * @since 2.2.0
+ */
+ public Attribute clone(Attribute attribute) {
+ return new Attribute(attribute);
+ }
+
+ /**
+ * Creates an attribute that represents a template.
+ *
+ * @param template The template.
+ * @return The attribute.
+ * @since 2.2.0
+ */
+ public Attribute createTemplateAttribute(String template) {
+ return Attribute.createTemplateAttribute(template);
+ }
+
+ /**
+ * Renders an attribute.
+ *
+ * @param attribute The attribute to render.
+ * @return The renderable object, ready to be rendered.
+ * @since 2.2.0
+ */
+ public Renderable render(final Attribute attribute) {
+ return new AbstractDefaultToStringRenderable(getVelocityContext(), null, getResponse(), getRequest()) {
+
+ public boolean render(InternalContextAdapter context, Writer writer) throws IOException {
+ Request velocityRequest = createVelocityRequest(getServletContext(), writer);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ container.render(attribute, velocityRequest);
+ return true;
+ }
+
+ };
+ }
+
+ /**
+ * Renders a definition. It can be used in conjunction with
+ * {@link #startAttributeContext()} and {@link #endAttributeContext()} to
+ * customize appearance.
+ *
+ * @param definitionName The name of the definition to render.
+ * @return The renderable that renders the definition.
+ * @since 2.2.0
+ */
+ public Renderable renderDefinition(final String definitionName) {
+ return new AbstractDefaultToStringRenderable(getVelocityContext(), null, getResponse(), getRequest()) {
+
+ public boolean render(InternalContextAdapter context, Writer writer) {
+ Request velocityRequest = createVelocityRequest(getServletContext(), writer);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ container.render(definitionName, velocityRequest);
+ return true;
+ }
+
+ };
+ }
+
+ /**
+ * Renders the current attribute context. It can be used in conjunction with
+ * {@link #startAttributeContext()} and {@link #endAttributeContext()} to
+ * customize appearance.
+ *
+ * @return The renderable that renders the current attribute context.
+ * @since 2.2.0
+ */
+ public Renderable renderAttributeContext() {
+ return new AbstractDefaultToStringRenderable(getVelocityContext(), null, getResponse(), getRequest()) {
+
+ public boolean render(InternalContextAdapter context, Writer writer) {
+ Request velocityRequest = createVelocityRequest(getServletContext(), writer);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ container.renderContext(velocityRequest);
+ return true;
+ }
+
+ };
+ }
+
+ /**
+ * Starts the attribute context. Remember to call {@link #endAttributeContext()}
+ * when finished!
+ *
+ * @return The started attribute context, ready to be customized.
+ * @since 2.2.0
+ */
+ public AttributeContext startAttributeContext() {
+ Request velocityRequest = createVelocityRequest(getServletContext(), null);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ return container.startContext(velocityRequest);
+ }
+
+ /**
+ * Ends the current attribute context. To be called after
+ * {@link #startAttributeContext()}.
+ *
+ * @return The tool itself.
+ * @since 2.2.0
+ */
+ public VelocityStyleTilesTool endAttributeContext() {
+ Request velocityRequest = createVelocityRequest(getServletContext(), null);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ container.endContext(velocityRequest);
+ return this;
+ }
+
+ /**
+ * Returns the current attribute context.
+ *
+ * @return The current attribute context.
+ * @since 2.2.0
+ */
+ public AttributeContext getAttributeContext() {
+ Request velocityRequest = createVelocityRequest(getServletContext(), null);
+ TilesContainer container = TilesAccess.getCurrentContainer(velocityRequest);
+ return container.getAttributeContext(velocityRequest);
+ }
+
+ /**
+ * Sets the current container for the current request.
+ *
+ * @param containerKey The key of the container to set as "current" for the
+ * current request.
+ * @return The tool itself.
+ * @since 2.2.0
+ */
+ public VelocityStyleTilesTool setCurrentContainer(String containerKey) {
+ Request velocityRequest = createVelocityRequest(getServletContext(), null);
+ TilesAccess.setCurrentContainer(velocityRequest, containerKey);
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return "";
+ }
+
+ /**
+ * Creates a Velocity request.
+ *
+ * @param servletContext The servlet context.
+ * @param writer The writer.
+ * @return The created request.
+ */
+ protected Request createVelocityRequest(ServletContext servletContext, Writer writer) {
+ return VelocityRequest.createVelocityRequest(ServletUtil.getApplicationContext(servletContext), getRequest(),
+ getResponse(), getVelocityContext(), writer);
+ }
+}
diff --git a/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/package-info.java b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/package-info.java
new file mode 100644
index 000000000..eeb9e3a27
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/tiles/velocity/template/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Classes that allow the use of "Tiles template" as a Velocity tool.
+ */
+package org.apache.tiles.velocity.template;
diff --git a/plugins/tiles/src/main/resources/META-INF/velocity.properties b/plugins/tiles/src/main/resources/META-INF/velocity.properties
new file mode 100644
index 000000000..4887c6cc3
--- /dev/null
+++ b/plugins/tiles/src/main/resources/META-INF/velocity.properties
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# This file was automatically generated by Autotag. Please do not edit it manually.
+
+userdirective=org.apache.tiles.velocity.template.InsertDefinitionDirective,\
+org.apache.tiles.velocity.template.ImportAttributeDirective,\
+org.apache.tiles.velocity.template.SetCurrentContainerDirective,\
+org.apache.tiles.velocity.template.AddListAttributeDirective,\
+org.apache.tiles.velocity.template.GetAsStringDirective,\
+org.apache.tiles.velocity.template.InsertAttributeDirective,\
+org.apache.tiles.velocity.template.PutAttributeDirective,\
+org.apache.tiles.velocity.template.DefinitionDirective,\
+org.apache.tiles.velocity.template.AddAttributeDirective,\
+org.apache.tiles.velocity.template.PutListAttributeDirective,\
+org.apache.tiles.velocity.template.InsertTemplateDirective
diff --git a/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity.properties b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity.properties
index 29ae759db..821c6d762 100644
--- a/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity.properties
+++ b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity.properties
@@ -44,19 +44,6 @@ input.encoding=ISO-8859-1
output.encoding=ISO-8859-1
-# ----------------------------------------------------------------------------
-# F O R E A C H P R O P E R T I E S
-# ----------------------------------------------------------------------------
-# These properties control how the counter is accessed in the #foreach
-# directive. By default the reference $velocityCount will be available
-# in the body of the #foreach directive. The default starting value
-# for this reference is 1.
-# ----------------------------------------------------------------------------
-
-directive.foreach.counter.name = velocityCount
-directive.foreach.counter.initial.value = 1
-
-
# ----------------------------------------------------------------------------
# I N C L U D E P R O P E R T I E S
# ----------------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
new file mode 100644
index 000000000..0528affab
--- /dev/null
+++ b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package ${packageName};
+
+import java.io.IOException;
+import java.io.Writer;
+
+#if(${clazz.hasBody()})
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+#end
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+#foreach($line in $stringTool.splitOnNewlines(${clazz.documentation}))
+ * ${line}
+#end
+ */
+public class ${clazz.tagClassPrefix}Directive extends Directive {
+
+ /**
+ * The template model.
+ */
+ private ${clazz.name} model = new ${clazz.name}();
+
+ @Override
+ public String getName() {
+ return "${suite.name}_${clazz.tagName}";
+ }
+
+ @Override
+ public int getType() {
+ return #if(${clazz.hasBody()})BLOCK#{else}LINE#{end};
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node)
+ throws IOException {
+ AutotagRuntime<${requestClass}> runtime = new ${runtimeClass}();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ ${requestClass} request = runtime.createRequest();
+#if(${clazz.hasBody()})
+ ModelBody modelBody = runtime.createModelBody();
+#end
+ model.execute(
+#foreach($parameter in ${clazz.parameters})
+ runtime.getParameter("${parameter.exportedName}", ${stringTool.getClassToCast(${parameter.type})}.class, $stringTool.getDefaultValue(${parameter.type}, ${parameter.defaultValue})),
+#end
+ request#if(${clazz.hasBody()}), modelBody#end
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
new file mode 100644
index 000000000..6360d64f4
--- /dev/null
+++ b/plugins/tiles/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# This file was automatically generated by Autotag. Please do not edit it manually.
+
+userdirective=#foreach($clazz in ${suite.getTemplateClasses()})#if($foreach.count > 1),\
+ #{end}${packageName}.${clazz.tagClassPrefix}Directive#end
\ No newline at end of file
diff --git a/plugins/tiles/src/main/resources/tools.xml b/plugins/tiles/src/main/resources/tools.xml
new file mode 100644
index 000000000..65d673763
--- /dev/null
+++ b/plugins/tiles/src/main/resources/tools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<tools>
+ <toolbox scope="request">
+ <tool key="tiles" class="org.apache.tiles.velocity.template.VelocityStyleTilesTool"/>
+ </toolbox>
+</tools>
diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
new file mode 100644
index 000000000..b9854bf1c
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateMethod;
+import org.apache.tiles.autotag.model.TemplateParameter;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.velocity.app.VelocityEngine;
+import org.junit.Test;
+
+/**
+ * Tests VelocityDirectiveGenerator.
+ */
+public class VelocityDirectiveGeneratorTest {
+
+ public static final String REQUEST_CLASS = "org.apache.tiles.autotag.velocity.Request";
+
+ /**
+ * Test method for VelocityDirectiveGenerator#generate(File, String,
+ * TemplateSuite, TemplateClass, java.util.Map).
+ *
+ * @throws Exception If something goes wrong.
+ */
+ @Test
+ public void testGenerate() throws Exception {
+ Properties props = new Properties();
+ InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
+ props.load(propsStream);
+ propsStream.close();
+ VelocityEngine velocityEngine = new VelocityEngine(props);
+
+ VelocityDirectiveGenerator generator = new VelocityDirectiveGenerator(velocityEngine);
+ File file = File.createTempFile("autotag", null);
+ file.delete();
+ file.mkdir();
+ file.deleteOnExit();
+ TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs.");
+
+ List<TemplateParameter> params = new ArrayList<TemplateParameter>();
+ TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false);
+ param.setDocumentation("Parameter one.");
+ params.add(param);
+ param = new TemplateParameter("two", "two", "int", null, false, false);
+ param.setDocumentation("Parameter two.");
+ params.add(param);
+ param = new TemplateParameter("three", "three", "boolean", null, false, false);
+ param.setDocumentation("Parameter three.");
+ params.add(param);
+ param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true);
+ param.setDocumentation("The request.");
+ params.add(param);
+ param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false);
+ param.setDocumentation("The body.");
+ params.add(param);
+ TemplateMethod executeMethod = new TemplateMethod("execute", params);
+
+ TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff",
+ "DoStuff", executeMethod);
+ clazz.setDocumentation("Documentation of the DoStuff class.");
+
+ generator.generate(file, "org.apache.tiles.autotag.velocity.test", suite, clazz, null,
+ "org.apache.tiles.autotag.velocity.test.Runtime", REQUEST_CLASS);
+
+ InputStream expected = getClass()
+ .getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat");
+ File effectiveFile = new File(file, "/org/apache/tiles/autotag/velocity/test/DoStuffDirective.java");
+ assertTrue(effectiveFile.exists());
+ InputStream effective = new FileInputStream(effectiveFile);
+ assertTrue(IOUtils.contentEquals(effective, expected));
+ effective.close();
+ expected.close();
+
+ suite.addTemplateClass(clazz);
+ params = new ArrayList<TemplateParameter>();
+ param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false);
+ param.setDocumentation("Parameter one.");
+ params.add(param);
+ param = new TemplateParameter("two", "two", "float", null, false, false);
+ param.setDocumentation("Parameter two.");
+ params.add(param);
+ param = new TemplateParameter("three", "three", "java.util.Date", null, false, false);
+ param.setDocumentation("Parameter three.");
+ params.add(param);
+ param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true);
+ param.setDocumentation("The request.");
+ params.add(param);
+ executeMethod = new TemplateMethod("execute", params);
+
+ clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody",
+ "DoStuffNoBody", executeMethod);
+ clazz.setDocumentation("Documentation of the DoStuffNoBody class.");
+
+ suite.addTemplateClass(clazz);
+
+ generator.generate(file, "org.apache.tiles.autotag.velocity.test", suite, clazz, null,
+ "org.apache.tiles.autotag.velocity.test.Runtime", REQUEST_CLASS);
+
+ expected = getClass()
+ .getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat");
+ effectiveFile = new File(file, "/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.java");
+ assertTrue(effectiveFile.exists());
+ effective = new FileInputStream(effectiveFile);
+ assertTrue(IOUtils.contentEquals(effective, expected));
+ effective.close();
+ expected.close();
+
+ FileUtils.deleteDirectory(file);
+ }
+
+}
diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
new file mode 100644
index 000000000..1ea2b37fc
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateMethod;
+import org.apache.tiles.autotag.model.TemplateParameter;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.velocity.app.VelocityEngine;
+import org.junit.Test;
+
+/**
+ * Tests VelocityPropertiesGenerator.
+ */
+public class VelocityPropertiesGeneratorTest {
+
+ public static final String REQUEST_CLASS = "org.apache.tiles.autotag.velocity.Request";
+
+ /**
+ * Test method for org.apache.tiles.autotag.velocity.VelocityPropertiesGenerator
+ * #generate(File, String, TemplateSuite, java.util.Map).
+ *
+ * @throws Exception If something goes wrong.
+ */
+ @Test
+ public void testGenerate() throws Exception {
+ Properties props = new Properties();
+ InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
+ props.load(propsStream);
+ propsStream.close();
+ VelocityEngine velocityEngine = new VelocityEngine(props);
+
+ VelocityPropertiesGenerator generator = new VelocityPropertiesGenerator(velocityEngine);
+ File file = File.createTempFile("autotag", null);
+ file.delete();
+ file.mkdir();
+ file.deleteOnExit();
+ TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD docs.");
+
+ List<TemplateParameter> params = new ArrayList<TemplateParameter>();
+ TemplateParameter param = new TemplateParameter("one", "one", "java.lang.String", null, true, false);
+ param.setDocumentation("Parameter one.");
+ params.add(param);
+ param = new TemplateParameter("two", "two", "int", null, false, false);
+ param.setDocumentation("Parameter two.");
+ params.add(param);
+ param = new TemplateParameter("three", "three", "long", null, false, false);
+ param.setDocumentation("Parameter three.");
+ params.add(param);
+ param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true);
+ param.setDocumentation("The request.");
+ params.add(param);
+ param = new TemplateParameter("modelBody", "modelBody", ModelBody.class.getName(), null, false, false);
+ param.setDocumentation("The body.");
+ params.add(param);
+ TemplateMethod executeMethod = new TemplateMethod("execute", params);
+
+ TemplateClass clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate", "doStuff",
+ "DoStuff", executeMethod);
+ clazz.setDocumentation("Documentation of the DoStuff class");
+
+ suite.addTemplateClass(clazz);
+ params = new ArrayList<TemplateParameter>();
+ param = new TemplateParameter("one", "one", "java.lang.Double", null, true, false);
+ param.setDocumentation("Parameter one.");
+ params.add(param);
+ param = new TemplateParameter("two", "two", "float", null, false, false);
+ param.setDocumentation("Parameter two.");
+ params.add(param);
+ param = new TemplateParameter("three", "three", "java.util.Date", null, false, false);
+ param.setDocumentation("Parameter three.");
+ params.add(param);
+ param = new TemplateParameter("request", "request", REQUEST_CLASS, null, false, true);
+ param.setDocumentation("The request.");
+ params.add(param);
+ executeMethod = new TemplateMethod("execute", params);
+
+ clazz = new TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate", "doStuffNoBody",
+ "DoStuffNoBody", executeMethod);
+ clazz.setDocumentation("Documentation of the DoStuffNoBody class");
+
+ suite.addTemplateClass(clazz);
+
+ generator.generate(file, "org.apache.tiles.autotag.velocity.test", suite, null);
+
+ InputStream expected = getClass().getResourceAsStream("/velocity.properties.test");
+ File effectiveFile = new File(file, "META-INF/velocity.properties");
+ assertTrue(effectiveFile.exists());
+ InputStream effective = new FileInputStream(effectiveFile);
+ assertTrue(IOUtils.contentEquals(effective, expected));
+ effective.close();
+ expected.close();
+
+ FileUtils.deleteDirectory(file);
+ }
+
+}
diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactoryTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactoryTest.java
new file mode 100644
index 000000000..e0924178a
--- /dev/null
+++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/velocity/VelocityTemplateGeneratorFactoryTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.autotag.velocity;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.apache.tiles.autotag.generate.TemplateGenerator;
+import org.apache.tiles.autotag.generate.TemplateGeneratorBuilder;
+import org.apache.velocity.app.VelocityEngine;
+import org.junit.Test;
+
+/**
+ * Tests JspTemplateGeneratorFactory.
+ */
+public class VelocityTemplateGeneratorFactoryTest {
+
+ /**
+ * Test method for VelocityTemplateGeneratorFactory#createTemplateGenerator().
+ */
+ @Test
+ public void testCreateTemplateGenerator() {
+ File classesOutputDirectory = createMock(File.class);
+ File resourcesOutputDirectory = createMock(File.class);
+ VelocityEngine velocityEngine = createMock(VelocityEngine.class);
+ TemplateGeneratorBuilder builder = createMock(TemplateGeneratorBuilder.class);
+ TemplateGenerator generator = createMock(TemplateGenerator.class);
+
+ expect(builder.setClassesOutputDirectory(classesOutputDirectory)).andReturn(builder);
+ expect(builder.setResourcesOutputDirectory(resourcesOutputDirectory)).andReturn(builder);
+ expect(builder.addResourcesTemplateSuiteGenerator(isA(VelocityPropertiesGenerator.class))).andReturn(builder);
+ expect(builder.addClassesTemplateClassGenerator(isA(VelocityDirectiveGenerator.class))).andReturn(builder);
+ expect(builder.build()).andReturn(generator);
+
+ replay(classesOutputDirectory, resourcesOutputDirectory, velocityEngine, builder, generator);
+ VelocityTemplateGeneratorFactory factory = new VelocityTemplateGeneratorFactory(classesOutputDirectory,
+ resourcesOutputDirectory, velocityEngine, builder);
+ assertSame(generator, factory.createTemplateGenerator());
+ verify(classesOutputDirectory, resourcesOutputDirectory, velocityEngine, builder, generator);
+ }
+
+}
diff --git a/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat b/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
new file mode 100644
index 000000000..8ae29b34a
--- /dev/null
+++ b/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.autotag.velocity.test;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * Documentation of the DoStuff class.
+ */
+public class DoStuffDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.autotag.template.DoStuffTemplate model = new org.apache.tiles.autotag.template.DoStuffTemplate();
+
+ @Override
+ public String getName() {
+ return "tldtest_doStuff";
+ }
+
+ @Override
+ public int getType() {
+ return BLOCK;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node)
+ throws IOException {
+ AutotagRuntime<org.apache.tiles.autotag.velocity.Request> runtime = new org.apache.tiles.autotag.velocity.test.Runtime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.autotag.velocity.Request request = runtime.createRequest();
+ ModelBody modelBody = runtime.createModelBody();
+ model.execute(
+ runtime.getParameter("one", java.lang.String.class, null),
+ runtime.getParameter("two", java.lang.Integer.class, 0),
+ runtime.getParameter("three", java.lang.Boolean.class, false),
+ request, modelBody
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat b/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
new file mode 100644
index 000000000..6ed645a66
--- /dev/null
+++ b/plugins/tiles/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+ * This file was automatically generated by Autotag. Please do not edit it manually.
+ */
+package org.apache.tiles.autotag.velocity.test;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * Documentation of the DoStuffNoBody class.
+ */
+public class DoStuffNoBodyDirective extends Directive {
+
+ /**
+ * The template model.
+ */
+ private org.apache.tiles.autotag.template.DoStuffNoBodyTemplate model = new org.apache.tiles.autotag.template.DoStuffNoBodyTemplate();
+
+ @Override
+ public String getName() {
+ return "tldtest_doStuffNoBody";
+ }
+
+ @Override
+ public int getType() {
+ return LINE;
+ }
+
+ @Override
+ public boolean render(InternalContextAdapter context, Writer writer, Node node)
+ throws IOException {
+ AutotagRuntime<org.apache.tiles.autotag.velocity.Request> runtime = new org.apache.tiles.autotag.velocity.test.Runtime();
+ if (runtime instanceof Directive) {
+ ((Directive) runtime).render(context, writer, node);
+ }
+ org.apache.tiles.autotag.velocity.Request request = runtime.createRequest();
+ model.execute(
+ runtime.getParameter("one", java.lang.Double.class, null),
+ runtime.getParameter("two", java.lang.Float.class, 0.0f),
+ runtime.getParameter("three", java.util.Date.class, null),
+ request
+ );
+ return true;
+ }
+}
diff --git a/plugins/tiles/src/test/resources/velocity.properties.test b/plugins/tiles/src/test/resources/velocity.properties.test
new file mode 100644
index 000000000..3ee9deeb8
--- /dev/null
+++ b/plugins/tiles/src/test/resources/velocity.properties.test
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# This file was automatically generated by Autotag. Please do not edit it manually.
+
+userdirective=org.apache.tiles.autotag.velocity.test.DoStuffDirective,\
+org.apache.tiles.autotag.velocity.test.DoStuffNoBodyDirective
\ No newline at end of file