Skip to content

Commit

Permalink
WW-5379 Use ValueStackProvider marker interface for Velocity context …
Browse files Browse the repository at this point in the history
…implementation flexibility
  • Loading branch information
kusalk committed Jan 2, 2024
1 parent 450ee91 commit 29027f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/apache/struts2/util/ValueStackProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.struts2.util;

import com.opensymphony.xwork2.util.ValueStack;

/**
* @since 6.4.0
*/
public interface ValueStackProvider {

ValueStack getValueStack();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
package org.apache.struts2.views.velocity;

import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.util.ValueStackProvider;
import org.apache.velocity.VelocityContext;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class StrutsVelocityContext extends VelocityContext {
public class StrutsVelocityContext extends VelocityContext implements ValueStackProvider {

private final ValueStack stack;
private final List<VelocityContext> chainedContexts;
Expand Down Expand Up @@ -104,6 +105,7 @@ protected Object chainedContextGet(String key) {
return null;
}

@Override
public ValueStack getValueStack() {
return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.components.Component;
import org.apache.struts2.util.ValueStackProvider;
import org.apache.struts2.views.util.ContextUtil;
import org.apache.struts2.views.velocity.StrutsVelocityContext;
import org.apache.velocity.context.AbstractContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapter;
Expand Down Expand Up @@ -86,8 +86,8 @@ public boolean render(InternalContextAdapter ctx, Writer writer, Node node) thro

private ValueStack extractValueStack(Context context) {
do {
if (context instanceof StrutsVelocityContext) {
return ((StrutsVelocityContext) context).getValueStack();
if (context instanceof ValueStackProvider) {
return ((ValueStackProvider) context).getValueStack();
}
context = extractContext(context);
} while (context != null);
Expand Down

0 comments on commit 29027f3

Please sign in to comment.