1 16 package org.apache.cocoon.matching; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.avalon.framework.parameters.Parameters; 20 import org.apache.avalon.framework.thread.ThreadSafe; 21 22 import org.apache.cocoon.environment.Cookie; 23 import org.apache.cocoon.environment.Request; 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.sitemap.PatternException; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 36 public class CookieMatcher extends AbstractLogEnabled implements Matcher, ThreadSafe { 37 38 public Map match(String pattern, Map objectModel, Parameters parameters) 39 throws PatternException { 40 41 if (pattern == null) { 42 throw new PatternException("No cookie name given."); 43 } 44 45 Request request = ObjectModelHelper.getRequest(objectModel); 46 Cookie[] cookies = request.getCookies(); 47 HashMap result = null; 48 49 if (cookies != null) { 50 for (int i = 0; i < cookies.length; i++) { 51 Cookie cookie = cookies[i]; 52 if (cookie.getName().equals(pattern)) { 53 result = new HashMap (); 54 result.put("1", cookie.getValue()); 55 break; 56 } 57 } 58 } 59 60 return result; 61 } 62 } 63 | Popular Tags |