1 16 package org.apache.cocoon.selection; 17 18 import java.util.Map ; 19 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 25 54 public class RegexpHeaderSelector extends AbstractRegexpSelector { 55 56 57 protected String headerName; 58 59 62 public RegexpHeaderSelector() { 63 super(); 64 } 65 66 75 public void configure(Configuration configuration) 76 throws ConfigurationException { 77 super.configure(configuration); 78 this.headerName = configuration.getChild("header-name").getValue(null); 79 } 80 81 89 public Object getSelectorContext(Map objectModel, Parameters parameters) { 90 String name = parameters.getParameter("header-name", this.headerName); 91 if (name == null) { 92 this.getLogger().warn("No header name given -- failing."); 93 return null; 94 } 95 return ObjectModelHelper.getRequest(objectModel).getHeader(name); 96 } 97 98 104 public boolean select(String expr, Map objectModel, Parameters params) { 105 String name = params.getParameter("header-name", this.headerName); 107 if (name != null) 108 ObjectModelHelper.getResponse(objectModel).addHeader("Vary", name); 109 return select(expr, getSelectorContext(objectModel, params)); 110 } 111 112 } 113 | Popular Tags |