Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/dinopolis/util/ResourceManager.java


1   /***********************************************************************
2    * @(#)$RCSfile: ResourceManager.java,v $   $Revision: 1.4 $ $Date: 2003/11/18 12:58:42 $
3    *
4    * Copyright (c) 2001 IICM, Graz University of Technology
5    * Inffeldgasse 16c, A-8010 Graz, Austria.
6    * 
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License (LGPL)
9    * as published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU Lesser General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Lesser General Public 
18   * License along with this program; if not, write to the
19   * Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   ***********************************************************************/
22  
23  
24  package org.dinopolis.util;
25  
26  import java.util.Locale;
27  import java.util.MissingResourceException;
28  
29  import org.dinopolis.util.resource.FileResources;
30  
31  //----------------------------------------------------------------------
32  /**
33   * This class can be asked to create a ResourceManager instance using one of
34   * the <code>getResourceManager</code> methods.
35   *
36   * @author Dieter Freismuth
37   * @version $Revision: 1.4 $
38   */
39  
40  public class ResourceManager
41  {
42    //----------------------------------------------------------------------
43    /**
44     * Get the appropriate ResourceBundle for the given base_name.
45     *
46     * @param base_name the base name of the resource bundle.
47     * @return the Resource.
48     * @exception MissingResourceException if the system resource file
49     * could not be located. 
50     */
51   
52    public static Resources getResources(String base_name)
53      throws MissingResourceException
54    {
55      return(FileResources.getResources(base_name));
56    }
57  
58    //----------------------------------------------------------------------
59    /**
60     * Get the appropriate ResourceBundle for the given base_name and searches the
61     * system bundle in the callers package name. 
62     *
63     * @param caller the caller, to search the system bundle for.
64     * @param base_name the base name of the resource bundle.
65     * @return the Resource.
66     * @exception MissingResourceException if the system resource file
67     */
68   
69    public static Resources getResources(Class caller, String base_name)
70      throws MissingResourceException
71    {
72      return(FileResources.getResources(caller, base_name));
73    }
74  
75    //----------------------------------------------------------------------
76    /**
77     * Get the appropriate ResourceBundle for the given base_name and the given
78     * locale.
79     *
80     * @param base_name the base name of the resource bundle.
81     * @param locale the locale.
82     * @return the Resource.
83     * @exception MissingResourceException if the system resource file
84     * could not be located. 
85     */
86  
87    public static Resources getResources(String base_name,
88                                         Locale locale)
89      throws MissingResourceException
90    {
91      return(FileResources.getResources(base_name, locale));
92    }
93  
94    //----------------------------------------------------------------------
95    /**
96     * Get the appropriate ResourceBundle for the given base_name and locale and
97     * searches the system bundle in the callers package name. 
98     *
99     * @param caller the caller, to search the system bundle for.
100    * @param base_name the base name of the resource bundle.
101    * @param locale the locale.
102    * @return the Resource.
103    * @exception MissingResourceException if the system resource file
104    * could not be located. 
105    */
106 
107   public static Resources getResources(Class caller, String base_name,
108                                        Locale locale)
109     throws MissingResourceException
110   {
111     return(FileResources.getResources(caller, base_name, locale));
112   }
113 
114   //----------------------------------------------------------------------
115   /**
116    * Get the appropriate ResourceBundle for the given base_name and the given
117    * dir_name. The dir_name specifies the directory name of the users resource
118    * file, relative to the users home directory.
119    *
120    * @param base_name the base name of the resource bundle.
121    * @param dir_name the name of the directory within the users homedir
122    * to look for a property file.
123    * @return the Resource.
124    * @exception MissingResourceException if the system resource file
125    * could not be located. 
126    */
127  
128   public static Resources getResources(String base_name, String dir_name)
129     throws MissingResourceException
130   {
131     return(FileResources.getResources(base_name, dir_name));
132   }
133 
134   //----------------------------------------------------------------------
135   /**
136    * Get the appropriate ResourceBundle for the given base_name and the given
137    * dir_name and searches the system bundle in the callers package name. The
138    * dir_name specifies the directory name of the users resource file, relative
139    * to the users home directory.
140    *
141    * @param caller the caller, to search the system bundle for.
142    * @param base_name the base name of the resource bundle.
143    * @return the Resource.
144    * @param dir_name the name of the directory within the users homedir
145    * to look for a property file.
146    * @exception MissingResourceException if the system resource file
147    * could not be located. 
148    */
149  
150   public static Resources getResources(Class caller, String base_name,
151                                        String dir_name)
152     throws MissingResourceException
153   {
154     return(FileResources.getResources(caller, base_name, dir_name));
155   }
156 
157   //----------------------------------------------------------------------
158   /**
159    * Get the appropriate ResourceManager for the given base_name, the given
160    * dir_name and the given locale. The dir_name specifies the
161    * directory name of the users resource file, relative to the users
162    * home directory.
163    *
164    * @param base_name the base name of the resource bundle.
165    * @param locale the locale.
166    * @param dir_name the name of the directory within the users homedir
167    * to look for a property file.
168    * @return the Resource.
169    * @exception MissingResourceException if the system resource file
170    * could not be located. 
171    */
172 
173   public static Resources getResources(String base_name, String dir_name,
174                                        Locale locale)
175     throws MissingResourceException
176   {
177     return(FileResources.getResources(base_name, dir_name, locale));
178   }
179 
180   //----------------------------------------------------------------------
181   /**
182    * Get the appropriate ResourceBundle. The ResourceBundle consists
183    * of two parts, the system resources (for default settings) and
184    * user specific settings. Any given properties in the users
185    * resources will overwrite the system resources!  The users
186    * resources are searched in the following order:
187    * $user_home/<code>dir_name</code>/<code>base_name</code>.properties,
188    * $user_home/.<code>dir_name</code>/<code>base_name</code>.properties,
189    * $user_home/<code>dir_name</code>.toLowerCase()/<code>base_name</code>.properties,
190    * $user_home/.<code>dir_name</code>.toLowerCase()/<code>base_name</code>.properties<p>
191    * 
192    * The system resources are expected to be in the same package than
193    * the caller!<p>
194    *
195    * Example:<br>
196    * caller: <code>org.dinopolis.util.ResourceManager</code><br>
197    * base_name: <code>TestResourceManager</code><br>
198    * dir_name: <code>test_resources</code><br>
199    * locale: <code>Locale.getDefault()</code><br>
200    * users home dir: ~dfreis<p>
201    *
202    * then, the users bundle is suspected to be:<br>
203    * "~dfreis/test_resources/TestResourceManager.properties", or if not found:<br>
204    * "~dfreis/.test_resources/TestResourceManager.properties"
205    *
206    * the system resources are expected to be in:<br>
207    * "org.dinopolis.util.ResourceManager.TestResourceManager.properties"
208    * within your classpath!<p>
209    * 
210    * The sample code of the caller for the given example will look
211    * like this:
212    * <xmp>
213    * ResourceManager resources = ResourceManager.getResources(getClass(), "TestResourceManager", 
214    *                                           "test_resources");
215    * </xmp>
216    *
217    * @param caller the caller, to search the system bundle for.
218    * @param base_name the base name of the resource bundle.
219    * @param locale the locale.
220    * @param dir_name the name of the directory within the users homedir
221    * to look for a property file.
222    * @return the Resource.
223    * @exception MissingResourceException if the system resource file
224    * could not be located.
225    */
226 
227   public static Resources getResources(Class caller, String base_name,
228                                        String dir_name, Locale locale)
229     throws MissingResourceException
230   {
231     return(FileResources.getResources(caller, base_name, dir_name, locale));
232   }
233  
234   //----------------------------------------------------------------------
235   /**
236    * Get the appropriate ResourceBundle for the given base_name, the given
237    * dir_name and the given locale. The dir_name specifies the directory name of
238    * the users resource file, relative to the users home directory.
239    *
240    * @param caller the caller, to search the system bundle for.
241    * @param base_name the base name of the resource bundle.
242    * @param locale the locale.
243    * @param dir_name the name of the directory within the users homedir
244    * to look for a property file.
245    * @param loader the classloader to use to load the resources.
246    * @return the Resource.
247    * @exception MissingResourceException if the system resource file
248    * could not be located. 
249    */
250   public static Resources getResources(Class caller, String base_name,
251                                        String dir_name,
252                                        Locale locale,
253                                        ClassLoader loader)
254   throws MissingResourceException
255   {
256     return(FileResources.getResources(caller, base_name, dir_name, locale, loader));
257   }
258  
259  
260  
261 }
262 
263 
264 
265 
266 
267 
268 
269 
270 
271 
272