WW-5049 Moves Velocity support into a dedicated plugin

This commit is contained in:
Lukasz Lenart
2019-11-25 09:33:05 +01:00
parent 8952cffd34
commit 5c55e69b4f
114 changed files with 471 additions and 176 deletions
+5
View File
@@ -94,6 +94,11 @@
<artifactId>struts2-async-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
@@ -24,7 +24,7 @@
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="ui-tags" extends="struts-default" namespace="/tags/ui">
<package name="ui-tags" extends="velocity-default" namespace="/tags/ui">
<action name="example" class="org.apache.struts2.showcase.UITagExample">
<result>/WEB-INF/tags/ui/example.jsp</result>
<result name="input">/WEB-INF/tags/ui/example.jsp</result>
@@ -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";
@@ -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);
@@ -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, ','));
@@ -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<Class> 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<Class> getVelocityDirectiveClasses() {
return getDirectiveClasses();
}
}
@@ -36,6 +36,6 @@ public interface TagLibraryDirectiveProvider {
*
* @return A list of Velocity directive classes
*/
public List<Class> getDirectiveClasses();
List<Class> getDirectiveClasses();
}
@@ -106,16 +106,13 @@
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="prototype"/>
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta-stream" class="org.apache.struts2.dispatcher.multipart.JakartaStreamMultiPartRequest" scope="prototype"/>
<bean type="org.apache.struts2.views.TagLibraryDirectiveProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
<bean type="org.apache.struts2.views.TagLibraryModelProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
<bean class="org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader" />
<bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" />
<bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" optional="true" />
<bean class="org.apache.struts2.components.template.TemplateEngineManager" />
<bean type="org.apache.struts2.components.template.TemplateEngine" name="ftl" class="org.apache.struts2.components.template.FreemarkerTemplateEngine" />
<bean type="org.apache.struts2.components.template.TemplateEngine" name="vm" class="org.apache.struts2.components.template.VelocityTemplateEngine" />
<bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />
<bean type="com.opensymphony.xwork2.conversion.impl.XWorkConverter" name="struts" class="com.opensymphony.xwork2.conversion.impl.XWorkConverter" />
@@ -201,7 +198,6 @@
<result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
@@ -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<String>() {{
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 {
+2 -1
View File
@@ -32,6 +32,7 @@
<name>Struts 2 Plugins</name>
<modules>
<module>async</module>
<module>bean-validation</module>
<module>cdi</module>
<module>config-browser</module>
@@ -55,7 +56,7 @@
<module>spring</module>
<module>testng</module>
<module>tiles</module>
<module>async</module>
<module>velocity</module>
</modules>
<dependencies>
+5
View File
@@ -40,6 +40,11 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+3 -8
View File
@@ -36,16 +36,11 @@
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
</dependency>
<!-- Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
<optional>true</optional>
</dependency>
+83
View File
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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.
*/
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>2.6-SNAPSHOT</version>
</parent>
<artifactId>struts2-velocity-plugin</artifactId>
<packaging>jar</packaging>
<name>Struts 2 Velocity Plugin</name>
<dependencies>
<!-- Velocity -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<!-- Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</dependency>
<!-- The Servlet API mocks in Spring Framework 4.0 support Servlet 3.0 and higher
So this is only necessary in tests-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mockobjects</groupId>
<artifactId>mockobjects-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
@@ -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);
}
}
}
@@ -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.
*
* <p>
* The following is a list of the allowed extension points:
*
* <table border="1" summary="">
* <tr>
* <th>Type</th>
* <th>Property</th>
* <th>Scope</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>org.apache.struts2.views.velocity.VelocityManager</td>
* <td>struts.velocity.manager.classname</td>
* <td>singleton</td>
* <td>Loads and processes Velocity templates</td>
* </tr>
* </table>
*/
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);
}
}
@@ -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";
}
@@ -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 {
}
}
/**
* <p>
* 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;
}
@@ -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<Class> 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<Class> getVelocityDirectiveClasses() {
return getDirectiveClasses();
}
}
@@ -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;
@@ -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;
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/*
* 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.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" />
<bean type="org.apache.struts2.components.template.TemplateEngine" name="vm"
class="org.apache.struts2.views.velocity.template.VelocityTemplateEngine" />
<bean type="org.apache.struts2.views.TagLibraryDirectiveProvider" name="s"
class="org.apache.struts2.views.velocity.VelocityTagLibrary" />
<package name="velocity-default" extends="struts-default">
<result-types>
<result-type name="velocity" class="org.apache.struts2.views.velocity.result.VelocityResult"/>
</result-types>
</package>
</struts>

Some files were not shown because too many files have changed in this diff Show More