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 41 public class SessionAttributeSelector extends AbstractLogEnabled 42 implements Configurable, ThreadSafe, Selector { 43 44 protected String defaultName; 45 46 public void configure(Configuration config) throws ConfigurationException { 47 this.defaultName = config.getChild("attribute-name").getValue(null); 48 } 49 50 public boolean select(String expression, Map objectModel, Parameters parameters) { 51 String name = parameters.getParameter("attribute-name", this.defaultName); 52 53 if (name == null) { 54 getLogger().warn("No attribute name given -- failing."); 55 return false; 56 } 57 58 Object value = ObjectModelHelper.getRequest(objectModel).getSession().getAttribute(name); 59 if (value == null) { 60 getLogger().debug("Session attribute '" + name + "' not set -- failing."); 61 return false; 62 } 63 64 return value.toString().equals(expression); 65 } 66 } 67 | Popular Tags |