All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opensymphony.xwork2.interceptor.StaticParametersInterceptor Maven / Gradle / Ivy

Go to download

XWork is an command-pattern framework that is used to power WebWork as well as other applications. XWork provides an Inversion of Control container, a powerful expression language, data type conversion, validation, and pluggable configuration.

There is a newer version: 2.1.3
Show newest version
/*
 * Copyright (c) 2002-2006 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.xwork2.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.Parameterizable;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * 
 *
 * 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 AbstractInterceptor { private boolean parse; private static final Log LOG = LogFactory.getLog(StaticParametersInterceptor.class); public void setParse(String value) { this.parse = Boolean.valueOf(value).booleanValue(); } public String intercept(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 ValueStack 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); } } return invocation.invoke(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy