Skip to content

Commit

Permalink
WW-5047 Upgrades to VelocityEngine 2.1 and VelocityTools 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Feb 1, 2020
1 parent 642b945 commit 71d4a7b
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 148 deletions.
11 changes: 0 additions & 11 deletions apps/showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@
<version>${log4j2.version}</version>
</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>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
Expand Down
10 changes: 2 additions & 8 deletions bundles/demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@
<dependencies>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<optional>true</optional>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>

<dependency>
Expand Down
13 changes: 0 additions & 13 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,6 @@
<artifactId>ognl</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>
<optional>true</optional>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public interface TagLibraryDirectiveProvider {
*
* @return A list of Velocity directive classes
*/
List<Class> getDirectiveClasses();
List<Class<?>> getDirectiveClasses();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,18 @@
*/
public class ContextUtil {
public static final String REQUEST = "request";
public static final String REQUEST2 = "request";
public static final String RESPONSE = "response";
public static final String RESPONSE2 = "response";
public static final String SESSION = "session";
public static final String BASE = "base";
public static final String STACK = "stack";
public static final String OGNL = "ognl";
public static final String STRUTS = "struts";
public static final String ACTION = "action";

public static Map getStandardContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
HashMap map = new HashMap();
public static Map<String, Object> getStandardContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
HashMap<String, Object> map = new HashMap<>();
map.put(REQUEST, req);
map.put(REQUEST2, req);
map.put(RESPONSE, res);
map.put(RESPONSE2, res);
map.put(SESSION, req.getSession(false));
map.put(BASE, req.getContextPath());
map.put(STACK, stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.struts2.util;

import com.mockobjects.dynamic.Mock;
import com.mockobjects.servlet.MockPageContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
Expand All @@ -31,7 +32,6 @@
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.struts.mock.MockPageContext;
import org.apache.struts2.ServletActionContext;


Expand Down
4 changes: 4 additions & 0 deletions plugins/embeddedjsp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
<%@ page import="com.opensymphony.xwork2.util.TextParseUtil" %>
<%@ page import="com.opensymphony.xwork2.util.WildcardUtil" %>
<%@ page import="org.apache.struts2.StrutsConstants" %>
<%@ page import="org.apache.struts2.StrutsConstants" %>
<%@ page import="org.apache.struts2.util.ComponentUtils" %>
<%@ page import="org.apache.struts2.util.ContainUtil" %>
<%@ page import="org.apache.struts2.util.StrutsUtil" %>
<%@ page import="org.apache.struts2.util.URLDecoderUtil" %>
<%@ page import="org.apache.struts2.util.VelocityStrutsUtil" %>
<%@ page import="org.apache.struts2.views.velocity.VelocityStrutsUtil" %>
<%@ taglib prefix="r" uri="http://jakarta.apache.org/taglibs/request-1.0" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
Expand Down
13 changes: 0 additions & 13 deletions plugins/portlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@
<artifactId>commons-lang3</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>
<optional>true</optional>
</dependency>

<!-- Portlet -->
<dependency>
<groupId>javax.portlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void init(ServletConfig config) throws ServletException {
// we can get these now that velocity is initialized
defaultContentType = getVelocityProperty(VelocityView.CONTENT_TYPE_KEY, VelocityView.DEFAULT_CONTENT_TYPE);

String encoding = getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, VelocityView.DEFAULT_OUTPUT_ENCODING);
String encoding = getVelocityProperty(RuntimeConstants.ENCODING_DEFAULT, VelocityView.DEFAULT_OUTPUT_ENCODING);

// For non Latin-1 encodings, ensure that the charset is
// included in the Content-Type header.
Expand Down
11 changes: 8 additions & 3 deletions plugins/velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@
<!-- Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-view</artifactId>
</dependency>

<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-view-jsp</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@

import com.opensymphony.xwork2.util.ValueStack;

import java.util.List;

public class StrutsVelocityContext extends VelocityContext {

ValueStack stack;
VelocityContext[] chainedContexts;
private ValueStack stack;
private List<VelocityContext> chainedContexts;

public StrutsVelocityContext(ValueStack stack) {
this(null, stack);
}

public StrutsVelocityContext(VelocityContext[] chainedContexts, ValueStack stack) {
public StrutsVelocityContext(List<VelocityContext> chainedContexts, ValueStack stack) {
this.chainedContexts = chainedContexts;
this.stack = stack;
}

public boolean internalContainsKey(Object key) {
public boolean internalContainsKey(String key) {
boolean contains = super.internalContainsKey(key);

// first let's check to see if we contain the requested key
Expand All @@ -46,13 +48,13 @@ public boolean internalContainsKey(Object key) {

// if not, let's search for the key in the ognl value stack
if (stack != null) {
Object o = stack.findValue(key.toString());
Object o = stack.findValue(key);

if (o != null) {
return true;
}

o = stack.getContext().get(key.toString());
o = stack.getContext().get(key);
if (o != null) {
return true;
}
Expand Down
Loading

0 comments on commit 71d4a7b

Please sign in to comment.