01: /*
02: * Title: InlineDecoratorMapper
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.Decorator;
13: import com.opensymphony.module.sitemesh.Page;
14: import com.opensymphony.module.sitemesh.RequestConstants;
15: import com.opensymphony.module.sitemesh.factory.FactoryException;
16:
17: import javax.servlet.http.HttpServletRequest;
18:
19: /**
20: * The InlineDecoratorMapper is used to determine the correct Decorator when
21: * using inline decorators.
22: *
23: * <p>It will check the request attribute value defined by the key
24: * {@link com.opensymphony.module.sitemesh.RequestConstants#DECORATOR} and use the appropriate named
25: * Decorator. This is passed across from the page:applyDecorator tag.</p>
26: *
27: * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
28: * @version $Revision: 1.2 $
29: *
30: * @see com.opensymphony.module.sitemesh.DecoratorMapper
31: */
32: public class InlineDecoratorMapper extends AbstractDecoratorMapper
33: implements RequestConstants {
34: public Decorator getDecorator(HttpServletRequest request, Page page) {
35: Decorator result = null;
36: if (request.getAttribute(DECORATOR) != null) {
37: // Retrieve name of decorator to use from request
38: String decoratorName = (String) request
39: .getAttribute(DECORATOR);
40: result = getNamedDecorator(request, decoratorName);
41: if (result == null)
42: throw new FactoryException(
43: "Cannot locate inline Decorator: "
44: + decoratorName);
45: }
46: return result == null ? super.getDecorator(request, page)
47: : result;
48: }
49: }
|