use of com.opensymphony.xwork2.config.entities.Parameterizable in project struts by apache.
the class StaticParametersInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionConfig config = invocation.getProxy().getConfig();
Object action = invocation.getAction();
final Map<String, String> parameters = config.getParams();
LOG.debug("Setting static parameters: {}", parameters);
// for actions marked as Parameterizable, pass the static parameters directly
if (action instanceof Parameterizable) {
((Parameterizable) action).setParams(parameters);
}
if (parameters != null) {
ActionContext ac = ActionContext.getContext();
Map<String, Object> contextMap = ac.getContextMap();
try {
ReflectionContextState.setCreatingNullObjects(contextMap, true);
ReflectionContextState.setReportingConversionErrors(contextMap, true);
final ValueStack stack = ac.getValueStack();
ValueStack newStack = valueStackFactory.createValueStack(stack);
boolean clearableStack = newStack instanceof ClearableValueStack;
if (clearableStack) {
// if the stack's context can be cleared, do that to prevent OGNL
// from having access to objects in the stack, see XW-641
((ClearableValueStack) newStack).clearContextValues();
Map<String, Object> context = newStack.getContext();
ReflectionContextState.setCreatingNullObjects(context, true);
ReflectionContextState.setDenyMethodExecution(context, true);
ReflectionContextState.setReportingConversionErrors(context, true);
// keep locale from original context
newStack.getActionContext().withLocale(stack.getActionContext().getLocale());
}
for (Map.Entry<String, String> entry : parameters.entrySet()) {
Object val = entry.getValue();
if (parse && val instanceof String) {
val = TextParseUtil.translateVariables(val.toString(), stack);
}
try {
newStack.setValue(entry.getKey(), val);
} catch (RuntimeException e) {
if (devMode) {
String developerNotification = localizedTextProvider.findText(ParametersInterceptor.class, "devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification:\n{0}", new Object[] { "Unexpected Exception caught setting '" + entry.getKey() + "' on '" + action.getClass() + ": " + e.getMessage() });
LOG.error(developerNotification);
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionMessage(developerNotification);
}
}
}
}
if (clearableStack) {
stack.getActionContext().withConversionErrors(newStack.getActionContext().getConversionErrors());
}
if (merge)
addParametersToContext(ac, parameters);
} finally {
ReflectionContextState.setCreatingNullObjects(contextMap, false);
ReflectionContextState.setReportingConversionErrors(contextMap, false);
}
}
return invocation.invoke();
}
Aggregations