1 9 10 package com.opensymphony.module.sitemesh.mapper; 11 12 import com.opensymphony.module.sitemesh.Config; 13 import com.opensymphony.module.sitemesh.Decorator; 14 import com.opensymphony.module.sitemesh.DecoratorMapper; 15 import com.opensymphony.module.sitemesh.Page; 16 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.Cookie ; 19 import java.util.Properties ; 20 21 33 public class CookieDecoratorMapper extends AbstractDecoratorMapper { 34 private String cookieName; 35 36 public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException { 37 super.init(config, properties, parent); 38 cookieName = properties.getProperty("cookie.name", null); 39 if (cookieName == null) { 40 throw new InstantiationException ("'cookie.name' name parameter not set for this decorator mapper"); 41 } 42 } 43 44 public Decorator getDecorator(HttpServletRequest request, Page page) { 45 Decorator result = null; 46 Cookie [] cookies = request.getCookies(); 47 if (cookies != null) { 48 for (int i = 0; i < cookies.length; i++) { 49 Cookie cookie = cookies[i]; 50 if (cookie.getName().equals(cookieName)) { 51 result = getNamedDecorator(request, cookie.getValue()); 52 } 53 } 54 } 55 return result == null ? super.getDecorator(request, page) : result; 56 } 57 } | Popular Tags |