1 16 package org.apache.cocoon.matching; 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 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 25 import java.util.Map ; 26 27 38 public class RegexpSessionAttributeMatcher extends AbstractRegexpMatcher 39 implements Configurable 40 { 41 private String defaultParam; 42 43 public void configure(Configuration config) throws ConfigurationException { 44 this.defaultParam = config.getChild("attribute-name").getValue(null); 45 if (getLogger().isDebugEnabled()) { 46 getLogger().debug("Default attribute-name is = '" + this.defaultParam + "'"); 47 } 48 } 49 50 protected String getMatchString(Map objectModel, Parameters parameters) { 51 52 String paramName = parameters.getParameter("attribute-name", this.defaultParam); 53 if (paramName == null) { 54 getLogger().warn("No attribute name given. FAILING"); 55 return null; 56 } 57 58 Object result = ObjectModelHelper.getRequest(objectModel).getSession().getAttribute(paramName); 59 if (result == null) { 60 getLogger().debug("Session attribute '" + paramName + "' not set."); 61 return null; 62 } 63 64 return result.toString(); 65 } 66 } 67 | Popular Tags |