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.logger.AbstractLogEnabled; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 26 import java.util.Map ; 27 28 42 public class RequestAttributeSelector extends AbstractLogEnabled 43 implements Configurable, ThreadSafe, Selector { 44 45 protected String defaultName; 46 47 public void configure(Configuration config) throws ConfigurationException { 48 this.defaultName = config.getChild("attribute-name").getValue(null); 49 } 50 51 public boolean select(String expression, Map objectModel, Parameters parameters) { 52 String name = parameters.getParameter("attribute-name", this.defaultName); 53 54 if (name == null) { 55 getLogger().warn("No attribute name given -- failing."); 56 return false; 57 } 58 59 Object value = ObjectModelHelper.getRequest(objectModel).getAttribute(name); 60 if (value == null) { 61 getLogger().debug("Request attribute '" + name + "' not set -- failing."); 62 return false; 63 } 64 65 return value.toString().equals(expression); 66 } 67 } 68 | Popular Tags |