1 /*
2 * Title: InlineDecoratorMapper
3 * Description:
4 *
5 * This software is published under the terms of the OpenSymphony Software
6 * License version 1.1, of which a copy has been included with this
7 * distribution in the LICENSE.txt file.
8 */
9
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 implements RequestConstants {
33 public Decorator getDecorator(HttpServletRequest request, Page page) {
34 Decorator result = null;
35 if (request.getAttribute(DECORATOR) != null) {
36 // Retrieve name of decorator to use from request
37 String decoratorName = (String)request.getAttribute(DECORATOR);
38 result = getNamedDecorator(request, decoratorName);
39 if (result == null) throw new FactoryException("Cannot locate inline Decorator: " + decoratorName);
40 }
41 return result == null ? super.getDecorator(request, page) : result;
42 }
43 }