KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > resources > ResourcesUtils


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.mdarad.framework.resources;
24
25 import java.util.Hashtable JavaDoc;
26 import java.util.Locale JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.struts.util.MessageResources;
30 import org.apache.struts.util.PropertyMessageResourcesFactory;
31
32 /**
33  * This class contains all the utilities needed to retrieved
34  * resources from a property file.
35  * @author Philippe Brouillette
36  * @version 1.0
37  */

38 public class ResourcesUtils {
39
40     /**
41      * Property that keeps the message resources objects
42      */

43     private static Map JavaDoc cachedMessageResources = new Hashtable JavaDoc();
44     
45     /**
46      * Instance of the resource factory.
47      */

48     private static PropertyMessageResourcesFactory cachedFactory =
49                 new PropertyMessageResourcesFactory();
50
51     /**
52      * Method that returns the a resource from a bundle
53      * @param bundle bundle name
54      * @param key key of the resource to be retrieved
55      * @param locale locale information
56      * @return A string that contains the resource
57      */

58     public static String JavaDoc getMessage(String JavaDoc bundle, String JavaDoc key, Locale JavaDoc locale) {
59         if (bundle != null) {
60             MessageResources res = (MessageResources) cachedMessageResources.get(bundle);
61             if (res == null) {
62                 res = cachedFactory.createResources(bundle);
63                 res.setReturnNull(false);
64                 cachedMessageResources.put(bundle, res);
65             }
66             
67             return res.getMessage(locale, key);
68         }
69         
70         return "";
71     }
72 }
Popular Tags