1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.util;
1819//standard java stuff20import java.util.Hashtable;
21import java.util.Map;
22import java.util.Iterator;
2324/***25Defines a standard object configuration26A Config provides the parameters passed in the current request as well27as init parameters.2829@author <a href="mailto:raphael@apache.org">Raphaël Luta</a>30@version $Id: BaseConfig.java,v 1.3 2004/02/23 03:23:42 jford Exp $31*/3233publicclassBaseConfigextends Hashtable implements Config34 {
3536private String name = null;
3738/***39 Returns the name for this configuration40 */41public String getName()
42 {
43returnthis.name;
44 }
4546/***47 Sets the name of this configuration48 */49publicvoid setName(String name)
50 {
51this.name = name;
52 }
5354/***55 Used to define a Portlet's parameters.56 */57publicvoid setInitParameters( Map init_params )
58 {
59 clear();
60 putAll( init_params );
61 }
6263/***64 Used to override Portlet's parameters.65 */66publicvoid addInitParameters( Map init_params )
67 {
68 Iterator keys = init_params.keySet().iterator();
6970while (keys.hasNext() )
71 {
72 String key = (String)keys.next();
7374if( ! containsKey( key ) )
75 {
76 put( key , (String)init_params.get( key ) );
77 }
78 }
79 }
808182/***83 Retrieves the PortletController parameters84 */85public Map getInitParameters()
86 {
87returnthis;
88 }
899091/***92 Used to define a PortletController's parameter.if value is null, removes93 the key from the stored properties94 */95publicvoid setInitParameter(String name, Object value)
96 {
97if (name!=null)
98 {
99if (value==null)
100 {
101 remove(name);
102 }
103else104 {
105 put(name,value);
106 }
107 }
108 }
109110/***111 Returns a parameter (or null) that was given the controller.112 */113public String getInitParameter(String name)
114 {
115return getInitParameter( name, null );
116 }
117118/***119 Returns a parameter (or defaultValue) that was given the controller.120 */121public String getInitParameter(String name, String defaultValue)
122 {
123 String value = null;
124125try126 {
127 value=(String)get(name);
128if (value==null) value=defaultValue;
129 }
130catch (RuntimeException e)
131 {
132 value=defaultValue;
133 }
134135return value;
136 }
137138/***139 Returns the parameter names of this Config.140 */141public Iterator getInitParameterNames()
142 {
143return keySet().iterator();
144 }
145146 }