1 /*
2 * Title: DefaultDecorator
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
14 import java.util.Map;
15 import java.util.Iterator;
16 import java.util.Collections;
17
18 /**
19 * Default implementation of Decorator. All properties are set by the
20 * constructor.
21 *
22 * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
23 * @version $Revision: 1.1 $
24 *
25 * @see com.opensymphony.module.sitemesh.Decorator
26 */
27 public class DefaultDecorator implements Decorator {
28 /** @see #getPage() */
29 protected String page = null;
30
31 /** @see #getName() */
32 protected String name = null;
33
34 /** @see #getURIPath() */
35 protected String uriPath = null;
36
37 /** @see #getRole() */
38 protected String role = null;
39
40 /** @see #getInitParameter(java.lang.String) */
41 protected Map parameters = null;
42
43 /** Constructor to set name, page and parameters. */
44 public DefaultDecorator(String name, String page, Map parameters) {
45 this(name, page, null, null, parameters);
46 }
47
48 /** Constructor to set all properties. */
49 public DefaultDecorator(String name, String page, String uriPath, Map parameters) {
50 this(name, page, uriPath, null, parameters);
51 }
52
53 /** Constructor to set all properties. */
54 public DefaultDecorator(String name, String page, String uriPath, String role, Map parameters) {
55 this.name = name;
56 this.page = page;
57 this.uriPath = uriPath;
58 this.role = role;
59 this.parameters = parameters;
60 }
61
62 /**
63 * URI of the Servlet/JSP to dispatch the request to (relative to the
64 * web-app context).
65 */
66 public String getPage() {
67 return page;
68 }
69
70 /** Name of Decorator. For information purposes only. */
71 public String getName() {
72 return name;
73 }
74
75 /** URI path of the Decorator. Enables support for decorators defined in seperate web-apps. */
76 public String getURIPath() {
77 return uriPath;
78 }
79
80 /** Role the user has to be in to get this decorator applied. */
81 public String getRole() {
82 return role;
83 }
84
85 /**
86 * Returns a String containing the value of the named initialization parameter,
87 * or null if the parameter does not exist.
88 *
89 * @param paramName Key of parameter.
90 * @return Value of parameter or null if not found.
91 */
92 public String getInitParameter(String paramName) {
93 if (parameters == null || !parameters.containsKey(paramName)) {
94 return null;
95 }
96
97 return (String) parameters.get(paramName);
98 }
99
100 /**
101 * Returns the names of the Decorator's initialization parameters as an Iterator
102 * of String objects, or an empty Iterator if the Decorator has no initialization parameters.
103 */
104 public Iterator getInitParameterNames() {
105 if (parameters == null) {
106 // make sure we always return an empty iterator
107 return Collections.EMPTY_MAP.keySet().iterator();
108 }
109
110 return parameters.keySet().iterator();
111 }
112 }