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.Properties ; 19 20 46 public class ParameterDecoratorMapper extends AbstractDecoratorMapper { 47 private String decoratorParameter = null, paramName = null, paramValue = null; 48 49 public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException { 50 super.init(config, properties, parent); 51 decoratorParameter = properties.getProperty("decorator.parameter", "decorator"); 52 paramName = properties.getProperty("parameter.name", null); 53 paramValue = properties.getProperty("parameter.value", null); 54 } 55 56 public Decorator getDecorator(HttpServletRequest request, Page page) { 57 Decorator result = null; 58 String decoratorParamValue = request.getParameter(decoratorParameter); 59 60 if ((paramName == null || paramValue.equals(request.getParameter(paramName))) 61 && decoratorParamValue != null && !decoratorParamValue.trim().equals("")) { 62 result = getNamedDecorator(request, decoratorParamValue); 63 } 64 return result == null ? super.getDecorator(request, page) : result; 65 } 66 } | Popular Tags |