Save This Page
Home » sitemesh-2.3 » com.opensymphony.module » sitemesh » mapper » [javadoc | source]
    1   package com.opensymphony.module.sitemesh.mapper;
    2   
    3   import com.opensymphony.module.sitemesh.Config;
    4   import com.opensymphony.module.sitemesh.Decorator;
    5   import com.opensymphony.module.sitemesh.DecoratorMapper;
    6   import com.opensymphony.module.sitemesh.Page;
    7   
    8   import javax.servlet.http.HttpServletRequest;
    9   import java.util.Properties;
   10   
   11   /**
   12    * <p>Will look at a session attribute to find the name of an appropriate decorator to use. If the
   13    * session attribute is present, the mapper will not do anything and allow the next mapper in the chain
   14    * to select a decorator.</p>
   15    * 
   16    * <p>By default, it will look at the 'decorator' session attribute, however this can be overriden by
   17    * configuring the mapper with a 'decorator.parameter' property.</p>
   18    *
   19    * @author Ricardo Lecheta
   20    */
   21   public class SessionDecoratorMapper extends AbstractDecoratorMapper {
   22   
   23       private String decoratorParameter = null;
   24   
   25       public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
   26           super.init(config, properties, parent);
   27           decoratorParameter = properties.getProperty("decorator.parameter", "decorator");
   28       }
   29   
   30       public Decorator getDecorator(HttpServletRequest request, Page page) {
   31           Decorator result = null;
   32           String decorator = (String) request.getSession().getAttribute(decoratorParameter);
   33   
   34           //get decorator from HttpSession
   35           if (decorator != null) {
   36               result = getNamedDecorator(request, decorator);
   37           }
   38           return result == null ? super.getDecorator(request, page) : result;
   39       }
   40   }

Save This Page
Home » sitemesh-2.3 » com.opensymphony.module » sitemesh » mapper » [javadoc | source]