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.Cookie; 26 import org.apache.cocoon.environment.ObjectModelHelper; 27 28 import java.util.Map ; 29 30 44 public class CookieSelector extends AbstractLogEnabled 45 implements Configurable, Selector, ThreadSafe { 46 47 protected String defaultName; 48 49 public void configure(Configuration config) throws ConfigurationException { 50 this.defaultName = config.getChild("cookie-name").getValue(null); 51 } 52 53 public boolean select(String expression, Map objectModel, Parameters parameters) { 54 55 String name = parameters.getParameter("cookie-name", this.defaultName); 56 if (name == null) { 57 getLogger().warn("No cookie name given -- failing."); 58 return false; 59 } 60 61 Cookie[] cookies = ObjectModelHelper.getRequest(objectModel).getCookies(); 62 if (cookies == null) { 63 getLogger().debug("Cookie '" + name + "' not set -- failing"); 64 return false; 65 } 66 67 String value = null; 69 for (int i = 0; i < cookies.length; i++) { 70 if (cookies[i].getName().equals(name)) { 71 value = cookies[i].getValue(); 72 break; 73 } 74 } 75 76 if (value == null) { 77 getLogger().debug("Cookie '" + name + "' not set -- failing"); 78 return false; 79 } 80 81 return value.equals(expression); 82 } 83 } 84 | Popular Tags |