Skip to content

Commit 5c55e69

Browse files
committed
WW-5049 Moves Velocity support into a dedicated plugin
1 parent 8952cff commit 5c55e69

File tree

114 files changed

+471
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+471
-176
lines changed

apps/showcase/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
<artifactId>struts2-async-plugin</artifactId>
9595
</dependency>
9696

97+
<dependency>
98+
<groupId>org.apache.struts</groupId>
99+
<artifactId>struts2-velocity-plugin</artifactId>
100+
</dependency>
101+
97102
<dependency>
98103
<groupId>javax.servlet</groupId>
99104
<artifactId>servlet-api</artifactId>

apps/showcase/src/main/resources/struts-tags-ui.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"http://struts.apache.org/dtds/struts-2.5.dtd">
2525

2626
<struts>
27-
<package name="ui-tags" extends="struts-default" namespace="/tags/ui">
27+
<package name="ui-tags" extends="velocity-default" namespace="/tags/ui">
2828
<action name="example" class="org.apache.struts2.showcase.UITagExample">
2929
<result>/WEB-INF/tags/ui/example.jsp</result>
3030
<result name="input">/WEB-INF/tags/ui/example.jsp</result>

core/src/main/java/org/apache/struts2/StrutsConstants.java

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public final class StrutsConstants {
102102

103103
/** Maximum strong sizing for MruCacheStorage for freemarker */
104104
public static final String STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE = "struts.freemarker.mru.max.strong.size";
105-
106-
/** org.apache.struts2.views.velocity.VelocityManager implementation class */
107-
public static final String STRUTS_VELOCITY_MANAGER_CLASSNAME = "struts.velocity.manager.classname";
108105

109106
/** The Velocity configuration file path */
110107
public static final String STRUTS_VELOCITY_CONFIGFILE = "struts.velocity.configfile";

core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java

-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.apache.struts2.util.ContentTypeMatcher;
6868
import org.apache.struts2.views.freemarker.FreemarkerManager;
6969
import org.apache.struts2.views.util.UrlHelper;
70-
import org.apache.struts2.views.velocity.VelocityManager;
7170

7271
/**
7372
* Selects the implementations of key framework extension points, using the loaded
@@ -367,8 +366,6 @@
367366
*/
368367
public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider {
369368

370-
private static final Logger LOG = LogManager.getLogger(DefaultBeanSelectionProvider.class);
371-
372369
public void register(ContainerBuilder builder, LocatableProperties props) {
373370
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props);
374371
alias(ActionFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, builder, props);
@@ -404,7 +401,6 @@ public void register(ContainerBuilder builder, LocatableProperties props) {
404401
alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props);
405402
alias(MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER, builder, props, Scope.PROTOTYPE);
406403
alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props);
407-
alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props);
408404
alias(UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER, builder, props);
409405
alias(ActionValidatorManager.class, StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, builder, props);
410406
alias(ValueStackFactory.class, StrutsConstants.STRUTS_VALUESTACKFACTORY, builder, props);

core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ public Map<String, String> getAllAsStringsMap() {
185185
map.put(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, freemarkerTemplatesCacheUpdateDelay);
186186
map.put(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE, Objects.toString(freemarkerBeanwrapperCache, null));
187187
map.put(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE, Objects.toString(freemarkerMruMaxStrongSize, null));
188-
map.put(StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, beanConfToString(velocityManagerClassname));
189188
map.put(StrutsConstants.STRUTS_VELOCITY_CONFIGFILE, velocityConfigfile);
190189
map.put(StrutsConstants.STRUTS_VELOCITY_TOOLBOXLOCATION, velocityToolboxlocation);
191190
map.put(StrutsConstants.STRUTS_VELOCITY_CONTEXTS, StringUtils.join(velocityContexts, ','));

core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java

+3-87
Original file line numberDiff line numberDiff line change
@@ -18,109 +18,25 @@
1818
*/
1919
package org.apache.struts2.views;
2020

21-
import java.util.Arrays;
22-
import java.util.List;
21+
import com.opensymphony.xwork2.util.ValueStack;
22+
import org.apache.struts2.views.freemarker.tags.StrutsModels;
2323

2424
import javax.servlet.http.HttpServletRequest;
2525
import javax.servlet.http.HttpServletResponse;
2626

27-
import org.apache.struts2.views.freemarker.tags.StrutsModels;
28-
import org.apache.struts2.views.velocity.components.ActionDirective;
29-
import org.apache.struts2.views.velocity.components.ActionErrorDirective;
30-
import org.apache.struts2.views.velocity.components.ActionMessageDirective;
31-
import org.apache.struts2.views.velocity.components.AnchorDirective;
32-
import org.apache.struts2.views.velocity.components.BeanDirective;
33-
import org.apache.struts2.views.velocity.components.CheckBoxDirective;
34-
import org.apache.struts2.views.velocity.components.CheckBoxListDirective;
35-
import org.apache.struts2.views.velocity.components.ComboBoxDirective;
36-
import org.apache.struts2.views.velocity.components.ComponentDirective;
37-
import org.apache.struts2.views.velocity.components.DateDirective;
38-
import org.apache.struts2.views.velocity.components.DoubleSelectDirective;
39-
import org.apache.struts2.views.velocity.components.FieldErrorDirective;
40-
import org.apache.struts2.views.velocity.components.FileDirective;
41-
import org.apache.struts2.views.velocity.components.FormDirective;
42-
import org.apache.struts2.views.velocity.components.HeadDirective;
43-
import org.apache.struts2.views.velocity.components.HiddenDirective;
44-
import org.apache.struts2.views.velocity.components.I18nDirective;
45-
import org.apache.struts2.views.velocity.components.IncludeDirective;
46-
import org.apache.struts2.views.velocity.components.LabelDirective;
47-
import org.apache.struts2.views.velocity.components.OptionTransferSelectDirective;
48-
import org.apache.struts2.views.velocity.components.ParamDirective;
49-
import org.apache.struts2.views.velocity.components.PasswordDirective;
50-
import org.apache.struts2.views.velocity.components.PropertyDirective;
51-
import org.apache.struts2.views.velocity.components.PushDirective;
52-
import org.apache.struts2.views.velocity.components.RadioDirective;
53-
import org.apache.struts2.views.velocity.components.ResetDirective;
54-
import org.apache.struts2.views.velocity.components.SelectDirective;
55-
import org.apache.struts2.views.velocity.components.SetDirective;
56-
import org.apache.struts2.views.velocity.components.SubmitDirective;
57-
import org.apache.struts2.views.velocity.components.TextAreaDirective;
58-
import org.apache.struts2.views.velocity.components.TextDirective;
59-
import org.apache.struts2.views.velocity.components.TextFieldDirective;
60-
import org.apache.struts2.views.velocity.components.TokenDirective;
61-
import org.apache.struts2.views.velocity.components.URLDirective;
62-
import org.apache.struts2.views.velocity.components.UpDownSelectDirective;
63-
64-
import com.opensymphony.xwork2.util.ValueStack;
65-
6627
/**
6728
* The default Struts tag library
6829
*/
69-
public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider {
30+
public class DefaultTagLibrary implements TagLibraryModelProvider {
7031

7132
public Object getModels(ValueStack stack, HttpServletRequest req,
7233
HttpServletResponse res) {
7334

7435
return new StrutsModels(stack, req, res);
7536
}
7637

77-
public List<Class> getDirectiveClasses() {
78-
Class[] directives = new Class[] {
79-
ActionDirective.class,
80-
BeanDirective.class,
81-
CheckBoxDirective.class,
82-
CheckBoxListDirective.class,
83-
ComboBoxDirective.class,
84-
ComponentDirective.class,
85-
DateDirective.class,
86-
DoubleSelectDirective.class,
87-
FileDirective.class,
88-
FormDirective.class,
89-
HeadDirective.class,
90-
HiddenDirective.class,
91-
AnchorDirective.class,
92-
I18nDirective.class,
93-
IncludeDirective.class,
94-
LabelDirective.class,
95-
ParamDirective.class,
96-
PasswordDirective.class,
97-
PushDirective.class,
98-
PropertyDirective.class,
99-
RadioDirective.class,
100-
SelectDirective.class,
101-
SetDirective.class,
102-
SubmitDirective.class,
103-
ResetDirective.class,
104-
TextAreaDirective.class,
105-
TextDirective.class,
106-
TextFieldDirective.class,
107-
TokenDirective.class,
108-
URLDirective.class,
109-
ActionErrorDirective.class,
110-
ActionMessageDirective.class,
111-
FieldErrorDirective.class,
112-
OptionTransferSelectDirective.class,
113-
UpDownSelectDirective.class
114-
};
115-
return Arrays.asList(directives);
116-
}
117-
11838
public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
11939
return getModels(stack, req, res);
12040
}
12141

122-
public List<Class> getVelocityDirectiveClasses() {
123-
return getDirectiveClasses();
124-
}
125-
12642
}

core/src/main/java/org/apache/struts2/views/TagLibraryDirectiveProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public interface TagLibraryDirectiveProvider {
3636
*
3737
* @return A list of Velocity directive classes
3838
*/
39-
public List<Class> getDirectiveClasses();
39+
List<Class> getDirectiveClasses();
4040

4141
}

core/src/main/resources/struts-default.xml

-4
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,13 @@
106106
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="prototype"/>
107107
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta-stream" class="org.apache.struts2.dispatcher.multipart.JakartaStreamMultiPartRequest" scope="prototype"/>
108108

109-
<bean type="org.apache.struts2.views.TagLibraryDirectiveProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
110109
<bean type="org.apache.struts2.views.TagLibraryModelProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
111110

112111
<bean class="org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader" />
113112
<bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" />
114-
<bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" optional="true" />
115113

116114
<bean class="org.apache.struts2.components.template.TemplateEngineManager" />
117115
<bean type="org.apache.struts2.components.template.TemplateEngine" name="ftl" class="org.apache.struts2.components.template.FreemarkerTemplateEngine" />
118-
<bean type="org.apache.struts2.components.template.TemplateEngine" name="vm" class="org.apache.struts2.components.template.VelocityTemplateEngine" />
119116
<bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />
120117

121118
<bean type="com.opensymphony.xwork2.conversion.impl.XWorkConverter" name="struts" class="com.opensymphony.xwork2.conversion.impl.XWorkConverter" />
@@ -201,7 +198,6 @@
201198
<result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
202199
<result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
203200
<result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
204-
<result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
205201
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
206202
<result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
207203
<result-type name="postback" class="org.apache.struts2.result.PostbackResult" />

core/src/test/java/org/apache/struts2/views/TemplateEngineManagerTest.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.apache.struts2.components.template.Template;
2828
import org.apache.struts2.components.template.TemplateEngine;
2929
import org.apache.struts2.components.template.TemplateEngineManager;
30-
import org.apache.struts2.components.template.VelocityTemplateEngine;
31-
import org.apache.struts2.dispatcher.mapper.CompositeActionMapper;
3230

3331
import com.mockobjects.dynamic.C;
3432
import com.mockobjects.dynamic.Mock;
@@ -47,9 +45,8 @@ public void setUp() throws Exception {
4745
mgr = new TemplateEngineManager();
4846
mockContainer = new Mock(Container.class);
4947
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
50-
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
5148
mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
52-
mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
49+
mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet<String>() {{
5350
add("jsp");
5451
add("vm");
5552
add("ftl");
@@ -60,18 +57,13 @@ public void setUp() throws Exception {
6057
}
6158

6259
public void testTemplateTypeFromTemplateNameAndDefaults() {
63-
6460
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
6561
assertTrue(engine instanceof JspTemplateEngine);
66-
engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), null);
67-
assertTrue(engine instanceof VelocityTemplateEngine);
6862
}
6963

7064
public void testTemplateTypeOverrides() {
7165
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), "ftl");
7266
assertTrue(engine instanceof FreemarkerTemplateEngine);
73-
engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), "ftl");
74-
assertTrue(engine instanceof VelocityTemplateEngine);
7567
engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.ftl"), "");
7668
assertTrue(engine instanceof FreemarkerTemplateEngine);
7769
}
@@ -81,7 +73,7 @@ public void testTemplateTypeUsesDefaultWhenNotSetInConfiguration() {
8173
TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
8274
Template template = new Template("/template", "simple", "foo." + TemplateEngineManager.DEFAULT_TEMPLATE_TYPE);
8375
TemplateEngine defaultTemplateEngine = mgr.getTemplateEngine(template, null);
84-
assertTrue(engine.getClass().equals(defaultTemplateEngine.getClass()));
76+
assertEquals(engine.getClass(), defaultTemplateEngine.getClass());
8577
}
8678

8779
protected void tearDown() throws Exception {

plugins/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<name>Struts 2 Plugins</name>
3333

3434
<modules>
35+
<module>async</module>
3536
<module>bean-validation</module>
3637
<module>cdi</module>
3738
<module>config-browser</module>
@@ -55,7 +56,7 @@
5556
<module>spring</module>
5657
<module>testng</module>
5758
<module>tiles</module>
58-
<module>async</module>
59+
<module>velocity</module>
5960
</modules>
6061

6162
<dependencies>

plugins/portlet/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<optional>true</optional>
4141
</dependency>
4242

43+
<dependency>
44+
<groupId>org.apache.struts</groupId>
45+
<artifactId>struts2-velocity-plugin</artifactId>
46+
</dependency>
47+
4348
<dependency>
4449
<groupId>junit</groupId>
4550
<artifactId>junit</artifactId>

plugins/sitemesh/pom.xml

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,11 @@
3636
<groupId>opensymphony</groupId>
3737
<artifactId>sitemesh</artifactId>
3838
</dependency>
39-
<!-- Velocity -->
40-
<dependency>
41-
<groupId>org.apache.velocity</groupId>
42-
<artifactId>velocity</artifactId>
43-
<optional>true</optional>
44-
</dependency>
4539

40+
<!-- Velocity -->
4641
<dependency>
47-
<groupId>org.apache.velocity</groupId>
48-
<artifactId>velocity-tools</artifactId>
42+
<groupId>org.apache.struts</groupId>
43+
<artifactId>struts2-velocity-plugin</artifactId>
4944
<optional>true</optional>
5045
</dependency>
5146

plugins/velocity/pom.xml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<groupId>org.apache.struts</groupId>
26+
<artifactId>struts2-plugins</artifactId>
27+
<version>2.6-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>struts2-velocity-plugin</artifactId>
31+
<packaging>jar</packaging>
32+
<name>Struts 2 Velocity Plugin</name>
33+
34+
<dependencies>
35+
36+
<!-- Velocity -->
37+
<dependency>
38+
<groupId>org.apache.struts</groupId>
39+
<artifactId>struts2-core</artifactId>
40+
</dependency>
41+
42+
<!-- Velocity -->
43+
<dependency>
44+
<groupId>org.apache.velocity</groupId>
45+
<artifactId>velocity</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.apache.velocity</groupId>
50+
<artifactId>velocity-tools</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>javax.servlet</groupId>
55+
<artifactId>servlet-api</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>javax.servlet.jsp</groupId>
60+
<artifactId>jsp-api</artifactId>
61+
</dependency>
62+
63+
<!-- The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher
64+
So this is only necessary in tests-->
65+
<dependency>
66+
<groupId>javax.servlet</groupId>
67+
<artifactId>javax.servlet-api</artifactId>
68+
<version>3.1.0</version>
69+
<scope>test</scope>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>mockobjects</groupId>
74+
<artifactId>mockobjects-core</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
78+
</dependencies>
79+
80+
<properties>
81+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
82+
</properties>
83+
</project>

0 commit comments

Comments
 (0)