| Method from org.apache.struts2.components.Component Detail: |
public void addAllParameters(Map params) {
parameters.putAll(params);
}
Adds all the given parameters to this component's own parameters. |
public void addParameter(String key,
Object value) {
if (key != null) {
Map params = getParameters();
if (value == null) {
params.remove(key);
} else {
params.put(key, value);
}
}
}
Adds the given key and value to this component's own parameter.
If the provided key is null nothing happens.
If the provided value is null any existing parameter with
the given key name is removed. |
public boolean altSyntax() {
return altSyntax(stack);
}
Is the altSyntax enabled? [TRUE]
See struts.properties where the altSyntax flag is defined. |
public static boolean altSyntax(ValueStack stack) {
return ContextUtil.isUseAltSyntax(stack.getContext());
}
Is the altSyntax enabled? [TRUE]
|
protected String completeExpressionIfAltSyntax(String expr) {
if (altSyntax()) {
return "%{" + expr + "}";
}
return expr;
}
Adds the sorrounding %{ } to the expression for proper processing. |
public void copyParams(Map params) {
stack.push(parameters);
stack.push(this);
try {
for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String key = (String) entry.getKey();
stack.setValue(key, entry.getValue());
}
} finally {
stack.pop();
stack.pop();
}
}
Pushes this component's parameter Map as well as the component itself on to the stack
and then copies the supplied parameters over. Because the component's parameter Map is
pushed before the component itself, any key-value pair that can't be assigned to componet
will be set in the parameters Map. |
protected String determineActionURL(String action,
String namespace,
String method,
HttpServletRequest req,
HttpServletResponse res,
Map parameters,
String scheme,
boolean includeContext,
boolean encodeResult,
boolean forceAddSchemeHostAndPort,
boolean escapeAmp) {
String finalAction = findString(action);
String finalMethod = method != null ? findString(method) : null;
String finalNamespace = determineNamespace(namespace, getStack(), req);
ActionMapping mapping = new ActionMapping(finalAction, finalNamespace, finalMethod, parameters);
String uri = actionMapper.getUriFromActionMapping(mapping);
return UrlHelper.buildUrl(uri, req, res, parameters, scheme, includeContext, encodeResult, forceAddSchemeHostAndPort, escapeAmp);
}
|
protected String determineNamespace(String namespace,
ValueStack stack,
HttpServletRequest req) {
String result;
if (namespace == null) {
result = TagUtils.buildNamespace(actionMapper, stack, req);
} else {
result = findString(namespace);
}
if (result == null) {
result = "";
}
return result;
}
Determines the namespace of the current page being renderdd. Useful for Form, URL, and href generations. |
public boolean end(Writer writer,
String body) {
return end(writer, body, true);
}
Callback for the end tag of this component.
Should the body be evaluated again?
NOTE: will pop component stack. |
protected boolean end(Writer writer,
String body,
boolean popComponentStack) {
assert(body != null);
try {
writer.write(body);
} catch (IOException e) {
throw new StrutsException("IOError while writing the body: " + e.getMessage(), e);
}
if (popComponentStack) {
popComponentStack();
}
return false;
}
Callback for the start tag of this component.
Should the body be evaluated again?
NOTE: has a parameter to determine to pop the component stack. |
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;
throw new StrutsException(msg, e);
}
Constructs a RuntimeException based on the given information.
A message is constructed and logged at ERROR level before being returned
as a RuntimeException. |
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--) {
Component component = (Component) componentStack.get(i);
if (clazz.isAssignableFrom(component.getClass()) && component != this) {
return component;
}
}
}
return null;
}
Finds the nearest ancestor of this component stack. |
protected String findString(String expr) {
return (String) findValue(expr, String.class);
}
Evaluates the OGNL stack to find a String value. |
protected String findString(String expr,
String field,
String errorMsg) {
if (expr == null) {
throw fieldError(field, errorMsg, null);
} else {
return findString(expr);
}
}
Evaluates the OGNL stack to find a String value.
If the given expression is null a error is logged and a RuntimeException is thrown
constructed with a messaged based on the given field and errorMsg paramter. |
protected String findStringIfAltSyntax(String expr) {
if (altSyntax()) {
return findString(expr);
}
return expr;
}
This check is needed for backwards compatibility with 2.1.x |
protected Object findValue(String expr) {
if (expr == null) {
return null;
}
expr = stripExpressionIfAltSyntax(expr);
return getStack().findValue(expr, throwExceptionOnELFailure);
}
Finds a value from the OGNL stack based on the given expression.
Will always evaluate expr against stack except when expr
is null. If altsyntax (%{...}) is applied, simply strip it off. |
protected Object findValue(String expr,
Class toType) {
if (altSyntax() && toType == String.class) {
return TextParseUtil.translateVariables('%', expr, stack);
} else {
expr = stripExpressionIfAltSyntax(expr);
return getStack().findValue(expr, toType, throwExceptionOnELFailure);
}
}
Evaluates the OGNL stack to find an Object of the given type. Will evaluate
expr the portion wrapped with altSyntax (%{...})
against stack when altSyntax is on, else the whole expr
is evaluated against the stack.
This method only supports the altSyntax. So this should be set to true. |
protected Object findValue(String expr,
String field,
String errorMsg) {
if (expr == null) {
throw fieldError(field, errorMsg, null);
} else {
Object value = null;
Exception problem = null;
try {
value = findValue(expr);
} catch (Exception e) {
problem = e;
}
if (value == null) {
throw fieldError(field, errorMsg, problem);
}
return value;
}
}
Evaluates the OGNL stack to find an Object value.
Function just like findValue(String) except that if the
given expression is null a error is logged and
a RuntimeException is thrown constructed with a
messaged based on the given field and errorMsg paramter. |
public Stack getComponentStack() {
Stack componentStack = (Stack) stack.getContext().get(COMPONENT_STACK);
if (componentStack == null) {
componentStack = new Stack();
stack.getContext().put(COMPONENT_STACK, componentStack);
}
return componentStack;
}
Gets the component stack of this component. |
public Map getParameters() {
return parameters;
}
|
public ValueStack getStack() {
return stack;
}
Gets the OGNL value stack assoicated with this component. |
protected void popComponentStack() {
getComponentStack().pop();
}
Pops the component stack. |
public void setActionMapper(ActionMapper mapper) {
this.actionMapper = mapper;
}
|
public void setThrowExceptionsOnELFailure(String throwException) {
this.throwExceptionOnELFailure = "true".equals(throwException);
}
|
public boolean start(Writer writer) {
return true;
}
Callback for the start tag of this component.
Should the body be evaluated? |
protected String stripExpressionIfAltSyntax(String expr) {
return stripExpressionIfAltSyntax(stack, expr);
}
If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off. |
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 (expr.startsWith("%{") && expr.endsWith("}")) {
return expr.substring(2, expr.length() - 1);
}
}
return expr;
}
If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off. |
protected String toString(Throwable t) {
FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
PrintWriter wrt = new PrintWriter(bout);
t.printStackTrace(wrt);
wrt.close();
return bout.toString();
}
Constructs a string representation of the given exception. |
public boolean usesBody() {
return false;
}
Overwrite to set if body shold be used. |