001: /*
002: * Title: DefaultDecorator
003: * Description:
004: *
005: * This software is published under the terms of the OpenSymphony Software
006: * License version 1.1, of which a copy has been included with this
007: * distribution in the LICENSE.txt file.
008: */
009:
010: package com.opensymphony.module.sitemesh.mapper;
011:
012: import com.opensymphony.module.sitemesh.Decorator;
013:
014: import java.util.Map;
015: import java.util.Iterator;
016: import java.util.Collections;
017:
018: /**
019: * Default implementation of Decorator. All properties are set by the
020: * constructor.
021: *
022: * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
023: * @version $Revision: 1.1 $
024: *
025: * @see com.opensymphony.module.sitemesh.Decorator
026: */
027: public class DefaultDecorator implements Decorator {
028: /** @see #getPage() */
029: protected String page = null;
030:
031: /** @see #getName() */
032: protected String name = null;
033:
034: /** @see #getURIPath() */
035: protected String uriPath = null;
036:
037: /** @see #getRole() */
038: protected String role = null;
039:
040: /** @see #getInitParameter(java.lang.String) */
041: protected Map parameters = null;
042:
043: /** Constructor to set name, page and parameters. */
044: public DefaultDecorator(String name, String page, Map parameters) {
045: this (name, page, null, null, parameters);
046: }
047:
048: /** Constructor to set all properties. */
049: public DefaultDecorator(String name, String page, String uriPath,
050: Map parameters) {
051: this (name, page, uriPath, null, parameters);
052: }
053:
054: /** Constructor to set all properties. */
055: public DefaultDecorator(String name, String page, String uriPath,
056: String role, Map parameters) {
057: this .name = name;
058: this .page = page;
059: this .uriPath = uriPath;
060: this .role = role;
061: this .parameters = parameters;
062: }
063:
064: /**
065: * URI of the Servlet/JSP to dispatch the request to (relative to the
066: * web-app context).
067: */
068: public String getPage() {
069: return page;
070: }
071:
072: /** Name of Decorator. For information purposes only. */
073: public String getName() {
074: return name;
075: }
076:
077: /** URI path of the Decorator. Enables support for decorators defined in seperate web-apps. */
078: public String getURIPath() {
079: return uriPath;
080: }
081:
082: /** Role the user has to be in to get this decorator applied. */
083: public String getRole() {
084: return role;
085: }
086:
087: /**
088: * Returns a String containing the value of the named initialization parameter,
089: * or null if the parameter does not exist.
090: *
091: * @param paramName Key of parameter.
092: * @return Value of parameter or null if not found.
093: */
094: public String getInitParameter(String paramName) {
095: if (parameters == null || !parameters.containsKey(paramName)) {
096: return null;
097: }
098:
099: return (String) parameters.get(paramName);
100: }
101:
102: /**
103: * Returns the names of the Decorator's initialization parameters as an Iterator
104: * of String objects, or an empty Iterator if the Decorator has no initialization parameters.
105: */
106: public Iterator getInitParameterNames() {
107: if (parameters == null) {
108: // make sure we always return an empty iterator
109: return Collections.EMPTY_MAP.keySet().iterator();
110: }
111:
112: return parameters.keySet().iterator();
113: }
114: }
|