1 16 package org.apache.cocoon.selection; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.cocoon.environment.ObjectModelHelper; 22 23 import java.util.Map ; 24 25 34 35 public class BrowserSelector extends NamedPatternsSelector { 36 37 public void configure(Configuration conf) throws ConfigurationException { 38 configure(conf, "browser", "name", "useragent"); 39 } 40 41 public boolean select(String expression, Map objectModel, Parameters parameters) { 42 ObjectModelHelper.getResponse(objectModel).addHeader("Vary", "User-Agent"); 44 45 String userAgent = ObjectModelHelper.getRequest(objectModel).getHeader("User-Agent"); 47 if (userAgent == null) { 48 getLogger().debug("No User-Agent header -- failing."); 49 return false; 50 } 51 52 return checkPatterns(expression, userAgent); 53 } 54 } 55 | Popular Tags |