mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3877 Drops altSyntax option
This commit is contained in:
@@ -44,9 +44,6 @@ public final class StrutsConstants {
|
||||
/** Comma separated list of patterns (java.util.regex.Pattern) to be excluded from Struts2-processing */
|
||||
public static final String STRUTS_ACTION_EXCLUDE_PATTERN = "struts.action.excludePattern";
|
||||
|
||||
/** Whether to use the alternative syntax for the tags or not */
|
||||
public static final String STRUTS_TAG_ALTSYNTAX = "struts.tag.altSyntax";
|
||||
|
||||
/** Whether to use the response encoding (JSP page encoding) for s:include tag processing (false - use STRUTS_I18N_ENCODING - by default) */
|
||||
public static final String STRUTS_TAG_INCLUDETAG_USERESPONSEENCODING = "struts.tag.includetag.useResponseEncoding";
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.reflect.MethodUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.reflect.MethodUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
@@ -42,7 +42,11 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
@@ -50,7 +54,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||
* Base class to extend for UI components.
|
||||
* <br>
|
||||
* This class is a good extension point when building reusable UI components.
|
||||
*
|
||||
*/
|
||||
public class Component {
|
||||
|
||||
@@ -65,7 +68,7 @@ public class Component {
|
||||
|
||||
protected boolean devMode = false;
|
||||
protected ValueStack stack;
|
||||
protected Map parameters;
|
||||
protected Map<String, Object> parameters;
|
||||
protected ActionMapper actionMapper;
|
||||
protected boolean throwExceptionOnELFailure;
|
||||
private UrlHelper urlHelper;
|
||||
@@ -73,7 +76,7 @@ public class Component {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param stack OGNL value stack.
|
||||
* @param stack OGNL value stack.
|
||||
*/
|
||||
public Component(ValueStack stack) {
|
||||
this.stack = stack;
|
||||
@@ -83,10 +86,11 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Gets the name of this component.
|
||||
*
|
||||
* @return the name of this component.
|
||||
*/
|
||||
private String getComponentName() {
|
||||
Class c = getClass();
|
||||
Class<?> c = getClass();
|
||||
String name = c.getName();
|
||||
int dot = name.lastIndexOf('.');
|
||||
|
||||
@@ -112,8 +116,10 @@ public class Component {
|
||||
public void setUrlHelper(UrlHelper urlHelper) {
|
||||
this.urlHelper = urlHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the OGNL value stack associated with this component.
|
||||
*
|
||||
* @return the OGNL value stack associated with this component.
|
||||
*/
|
||||
public ValueStack getStack() {
|
||||
@@ -122,6 +128,7 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Gets the component stack of this component.
|
||||
*
|
||||
* @return the component stack of this component, never <tt>null</tt>.
|
||||
*/
|
||||
public Stack<Component> getComponentStack() {
|
||||
@@ -137,7 +144,7 @@ public class Component {
|
||||
* Callback for the start tag of this component.
|
||||
* Should the body be evaluated?
|
||||
*
|
||||
* @param writer the output writer.
|
||||
* @param writer the output writer.
|
||||
* @return true if the body should be evaluated
|
||||
*/
|
||||
public boolean start(Writer writer) {
|
||||
@@ -149,8 +156,9 @@ public class Component {
|
||||
* Should the body be evaluated again?
|
||||
* <br>
|
||||
* <b>NOTE:</b> will pop component stack.
|
||||
* @param writer the output writer.
|
||||
* @param body the rendered body.
|
||||
*
|
||||
* @param writer the output writer.
|
||||
* @param body the rendered body.
|
||||
* @return true if the body should be evaluated again
|
||||
*/
|
||||
public boolean end(Writer writer, String body) {
|
||||
@@ -162,13 +170,14 @@ public class Component {
|
||||
* Should the body be evaluated again?
|
||||
* <br>
|
||||
* <b>NOTE:</b> has a parameter to determine to pop the component stack.
|
||||
* @param writer the output writer.
|
||||
* @param body the rendered body.
|
||||
* @param popComponentStack should the component stack be popped?
|
||||
*
|
||||
* @param writer the output writer.
|
||||
* @param body the rendered body.
|
||||
* @param popComponentStack should the component stack be popped?
|
||||
* @return true if the body should be evaluated again
|
||||
*/
|
||||
protected boolean end(Writer writer, String body, boolean popComponentStack) {
|
||||
assert(body != null);
|
||||
assert (body != null);
|
||||
|
||||
try {
|
||||
writer.write(body);
|
||||
@@ -190,17 +199,18 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Finds the nearest ancestor of this component stack.
|
||||
*
|
||||
* @param clazz the class to look for, or if assignable from.
|
||||
* @return the component if found, <tt>null</tt> if not.
|
||||
* @return the component if found, <tt>null</tt> if not.
|
||||
*/
|
||||
protected Component findAncestor(Class clazz) {
|
||||
protected Component findAncestor(Class<?> clazz) {
|
||||
Stack componentStack = getComponentStack();
|
||||
int currPosition = componentStack.search(this);
|
||||
if (currPosition >= 0) {
|
||||
int start = componentStack.size() - currPosition - 1;
|
||||
|
||||
//for (int i = componentStack.size() - 2; i >= 0; i--) {
|
||||
for (int i = start; i >=0; i--) {
|
||||
for (int i = start; i >= 0; i--) {
|
||||
Component component = (Component) componentStack.get(i);
|
||||
if (clazz.isAssignableFrom(component.getClass()) && component != this) {
|
||||
return component;
|
||||
@@ -213,8 +223,9 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Evaluates the OGNL stack to find a String value.
|
||||
* @param expr OGNL expression.
|
||||
* @return the String value found.
|
||||
*
|
||||
* @param expr OGNL expression.
|
||||
* @return the String value found.
|
||||
*/
|
||||
protected String findString(String expr) {
|
||||
return (String) findValue(expr, String.class);
|
||||
@@ -226,10 +237,10 @@ public class Component {
|
||||
* If the given expression is <tt>null</tt> a error is logged and a <code>RuntimeException</code> is thrown
|
||||
* constructed with a messaged based on the given field and errorMsg parameter.
|
||||
*
|
||||
* @param expr OGNL expression.
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @return the String value found.
|
||||
* @param expr OGNL expression.
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @return the String value found.
|
||||
* @throws StrutsException is thrown in case of expression is null.
|
||||
*/
|
||||
protected String findString(String expr, String field, String errorMsg) {
|
||||
@@ -245,15 +256,16 @@ public class Component {
|
||||
* <br>
|
||||
* A message is constructed and logged at ERROR level before being returned
|
||||
* as a <code>RuntimeException</code>.
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @param e the caused exception, can be <tt>null</tt>.
|
||||
* @return the constructed <code>StrutsException</code>.
|
||||
*
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @param e the caused exception, can be <tt>null</tt>.
|
||||
* @return the constructed <code>StrutsException</code>.
|
||||
*/
|
||||
protected StrutsException fieldError(String field, String errorMsg, Exception e) {
|
||||
String msg = "tag '" + getComponentName() + "', field '" + field +
|
||||
( parameters != null && parameters.containsKey("name")?"', name '" + parameters.get("name"):"") +
|
||||
"': " + errorMsg;
|
||||
(parameters != null && parameters.containsKey("name") ? "', name '" + parameters.get("name") : "") +
|
||||
"': " + errorMsg;
|
||||
throw new StrutsException(msg, e);
|
||||
}
|
||||
|
||||
@@ -262,7 +274,7 @@ public class Component {
|
||||
* Will always evaluate <code>expr</code> against stack except when <code>expr</code>
|
||||
* is null. If altsyntax (%{...}) is applied, simply strip it off.
|
||||
*
|
||||
* @param expr the expression. Returns <tt>null</tt> if expr is null.
|
||||
* @param expr the expression. Returns <tt>null</tt> if expr is null.
|
||||
* @return the value, <tt>null</tt> if not found.
|
||||
*/
|
||||
protected Object findValue(String expr) {
|
||||
@@ -270,54 +282,39 @@ public class Component {
|
||||
return null;
|
||||
}
|
||||
|
||||
expr = stripExpressionIfAltSyntax(expr);
|
||||
expr = stripExpression(expr);
|
||||
|
||||
return getStack().findValue(expr, throwExceptionOnELFailure);
|
||||
}
|
||||
|
||||
/**
|
||||
* If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.
|
||||
* If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.
|
||||
*
|
||||
* @param expr the expression (must be not null)
|
||||
* @return the stripped expression if altSyntax is enabled. Otherwise
|
||||
* the parameter expression is returned as is.
|
||||
*/
|
||||
protected String stripExpressionIfAltSyntax(String expr) {
|
||||
return ComponentUtils.stripExpressionIfAltSyntax(stack, expr);
|
||||
}
|
||||
|
||||
/**
|
||||
* See <code>struts.properties</code> where the altSyntax flag is defined.
|
||||
* @return if the altSyntax enabled? [TRUE]
|
||||
*/
|
||||
public boolean altSyntax() {
|
||||
return ComponentUtils.altSyntax(stack);
|
||||
protected String stripExpression(String expr) {
|
||||
return ComponentUtils.stripExpression(expr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the surrounding %{ } to the expression for proper processing.
|
||||
*
|
||||
* @param expr the expression.
|
||||
* @return the modified expression if altSyntax is enabled, or the parameter
|
||||
* @return the modified expression if altSyntax is enabled, or the parameter
|
||||
* expression otherwise.
|
||||
*/
|
||||
protected String completeExpressionIfAltSyntax(String expr) {
|
||||
if (altSyntax() && !ComponentUtils.containsExpression(expr)) {
|
||||
return "%{" + expr + "}";
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* This check is needed for backwards compatibility with 2.1.x
|
||||
* @param expr the expression.
|
||||
* @return the found string if altSyntax is enabled. The parameter
|
||||
* expression otherwise.
|
||||
*/
|
||||
protected String findStringIfAltSyntax(String expr) {
|
||||
if (altSyntax()) {
|
||||
return findString(expr);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
protected String completeExpression(String expr) {
|
||||
if (expr == null) {
|
||||
return null;
|
||||
}
|
||||
if (ComponentUtils.isExpression(expr)) {
|
||||
LOG.warn("Expression {} is already an expression!", expr);
|
||||
return expr;
|
||||
}
|
||||
return "%{" + expr + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -331,10 +328,10 @@ public class Component {
|
||||
* messaged based on the given field and errorMsg parameter.
|
||||
* </p>
|
||||
*
|
||||
* @param expr OGNL expression.
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @return the Object found, is never <tt>null</tt>.
|
||||
* @param expr OGNL expression.
|
||||
* @param field field name used when throwing <code>RuntimeException</code>.
|
||||
* @param errorMsg error message used when throwing <code>RuntimeException</code>.
|
||||
* @return the Object found, is never <tt>null</tt>.
|
||||
* @throws StrutsException is thrown in case of not found in the OGNL stack, or expression is <tt>null</tt>.
|
||||
*/
|
||||
protected Object findValue(String expr, String field, String errorMsg) {
|
||||
@@ -364,19 +361,20 @@ public class Component {
|
||||
* is evaluated against the stack.
|
||||
* <br>
|
||||
* This method only supports the altSyntax. So this should be set to true.
|
||||
* @param expr OGNL expression.
|
||||
* @param toType the type expected to find.
|
||||
* @return the Object found, or <tt>null</tt> if not found.
|
||||
*
|
||||
* @param expr OGNL expression.
|
||||
* @param toType the type expected to find.
|
||||
* @return the Object found, or <tt>null</tt> if not found.
|
||||
*/
|
||||
protected Object findValue(String expr, Class toType) {
|
||||
if (altSyntax() && toType == String.class) {
|
||||
protected Object findValue(String expr, Class<?> toType) {
|
||||
if (toType == String.class) {
|
||||
if (ComponentUtils.containsExpression(expr)) {
|
||||
return TextParseUtil.translateVariables('%', expr, stack);
|
||||
} else {
|
||||
return expr;
|
||||
}
|
||||
} else {
|
||||
expr = stripExpressionIfAltSyntax(expr);
|
||||
expr = stripExpression(expr);
|
||||
|
||||
return getStack().findValue(expr, toType, throwExceptionOnELFailure);
|
||||
}
|
||||
@@ -384,26 +382,28 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Detects if altSyntax is enabled and then checks if expression contains %{...}
|
||||
*
|
||||
* @param expr a string to examined
|
||||
* @return true if altSyntax is enabled and expr contains %{...}
|
||||
*/
|
||||
protected boolean recursion(String expr) {
|
||||
return ComponentUtils.altSyntax(stack) && ComponentUtils.containsExpression(expr);
|
||||
return ComponentUtils.containsExpression(expr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an action URL by consulting the {@link org.apache.struts2.dispatcher.mapper.ActionMapper}.
|
||||
* @param action the action
|
||||
* @param namespace the namespace
|
||||
* @param method the method
|
||||
* @param req HTTP request
|
||||
* @param res HTTP response
|
||||
* @param parameters parameters
|
||||
* @param scheme http or https
|
||||
* @param includeContext should the context path be included or not
|
||||
* @param encodeResult should the url be encoded
|
||||
* @param forceAddSchemeHostAndPort should the scheme host and port be forced
|
||||
* @param escapeAmp should ampersand (&) be escaped to &amp;
|
||||
*
|
||||
* @param action the action
|
||||
* @param namespace the namespace
|
||||
* @param method the method
|
||||
* @param req HTTP request
|
||||
* @param res HTTP response
|
||||
* @param parameters parameters
|
||||
* @param scheme http or https
|
||||
* @param includeContext should the context path be included or not
|
||||
* @param encodeResult should the url be encoded
|
||||
* @param forceAddSchemeHostAndPort should the scheme host and port be forced
|
||||
* @param escapeAmp should ampersand (&) be escaped to &amp;
|
||||
* @return the action url.
|
||||
*/
|
||||
protected String determineActionURL(String action, String namespace, String method,
|
||||
@@ -420,10 +420,11 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Determines the namespace of the current page being renderdd. Useful for Form, URL, and href generations.
|
||||
* @param namespace the namespace
|
||||
* @param stack OGNL value stack
|
||||
* @param req HTTP request
|
||||
* @return the namepsace of the current page being rendered, is never <tt>null</tt>.
|
||||
*
|
||||
* @param namespace the namespace
|
||||
* @param stack OGNL value stack
|
||||
* @param req HTTP request
|
||||
* @return the namepsace of the current page being rendered, is never <tt>null</tt>.
|
||||
*/
|
||||
protected String determineNamespace(String namespace, ValueStack stack, HttpServletRequest req) {
|
||||
String result;
|
||||
@@ -447,15 +448,14 @@ public class Component {
|
||||
* pushed before the component itself, any key-value pair that can't be assigned to component
|
||||
* will be set in the parameters Map.
|
||||
*
|
||||
* @param params the parameters to copy.
|
||||
* @param params the parameters to copy.
|
||||
*/
|
||||
public void copyParams(Map params) {
|
||||
public void copyParams(Map<String, Object> params) {
|
||||
stack.push(parameters);
|
||||
stack.push(this);
|
||||
try {
|
||||
for (Object o : params.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) o;
|
||||
String key = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
|
||||
if (key.indexOf('-') >= 0) {
|
||||
// UI component attributes may contain hypens (e.g. data-ajax), but ognl
|
||||
@@ -474,12 +474,13 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Constructs a string representation of the given exception.
|
||||
* @param t the exception
|
||||
*
|
||||
* @param t the exception
|
||||
* @return the exception as a string.
|
||||
*/
|
||||
protected String toString(Throwable t) {
|
||||
try (FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
|
||||
PrintWriter wrt = new PrintWriter(bout)) {
|
||||
PrintWriter wrt = new PrintWriter(bout)) {
|
||||
t.printStackTrace(wrt);
|
||||
return bout.toString();
|
||||
}
|
||||
@@ -487,17 +488,19 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Gets the parameters.
|
||||
*
|
||||
* @return the parameters. Is never <tt>null</tt>.
|
||||
*/
|
||||
public Map getParameters() {
|
||||
public Map<String, Object> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the given parameters to this component's own parameters.
|
||||
*
|
||||
* @param params the parameters to add.
|
||||
*/
|
||||
public void addAllParameters(Map params) {
|
||||
public void addAllParameters(Map<String, Object> params) {
|
||||
parameters.putAll(params);
|
||||
}
|
||||
|
||||
@@ -507,12 +510,13 @@ public class Component {
|
||||
* If the provided key is <tt>null</tt> nothing happens.
|
||||
* If the provided value is <tt>null</tt> any existing parameter with
|
||||
* the given key name is removed.
|
||||
* @param key the key of the new parameter to add.
|
||||
*
|
||||
* @param key the key of the new parameter to add.
|
||||
* @param value the value associated with the key.
|
||||
*/
|
||||
public void addParameter(String key, Object value) {
|
||||
if (key != null) {
|
||||
Map params = getParameters();
|
||||
Map<String, Object> params = getParameters();
|
||||
|
||||
if (value == null) {
|
||||
params.remove(key);
|
||||
@@ -524,6 +528,7 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Overwrite to set if body should be used.
|
||||
*
|
||||
* @return always false for this component.
|
||||
*/
|
||||
public boolean usesBody() {
|
||||
@@ -532,9 +537,8 @@ public class Component {
|
||||
|
||||
/**
|
||||
* Override to set if body content should be HTML-escaped.
|
||||
*
|
||||
*
|
||||
* @return always true (default) for this component.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public boolean escapeHtmlBody() {
|
||||
@@ -557,13 +561,13 @@ public class Component {
|
||||
* @return list of attributes
|
||||
*/
|
||||
protected Collection<String> getStandardAttributes() {
|
||||
Class clz = getClass();
|
||||
Class<?> clz = getClass();
|
||||
Collection<String> standardAttributes = standardAttributesMap.get(clz);
|
||||
if (standardAttributes == null) {
|
||||
Collection<Method> methods = MethodUtils.getMethodsListWithAnnotation(clz, StrutsTagAttribute.class,
|
||||
true, true);
|
||||
true, true);
|
||||
standardAttributes = new HashSet<>(methods.size());
|
||||
for(Method m : methods) {
|
||||
for (Method m : methods) {
|
||||
standardAttributes.add(StringUtils.uncapitalize(m.getName().substring(3)));
|
||||
}
|
||||
standardAttributesMap.putIfAbsent(clz, standardAttributes);
|
||||
|
||||
@@ -368,7 +368,7 @@ public class Date extends ContextBean {
|
||||
private ZoneId getTimeZone() {
|
||||
ZoneId tz = ZoneId.systemDefault();
|
||||
if (timezone != null) {
|
||||
timezone = stripExpressionIfAltSyntax(timezone);
|
||||
timezone = stripExpression(timezone);
|
||||
String actualTimezone = (String) getStack().findValue(timezone, String.class);
|
||||
if (actualTimezone != null) {
|
||||
timezone = actualTimezone;
|
||||
|
||||
@@ -29,16 +29,15 @@ import java.util.Map;
|
||||
* <p>
|
||||
* DoubleListUIBean is the standard superclass of all Struts double list handling components.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <!-- START SNIPPET: javadoc -->
|
||||
* <p>
|
||||
* Note that the doublelistkey and doublelistvalue attribute will default to "key" and "value"
|
||||
* respectively only when the doublelist attribute is evaluated to a Map or its descendant.
|
||||
* Other thing else, will result in doublelistkey and doublelistvalue to be null and not used.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <!-- END SNIPPET: javadoc -->
|
||||
*
|
||||
*/
|
||||
public abstract class DoubleListUIBean extends ListUIBean {
|
||||
|
||||
@@ -137,21 +136,21 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
Object tmpDoubleList = findValue(doubleList);
|
||||
if (doubleListKey != null) {
|
||||
addParameter("doubleListKey", doubleListKey);
|
||||
}else if (tmpDoubleList instanceof Map) {
|
||||
} else if (tmpDoubleList instanceof Map) {
|
||||
addParameter("doubleListKey", "key");
|
||||
}
|
||||
|
||||
if (doubleListValue != null) {
|
||||
doubleListValue = stripExpressionIfAltSyntax(doubleListValue);
|
||||
doubleListValue = stripExpression(doubleListValue);
|
||||
|
||||
addParameter("doubleListValue", doubleListValue);
|
||||
}else if (tmpDoubleList instanceof Map) {
|
||||
} else if (tmpDoubleList instanceof Map) {
|
||||
addParameter("doubleListValue", "value");
|
||||
}
|
||||
if (doubleListCssClass != null) {
|
||||
addParameter("doubleListCssClass", findString(doubleListCssClass));
|
||||
}
|
||||
if (doubleListCssStyle!= null) {
|
||||
if (doubleListCssStyle != null) {
|
||||
addParameter("doubleListCssStyle", findString(doubleListCssStyle));
|
||||
}
|
||||
if (doubleListTitle != null) {
|
||||
@@ -169,7 +168,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
}
|
||||
}
|
||||
|
||||
Class valueClazz = getValueClassType();
|
||||
Class<?> valueClazz = getValueClassType();
|
||||
|
||||
if (valueClazz != null) {
|
||||
if (doubleValue != null) {
|
||||
@@ -187,10 +186,9 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
|
||||
Form form = (Form) findAncestor(Form.class);
|
||||
if (doubleId != null) {
|
||||
// this check is needed for backwards compatibility with 2.1.x
|
||||
addParameter("doubleId", findStringIfAltSyntax(doubleId));
|
||||
addParameter("doubleId", findString(doubleId));
|
||||
} else if (form != null) {
|
||||
addParameter("doubleId", form.getParameters().get("id") + "_" +escape(doubleName !=null ? findString(doubleName) : null));
|
||||
addParameter("doubleId", form.getParameters().get("id") + "_" + escape(doubleName != null ? findString(doubleName) : null));
|
||||
} else {
|
||||
addParameter("doubleId", escape(doubleName != null ? findString(doubleName) : null));
|
||||
}
|
||||
@@ -269,23 +267,23 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
}
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The second iterable source to populate from.", required=true)
|
||||
@StrutsTagAttribute(description = "The second iterable source to populate from.", required = true)
|
||||
public void setDoubleList(String doubleList) {
|
||||
this.doubleList = doubleList;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The key expression to use for second list")
|
||||
@StrutsTagAttribute(description = "The key expression to use for second list")
|
||||
public void setDoubleListKey(String doubleListKey) {
|
||||
this.doubleListKey = doubleListKey;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The value expression to use for second list")
|
||||
@StrutsTagAttribute(description = "The value expression to use for second list")
|
||||
public void setDoubleListValue(String doubleListValue) {
|
||||
this.doubleListValue = doubleListValue;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description = "Property of second list objects to get css class from")
|
||||
public void setDoubleListCssClass(String doubleListCssClass) {
|
||||
public void setDoubleListCssClass(String doubleListCssClass) {
|
||||
this.doubleListCssClass = doubleListCssClass;
|
||||
}
|
||||
|
||||
@@ -299,17 +297,17 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
this.doubleListTitle = doubleListTitle;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The name for complete component", required=true)
|
||||
@StrutsTagAttribute(description = "The name for complete component", required = true)
|
||||
public void setDoubleName(String doubleName) {
|
||||
this.doubleName = doubleName;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The value expression for complete component")
|
||||
@StrutsTagAttribute(description = "The value expression for complete component")
|
||||
public void setDoubleValue(String doubleValue) {
|
||||
this.doubleValue = doubleValue;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The form name this component resides in and populates to")
|
||||
@StrutsTagAttribute(description = "The form name this component resides in and populates to")
|
||||
public void setFormName(String formName) {
|
||||
this.formName = formName;
|
||||
}
|
||||
@@ -318,7 +316,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return formName;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The css class for the second list")
|
||||
@StrutsTagAttribute(description = "The css class for the second list")
|
||||
public void setDoubleCssClass(String doubleCssClass) {
|
||||
this.doubleCssClass = doubleCssClass;
|
||||
}
|
||||
@@ -327,7 +325,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleCssClass;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The css style for the second list")
|
||||
@StrutsTagAttribute(description = "The css style for the second list")
|
||||
public void setDoubleCssStyle(String doubleCssStyle) {
|
||||
this.doubleCssStyle = doubleCssStyle;
|
||||
}
|
||||
@@ -336,7 +334,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleCssStyle;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The header key for the second list")
|
||||
@StrutsTagAttribute(description = "The header key for the second list")
|
||||
public void setDoubleHeaderKey(String doubleHeaderKey) {
|
||||
this.doubleHeaderKey = doubleHeaderKey;
|
||||
}
|
||||
@@ -345,7 +343,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleHeaderKey;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The header value for the second list")
|
||||
@StrutsTagAttribute(description = "The header value for the second list")
|
||||
public void setDoubleHeaderValue(String doubleHeaderValue) {
|
||||
this.doubleHeaderValue = doubleHeaderValue;
|
||||
}
|
||||
@@ -354,7 +352,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleHeaderValue;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Decides if the second list will add an empty option")
|
||||
@StrutsTagAttribute(description = "Decides if the second list will add an empty option")
|
||||
public void setDoubleEmptyOption(String doubleEmptyOption) {
|
||||
this.doubleEmptyOption = doubleEmptyOption;
|
||||
}
|
||||
@@ -368,7 +366,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleDisabled;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Decides if a disable attribute should be added to the second list")
|
||||
@StrutsTagAttribute(description = "Decides if a disable attribute should be added to the second list")
|
||||
public void setDoubleDisabled(String doubleDisabled) {
|
||||
this.doubleDisabled = doubleDisabled;
|
||||
}
|
||||
@@ -377,7 +375,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleId;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="The id of the second list")
|
||||
@StrutsTagAttribute(description = "The id of the second list")
|
||||
public void setDoubleId(String doubleId) {
|
||||
this.doubleId = doubleId;
|
||||
}
|
||||
@@ -386,7 +384,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleMultiple;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description=" Decides if multiple attribute should be set on the second list")
|
||||
@StrutsTagAttribute(description = " Decides if multiple attribute should be set on the second list")
|
||||
public void setDoubleMultiple(String doubleMultiple) {
|
||||
this.doubleMultiple = doubleMultiple;
|
||||
}
|
||||
@@ -395,7 +393,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnblur;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onblur attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onblur attribute of the second list")
|
||||
public void setDoubleOnblur(String doubleOnblur) {
|
||||
this.doubleOnblur = doubleOnblur;
|
||||
}
|
||||
@@ -404,7 +402,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnchange;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onchange attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onchange attribute of the second list")
|
||||
public void setDoubleOnchange(String doubleOnchange) {
|
||||
this.doubleOnchange = doubleOnchange;
|
||||
}
|
||||
@@ -413,7 +411,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnclick;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onclick attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onclick attribute of the second list")
|
||||
public void setDoubleOnclick(String doubleOnclick) {
|
||||
this.doubleOnclick = doubleOnclick;
|
||||
}
|
||||
@@ -422,7 +420,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOndblclick;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the ondbclick attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the ondbclick attribute of the second list")
|
||||
public void setDoubleOndblclick(String doubleOndblclick) {
|
||||
this.doubleOndblclick = doubleOndblclick;
|
||||
}
|
||||
@@ -431,7 +429,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnfocus;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onfocus attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onfocus attribute of the second list")
|
||||
public void setDoubleOnfocus(String doubleOnfocus) {
|
||||
this.doubleOnfocus = doubleOnfocus;
|
||||
}
|
||||
@@ -440,7 +438,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnkeydown;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onkeydown attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onkeydown attribute of the second list")
|
||||
public void setDoubleOnkeydown(String doubleOnkeydown) {
|
||||
this.doubleOnkeydown = doubleOnkeydown;
|
||||
}
|
||||
@@ -449,7 +447,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnkeypress;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onkeypress attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onkeypress attribute of the second list")
|
||||
public void setDoubleOnkeypress(String doubleOnkeypress) {
|
||||
this.doubleOnkeypress = doubleOnkeypress;
|
||||
}
|
||||
@@ -458,7 +456,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnkeyup;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onkeyup attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onkeyup attribute of the second list")
|
||||
public void setDoubleOnkeyup(String doubleOnkeyup) {
|
||||
this.doubleOnkeyup = doubleOnkeyup;
|
||||
}
|
||||
@@ -467,7 +465,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnmousedown;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onmousedown attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onmousedown attribute of the second list")
|
||||
public void setDoubleOnmousedown(String doubleOnmousedown) {
|
||||
this.doubleOnmousedown = doubleOnmousedown;
|
||||
}
|
||||
@@ -476,7 +474,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnmousemove;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onmousemove attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onmousemove attribute of the second list")
|
||||
public void setDoubleOnmousemove(String doubleOnmousemove) {
|
||||
this.doubleOnmousemove = doubleOnmousemove;
|
||||
}
|
||||
@@ -485,7 +483,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnmouseout;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onmouseout attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onmouseout attribute of the second list")
|
||||
public void setDoubleOnmouseout(String doubleOnmouseout) {
|
||||
this.doubleOnmouseout = doubleOnmouseout;
|
||||
}
|
||||
@@ -494,7 +492,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnmouseover;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onmouseover attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onmouseover attribute of the second list")
|
||||
public void setDoubleOnmouseover(String doubleOnmouseover) {
|
||||
this.doubleOnmouseover = doubleOnmouseover;
|
||||
}
|
||||
@@ -503,7 +501,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnmouseup;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onmouseup attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onmouseup attribute of the second list")
|
||||
public void setDoubleOnmouseup(String doubleOnmouseup) {
|
||||
this.doubleOnmouseup = doubleOnmouseup;
|
||||
}
|
||||
@@ -512,7 +510,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleOnselect;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the onselect attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the onselect attribute of the second list")
|
||||
public void setDoubleOnselect(String doubleOnselect) {
|
||||
this.doubleOnselect = doubleOnselect;
|
||||
}
|
||||
@@ -521,7 +519,7 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleSize;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the size attribute of the second list")
|
||||
@StrutsTagAttribute(description = "Set the size attribute of the second list")
|
||||
public void setDoubleSize(String doubleSize) {
|
||||
this.doubleSize = doubleSize;
|
||||
}
|
||||
@@ -546,36 +544,36 @@ public abstract class DoubleListUIBean extends ListUIBean {
|
||||
return doubleValue;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Decides of an empty option is to be inserted in the second list", type="Boolean", defaultValue="false")
|
||||
@StrutsTagAttribute(description = "Decides of an empty option is to be inserted in the second list", type = "Boolean", defaultValue = "false")
|
||||
public void setEmptyOption(String emptyOption) {
|
||||
this.emptyOption = emptyOption;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the header key of the second list. Must not be empty! " +
|
||||
"'-1' and '' is correct, '' is bad.")
|
||||
@StrutsTagAttribute(description = "Set the header key of the second list. Must not be empty! " +
|
||||
"'-1' and '' is correct, '' is bad.")
|
||||
public void setHeaderKey(String headerKey) {
|
||||
this.headerKey = headerKey;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description=" Set the header value of the second list")
|
||||
@StrutsTagAttribute(description = " Set the header value of the second list")
|
||||
public void setHeaderValue(String headerValue) {
|
||||
this.headerValue = headerValue;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Creates a multiple select. " +
|
||||
"The tag will pre-select multiple values if the values are passed as an Array " +
|
||||
"(of appropriate types) via the value attribute.")
|
||||
@StrutsTagAttribute(description = "Creates a multiple select. " +
|
||||
"The tag will pre-select multiple values if the values are passed as an Array " +
|
||||
"(of appropriate types) via the value attribute.")
|
||||
public void setMultiple(String multiple) {
|
||||
// TODO: Passing a Collection may work too?
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Size of the element box (# of elements to show)", type="Integer")
|
||||
@StrutsTagAttribute(description = "Size of the element box (# of elements to show)", type = "Integer")
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set the html accesskey attribute.")
|
||||
@StrutsTagAttribute(description = "Set the html accesskey attribute.")
|
||||
public void setDoubleAccesskey(String doubleAccesskey) {
|
||||
this.doubleAccesskey = doubleAccesskey;
|
||||
}
|
||||
|
||||
@@ -18,24 +18,23 @@
|
||||
*/
|
||||
package org.apache.struts2.components;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts2.views.annotations.StrutsTagAttribute;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.views.annotations.StrutsTagAttribute;
|
||||
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* FormButton.
|
||||
*/
|
||||
public abstract class FormButton extends ClosingUIBean {
|
||||
|
||||
static final String BUTTONTYPE_INPUT = "input";
|
||||
static final String BUTTONTYPE_BUTTON = "button";
|
||||
static final String BUTTONTYPE_IMAGE = "image";
|
||||
private static final String BUTTON_TYPE_INPUT = "input";
|
||||
private static final String BUTTON_TYPE_BUTTON = "button";
|
||||
private static final String BUTTON_TYPE_IMAGE = "image";
|
||||
|
||||
protected String action;
|
||||
protected String method;
|
||||
@@ -49,9 +48,8 @@ public abstract class FormButton extends ClosingUIBean {
|
||||
public void evaluateExtraParams() {
|
||||
super.evaluateExtraParams();
|
||||
|
||||
String submitType = BUTTONTYPE_INPUT;
|
||||
if (type != null && (BUTTONTYPE_BUTTON.equalsIgnoreCase(type) || (supportsImageType() && BUTTONTYPE_IMAGE.equalsIgnoreCase(type))))
|
||||
{
|
||||
String submitType = BUTTON_TYPE_INPUT;
|
||||
if (type != null && (BUTTON_TYPE_BUTTON.equalsIgnoreCase(type) || (supportsImageType() && BUTTON_TYPE_IMAGE.equalsIgnoreCase(type)))) {
|
||||
submitType = type;
|
||||
}
|
||||
|
||||
@@ -59,7 +57,7 @@ public abstract class FormButton extends ClosingUIBean {
|
||||
|
||||
addParameter("type", submitType);
|
||||
|
||||
if (!BUTTONTYPE_INPUT.equals(submitType) && (label == null)) {
|
||||
if (!BUTTON_TYPE_INPUT.equals(submitType) && (label == null)) {
|
||||
addParameter("label", getParameters().get("nameValue"));
|
||||
}
|
||||
|
||||
@@ -101,15 +99,14 @@ public abstract class FormButton extends ClosingUIBean {
|
||||
String _tmp_id = "";
|
||||
if (id != null) {
|
||||
// this check is needed for backwards compatibility with 2.1.x
|
||||
_tmp_id = findStringIfAltSyntax(id);
|
||||
}
|
||||
else {
|
||||
_tmp_id = findString(id);
|
||||
} else {
|
||||
if (form != null && form.getParameters().get("id") != null) {
|
||||
_tmp_id = _tmp_id + form.getParameters().get("id").toString() + "_";
|
||||
}
|
||||
if (name != null) {
|
||||
_tmp_id = _tmp_id + escape(name);
|
||||
} else if (action != null || method != null){
|
||||
} else if (action != null || method != null) {
|
||||
if (action != null) {
|
||||
_tmp_id = _tmp_id + escape(action);
|
||||
}
|
||||
@@ -139,19 +136,19 @@ public abstract class FormButton extends ClosingUIBean {
|
||||
this.actionMapper = mapper;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set action attribute.")
|
||||
@StrutsTagAttribute(description = "Set action attribute.")
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Set method attribute.")
|
||||
@StrutsTagAttribute(description = "Set method attribute.")
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
|
||||
@StrutsTagAttribute(description="The type of submit to use. Valid values are <i>input</i>, " +
|
||||
"<i>button</i> and <i>image</i>.", defaultValue="input")
|
||||
@StrutsTagAttribute(description = "The type of submit to use. Valid values are <i>input</i>, " +
|
||||
"<i>button</i> and <i>image</i>.", defaultValue = "input")
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class Label extends UIBean {
|
||||
addParameter("nameValue", providedLabel);
|
||||
}
|
||||
} else if (name != null) {
|
||||
String expr = completeExpressionIfAltSyntax(name);
|
||||
String expr = completeExpression(name);
|
||||
addParameter("nameValue", findString(expr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class ListUIBean extends UIBean {
|
||||
}
|
||||
|
||||
if (listKey != null) {
|
||||
listKey = stripExpressionIfAltSyntax(listKey);
|
||||
listKey = stripExpression(listKey);
|
||||
addParameter("listKey", listKey);
|
||||
} else if (value instanceof Map) {
|
||||
addParameter("listKey", "key");
|
||||
@@ -113,12 +113,12 @@ public abstract class ListUIBean extends UIBean {
|
||||
}
|
||||
|
||||
if (listValueKey != null) {
|
||||
listValueKey = stripExpressionIfAltSyntax(listValueKey);
|
||||
listValueKey = stripExpression(listValueKey);
|
||||
addParameter("listValueKey", listValueKey);
|
||||
}
|
||||
|
||||
if (listValue != null) {
|
||||
listValue = stripExpressionIfAltSyntax(listValue);
|
||||
listValue = stripExpression(listValue);
|
||||
addParameter("listValue", listValue);
|
||||
} else if (value instanceof Map) {
|
||||
addParameter("listValue", "value");
|
||||
@@ -127,7 +127,7 @@ public abstract class ListUIBean extends UIBean {
|
||||
}
|
||||
|
||||
if (listLabelKey != null) {
|
||||
listLabelKey = stripExpressionIfAltSyntax(listLabelKey);
|
||||
listLabelKey = stripExpression(listLabelKey);
|
||||
addParameter("listLabelKey", listLabelKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ public class Property extends Component {
|
||||
value = "top";
|
||||
}
|
||||
else {
|
||||
value = stripExpressionIfAltSyntax(value);
|
||||
value = stripExpression(value);
|
||||
}
|
||||
|
||||
// exception: don't call findString(), since we don't want the
|
||||
|
||||
@@ -788,13 +788,13 @@ public abstract class UIBean extends Component {
|
||||
parameters.put("nameValue", parameters.get("value"));
|
||||
} else {
|
||||
if (evaluateNameValue()) {
|
||||
final Class valueClazz = getValueClassType();
|
||||
final Class<?> valueClazz = getValueClassType();
|
||||
|
||||
if (valueClazz != null) {
|
||||
if (value != null) {
|
||||
addParameter("nameValue", findValue(value, valueClazz));
|
||||
} else if (name != null) {
|
||||
String expr = completeExpressionIfAltSyntax(name);
|
||||
String expr = completeExpression(name);
|
||||
if (recursion(name)) {
|
||||
addParameter("nameValue", expr);
|
||||
} else {
|
||||
@@ -834,19 +834,18 @@ public abstract class UIBean extends Component {
|
||||
if (tooltip != null) {
|
||||
addParameter("tooltip", findString(tooltip));
|
||||
|
||||
Map tooltipConfigMap = getTooltipConfig(this);
|
||||
Map<String, String> tooltipConfigMap = getTooltipConfig(this);
|
||||
|
||||
if (form != null) { // inform the containing form that we need tooltip javascript included
|
||||
form.addParameter("hasTooltip", Boolean.TRUE);
|
||||
|
||||
// tooltipConfig defined in component itself will take precedence
|
||||
// over those defined in the containing form
|
||||
Map overallTooltipConfigMap = getTooltipConfig(form);
|
||||
Map<String, String> overallTooltipConfigMap = getTooltipConfig(form);
|
||||
overallTooltipConfigMap.putAll(tooltipConfigMap); // override parent form's tooltip config
|
||||
|
||||
for (Object o : overallTooltipConfigMap.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) o;
|
||||
addParameter((String) entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, String> entry : overallTooltipConfigMap.entrySet()) {
|
||||
addParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -899,7 +898,7 @@ public abstract class UIBean extends Component {
|
||||
protected String escape(String name) {
|
||||
// escape any possible values that can make the ID painful to work with in JavaScript
|
||||
if (name != null) {
|
||||
return name.replaceAll("[\\/\\.\\[\\]\'\"]", "_");
|
||||
return name.replaceAll("[/.\\[\\]'\"]", "_");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -926,7 +925,7 @@ public abstract class UIBean extends Component {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Class getValueClassType() {
|
||||
protected Class<?> getValueClassType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@@ -948,7 +947,7 @@ public abstract class UIBean extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
protected Map getTooltipConfig(UIBean component) {
|
||||
protected Map<String, String> getTooltipConfig(UIBean component) {
|
||||
Object tooltipConfigObj = component.getParameters().get("tooltipConfig");
|
||||
Map<String, String> tooltipConfig = new LinkedHashMap<>();
|
||||
|
||||
@@ -1005,7 +1004,7 @@ public abstract class UIBean extends Component {
|
||||
String generatedId;
|
||||
if (id != null) {
|
||||
// this check is needed for backwards compatibility with 2.1.x
|
||||
tryId = findStringIfAltSyntax(id);
|
||||
tryId = findString(id);
|
||||
} else if (null == (generatedId = escape(name != null ? findString(name) : null))) {
|
||||
LOG.debug("Cannot determine id attribute for [{}], consider defining id, name or key attribute!", this);
|
||||
tryId = null;
|
||||
@@ -1261,17 +1260,16 @@ public abstract class UIBean extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* supports dynamic attributes for freemarker ui tags
|
||||
* @see https://issues.apache.org/jira/browse/WW-3174
|
||||
* @see https://issues.apache.org/jira/browse/WW-4166
|
||||
* @see <a href="https://issues.apache.org/jira/browse/WW-3174">WW-3174</a>
|
||||
* @see <a href="https://issues.apache.org/jira/browse/WW-4166">WW-4166</a>
|
||||
*/
|
||||
public void copyParams(Map params) {
|
||||
@Override
|
||||
public void copyParams(Map<String, Object> params) {
|
||||
super.copyParams(params);
|
||||
for (Object o : params.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) o;
|
||||
String key = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object>entry : params.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (!isValidTagAttribute(key) && !key.equals("dynamicAttributes")) {
|
||||
dynamicAttributes.put(key, entry.getValue());
|
||||
}
|
||||
|
||||
@@ -169,7 +169,6 @@ public class ConstantConfig {
|
||||
map.put(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, Objects.toString(configurationXmlReload, null));
|
||||
map.put(StrutsConstants.STRUTS_ACTION_EXTENSION, StringUtils.join(actionExtension, ','));
|
||||
map.put(StrutsConstants.STRUTS_ACTION_EXCLUDE_PATTERN, StringUtils.join(actionExcludePattern, ','));
|
||||
map.put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, Objects.toString(tagAltSyntax, null));
|
||||
map.put(StrutsConstants.STRUTS_URL_HTTP_PORT, Objects.toString(urlHttpPort, null));
|
||||
map.put(StrutsConstants.STRUTS_URL_HTTPS_PORT, Objects.toString(urlHttpsPort, null));
|
||||
map.put(StrutsConstants.STRUTS_URL_INCLUDEPARAMS, urlIncludeParams);
|
||||
@@ -327,14 +326,6 @@ public class ConstantConfig {
|
||||
this.actionExcludePattern = actionExcludePattern;
|
||||
}
|
||||
|
||||
public Boolean getTagAltSyntax() {
|
||||
return tagAltSyntax;
|
||||
}
|
||||
|
||||
public void setTagAltSyntax(Boolean tagAltSyntax) {
|
||||
this.tagAltSyntax = tagAltSyntax;
|
||||
}
|
||||
|
||||
public Integer getUrlHttpPort() {
|
||||
return urlHttpPort;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
*/
|
||||
package org.apache.struts2.util;
|
||||
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.views.util.ContextUtil;
|
||||
|
||||
/**
|
||||
* Various static methods used with components
|
||||
*/
|
||||
@@ -29,32 +26,18 @@ public class ComponentUtils {
|
||||
/**
|
||||
* If altSyntax (%{...}) is applied, simply strip the "%{" and "}" off.
|
||||
*
|
||||
* @param stack the ValueStack where the context value is searched for.
|
||||
* @param expr the expression (must be not null)
|
||||
* @param expr the expression (must be not null)
|
||||
* @return the stripped expression if altSyntax is enabled. Otherwise
|
||||
* the parameter expression is returned as is.
|
||||
* the parameter expression is returned as is.
|
||||
*/
|
||||
public static String stripExpressionIfAltSyntax(ValueStack stack, String expr) {
|
||||
if (altSyntax(stack)) {
|
||||
// does the expression start with %{ and end with }? if so, just cut it off!
|
||||
if (isExpression(expr)) {
|
||||
return expr.substring(2, expr.length() - 1);
|
||||
}
|
||||
public static String stripExpression(String expr) {
|
||||
// does the expression start with %{ and end with }? if so, just cut it off!
|
||||
if (isExpression(expr)) {
|
||||
return expr.substring(2, expr.length() - 1);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the altSyntax enabled? [TRUE]
|
||||
*
|
||||
* @param stack the ValueStack where the context value is searched for.
|
||||
* @return true if altSyntax is activated. False otherwise.
|
||||
* See <code>struts.properties</code> where the altSyntax flag is defined.
|
||||
*/
|
||||
public static boolean altSyntax(ValueStack stack) {
|
||||
return ContextUtil.isUseAltSyntax(stack.getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is expression base on altSyntax
|
||||
*
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
*/
|
||||
package org.apache.struts2.views.jsp;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.jsp.tagext.BodyTagSupport;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.util.ComponentUtils;
|
||||
import org.apache.struts2.util.FastByteArrayOutputStream;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import javax.servlet.jsp.tagext.BodyTagSupport;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Contains common functonalities for Struts JSP Tags.
|
||||
*
|
||||
*/
|
||||
public class StrutsBodyTagSupport extends BodyTagSupport {
|
||||
|
||||
@@ -45,25 +42,23 @@ public class StrutsBodyTagSupport extends BodyTagSupport {
|
||||
}
|
||||
|
||||
protected Object findValue(String expr) {
|
||||
expr = ComponentUtils.stripExpressionIfAltSyntax(getStack(), expr);
|
||||
expr = ComponentUtils.stripExpression(expr);
|
||||
|
||||
return getStack().findValue(expr);
|
||||
}
|
||||
|
||||
protected Object findValue(String expr, Class toType) {
|
||||
if (ComponentUtils.altSyntax(getStack()) && toType == String.class) {
|
||||
return TextParseUtil.translateVariables('%', expr, getStack());
|
||||
//return translateVariables(expr, getStack());
|
||||
protected Object findValue(String expr, Class<?> toType) {
|
||||
if (toType == String.class) {
|
||||
return TextParseUtil.translateVariables('%', expr, getStack());
|
||||
} else {
|
||||
expr = ComponentUtils.stripExpressionIfAltSyntax(getStack(), expr);
|
||||
|
||||
expr = ComponentUtils.stripExpression(expr);
|
||||
return getStack().findValue(expr, toType);
|
||||
}
|
||||
}
|
||||
|
||||
protected String toString(Throwable t) {
|
||||
try (FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
|
||||
PrintWriter wrt = new PrintWriter(bout)) {
|
||||
PrintWriter wrt = new PrintWriter(bout)) {
|
||||
t.printStackTrace(wrt);
|
||||
|
||||
return bout.toString();
|
||||
|
||||
@@ -60,25 +60,6 @@ public class ContextUtil {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if either Configuration's altSyntax is on or the stack context's useAltSyntax is on
|
||||
*
|
||||
* @param context stack's context
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isUseAltSyntax(Map<String, Object> context) {
|
||||
// We didn't make altSyntax static cause, if so, struts.configuration.xml.reload will not work
|
||||
// plus the Configuration implementation should cache the properties, which the framework's
|
||||
// configuration implementation does
|
||||
String tagAltSytnax = ActionContext.of(context).getContainer().getInstance(String.class, StrutsConstants.STRUTS_TAG_ALTSYNTAX);
|
||||
|
||||
return "true".equals(tagAltSytnax) || (
|
||||
(context.containsKey("useAltSyntax") &&
|
||||
context.get("useAltSyntax") != null &&
|
||||
"true".equals(context.get("useAltSyntax").toString()))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String for overriding the default templateSuffix if templateSuffix is on the stack
|
||||
*
|
||||
|
||||
@@ -122,10 +122,6 @@ struts.mapper.action.prefix.enabled = false
|
||||
### Blocks access to actions in other namespace than current with action: prefix
|
||||
struts.mapper.action.prefix.crossNamespaces = false
|
||||
|
||||
### use alternative syntax that requires %{} in most places
|
||||
### to evaluate expressions for String attributes for tags
|
||||
struts.tag.altSyntax=true
|
||||
|
||||
### when set to true, Struts will act much more friendly for developers. This
|
||||
### includes:
|
||||
### - struts.i18n.reload = true
|
||||
|
||||
@@ -18,67 +18,22 @@
|
||||
*/
|
||||
package org.apache.struts2.util;
|
||||
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
|
||||
public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testStripExpression() throws Exception {
|
||||
public void testStripExpression() {
|
||||
// given
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
String anExpression = "%{foo}";
|
||||
|
||||
// when
|
||||
String actual = ComponentUtils.stripExpressionIfAltSyntax(stack, anExpression);
|
||||
String actual = ComponentUtils.stripExpression(anExpression);
|
||||
|
||||
// then
|
||||
assertEquals(actual, "foo");
|
||||
}
|
||||
|
||||
public void testNoStripExpressionIfNoAltSyntax() throws Exception {
|
||||
// given
|
||||
loadConfigurationProviders(new MockConfigurationProvider());
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
String anExpression = "%{foo}";
|
||||
|
||||
// when
|
||||
String actual = ComponentUtils.stripExpressionIfAltSyntax(stack, anExpression);
|
||||
|
||||
// then
|
||||
assertEquals(actual, "%{foo}");
|
||||
}
|
||||
|
||||
public void testAltSyntaxIsTrue() throws Exception {
|
||||
// given
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
|
||||
// when
|
||||
boolean actual = ComponentUtils.altSyntax(stack);
|
||||
|
||||
// then
|
||||
assertTrue(actual);
|
||||
}
|
||||
|
||||
public void testAltSyntaxIsFalse() throws Exception {
|
||||
// given
|
||||
loadConfigurationProviders(new MockConfigurationProvider());
|
||||
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
|
||||
|
||||
// when
|
||||
boolean actual = ComponentUtils.altSyntax(stack);
|
||||
|
||||
// then
|
||||
assertFalse(actual);
|
||||
}
|
||||
|
||||
public void testIsExpressionIsTrue() throws Exception {
|
||||
public void testIsExpressionIsTrue() {
|
||||
// given
|
||||
String anExpression = "%{foo}";
|
||||
|
||||
@@ -89,7 +44,7 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertTrue(actual);
|
||||
}
|
||||
|
||||
public void testIsExpressionIsFalseWhenCombined() throws Exception {
|
||||
public void testIsExpressionIsFalseWhenCombined() {
|
||||
// given
|
||||
String anExpression = "bar%{foo}";
|
||||
|
||||
@@ -100,7 +55,7 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertFalse(actual);
|
||||
}
|
||||
|
||||
public void testIsExpressionIsFalse() throws Exception {
|
||||
public void testIsExpressionIsFalse() {
|
||||
// given
|
||||
String anExpression = "foo";
|
||||
|
||||
@@ -111,11 +66,11 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertFalse(actual);
|
||||
}
|
||||
|
||||
public void testIsExpressionIsFalseWhenNull() throws Exception {
|
||||
public void testIsExpressionIsFalseWhenNull() {
|
||||
assertFalse(ComponentUtils.isExpression(null));
|
||||
}
|
||||
|
||||
public void testContainsExpressionIsTrue() throws Exception {
|
||||
public void testContainsExpressionIsTrue() {
|
||||
// given
|
||||
String anExpression = "%{foo}";
|
||||
|
||||
@@ -126,7 +81,7 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertTrue(actual);
|
||||
}
|
||||
|
||||
public void testIsContainsIsTrueWhenCombined() throws Exception {
|
||||
public void testIsContainsIsTrueWhenCombined() {
|
||||
// given
|
||||
String anExpression = "bar%{foo}";
|
||||
|
||||
@@ -137,7 +92,7 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertTrue(actual);
|
||||
}
|
||||
|
||||
public void testContainsExpressionIsFalse() throws Exception {
|
||||
public void testContainsExpressionIsFalse() {
|
||||
// given
|
||||
String anExpression = "foo";
|
||||
|
||||
@@ -148,27 +103,7 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
|
||||
assertFalse(actual);
|
||||
}
|
||||
|
||||
public void testContainsExpressionIsFalseWhenNull() throws Exception {
|
||||
public void testContainsExpressionIsFalseWhenNull() {
|
||||
assertFalse(ComponentUtils.containsExpression(null));
|
||||
}
|
||||
}
|
||||
|
||||
class MockConfigurationProvider implements ConfigurationProvider {
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
|
||||
public boolean needsReload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
builder.constant(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,18 @@
|
||||
*/
|
||||
package org.apache.struts2.views.jsp;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
|
||||
import com.mockobjects.servlet.MockJspWriter;
|
||||
import com.mockobjects.servlet.MockPageContext;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
|
||||
/**
|
||||
* PropertyTag test case.
|
||||
*
|
||||
*/
|
||||
public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
@@ -163,8 +158,6 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testWithAltSyntax1() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("tm_jee");
|
||||
stack.push(foo);
|
||||
@@ -193,27 +186,27 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testEscapeJavaScript() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("\t\b\n\f\r\"\'/\\");
|
||||
foo.setTitle("\t\b\n\f\r\"'/\\");
|
||||
stack.push(foo);
|
||||
|
||||
MockJspWriter jspWriter = new MockJspWriter();
|
||||
jspWriter.setExpectedData("Foo is: \\t\\b\\n\\f\\r\\\"\\\'\\/\\\\");
|
||||
jspWriter.setExpectedData("Foo is: \\t\\b\\n\\f\\r\\\"\\'\\/\\\\");
|
||||
|
||||
MockPageContext pageContext = new MockPageContext();
|
||||
pageContext.setJspWriter(jspWriter);
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeJavaScript(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeJavaScript(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -221,10 +214,8 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.verify();
|
||||
}
|
||||
|
||||
public void testEscapeXml() throws Exception {
|
||||
public void testEscapeXml() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("<>'\"&");
|
||||
stack.push(foo);
|
||||
@@ -237,13 +228,15 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeXml(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeXml(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -251,10 +244,8 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.verify();
|
||||
}
|
||||
|
||||
public void testEscapeCsv() throws Exception {
|
||||
public void testEscapeCsv() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("\"something,\",\"");
|
||||
stack.push(foo);
|
||||
@@ -267,13 +258,15 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeCsv(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setEscapeHtml(false);
|
||||
tag.setEscapeCsv(true);
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -283,8 +276,6 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testWithAltSyntax2() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("tm_jee");
|
||||
stack.push(foo);
|
||||
@@ -297,11 +288,13 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("formatTitle()");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("formatTitle()");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -311,8 +304,6 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testWithoutAltSyntax1() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("tm_jee");
|
||||
stack.push(foo);
|
||||
@@ -325,11 +316,13 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("formatTitle()");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("formatTitle()");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -340,8 +333,6 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testWithoutAltSyntax2() throws Exception {
|
||||
// setups
|
||||
initDispatcher(new HashMap() {{ put(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");}});
|
||||
|
||||
Foo foo = new Foo();
|
||||
foo.setTitle("tm_jee");
|
||||
stack.push(foo);
|
||||
@@ -353,11 +344,13 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
pageContext.setRequest(request);
|
||||
|
||||
// test
|
||||
{PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();}
|
||||
{
|
||||
PropertyTag tag = new PropertyTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setValue("%{formatTitle()}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
}
|
||||
|
||||
// verify test
|
||||
request.verify();
|
||||
@@ -373,7 +366,7 @@ public class PropertyTagTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
|
||||
public class Foo {
|
||||
public static class Foo {
|
||||
private String title;
|
||||
|
||||
public void setTitle(String title) {
|
||||
|
||||
@@ -18,31 +18,21 @@
|
||||
*/
|
||||
package org.apache.struts2.views.jsp.ui;
|
||||
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.RuntimeConfiguration;
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Scope.Strategy;
|
||||
import com.opensymphony.xwork2.validator.ValidationInterceptor;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.TestAction;
|
||||
import org.apache.struts2.TestConfigurationProvider;
|
||||
import org.apache.struts2.components.Form;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
|
||||
import org.apache.struts2.views.jsp.AbstractUITagTest;
|
||||
import org.apache.struts2.views.jsp.ActionTag;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,8 +40,8 @@ import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
|
||||
*/
|
||||
public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
|
||||
public void testFormWithActionAttributeContainingQueryString() throws Exception {
|
||||
|
||||
public void testFormWithActionAttributeContainingQueryString() throws Exception {
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setName("myForm");
|
||||
@@ -66,10 +56,10 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-26.txt"));
|
||||
}
|
||||
|
||||
|
||||
public void testFormWithActionAttributeContainingBothActionAndMethod() throws Exception {
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
@@ -114,7 +104,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-13.txt"));
|
||||
}
|
||||
|
||||
|
||||
public void testFormWithActionAttributeContainingBothActionAndDMIMethod() throws Exception {
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
@@ -126,13 +116,13 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
tag.setTitle("mytitle");
|
||||
tag.setOnsubmit("submitMe()");
|
||||
|
||||
((DefaultActionMapper)container.getInstance(ActionMapper.class)).setAllowDynamicMethodCalls("true");
|
||||
((DefaultActionMapper) container.getInstance(ActionMapper.class)).setAllowDynamicMethodCalls("true");
|
||||
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-23.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFormWithFocusElement() throws Exception {
|
||||
FormTag tag = new FormTag();
|
||||
@@ -208,7 +198,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
verify(FormTag.class.getResource("Formtag-29.txt"));
|
||||
}
|
||||
|
||||
public void testFormNoNameOrId() throws Exception {
|
||||
public void testFormNoNameOrId() throws Exception {
|
||||
|
||||
request.setupGetServletPath("/testAction");
|
||||
|
||||
@@ -330,7 +320,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
verify(FormTag.class.getResource("Formtag-22.txt"));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Tests the numbers are formatted correctly to not break the javascript, using doubles
|
||||
*/
|
||||
public void testFormWithCustomOnsubmitEnabledWithValidateEnabled4() throws Exception {
|
||||
@@ -420,7 +410,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
* </p>
|
||||
*/
|
||||
public void testFormTagWithDifferentActionExtension() throws Exception {
|
||||
initDispatcher(new HashMap<String,String>(){{
|
||||
initDispatcher(new HashMap<String, String>() {{
|
||||
put(StrutsConstants.STRUTS_ACTION_EXTENSION, "jspa");
|
||||
put("configProviders", TestConfigurationProvider.class.getName());
|
||||
}});
|
||||
@@ -630,7 +620,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
public void testFormWithActionAndExtension() throws Exception {
|
||||
request.setupGetServletPath("/BLA");
|
||||
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setAction("/testNamespace/testNamespaceAction.jspa");
|
||||
@@ -684,7 +674,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-27.txt"));
|
||||
}
|
||||
|
||||
|
||||
public void testFormWithTopLabelPositionCssXhtml() throws Exception {
|
||||
FormTag form = new FormTag();
|
||||
form.setTheme("css_xhtml");
|
||||
@@ -725,7 +715,7 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-28.txt"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
|
||||
import com.mockobjects.dynamic.C;
|
||||
import com.mockobjects.dynamic.Mock;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
|
||||
/**
|
||||
* Test case for ContextUtil
|
||||
*
|
||||
*/
|
||||
public class ContextUtilTest extends StrutsInternalTestCase {
|
||||
|
||||
private void setAltSyntax(ValueStack stack, String val) {
|
||||
Mock container = new Mock(Container.class);
|
||||
container.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_TAG_ALTSYNTAX)), val);
|
||||
stack.getActionContext().withContainer((Container) container.proxy());
|
||||
}
|
||||
|
||||
public void testAltSyntaxMethod1() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", "true");
|
||||
|
||||
setAltSyntax(stack, "true");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
|
||||
public void testAltSyntaxMethod2() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", "false");
|
||||
|
||||
setAltSyntax(stack, "true");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
|
||||
public void testAltSyntaxMethod3() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", "true");
|
||||
|
||||
setAltSyntax(stack, "false");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
|
||||
public void testAltSyntaxMethod4() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", "false");
|
||||
|
||||
setAltSyntax(stack, "false");
|
||||
assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
|
||||
//========================================================
|
||||
|
||||
public void testAltSyntaxMethod5() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", Boolean.TRUE);
|
||||
|
||||
setAltSyntax(stack, "true");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
public void testAltSyntaxMethod6() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", Boolean.FALSE);
|
||||
|
||||
setAltSyntax(stack, "true");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
public void testAltSyntaxMethod7() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", Boolean.TRUE);
|
||||
|
||||
setAltSyntax(stack, "false");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
public void testAltSyntaxMethod8() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", Boolean.FALSE);
|
||||
|
||||
setAltSyntax(stack, "false");
|
||||
assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
public void testAltSyntaxMethod9() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
stack.getContext().put("useAltSyntax", null);
|
||||
|
||||
setAltSyntax(stack, "true");
|
||||
assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
|
||||
}
|
||||
}
|
||||
+6
-14
@@ -24,7 +24,6 @@ import org.apache.struts2.components.template.TemplateRenderingContext;
|
||||
import org.apache.struts2.util.ComponentUtils;
|
||||
import org.apache.struts2.views.java.Attributes;
|
||||
import org.apache.struts2.views.java.TagHandler;
|
||||
import org.apache.struts2.views.util.ContextUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,7 +31,6 @@ public abstract class AbstractTagHandler implements TagHandler {
|
||||
|
||||
protected TagHandler nextTagHandler;
|
||||
protected TemplateRenderingContext context;
|
||||
protected boolean altSyntax;
|
||||
|
||||
public void characters(String text) throws IOException {
|
||||
characters(text, true);
|
||||
@@ -64,7 +62,6 @@ public abstract class AbstractTagHandler implements TagHandler {
|
||||
|
||||
public void setup(TemplateRenderingContext context) {
|
||||
this.context = context;
|
||||
this.altSyntax = ContextUtil.isUseAltSyntax(context.getStack().getContext());
|
||||
processParams();
|
||||
}
|
||||
|
||||
@@ -72,7 +69,11 @@ public abstract class AbstractTagHandler implements TagHandler {
|
||||
}
|
||||
|
||||
protected String findString(String expr) {
|
||||
return (String) findValue(expr, String.class);
|
||||
if (expr == null) {
|
||||
return null;
|
||||
}
|
||||
ValueStack stack = context.getStack();
|
||||
return TextParseUtil.translateVariables('%', expr, stack);
|
||||
}
|
||||
|
||||
protected Object findValue(String expr) {
|
||||
@@ -81,16 +82,7 @@ public abstract class AbstractTagHandler implements TagHandler {
|
||||
}
|
||||
|
||||
ValueStack stack = context.getStack();
|
||||
return stack.findValue(ComponentUtils.stripExpressionIfAltSyntax(stack, expr));
|
||||
return stack.findValue(ComponentUtils.stripExpression(expr));
|
||||
}
|
||||
|
||||
private Object findValue(String expr, Class toType) {
|
||||
ValueStack stack = context.getStack();
|
||||
|
||||
if (altSyntax && toType == String.class) {
|
||||
return TextParseUtil.translateVariables('%', expr, stack);
|
||||
} else {
|
||||
return stack.findValue(ComponentUtils.stripExpressionIfAltSyntax(stack, expr), toType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class DynamicAttributesHandler extends AbstractTagHandler {
|
||||
protected void processDynamicAttributes(Attributes a) {
|
||||
Map<String, String> dynamicAttributes = (Map<String, String>) context.getParameters().get("dynamicAttributes");
|
||||
for (Map.Entry<String, String> entry : dynamicAttributes.entrySet()) {
|
||||
if (altSyntax && ComponentUtils.isExpression(entry.getValue())) {
|
||||
if (ComponentUtils.isExpression(entry.getValue())) {
|
||||
String value = ObjectUtils.defaultIfNull(findString(entry.getValue()), entry.getValue());
|
||||
a.put(entry.getKey(), value);
|
||||
} else {
|
||||
|
||||
-2
@@ -28,7 +28,6 @@ import com.opensymphony.xwork2.util.OgnlTextParser;
|
||||
import com.opensymphony.xwork2.util.TextParser;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.components.Component;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
import org.apache.struts2.components.template.Template;
|
||||
@@ -113,7 +112,6 @@ public abstract class AbstractTest extends TestCase {
|
||||
|
||||
Container container = createNiceMock(Container.class);
|
||||
XWorkConverter converter = new ConverterEx();
|
||||
expect(container.getInstance(String.class, StrutsConstants.STRUTS_TAG_ALTSYNTAX)).andReturn("true").anyTimes();
|
||||
expect(container.getInstance(XWorkConverter.class)).andReturn(converter).anyTimes();
|
||||
TextParser parser = new OgnlTextParser();
|
||||
expect(container.getInstance(TextParser.class)).andReturn(parser).anyTimes();
|
||||
|
||||
Reference in New Issue
Block a user