KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > mapper > DefaultDecorator


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 JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Collections JavaDoc;
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 JavaDoc page = null;
30
31     /** @see #getName() */
32     protected String JavaDoc name = null;
33
34     /** @see #getURIPath() */
35     protected String JavaDoc uriPath = null;
36
37     /** @see #getRole() */
38     protected String JavaDoc role = null;
39
40     /** @see #getInitParameter(java.lang.String) */
41     protected Map JavaDoc parameters = null;
42
43     /** Constructor to set name, page and parameters. */
44     public DefaultDecorator(String JavaDoc name, String JavaDoc page, Map JavaDoc parameters) {
45         this(name, page, null, null, parameters);
46     }
47
48     /** Constructor to set all properties. */
49     public DefaultDecorator(String JavaDoc name, String JavaDoc page, String JavaDoc uriPath, Map JavaDoc parameters) {
50         this(name, page, uriPath, null, parameters);
51     }
52
53     /** Constructor to set all properties. */
54     public DefaultDecorator(String JavaDoc name, String JavaDoc page, String JavaDoc uriPath, String JavaDoc role, Map JavaDoc 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 JavaDoc getPage() {
67         return page;
68     }
69
70     /** Name of Decorator. For information purposes only. */
71     public String JavaDoc getName() {
72         return name;
73     }
74
75     /** URI path of the Decorator. Enables support for decorators defined in seperate web-apps. */
76     public String JavaDoc getURIPath() {
77         return uriPath;
78     }
79
80     /** Role the user has to be in to get this decorator applied. */
81     public String JavaDoc 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 JavaDoc getInitParameter(String JavaDoc paramName) {
93         if (parameters == null || !parameters.containsKey(paramName)) {
94             return null;
95         }
96
97         return (String JavaDoc) 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 JavaDoc 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 }
Popular Tags