
com.opensymphony.xwork.interceptor.StaticParametersInterceptor Maven / Gradle / Ivy
/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork.interceptor;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.config.entities.ActionConfig;
import com.opensymphony.xwork.config.entities.Parameterizable;
import com.opensymphony.xwork.util.OgnlValueStack;
import com.opensymphony.xwork.util.TextParseUtil;
import java.util.Iterator;
import java.util.Map;
/**
*
*
* This interceptor populates the action with the static parameters defined in the action configuration. If the action
* implements {@link Parameterizable}, a map of the static parameters will be also be passed directly to the action.
*
* Parameters are typically defined with <param> elements within xwork.xml.
*
*
*
* Interceptor parameters:
*
*
*
*
*
* - None
*
*
*
*
*
* Extending the interceptor:
*
*
*
* There are no extension points to this interceptor.
*
*
*
* Example code:
*
*
*
* <action name="someAction" class="com.examples.SomeAction">
* <interceptor-ref name="static-params">
* <param name="parse">true</param>
* </interceptor-ref>
* <result name="success">good_result.ftl</result>
* </action>
*
*
*
* @author Patrick Lightbody
*/
public class StaticParametersInterceptor extends AroundInterceptor {
private boolean parse;
public void setParse(String value) {
this.parse = Boolean.valueOf(value).booleanValue();
}
protected void after(ActionInvocation invocation, String result) throws Exception {
}
protected void before(ActionInvocation invocation) throws Exception {
ActionConfig config = invocation.getProxy().getConfig();
Object action = invocation.getAction();
final Map parameters = config.getParams();
if (log.isDebugEnabled()) {
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) {
final OgnlValueStack stack = ActionContext.getContext().getValueStack();
for (Iterator iterator = parameters.entrySet().iterator();
iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
stack.setValue(entry.getKey().toString(), entry.getValue());
Object val = entry.getValue();
if (parse && val instanceof String) {
val = TextParseUtil.translateVariables((String) val, stack);
}
stack.setValue(entry.getKey().toString(), val);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy