package de.toi.bot.cbs.wsp.admin.util; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.opensymphony.xwork.ActionInvocation; import com.opensymphony.xwork.interceptor.AroundInterceptor; /** * interceptor tweaking boolean parameters. parameters with names * starting by PREFIX will be stripped of it, and if no value is available under * stripped name explicitely set to false. * * this helps to overcome problem with boolean checkboxes ( unchecked value is not sent * by browser ) * @author k.pribluda * */ public class BooleanTweaker extends AroundInterceptor { public final static String PREFIX = "_FALSE_."; public final static String FALSE = "false"; private static final Log LOG = LogFactory.getLog(BooleanTweaker.class); protected void after(ActionInvocation arg0, String arg1) throws Exception { } protected void before(ActionInvocation ai) throws Exception { final Map parameters = ai.getInvocationContext().getParameters(); String key; Map toSet = new HashMap(); for(Iterator iter = parameters.keySet().iterator(); iter.hasNext();) { key = iter.next().toString(); if(key.startsWith(PREFIX)) { key = key.substring(PREFIX.length()); if(!parameters.containsKey(key)) { toSet.put(key,FALSE); } } } parameters.putAll(toSet); } }