1 16 package org.apache.cocoon.selection; 17 18 import org.apache.avalon.framework.configuration.Configurable; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.avalon.framework.thread.ThreadSafe; 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 25 import java.util.Map ; 26 27 42 public class RequestParameterSelector extends AbstractSwitchSelector 43 implements Configurable, ThreadSafe { 44 45 protected String defaultName; 46 47 public void configure(Configuration config) throws ConfigurationException { 48 this.defaultName = config.getChild("parameter-name").getValue(null); 49 } 50 51 public Object getSelectorContext(Map objectModel, Parameters parameters) { 52 53 String name = parameters.getParameter("parameter-name", this.defaultName); 54 55 if (name == null) { 56 getLogger().warn("No parameter name given -- failing."); 57 return null; 58 } 59 60 return ObjectModelHelper.getRequest(objectModel).getParameter(name); 61 } 62 63 public boolean select(String expression, Object selectorContext) { 64 if (selectorContext == null) { 65 getLogger().debug("Request parameter '" + selectorContext + "' not set -- failing."); 66 return false; 67 } 68 69 return selectorContext.equals(expression); 70 } 71 } 72 | Popular Tags |