1 16 17 package org.apache.cocoon.components.modules.input; 18 19 import java.util.Iterator ; 20 import java.util.LinkedList ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.thread.ThreadSafe; 27 import org.apache.cocoon.components.modules.input.AbstractInputModule; 28 import org.apache.cocoon.environment.ObjectModelHelper; 29 import org.apache.cocoon.environment.http.HttpCookie; 30 import org.apache.regexp.RE; 31 32 38 public class CookieModule extends AbstractInputModule implements ThreadSafe { 39 40 44 public Object getAttribute(String name, Configuration modeConf, 45 Map objectModel) throws ConfigurationException { 46 47 HttpCookie cookie = (HttpCookie) getCookieMap(objectModel).get(name); 48 String value = (cookie == null ? null : cookie.getValue()); 49 50 if (getLogger().isDebugEnabled()) { 51 getLogger().debug("Cookie[" + name + "]=" + value); 52 } 53 return value; 54 } 55 56 62 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 63 throws ConfigurationException { 64 65 return getCookieMap(objectModel).keySet().iterator(); 66 } 67 68 75 public Object [] getAttributeValues(String name, Configuration modeConf, 76 Map objectModel) throws ConfigurationException { 77 78 Map allCookies = getCookieMap(objectModel); 79 80 Iterator it = allCookies.values().iterator(); 81 List matched = new LinkedList (); 82 RE regexp = new RE(name); 83 while (it.hasNext()) { 84 HttpCookie cookie = (HttpCookie) it.next(); 85 if (regexp.match(cookie.getName())) { 86 matched.add(cookie.getValue()); 87 } 88 } 89 return matched.toArray(); 90 } 91 92 98 protected Map getCookieMap(Map objectModel) { 99 return ObjectModelHelper.getRequest(objectModel).getCookieMap(); 100 } 101 } 102 | Popular Tags |