01: package com.opensymphony.module.sitemesh.mapper;
02:
03: import com.opensymphony.module.sitemesh.Config;
04: import com.opensymphony.module.sitemesh.Decorator;
05: import com.opensymphony.module.sitemesh.DecoratorMapper;
06: import com.opensymphony.module.sitemesh.Page;
07:
08: import javax.servlet.http.HttpServletRequest;
09: 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,
26: DecoratorMapper parent) throws InstantiationException {
27: super .init(config, properties, parent);
28: decoratorParameter = properties.getProperty(
29: "decorator.parameter", "decorator");
30: }
31:
32: public Decorator getDecorator(HttpServletRequest request, Page page) {
33: Decorator result = null;
34: String decorator = (String) request.getSession().getAttribute(
35: decoratorParameter);
36:
37: //get decorator from HttpSession
38: if (decorator != null) {
39: result = getNamedDecorator(request, decorator);
40: }
41: return result == null ? super.getDecorator(request, page)
42: : result;
43: }
44: }
|