1 9 10 package com.opensymphony.module.sitemesh.mapper; 11 12 import com.opensymphony.module.sitemesh.mapper.AbstractDecoratorMapper; 13 import com.opensymphony.module.sitemesh.Page; 14 import com.opensymphony.module.sitemesh.Decorator; 15 import com.opensymphony.module.sitemesh.DecoratorMapper; 16 import com.opensymphony.module.sitemesh.Config; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import java.util.Properties ; 20 import java.util.Enumeration ; 21 import java.lang.String ; 22 23 41 public final class OSDecoratorMapper extends AbstractDecoratorMapper { 42 45 protected Properties properties; 46 47 55 public void init(Config config, Properties properties, DecoratorMapper parent) throws java.lang.InstantiationException { 56 this.properties = properties; 57 this.parent = parent; 58 } 59 60 70 public Decorator getDecorator(HttpServletRequest request, Page page) { 71 String osHeader = request.getHeader("UA-OS").toLowerCase(); 72 if (osHeader == null) return parent.getDecorator(request, page); 73 74 for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { 77 String os = (String ) e.nextElement(); 78 79 if (osHeader.indexOf(os.toLowerCase()) != -1) { 81 String decoratorName = parent.getDecorator(request, page).getName(); 82 if (decoratorName != null) { 83 decoratorName += '-' + properties.getProperty(os); 84 } 85 return getNamedDecorator(request, decoratorName); 86 } 87 } 88 89 return parent.getDecorator(request, page); 90 } 91 } | Popular Tags |