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 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 27 import java.util.Map ; 28 29 43 public class HeaderSelector extends AbstractLogEnabled 44 implements Configurable, ThreadSafe, Selector { 45 46 protected String defaultName; 47 48 public void configure(Configuration config) throws ConfigurationException { 49 this.defaultName = config.getChild("parameter-name").getValue(null); 51 if (defaultName != null) { 52 getLogger().warn("'parameter-name' is deprecated. Please use 'header-name'"); 53 } 54 this.defaultName = config.getChild("header-name").getValue(this.defaultName); 56 } 57 58 public boolean select(String expression, Map objectModel, Parameters parameters) { 59 String name = parameters.getParameter("parameter-name", null); 61 if (name != null) { 62 getLogger().warn("'parameter-name' is deprecated. Please use 'header-name'"); 63 } else { 64 name = this.defaultName; 65 } 66 67 name = parameters.getParameter("header-name", name); 69 70 if (name == null) { 71 getLogger().warn("No header name given -- failing."); 72 return false; 73 } 74 75 String value = ObjectModelHelper.getRequest(objectModel).getHeader(name); 76 if (value == null) { 77 getLogger().debug("Header '" + name + "' not set -- failing."); 78 return false; 79 } 80 81 return value.equals(expression); 82 } 83 } 84 | Popular Tags |