01: /*
02: * Title: PrintableDecoratorMapper
03: * Description:
04: *
05: * This software is published under the terms of the OpenSymphony Software
06: * License version 1.1, of which a copy has been included with this
07: * distribution in the LICENSE.txt file.
08: */
09:
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: /**
21: * The PrintableDecoratorMapper is a sample DecoratorMapper that will
22: * check to see whether 'printable=true' is supplied as a request parameter
23: * and if so, use the specified decorator instead. The name of this decorator
24: * should be supplied in the <code>decorator</code> property.
25: *
26: * <p>The exact 'printable=true' request criteria can be overriden with the
27: * <code>parameter.name</code> and <code>parameter.value</code> properties.</p>
28: *
29: * <p>Although this DecoratorMapper was designed for creating printable versions
30: * of a page, it can be used for much more imaginative purposes.</p>
31: *
32: * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
33: * @version $Revision: 1.2 $
34: *
35: * @see com.opensymphony.module.sitemesh.DecoratorMapper
36: */
37: public class PrintableDecoratorMapper extends AbstractDecoratorMapper {
38: private String decorator, paramName, paramValue;
39:
40: public void init(Config config, Properties properties,
41: DecoratorMapper parent) throws InstantiationException {
42: super .init(config, properties, parent);
43: decorator = properties.getProperty("decorator");
44: paramName = properties.getProperty("parameter.name",
45: "printable");
46: paramValue = properties.getProperty("parameter.value", "true");
47: }
48:
49: public Decorator getDecorator(HttpServletRequest request, Page page) {
50: Decorator result = null;
51: if (decorator != null
52: && paramValue.equalsIgnoreCase(request
53: .getParameter(paramName))) {
54: result = getNamedDecorator(request, decorator);
55: }
56: return result == null ? super.getDecorator(request, page)
57: : result;
58: }
59: }
|