1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.xmerge.util;
25 
26 import java.util.ResourceBundle;
27 
28 /**
29  *  <p>Provides a singleton resource class for converter messages.</p>
30  *
31  *  <p>By default, this class will search for a
32  *  <code>ResourceBundle</code> class file or properties file based
33  *  on the default locale.</p>
34  *
35  *  <p>A properties file resources.properties will be provided.</p>
36  *
37  *  <p>Note that if the resource bundle object is not loaded, the
38  *  construction of the singleton object will throw a
39  *  <code>MissingResourceException</code>, which is a
40  *  <code>RuntimeException</code>, thus I opted to not explicitly
41  *  declare it.  If it does throw <code>MissingResourceException</code>,
42  *  it may be due to a packaging problem.</p>
43  *
44  *  @author      Herbie Ong
45  */
46 public final class Resources
47 {
48     private ResourceBundle rb = null;
49 
50     private static Resources instance = null;
51 
52 
53     /**
54      *  This method returns the singleton instance
55      *  of this class.
56      *
57      *  @return  The singleton <code>Resources</code>
58      *           instance.
59      */
getInstance()60     public synchronized static Resources getInstance()
61     {
62         if (instance == null)
63         {
64             instance = new Resources();
65         }
66 
67         return instance;
68     }
69 
70 
71     /**
72      *  Default constructor is only accessible within this class.
73      *  Load the resource bundle that contains the resource
74      *  <code>String</code> values.
75      */
Resources()76     private Resources()
77     {
78         rb = ResourceBundle.getBundle("org.openoffice.xmerge.util.resources");
79     }
80 
81 
82     /**
83      *  This method returns the corresponding <code>String</code> given
84      *  the key.
85      *
86      *  @param   key     Key string for getting the message
87      *                   <code>String</code>.
88      *  @return  Message <code>String</code> corresponding to the key.
89      */
getString(String key)90     public String getString(String key)
91     {
92         return rb.getString(key);
93     }
94 }
95 
96