View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.i18n;
17  
18  import java.util.Locale;
19  import java.util.ResourceBundle;
20  
21  import org.apache.juddi.registry.RegistryEngine;
22  import org.apache.juddi.util.Config;
23  
24  /***
25   * @author Steve Viens (sviens@apache.org)
26   */
27  public class RegistryResourceBundle
28  {
29    private static final String BASE_MESSAGE_BUNDLE = "org.apache.juddi.i18n.MessagesBundle";
30    
31    private static ResourceBundle bundle = null;
32    
33    public static String getString(String key)
34    {
35      if ((key == null) || (key.trim().length() == 0))
36        return null;    
37      return getBundle().getString(key);
38    }
39    
40    private static ResourceBundle getBundle()
41    {
42      if (bundle == null)
43        bundle = createBundle();
44      return bundle;
45    }
46    
47    private static synchronized ResourceBundle createBundle()
48    {
49      if (bundle != null)
50        return bundle;
51      
52      String language = Config.getStringProperty(RegistryEngine.PROPNAME_I18N_LANGUAGE_CODE);   
53      if ((language == null) || (language.trim().length() == 0))
54        language = RegistryEngine.DEFAULT_I18N_LANGUAGE_CODE;
55      
56      String country = Config.getStringProperty(RegistryEngine.PROPNAME_I18N_COUNTRY_CODE);
57      if ((country == null) || (country.trim().length() == 0))
58        country = RegistryEngine.DEFAULT_I18N_COUNTRY_CODE;
59      
60      bundle = ResourceBundle.getBundle(
61          BASE_MESSAGE_BUNDLE,
62          new Locale(language,country));
63      
64      return bundle;
65    }
66    
67    
68    /****************************************************************************/
69    /****************************** TEST DRIVER *********************************/
70    /****************************************************************************/
71  
72  
73    public static void main(String[] args)
74    {
75      System.out.println(RegistryResourceBundle.getString("E_authTokenRequired"));
76    }
77  }