View Javadoc

1   package org.apache.turbine.services.resources;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.commons.configuration.Configuration;
23  
24  import org.apache.turbine.Turbine;
25  import org.apache.turbine.TurbineConstants;
26  import org.apache.turbine.services.security.SecurityService;
27  
28  /***
29   * This is a static class for defining the default Turbine configuration
30   * keys used by core Turbine components.
31   *
32   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
33   * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
34   * @author <a href="mailto:luta.raphael@networks.vivendi.net">Raphaël Luta</a>
35   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
36   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
37   * @version $Id: TurbineResources.java 278958 2005-09-06 09:35:39Z henning $
38   * @deprecated as of Turbine 2.2 use Turbine.getConfiguration()
39   */
40  public abstract class TurbineResources
41  {
42      /*** @deprecated Use the corresponding constant from TurbineConstants */
43      public static final String MAIL_SERVER_KEY = TurbineConstants.MAIL_SERVER_KEY;
44  
45      /*** @deprecated Use the corresponding constant from TurbineConstants */
46      public static final String MODULE_CACHE_KEY = TurbineConstants.MODULE_CACHE_KEY;
47  
48      /*** @deprecated Use the corresponding constant from TurbineConstants */
49      public static final String MODULE_PACKAGES_KEY = TurbineConstants.MODULE_PACKAGES;
50  
51      /*** @deprecated Use the corresponding constant from TurbineConstants */
52      public static final String ACTION_CACHE_SIZE_KEY = TurbineConstants.ACTION_CACHE_SIZE_KEY;
53  
54      /*** @deprecated Use the corresponding constant from TurbineConstants */
55      public static final String LAYOUT_CACHE_SIZE_KEY = TurbineConstants.LAYOUT_CACHE_SIZE_KEY;
56  
57      /*** @deprecated Use the corresponding constant from TurbineConstants */
58      public static final String NAVIGATION_CACHE_SIZE_KEY = TurbineConstants.NAVIGATION_CACHE_SIZE_KEY;
59  
60      /*** @deprecated Use the corresponding constant from TurbineConstants */
61      public static final String PAGE_CACHE_SIZE_KEY = TurbineConstants.PAGE_CACHE_SIZE_KEY;
62  
63      /*** @deprecated Use the corresponding constant from TurbineConstants */
64      public static final String SCREEN_CACHE_SIZE_KEY = TurbineConstants.SCREEN_CACHE_SIZE_KEY;
65  
66      /*** @deprecated Use the corresponding constant from SecurityService */
67      public static final String USER_CLASS_KEY = SecurityService.USER_CLASS_KEY;
68  
69      /*** @deprecated No longer used */
70      public static final String MAX_FILE_SIZE_KEY = "max.file.size.bytes";
71  
72      /*** @deprecated No longer used */
73      public static final String FILE_SERVER = "file.server";
74  
75      /*** @deprecated Use the corresponding constant from TurbineConstants */
76      public static final String LOGIN_MESSAGE = TurbineConstants.LOGIN_MESSAGE;
77  
78      /*** @deprecated Use the corresponding constant from TurbineConstants */
79      public static final String LOGIN_ERROR = TurbineConstants.LOGIN_ERROR;
80  
81      /*** @deprecated Use the corresponding constant from TurbineConstants */
82      public static final String LOGIN_MESSAGE_NOSCREEN = TurbineConstants.LOGIN_MESSAGE_NOSCREEN;
83  
84      /*** @deprecated Use the corresponding constant from TurbineConstants */
85      public static final String LOGOUT_MESSAGE = TurbineConstants.LOGOUT_MESSAGE;
86  
87      /***
88       * Set a property in with a key=value pair.
89       *
90       * @param key
91       * @param value
92       */
93      public static void setProperty(String key, String value)
94      {
95          Turbine.getConfiguration().setProperty(key, value);
96      }
97  
98      /***
99       * The purpose of this method is to get the configuration resource
100      * with the given name as a boolean value.
101      *
102      * @param name The resource name.
103      * @return The value of the named resource as a boolean.
104      */
105     public static boolean getBoolean(String name)
106     {
107         return Turbine.getConfiguration().getBoolean(name);
108     }
109 
110     /***
111      * The purppose of this method is to get the configuration
112      * resource with the given name as a boolean value, or a default
113      * value.
114      *
115      * @param name The resource name.
116      * @param def The default value of the resource.
117      * @return The value of the named resource as a boolean.
118      */
119     public static boolean getBoolean(String name,
120                                      boolean def)
121     {
122         return Turbine.getConfiguration().getBoolean(name, def);
123     }
124 
125     /***
126      * The purpose of this method is to get the configuration resource
127      * with the given name as a double.
128      *
129      * @param name The resoource name.
130      * @return The value of the named resource as double.
131      */
132     public static double getDouble(String name)
133     {
134         return Turbine.getConfiguration().getDouble(name);
135     }
136 
137     /***
138      * The purpose of this method is to get the configuration resource
139      * with the given name as a double, or a default value.
140      *
141      * @param name The resource name.
142      * @param def The default value of the resource.
143      * @return The value of the named resource as a double.
144      */
145     public static double getDouble(String name,
146                                    double def)
147     {
148         return Turbine.getConfiguration().getDouble(name, def);
149     }
150 
151     /***
152      * The purpose of this method is to get the configuration resource
153      * with the given name as a float.
154      *
155      * @param name The resource name.
156      * @return The value of the resource as a float.
157      */
158     public static float getFloat(String name)
159     {
160         return Turbine.getConfiguration().getFloat(name);
161     }
162 
163     /***
164      * The purpose of this method is to get the configuration resource
165      * with the given name as a float, or a default value.
166      *
167      * @param name The resource name.
168      * @param def The default value of the resource.
169      * @return The value of the resource as a float.
170      */
171     public static float getFloat(String name,
172                                  float def)
173     {
174         return Turbine.getConfiguration().getFloat(name, def);
175     }
176 
177     /***
178      * The purpose of this method is to get the configuration resource
179      * with the given name as an integer.
180      *
181      * @param name The resource name.
182      * @return The value of the resource as an integer.
183      */
184     public static int getInt(String name)
185     {
186         return Turbine.getConfiguration().getInt(name);
187     }
188 
189     /***
190      * The purpose of this method is to get the configuration resource
191      * with the given name as an integer, or a default value.
192      *
193      * @param name The resource name.
194      * @param def The default value of the resource.
195      * @return The value of the resource as an integer.
196      */
197     public static int getInt(String name,
198                              int def)
199     {
200         return Turbine.getConfiguration().getInt(name, def);
201     }
202 
203     /***
204      * Get the list of the keys contained in the configuration
205      * repository.
206      *
207      * @return An Enumeration with all the keys.
208      */
209     public static Iterator getKeys()
210     {
211         return Turbine.getConfiguration().getKeys();
212     }
213 
214     /***
215      * Get the list of the keys contained in the configuration
216      * repository that match the specified prefix.
217      *
218      * @param prefix A String prefix to test against.
219      * @return An Enumeration of keys that match the prefix.
220      */
221     public static Iterator getKeys(String prefix)
222     {
223         return Turbine.getConfiguration().getKeys(prefix);
224     }
225 
226     /***
227      * The purpose of this method is to get the configuration resource
228      * with the given name as a long.
229      *
230      * @param name The resource name.
231      * @return The value of the resource as a long.
232      */
233     public static long getLong(String name)
234     {
235         return Turbine.getConfiguration().getLong(name);
236     }
237 
238     /***
239      * The purpose of this method is to get the configuration resource
240      * with the given name as a long, or a default value.
241      *
242      * @param name The resource name.
243      * @param def The default value of the resource.
244      * @return The value of the resource as a long.
245      */
246     public static long getLong(String name,
247                                long def)
248     {
249         return Turbine.getConfiguration().getLong(name, def);
250     }
251 
252     /***
253      * The purpose of this method is to get the configuration resource
254      * with the given name as a string.
255      *
256      * @param name The resource name.
257      * @return The value of the resource as a string.
258      */
259     public static String getString(String name)
260     {
261         return Turbine.getConfiguration().getString(name);
262     }
263 
264     /***
265      * The purpose of this method is to get the configuration resource
266      * with the given name as a string, or a default value.
267      *
268      * @param name The resource name.
269      * @param def The default value of the resource.
270      * @return The value of the resource as a string.
271      */
272     public static String getString(String name,
273                                    String def)
274     {
275         return Turbine.getConfiguration().getString(name, def);
276     }
277 
278     /***
279      * The purpose of this method is to get the configuration resource
280      * with the given name as a string array.
281      *
282      * @param name The resource name.
283      * @return The value of the resource as a string array.
284      */
285     public static String[] getStringArray(String name)
286     {
287         return Turbine.getConfiguration().getStringArray(name);
288     }
289 
290     /***
291      * The purpose of this method is to get the configuration resource
292      * with the given name as a vector.
293      *
294      * @param name The resource name.
295      * @return The value of the resource as a vector.
296      */
297     public static List getList(String name)
298     {
299         return Turbine.getConfiguration().getList(name);
300     }
301 
302     /***
303      * The purpose of this method is to get the configuration resource
304      * with the given name as a vector, or a default value.
305      *
306      * @param name The resource name.
307      * @param def The default value of the resource.
308      * @return The value of the resource as a vector.
309      */
310     public static List getList(String name,
311                                    List def)
312     {
313         return Turbine.getConfiguration().getList(name, def);
314     }
315 
316     /***
317      * Get the configuration.
318      *
319      * @return configuration.
320      */
321     public static Configuration getConfiguration()
322     {
323         return Turbine.getConfiguration();
324     }
325 
326     /***
327      * The purpose of this method is to extract a subset configuration
328      * sharing a common name prefix.
329      *
330      * @param prefix the common name prefix
331      * @return A Configuration providing the subset of configuration.
332      */
333     public static Configuration getConfiguration(String prefix)
334     {
335         return Turbine.getConfiguration().subset(prefix);
336     }
337 }