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 java.util.*; 19 20 41 public class PageDecoratorMapper extends AbstractDecoratorMapper { 42 private List pageProps = null; 43 44 public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException { 45 super.init(config, properties, parent); 46 pageProps = new ArrayList(); 47 Iterator i = properties.entrySet().iterator(); 48 while (i.hasNext()) { 49 Map.Entry entry = (Map.Entry) i.next(); 50 String key = (String ) entry.getKey(); 51 if (key.startsWith("property")) { 52 pageProps.add(entry.getValue()); 53 } 54 } 55 } 56 57 public Decorator getDecorator(HttpServletRequest request, Page page) { 58 Decorator result = null; 59 Iterator i = pageProps.iterator(); 60 while (i.hasNext()) { 61 String propName = (String )i.next(); 62 result = getByProperty(request, page, propName); 63 if (result != null) break; 64 } 65 return result == null ? super.getDecorator(request, page) : result; 66 } 67 68 private Decorator getByProperty(HttpServletRequest request, Page p, String name) { 69 if (p.isPropertySet(name)) { 70 return getNamedDecorator(request, p.getProperty(name)); 71 } 72 return null; 73 } 74 } | Popular Tags |