diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml
index c0b902366..99bceb716 100644
--- a/apps/showcase/pom.xml
+++ b/apps/showcase/pom.xml
@@ -94,6 +94,11 @@
struts2-async-plugin
+
+ org.apache.struts
+ struts2-velocity-plugin
+
+
javax.servlet
servlet-api
diff --git a/apps/showcase/src/main/resources/struts-tags-ui.xml b/apps/showcase/src/main/resources/struts-tags-ui.xml
index 69b9bdac0..13e33d65b 100644
--- a/apps/showcase/src/main/resources/struts-tags-ui.xml
+++ b/apps/showcase/src/main/resources/struts-tags-ui.xml
@@ -24,7 +24,7 @@
"http://struts.apache.org/dtds/struts-2.5.dtd">
-
+
/WEB-INF/tags/ui/example.jsp
/WEB-INF/tags/ui/example.jsp
diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index 3f9da83a0..2d1209548 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -102,9 +102,6 @@ public final class StrutsConstants {
/** Maximum strong sizing for MruCacheStorage for freemarker */
public static final String STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE = "struts.freemarker.mru.max.strong.size";
-
- /** org.apache.struts2.views.velocity.VelocityManager implementation class */
- public static final String STRUTS_VELOCITY_MANAGER_CLASSNAME = "struts.velocity.manager.classname";
/** The Velocity configuration file path */
public static final String STRUTS_VELOCITY_CONFIGFILE = "struts.velocity.configfile";
diff --git a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
index 0ebe8cddc..1e976f01b 100644
--- a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
+++ b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
@@ -67,7 +67,6 @@ import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.util.ContentTypeMatcher;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.util.UrlHelper;
-import org.apache.struts2.views.velocity.VelocityManager;
/**
* Selects the implementations of key framework extension points, using the loaded
@@ -367,8 +366,6 @@ import org.apache.struts2.views.velocity.VelocityManager;
*/
public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider {
- private static final Logger LOG = LogManager.getLogger(DefaultBeanSelectionProvider.class);
-
public void register(ContainerBuilder builder, LocatableProperties props) {
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props);
alias(ActionFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, builder, props);
@@ -404,7 +401,6 @@ public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider
alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props);
alias(MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER, builder, props, Scope.PROTOTYPE);
alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props);
- alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props);
alias(UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER, builder, props);
alias(ActionValidatorManager.class, StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, builder, props);
alias(ValueStackFactory.class, StrutsConstants.STRUTS_VALUESTACKFACTORY, builder, props);
diff --git a/core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java b/core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java
index d92ce008a..904296ff9 100644
--- a/core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java
+++ b/core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java
@@ -185,7 +185,6 @@ public class ConstantConfig {
map.put(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, freemarkerTemplatesCacheUpdateDelay);
map.put(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE, Objects.toString(freemarkerBeanwrapperCache, null));
map.put(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE, Objects.toString(freemarkerMruMaxStrongSize, null));
- map.put(StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, beanConfToString(velocityManagerClassname));
map.put(StrutsConstants.STRUTS_VELOCITY_CONFIGFILE, velocityConfigfile);
map.put(StrutsConstants.STRUTS_VELOCITY_TOOLBOXLOCATION, velocityToolboxlocation);
map.put(StrutsConstants.STRUTS_VELOCITY_CONTEXTS, StringUtils.join(velocityContexts, ','));
diff --git a/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java b/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
index 5a01df3c4..cab6c4018 100644
--- a/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
+++ b/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
@@ -18,55 +18,16 @@
*/
package org.apache.struts2.views;
-import java.util.Arrays;
-import java.util.List;
+import com.opensymphony.xwork2.util.ValueStack;
+import org.apache.struts2.views.freemarker.tags.StrutsModels;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.struts2.views.freemarker.tags.StrutsModels;
-import org.apache.struts2.views.velocity.components.ActionDirective;
-import org.apache.struts2.views.velocity.components.ActionErrorDirective;
-import org.apache.struts2.views.velocity.components.ActionMessageDirective;
-import org.apache.struts2.views.velocity.components.AnchorDirective;
-import org.apache.struts2.views.velocity.components.BeanDirective;
-import org.apache.struts2.views.velocity.components.CheckBoxDirective;
-import org.apache.struts2.views.velocity.components.CheckBoxListDirective;
-import org.apache.struts2.views.velocity.components.ComboBoxDirective;
-import org.apache.struts2.views.velocity.components.ComponentDirective;
-import org.apache.struts2.views.velocity.components.DateDirective;
-import org.apache.struts2.views.velocity.components.DoubleSelectDirective;
-import org.apache.struts2.views.velocity.components.FieldErrorDirective;
-import org.apache.struts2.views.velocity.components.FileDirective;
-import org.apache.struts2.views.velocity.components.FormDirective;
-import org.apache.struts2.views.velocity.components.HeadDirective;
-import org.apache.struts2.views.velocity.components.HiddenDirective;
-import org.apache.struts2.views.velocity.components.I18nDirective;
-import org.apache.struts2.views.velocity.components.IncludeDirective;
-import org.apache.struts2.views.velocity.components.LabelDirective;
-import org.apache.struts2.views.velocity.components.OptionTransferSelectDirective;
-import org.apache.struts2.views.velocity.components.ParamDirective;
-import org.apache.struts2.views.velocity.components.PasswordDirective;
-import org.apache.struts2.views.velocity.components.PropertyDirective;
-import org.apache.struts2.views.velocity.components.PushDirective;
-import org.apache.struts2.views.velocity.components.RadioDirective;
-import org.apache.struts2.views.velocity.components.ResetDirective;
-import org.apache.struts2.views.velocity.components.SelectDirective;
-import org.apache.struts2.views.velocity.components.SetDirective;
-import org.apache.struts2.views.velocity.components.SubmitDirective;
-import org.apache.struts2.views.velocity.components.TextAreaDirective;
-import org.apache.struts2.views.velocity.components.TextDirective;
-import org.apache.struts2.views.velocity.components.TextFieldDirective;
-import org.apache.struts2.views.velocity.components.TokenDirective;
-import org.apache.struts2.views.velocity.components.URLDirective;
-import org.apache.struts2.views.velocity.components.UpDownSelectDirective;
-
-import com.opensymphony.xwork2.util.ValueStack;
-
/**
* The default Struts tag library
*/
-public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider {
+public class DefaultTagLibrary implements TagLibraryModelProvider {
public Object getModels(ValueStack stack, HttpServletRequest req,
HttpServletResponse res) {
@@ -74,53 +35,8 @@ public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibrar
return new StrutsModels(stack, req, res);
}
- public List getDirectiveClasses() {
- Class[] directives = new Class[] {
- ActionDirective.class,
- BeanDirective.class,
- CheckBoxDirective.class,
- CheckBoxListDirective.class,
- ComboBoxDirective.class,
- ComponentDirective.class,
- DateDirective.class,
- DoubleSelectDirective.class,
- FileDirective.class,
- FormDirective.class,
- HeadDirective.class,
- HiddenDirective.class,
- AnchorDirective.class,
- I18nDirective.class,
- IncludeDirective.class,
- LabelDirective.class,
- ParamDirective.class,
- PasswordDirective.class,
- PushDirective.class,
- PropertyDirective.class,
- RadioDirective.class,
- SelectDirective.class,
- SetDirective.class,
- SubmitDirective.class,
- ResetDirective.class,
- TextAreaDirective.class,
- TextDirective.class,
- TextFieldDirective.class,
- TokenDirective.class,
- URLDirective.class,
- ActionErrorDirective.class,
- ActionMessageDirective.class,
- FieldErrorDirective.class,
- OptionTransferSelectDirective.class,
- UpDownSelectDirective.class
- };
- return Arrays.asList(directives);
- }
-
public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return getModels(stack, req, res);
}
- public List getVelocityDirectiveClasses() {
- return getDirectiveClasses();
- }
-
}
diff --git a/core/src/main/java/org/apache/struts2/views/TagLibraryDirectiveProvider.java b/core/src/main/java/org/apache/struts2/views/TagLibraryDirectiveProvider.java
index 4df60a0e1..76368467d 100644
--- a/core/src/main/java/org/apache/struts2/views/TagLibraryDirectiveProvider.java
+++ b/core/src/main/java/org/apache/struts2/views/TagLibraryDirectiveProvider.java
@@ -36,6 +36,6 @@ public interface TagLibraryDirectiveProvider {
*
* @return A list of Velocity directive classes
*/
- public List getDirectiveClasses();
+ List getDirectiveClasses();
}
diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml
index ed850bdc5..6ab501d19 100644
--- a/core/src/main/resources/struts-default.xml
+++ b/core/src/main/resources/struts-default.xml
@@ -106,16 +106,13 @@
-
-
-
@@ -201,7 +198,6 @@
-
diff --git a/core/src/test/java/org/apache/struts2/views/TemplateEngineManagerTest.java b/core/src/test/java/org/apache/struts2/views/TemplateEngineManagerTest.java
index 3fb8d0dab..dbd406d06 100644
--- a/core/src/test/java/org/apache/struts2/views/TemplateEngineManagerTest.java
+++ b/core/src/test/java/org/apache/struts2/views/TemplateEngineManagerTest.java
@@ -27,8 +27,6 @@ import org.apache.struts2.components.template.JspTemplateEngine;
import org.apache.struts2.components.template.Template;
import org.apache.struts2.components.template.TemplateEngine;
import org.apache.struts2.components.template.TemplateEngineManager;
-import org.apache.struts2.components.template.VelocityTemplateEngine;
-import org.apache.struts2.dispatcher.mapper.CompositeActionMapper;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.Mock;
@@ -47,9 +45,8 @@ public class TemplateEngineManagerTest extends TestCase {
mgr = new TemplateEngineManager();
mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
- mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
- mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
+ mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
add("jsp");
add("vm");
add("ftl");
@@ -60,18 +57,13 @@ public class TemplateEngineManagerTest extends TestCase {
}
public void testTemplateTypeFromTemplateNameAndDefaults() {
-
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
assertTrue(engine instanceof JspTemplateEngine);
- engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), null);
- assertTrue(engine instanceof VelocityTemplateEngine);
}
public void testTemplateTypeOverrides() {
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), "ftl");
assertTrue(engine instanceof FreemarkerTemplateEngine);
- engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), "ftl");
- assertTrue(engine instanceof VelocityTemplateEngine);
engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.ftl"), "");
assertTrue(engine instanceof FreemarkerTemplateEngine);
}
@@ -81,7 +73,7 @@ public class TemplateEngineManagerTest extends TestCase {
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
Template template = new Template("/template", "simple", "foo." + TemplateEngineManager.DEFAULT_TEMPLATE_TYPE);
TemplateEngine defaultTemplateEngine = mgr.getTemplateEngine(template, null);
- assertTrue(engine.getClass().equals(defaultTemplateEngine.getClass()));
+ assertEquals(engine.getClass(), defaultTemplateEngine.getClass());
}
protected void tearDown() throws Exception {
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 4ecdd0e2e..66bb555d9 100644
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -32,6 +32,7 @@
Struts 2 Plugins
+ async
bean-validation
cdi
config-browser
@@ -55,7 +56,7 @@
spring
testng
tiles
- async
+ velocity
diff --git a/plugins/portlet/pom.xml b/plugins/portlet/pom.xml
index 06146d0ff..81f08b65c 100644
--- a/plugins/portlet/pom.xml
+++ b/plugins/portlet/pom.xml
@@ -40,6 +40,11 @@
true
+
+ org.apache.struts
+ struts2-velocity-plugin
+
+
junit
junit
diff --git a/plugins/sitemesh/pom.xml b/plugins/sitemesh/pom.xml
index 66375ae5e..8a47ea227 100644
--- a/plugins/sitemesh/pom.xml
+++ b/plugins/sitemesh/pom.xml
@@ -36,16 +36,11 @@
opensymphony
sitemesh
+
- org.apache.velocity
- velocity
- true
-
-
-
- org.apache.velocity
- velocity-tools
+ org.apache.struts
+ struts2-velocity-plugin
true
diff --git a/plugins/velocity/pom.xml b/plugins/velocity/pom.xml
new file mode 100644
index 000000000..de58b17b4
--- /dev/null
+++ b/plugins/velocity/pom.xml
@@ -0,0 +1,83 @@
+
+
+
+ 4.0.0
+
+ org.apache.struts
+ struts2-plugins
+ 2.6-SNAPSHOT
+
+
+ struts2-velocity-plugin
+ jar
+ Struts 2 Velocity Plugin
+
+
+
+
+
+ org.apache.struts
+ struts2-core
+
+
+
+
+ org.apache.velocity
+ velocity
+
+
+
+ org.apache.velocity
+ velocity-tools
+
+
+
+ javax.servlet
+ servlet-api
+
+
+
+ javax.servlet.jsp
+ jsp-api
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ test
+
+
+
+ mockobjects
+ mockobjects-core
+ test
+
+
+
+
+
+ UTF-8
+
+
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/StrutsResourceLoader.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsResourceLoader.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/StrutsResourceLoader.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsResourceLoader.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java
similarity index 87%
rename from core/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java
index 469e57029..f8f6075f5 100644
--- a/core/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java
@@ -24,11 +24,9 @@ import com.opensymphony.xwork2.util.ValueStack;
public class StrutsVelocityContext extends VelocityContext {
- private static final long serialVersionUID = 8497212428904436963L;
ValueStack stack;
VelocityContext[] chainedContexts;
-
public StrutsVelocityContext(ValueStack stack) {
this(null, stack);
}
@@ -38,7 +36,6 @@ public class StrutsVelocityContext extends VelocityContext {
this.stack = stack;
}
-
public boolean internalContainsKey(Object key) {
boolean contains = super.internalContainsKey(key);
@@ -63,8 +60,8 @@ public class StrutsVelocityContext extends VelocityContext {
// if we still haven't found it, le's search through our chained contexts
if (chainedContexts != null) {
- for (int index = 0; index < chainedContexts.length; index++) {
- if (chainedContexts[index].containsKey(key)) {
+ for (VelocityContext chainedContext : chainedContexts) {
+ if (chainedContext.containsKey(key)) {
return true;
}
}
@@ -97,9 +94,9 @@ public class StrutsVelocityContext extends VelocityContext {
// finally, if we're chained to other contexts, let's look in them
if (chainedContexts != null) {
- for (int index = 0; index < chainedContexts.length; index++) {
- if (chainedContexts[index].containsKey(key)) {
- return chainedContexts[index].internalGet(key);
+ for (VelocityContext chainedContext : chainedContexts) {
+ if (chainedContext.containsKey(key)) {
+ return chainedContext.internalGet(key);
}
}
}
diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityBeanSelectionProvider.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityBeanSelectionProvider.java
new file mode 100644
index 000000000..5690813d9
--- /dev/null
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityBeanSelectionProvider.java
@@ -0,0 +1,54 @@
+/*
+ * 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.struts2.views.velocity;
+
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import org.apache.struts2.config.AbstractBeanSelectionProvider;
+
+/**
+ * Please see {@link org.apache.struts2.config.DefaultBeanSelectionProvider} for more details.
+ *
+ *
+ * The following is a list of the allowed extension points:
+ *
+ *
+ *
+ * | Type |
+ * Property |
+ * Scope |
+ * Description |
+ *
+ *
+ * | org.apache.struts2.views.velocity.VelocityManager |
+ * struts.velocity.manager.classname |
+ * singleton |
+ * Loads and processes Velocity templates |
+ *
+ *
+ */
+public class VelocityBeanSelectionProvider extends AbstractBeanSelectionProvider {
+
+ @Override
+ public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+ alias(VelocityManager.class, VelocityConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props);
+ }
+
+}
diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityConstants.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityConstants.java
new file mode 100644
index 000000000..f9056621c
--- /dev/null
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityConstants.java
@@ -0,0 +1,26 @@
+/*
+ * 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.struts2.views.velocity;
+
+public final class VelocityConstants {
+
+ /** org.apache.struts2.views.velocity.VelocityManager implementation class */
+ public static final String STRUTS_VELOCITY_MANAGER_CLASSNAME = "struts.velocity.manager.classname";
+
+}
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
similarity index 94%
rename from core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
index f94ac7ef6..b65338041 100644
--- a/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
@@ -53,22 +53,15 @@ import java.util.*;
* Manages the environment for Velocity result types
*/
public class VelocityManager {
+
private static final Logger LOG = LogManager.getLogger(VelocityManager.class);
+
public static final String STRUTS = "struts";
+
private ObjectFactory objectFactory;
public static final String KEY_VELOCITY_STRUTS_CONTEXT = ".KEY_velocity.struts2.context";
- /**
- * the parent JSP tag
- */
- public static final String PARENT = "parent";
-
- /**
- * the current JSP tag
- */
- public static final String TAG = "tag";
-
private VelocityEngine velocityEngine;
/**
@@ -77,7 +70,6 @@ public class VelocityManager {
protected ToolboxManager toolboxManager = null;
private String toolBoxLocation;
-
/**
* Names of contexts that will be chained on every request
*/
@@ -137,8 +129,8 @@ public class VelocityManager {
VelocityContext[] chainedContexts = prepareChainedContexts(req, res, stack.getContext());
StrutsVelocityContext context = new StrutsVelocityContext(chainedContexts, stack);
Map standardMap = ContextUtil.getStandardContext(stack, req, res);
- for (Iterator iterator = standardMap.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
+ for (Object o : standardMap.entrySet()) {
+ Map.Entry entry = (Map.Entry) o;
context.put((String) entry.getKey(), entry.getValue());
}
context.put(STRUTS, new VelocityStrutsUtil(velocityEngine, context, stack, req, res));
@@ -236,13 +228,13 @@ public class VelocityManager {
String defaultUserDirective = properties.getProperty("userdirective");
- /**
- * if the user has specified an external velocity configuration file, we'll want to search for it in the
- * following order
- *
- * 1. relative to the context path
- * 2. relative to /WEB-INF
- * 3. in the class path
+ /*
+ if the user has specified an external velocity configuration file, we'll want to search for it in the
+ following order
+
+ 1. relative to the context path
+ 2. relative to /WEB-INF
+ 3. in the class path
*/
String configfile;
@@ -301,16 +293,15 @@ public class VelocityManager {
if (in != null) {
try {
in.close();
- } catch (IOException e) {
+ } catch (IOException ignore) {
}
}
}
// overide with programmatically set properties
if (this.velocityProperties != null) {
- Iterator keys = this.velocityProperties.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
+ for (Object o : this.velocityProperties.keySet()) {
+ String key = (String) o;
properties.setProperty(key, this.velocityProperties.getProperty(key));
}
}
@@ -330,8 +321,8 @@ public class VelocityManager {
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing Velocity with the following properties ...");
- for (Iterator iter = properties.keySet().iterator(); iter.hasNext(); ) {
- String key = (String) iter.next();
+ for (Object o : properties.keySet()) {
+ String key = (String) o;
String value = properties.getProperty(key);
LOG.debug(" '{}' = '{}'", key, value);
}
@@ -394,9 +385,6 @@ public class VelocityManager {
}
}
-
-
-
/**
*
* Instantiates a new VelocityEngine.
@@ -488,11 +476,11 @@ public class VelocityManager {
} else {
// remove strutsfile from resource loader property
String prop = properties.getProperty(Velocity.RESOURCE_LOADER);
- if (prop.indexOf("strutsfile,") != -1) {
+ if (prop.contains("strutsfile,")) {
prop = replace(prop, "strutsfile,", "");
- } else if (prop.indexOf(", strutsfile") != -1) {
+ } else if (prop.contains(", strutsfile")) {
prop = replace(prop, ", strutsfile", "");
- } else if (prop.indexOf("strutsfile") != -1) {
+ } else if (prop.contains("strutsfile")) {
prop = replace(prop, "strutsfile", "");
}
@@ -536,7 +524,7 @@ public class VelocityManager {
sb.append(clazz.getName()).append(",");
}
- private static final String replace(String string, String oldString, String newString) {
+ private String replace(String string, String oldString, String newString) {
if (string == null) {
return null;
}
diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityTagLibrary.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityTagLibrary.java
new file mode 100644
index 000000000..6135164b2
--- /dev/null
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityTagLibrary.java
@@ -0,0 +1,113 @@
+/*
+ * 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.struts2.views.velocity;
+
+import org.apache.struts2.views.TagLibraryDirectiveProvider;
+import org.apache.struts2.views.velocity.components.ActionDirective;
+import org.apache.struts2.views.velocity.components.ActionErrorDirective;
+import org.apache.struts2.views.velocity.components.ActionMessageDirective;
+import org.apache.struts2.views.velocity.components.AnchorDirective;
+import org.apache.struts2.views.velocity.components.BeanDirective;
+import org.apache.struts2.views.velocity.components.CheckBoxDirective;
+import org.apache.struts2.views.velocity.components.CheckBoxListDirective;
+import org.apache.struts2.views.velocity.components.ComboBoxDirective;
+import org.apache.struts2.views.velocity.components.ComponentDirective;
+import org.apache.struts2.views.velocity.components.DateDirective;
+import org.apache.struts2.views.velocity.components.DoubleSelectDirective;
+import org.apache.struts2.views.velocity.components.FieldErrorDirective;
+import org.apache.struts2.views.velocity.components.FileDirective;
+import org.apache.struts2.views.velocity.components.FormDirective;
+import org.apache.struts2.views.velocity.components.HeadDirective;
+import org.apache.struts2.views.velocity.components.HiddenDirective;
+import org.apache.struts2.views.velocity.components.I18nDirective;
+import org.apache.struts2.views.velocity.components.IncludeDirective;
+import org.apache.struts2.views.velocity.components.LabelDirective;
+import org.apache.struts2.views.velocity.components.OptionTransferSelectDirective;
+import org.apache.struts2.views.velocity.components.ParamDirective;
+import org.apache.struts2.views.velocity.components.PasswordDirective;
+import org.apache.struts2.views.velocity.components.PropertyDirective;
+import org.apache.struts2.views.velocity.components.PushDirective;
+import org.apache.struts2.views.velocity.components.RadioDirective;
+import org.apache.struts2.views.velocity.components.ResetDirective;
+import org.apache.struts2.views.velocity.components.SelectDirective;
+import org.apache.struts2.views.velocity.components.SetDirective;
+import org.apache.struts2.views.velocity.components.SubmitDirective;
+import org.apache.struts2.views.velocity.components.TextAreaDirective;
+import org.apache.struts2.views.velocity.components.TextDirective;
+import org.apache.struts2.views.velocity.components.TextFieldDirective;
+import org.apache.struts2.views.velocity.components.TokenDirective;
+import org.apache.struts2.views.velocity.components.URLDirective;
+import org.apache.struts2.views.velocity.components.UpDownSelectDirective;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class VelocityTagLibrary implements TagLibraryDirectiveProvider {
+
+ @Override
+ public List getDirectiveClasses() {
+ Class[] directives = new Class[] {
+ ActionDirective.class,
+ BeanDirective.class,
+ CheckBoxDirective.class,
+ CheckBoxListDirective.class,
+ ComboBoxDirective.class,
+ ComponentDirective.class,
+ DateDirective.class,
+ DoubleSelectDirective.class,
+ FileDirective.class,
+ FormDirective.class,
+ HeadDirective.class,
+ HiddenDirective.class,
+ AnchorDirective.class,
+ I18nDirective.class,
+ IncludeDirective.class,
+ LabelDirective.class,
+ ParamDirective.class,
+ PasswordDirective.class,
+ PushDirective.class,
+ PropertyDirective.class,
+ RadioDirective.class,
+ SelectDirective.class,
+ SetDirective.class,
+ SubmitDirective.class,
+ ResetDirective.class,
+ TextAreaDirective.class,
+ TextDirective.class,
+ TextFieldDirective.class,
+ TokenDirective.class,
+ URLDirective.class,
+ ActionErrorDirective.class,
+ ActionMessageDirective.class,
+ FieldErrorDirective.class,
+ OptionTransferSelectDirective.class,
+ UpDownSelectDirective.class
+ };
+ return Arrays.asList(directives);
+ }
+
+ /**
+ * @deprecated please use {#getDirectiveClasses}
+ */
+ @Deprecated()
+ public List getVelocityDirectiveClasses() {
+ return getDirectiveClasses();
+ }
+
+}
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/AbstractDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ActionDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ActionDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ActionErrorDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionErrorDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ActionErrorDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionErrorDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ActionMessageDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionMessageDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ActionMessageDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ActionMessageDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/AnchorDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/AnchorDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/AnchorDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/AnchorDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/BeanDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/BeanDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/BeanDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/BeanDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxListDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxListDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxListDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/CheckBoxListDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ComboBoxDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ComboBoxDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ComboBoxDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ComboBoxDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ComponentDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ComponentDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ComponentDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ComponentDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/DateDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/DateDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/DateDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/DateDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/DoubleSelectDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/DoubleSelectDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/DoubleSelectDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/DoubleSelectDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/FieldErrorDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FieldErrorDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/FieldErrorDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FieldErrorDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/FileDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FileDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/FileDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FileDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/FormDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FormDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/FormDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/FormDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/HeadDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/HeadDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/HeadDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/HeadDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/HiddenDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/HiddenDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/HiddenDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/HiddenDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/I18nDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/I18nDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/I18nDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/I18nDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/IncludeDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/IncludeDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/IncludeDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/IncludeDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/InputTransferSelectDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/InputTransferSelectDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/InputTransferSelectDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/InputTransferSelectDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/LabelDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/LabelDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/LabelDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/LabelDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/OptGroupDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/OptGroupDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/OptGroupDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/OptGroupDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/OptionTransferSelectDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/OptionTransferSelectDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/OptionTransferSelectDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/OptionTransferSelectDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ParamDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ParamDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ParamDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ParamDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/PasswordDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PasswordDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/PasswordDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PasswordDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/PropertyDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PropertyDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/PropertyDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PropertyDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/PushDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PushDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/PushDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/PushDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/RadioDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/RadioDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/RadioDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/RadioDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/ResetDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ResetDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/ResetDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/ResetDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/SelectDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SelectDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/SelectDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SelectDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/SetDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SetDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/SetDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SetDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/SubmitDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SubmitDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/SubmitDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/SubmitDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/TextAreaDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextAreaDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/TextAreaDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextAreaDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/TextDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/TextDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/TextFieldDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextFieldDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/TextFieldDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TextFieldDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/TokenDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TokenDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/TokenDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/TokenDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/URLDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/URLDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/URLDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/URLDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/components/UpDownSelectDirective.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/UpDownSelectDirective.java
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/components/UpDownSelectDirective.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/components/UpDownSelectDirective.java
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/package.html b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/package.html
similarity index 100%
rename from core/src/main/java/org/apache/struts2/views/velocity/package.html
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/package.html
diff --git a/core/src/main/java/org/apache/struts2/result/VelocityResult.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java
similarity index 98%
rename from core/src/main/java/org/apache/struts2/result/VelocityResult.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java
index b552fb7df..c62f6870f 100644
--- a/core/src/main/java/org/apache/struts2/result/VelocityResult.java
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.result;
+package org.apache.struts2.views.velocity.result;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.result.StrutsResultSupport;
import org.apache.struts2.views.JspSupportServlet;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.Template;
diff --git a/core/src/main/java/org/apache/struts2/components/template/VelocityTemplateEngine.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java
similarity index 93%
rename from core/src/main/java/org/apache/struts2/components/template/VelocityTemplateEngine.java
rename to plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java
index 24f456471..423029e32 100644
--- a/core/src/main/java/org/apache/struts2/components/template/VelocityTemplateEngine.java
+++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java
@@ -16,12 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.components.template;
+package org.apache.struts2.views.velocity.template;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.components.template.BaseTemplateEngine;
+import org.apache.struts2.components.template.Template;
+import org.apache.struts2.components.template.TemplateRenderingContext;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
@@ -29,7 +32,6 @@ import org.apache.velocity.context.Context;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;
diff --git a/plugins/velocity/src/main/resources/struts-plugin.xml b/plugins/velocity/src/main/resources/struts-plugin.xml
new file mode 100644
index 000000000..00a4207f4
--- /dev/null
+++ b/plugins/velocity/src/main/resources/struts-plugin.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/core/src/main/resources/template/archive/ajax/a-close.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/a-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/a-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/a-close.vm
diff --git a/core/src/main/resources/template/archive/ajax/a.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/a.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/a.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/a.vm
diff --git a/core/src/main/resources/template/archive/ajax/div-close.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/div-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/div-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/div-close.vm
diff --git a/core/src/main/resources/template/archive/ajax/div.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/div.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/div.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/div.vm
diff --git a/core/src/main/resources/template/archive/ajax/form-close.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/form-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/form-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/form-close.vm
diff --git a/core/src/main/resources/template/archive/ajax/form.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/form.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/form.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/form.vm
diff --git a/core/src/main/resources/template/archive/ajax/submit.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/submit.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/submit.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/submit.vm
diff --git a/core/src/main/resources/template/archive/ajax/tab-close.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/tab-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/tab-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/tab-close.vm
diff --git a/core/src/main/resources/template/archive/ajax/tab.vm b/plugins/velocity/src/main/resources/template/velocity/ajax/tab.vm
similarity index 100%
rename from core/src/main/resources/template/archive/ajax/tab.vm
rename to plugins/velocity/src/main/resources/template/velocity/ajax/tab.vm
diff --git a/core/src/main/resources/template/archive/simple/checkbox.vm b/plugins/velocity/src/main/resources/template/velocity/simple/checkbox.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/checkbox.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/checkbox.vm
diff --git a/core/src/main/resources/template/archive/simple/checkboxlist.vm b/plugins/velocity/src/main/resources/template/velocity/simple/checkboxlist.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/checkboxlist.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/checkboxlist.vm
diff --git a/core/src/main/resources/template/archive/simple/combobox.vm b/plugins/velocity/src/main/resources/template/velocity/simple/combobox.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/combobox.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/combobox.vm
diff --git a/core/src/main/resources/template/archive/simple/debug.vm b/plugins/velocity/src/main/resources/template/velocity/simple/debug.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/debug.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/debug.vm
diff --git a/core/src/main/resources/template/archive/simple/doubleselect.vm b/plugins/velocity/src/main/resources/template/velocity/simple/doubleselect.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/doubleselect.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/doubleselect.vm
diff --git a/core/src/main/resources/template/archive/simple/empty.vm b/plugins/velocity/src/main/resources/template/velocity/simple/empty.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/empty.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/empty.vm
diff --git a/core/src/main/resources/template/archive/simple/file.vm b/plugins/velocity/src/main/resources/template/velocity/simple/file.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/file.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/file.vm
diff --git a/core/src/main/resources/template/archive/simple/form-close.vm b/plugins/velocity/src/main/resources/template/velocity/simple/form-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/form-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/form-close.vm
diff --git a/core/src/main/resources/template/archive/simple/form.vm b/plugins/velocity/src/main/resources/template/velocity/simple/form.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/form.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/form.vm
diff --git a/core/src/main/resources/template/archive/simple/hidden.vm b/plugins/velocity/src/main/resources/template/velocity/simple/hidden.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/hidden.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/hidden.vm
diff --git a/core/src/main/resources/template/archive/simple/label.vm b/plugins/velocity/src/main/resources/template/velocity/simple/label.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/label.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/label.vm
diff --git a/core/src/main/resources/template/archive/simple/password.vm b/plugins/velocity/src/main/resources/template/velocity/simple/password.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/password.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/password.vm
diff --git a/core/src/main/resources/template/archive/simple/radiomap.vm b/plugins/velocity/src/main/resources/template/velocity/simple/radiomap.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/radiomap.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/radiomap.vm
diff --git a/core/src/main/resources/template/archive/simple/scripting-events.vm b/plugins/velocity/src/main/resources/template/velocity/simple/scripting-events.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/scripting-events.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/scripting-events.vm
diff --git a/core/src/main/resources/template/archive/simple/select.vm b/plugins/velocity/src/main/resources/template/velocity/simple/select.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/select.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/select.vm
diff --git a/core/src/main/resources/template/archive/simple/submit.vm b/plugins/velocity/src/main/resources/template/velocity/simple/submit.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/submit.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/submit.vm
diff --git a/core/src/main/resources/template/archive/simple/table.vm b/plugins/velocity/src/main/resources/template/velocity/simple/table.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/table.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/table.vm
diff --git a/core/src/main/resources/template/archive/simple/text.vm b/plugins/velocity/src/main/resources/template/velocity/simple/text.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/text.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/text.vm
diff --git a/core/src/main/resources/template/archive/simple/textarea.vm b/plugins/velocity/src/main/resources/template/velocity/simple/textarea.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/textarea.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/textarea.vm
diff --git a/core/src/main/resources/template/archive/simple/token.vm b/plugins/velocity/src/main/resources/template/velocity/simple/token.vm
similarity index 100%
rename from core/src/main/resources/template/archive/simple/token.vm
rename to plugins/velocity/src/main/resources/template/velocity/simple/token.vm
diff --git a/core/src/main/resources/template/archive/xhtml/checkbox.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/checkbox.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/checkbox.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/checkbox.vm
diff --git a/core/src/main/resources/template/archive/xhtml/checkboxlist.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/checkboxlist.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/checkboxlist.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/checkboxlist.vm
diff --git a/core/src/main/resources/template/archive/xhtml/combobox.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/combobox.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/combobox.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/combobox.vm
diff --git a/core/src/main/resources/template/archive/xhtml/controlfooter.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/controlfooter.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/controlfooter.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/controlfooter.vm
diff --git a/core/src/main/resources/template/archive/xhtml/controlheader.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/controlheader.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/controlheader.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/controlheader.vm
diff --git a/core/src/main/resources/template/archive/xhtml/debug.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/debug.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/debug.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/debug.vm
diff --git a/core/src/main/resources/template/archive/xhtml/doubleselect.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/doubleselect.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/doubleselect.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/doubleselect.vm
diff --git a/core/src/main/resources/template/archive/xhtml/empty.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/empty.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/empty.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/empty.vm
diff --git a/core/src/main/resources/template/archive/xhtml/file.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/file.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/file.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/file.vm
diff --git a/core/src/main/resources/template/archive/xhtml/form-close.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/form-close.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/form-close.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/form-close.vm
diff --git a/core/src/main/resources/template/archive/xhtml/form.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/form.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/form.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/form.vm
diff --git a/core/src/main/resources/template/archive/xhtml/hidden.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/hidden.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/hidden.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/hidden.vm
diff --git a/core/src/main/resources/template/archive/xhtml/label.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/label.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/label.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/label.vm
diff --git a/core/src/main/resources/template/archive/xhtml/password.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/password.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/password.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/password.vm
diff --git a/core/src/main/resources/template/archive/xhtml/radiomap.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/radiomap.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/radiomap.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/radiomap.vm
diff --git a/core/src/main/resources/template/archive/xhtml/select.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/select.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/select.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/select.vm
diff --git a/core/src/main/resources/template/archive/xhtml/submit.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/submit.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/submit.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/submit.vm
diff --git a/core/src/main/resources/template/archive/xhtml/table.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/table.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/table.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/table.vm
diff --git a/core/src/main/resources/template/archive/xhtml/text.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/text.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/text.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/text.vm
diff --git a/core/src/main/resources/template/archive/xhtml/textarea.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/textarea.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/textarea.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/textarea.vm
diff --git a/core/src/main/resources/template/archive/xhtml/token.vm b/plugins/velocity/src/main/resources/template/velocity/xhtml/token.vm
similarity index 100%
rename from core/src/main/resources/template/archive/xhtml/token.vm
rename to plugins/velocity/src/main/resources/template/velocity/xhtml/token.vm
diff --git a/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java
similarity index 85%
rename from core/src/test/java/org/apache/struts2/result/VelocityResultTest.java
rename to plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java
index 9ba000fde..7fa4bb9d1 100644
--- a/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java
+++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/result/VelocityResultTest.java
@@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.result;
+package org.apache.struts2.views.velocity.result;
-import org.apache.struts2.StrutsInternalTestCase;
+import com.opensymphony.xwork2.XWorkTestCase;
+import junit.framework.TestCase;
import org.apache.struts2.result.StrutsResultSupport;
-import org.apache.struts2.result.VelocityResult;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
@@ -36,7 +36,7 @@ import com.opensymphony.xwork2.util.ValueStack;
/**
*
*/
-public class VelocityResultTest extends StrutsInternalTestCase {
+public class VelocityResultTest extends XWorkTestCase {
ActionInvocation actionInvocation;
Mock mockActionProxy;
@@ -56,11 +56,11 @@ public class VelocityResultTest extends StrutsInternalTestCase {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(bean);
- assertEquals(location, stack.findValue("location"));
+ TestCase.assertEquals(location, stack.findValue("location"));
result.setLocation("${location}");
result.execute(actionInvocation);
- assertEquals(location, result.finalLocation);
+ TestCase.assertEquals(location, result.finalLocation);
}
public void testCanResolveLocationUsingStaticExpression() throws Exception {
@@ -68,15 +68,15 @@ public class VelocityResultTest extends StrutsInternalTestCase {
String location = "/any.action";
result.setLocation("${'" + location + "'}");
result.execute(actionInvocation);
- assertEquals(location, result.finalLocation);
+ TestCase.assertEquals(location, result.finalLocation);
}
public void testResourcesFoundUsingAbsolutePath() throws Exception {
String location = "/WEB-INF/views/registration.vm";
Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8");
- assertNotNull(template);
- assertEquals("expect absolute locations to be handled as is", location, velocity.templateName);
+ TestCase.assertNotNull(template);
+ TestCase.assertEquals("expect absolute locations to be handled as is", location, velocity.templateName);
}
public void testResourcesFoundUsingNames() throws Exception {
@@ -84,8 +84,8 @@ public class VelocityResultTest extends StrutsInternalTestCase {
String expectedTemplateName = namespace + "/" + location;
Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8");
- assertNotNull(template);
- assertEquals("expect the prefix to be appended to the path when the location is not absolute", expectedTemplateName, velocity.templateName);
+ TestCase.assertNotNull(template);
+ TestCase.assertEquals("expect the prefix to be appended to the path when the location is not absolute", expectedTemplateName, velocity.templateName);
}
protected void setUp() throws Exception {
diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngineTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngineTest.java
new file mode 100644
index 000000000..b206e2a4f
--- /dev/null
+++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngineTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.struts2.views.velocity.template;
+
+import com.mockobjects.dynamic.C;
+import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.XWorkTestCase;
+import com.opensymphony.xwork2.inject.Container;
+import org.apache.struts2.components.template.FreemarkerTemplateEngine;
+import org.apache.struts2.components.template.JspTemplateEngine;
+import org.apache.struts2.components.template.Template;
+import org.apache.struts2.components.template.TemplateEngine;
+import org.apache.struts2.components.template.TemplateEngineManager;
+
+import java.util.HashSet;
+
+public class VelocityTemplateEngineTest extends XWorkTestCase {
+
+ private TemplateEngineManager mgr;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ mgr = new TemplateEngineManager();
+ Mock mockContainer = new Mock(Container.class);
+ mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
+ mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
+ mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
+ mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
+ add("jsp");
+ add("vm");
+ add("ftl");
+ }});
+
+ mgr.setContainer((Container) mockContainer.proxy());
+ mgr.setDefaultTemplateType("jsp");
+ }
+
+ public void testTemplateTypeFromTemplateNameAndDefaults() {
+
+ TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
+ assertTrue(engine instanceof JspTemplateEngine);
+ engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), null);
+ assertTrue(engine instanceof VelocityTemplateEngine);
+ }
+
+ public void testTemplateTypeOverrides() {
+ TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), "ftl");
+ assertTrue(engine instanceof FreemarkerTemplateEngine);
+ engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), "ftl");
+ assertTrue(engine instanceof VelocityTemplateEngine);
+ engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.ftl"), "");
+ assertTrue(engine instanceof FreemarkerTemplateEngine);
+ }
+
+ public void testTemplateTypeUsesDefaultWhenNotSetInConfiguration() {
+ mgr.setDefaultTemplateType(null);
+ TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
+ Template template = new Template("/template", "simple", "foo." + TemplateEngineManager.DEFAULT_TEMPLATE_TYPE);
+ TemplateEngine defaultTemplateEngine = mgr.getTemplateEngine(template, null);
+ assertEquals(engine.getClass(), defaultTemplateEngine.getClass());
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f8128dc17..c8c638751 100644
--- a/pom.xml
+++ b/pom.xml
@@ -691,6 +691,11 @@
struts2-osgi-demo-bundle
${project.version}
+
+ org.apache.struts
+ struts2-velocity-plugin
+ ${project.version}
+
org.freemarker
@@ -731,7 +736,6 @@
org.apache.velocity
velocity
1.7
- true