KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > core > RequestDecoratorMapper


1 /*
2  * This file is nearly identical to the SessionDecoratorMapper available in the
3  * SiteMesh CVS and written by Ricardo Lecheta. It has been kept out of the
4  * SiteMesh package to point out that this file is not part of the current
5  * SiteMesh official release.
6  */

7 package org.meshcms.core;
8
9 import java.util.*;
10 import javax.servlet.http.*;
11 import com.opensymphony.module.sitemesh.*;
12 import com.opensymphony.module.sitemesh.mapper.*;
13
14 /**
15  * <p>Will look at a request attribute to find the name of an appropriate decorator to use. If the
16  * request attribute is not present, the mapper will not do anything and allow the next mapper in the chain
17  * to select a decorator.</p>
18  *
19  * <p>By default, it will look at the 'decorator' session attribute, however this can be overriden by
20  * configuring the mapper with a 'decorator.parameter' property.</p>
21  *
22  * @author Ricardo Lecheta
23  */

24 public class RequestDecoratorMapper extends AbstractDecoratorMapper {
25   private String JavaDoc decoratorParameter = null;
26
27   public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException JavaDoc {
28     super.init(config, properties, parent);
29     decoratorParameter = properties.getProperty("decorator.parameter", "decorator");
30   }
31
32   public Decorator getDecorator(HttpServletRequest request, Page page) {
33     Decorator result = null;
34     String JavaDoc decorator = (String JavaDoc) request.getAttribute(decoratorParameter);
35
36     if (decorator != null) {
37       result = getNamedDecorator(request, decorator);
38     }
39         
40     return result == null ? super.getDecorator(request, page) : result;
41   }
42 }
43
Popular Tags