KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > resources > Resources


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.resources;
22
23 import java.text.MessageFormat JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.MissingResourceException JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 /**
29  * Encapsulates the retrieval of internationalized resources.
30  */

31 public final class Resources
32 {
33   public static final String JavaDoc RESOURCE_BUNDLE_LOC =
34                           "com.presumo.jms.resources.jms";
35
36   private static ResourceBundle JavaDoc resources;
37   static {
38     try {
39       resources = ResourceBundle.getBundle(RESOURCE_BUNDLE_LOC,
40                                            Locale.getDefault());
41     } catch (MissingResourceException JavaDoc mre) {
42       System.err.println(RESOURCE_BUNDLE_LOC + " not found.");
43       System.exit(1);
44     }
45   }
46
47   public static ResourceBundle JavaDoc getBundle()
48   {
49     return resources;
50   }
51   
52   public static String JavaDoc getResourceString(String JavaDoc key)
53   {
54     String JavaDoc str;
55     try {
56         str = resources.getString(key);
57     } catch (MissingResourceException JavaDoc mre) {
58         str = null;
59     }
60     return str;
61   }
62   
63   public static String JavaDoc getResourceString(String JavaDoc key, Object JavaDoc param)
64   {
65     return getResourceString(key, new Object JavaDoc [] { param });
66   }
67   
68   public static String JavaDoc getResourceString(String JavaDoc key, Object JavaDoc [] params)
69   {
70     String JavaDoc str = getResourceString(key);
71     if (str != null)
72       str = MessageFormat.format(str, params);
73     
74     return str;
75   }
76 }
Popular Tags