View Javadoc

1   /*
2    * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH
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 de.smartics.maven.util.eclipse;
17  
18  /*
19   * Copyright 2001-2005 The Apache Software Foundation. Licensed under the Apache
20   * License, Version 2.0 (the "License"); you may not use this file except in
21   * compliance with the License. You may obtain a copy of the License at
22   * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
23   * or agreed to in writing, software distributed under the License is
24   * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25   * KIND, either express or implied. See the License for the specific language
26   * governing permissions and limitations under the License.
27   */
28  
29  import java.text.MessageFormat;
30  import java.util.MissingResourceException;
31  import java.util.ResourceBundle;
32  
33  /**
34   * This is a simple wrapper for the messages of this package.
35   * 
36   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
37   * @version $Revision: 12040 $
38   */
39  public final class Messages
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    /**
46     * The name of the bundle this is a wrapper for.
47     * <p>
48     * The value of this constant is {@value}.
49     */
50    private static final String BUNDLE_NAME = "de.smartics.maven.util.eclipse.messages";
51  
52    /**
53     * The wrapped resource bundle.
54     */
55    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
56        .getBundle(BUNDLE_NAME);
57  
58    // --- members --------------------------------------------------------------
59  
60    // ****************************** Initializer *******************************
61  
62    // ****************************** Constructors ******************************
63  
64    /**
65     * Utility class pattern.
66     */
67    private Messages()
68    {
69    }
70  
71    // ****************************** Inner Classes *****************************
72  
73    // ********************************* Methods ********************************
74  
75    // --- init -----------------------------------------------------------------
76  
77    // --- get&set --------------------------------------------------------------
78  
79    /**
80     * Returns the message for the given key.
81     * 
82     * @param key the key to lookup the localized message.
83     * @return the localized message.
84     */
85    public static String getString(final String key)
86    {
87      try
88      {
89        return RESOURCE_BUNDLE.getString(key);
90      }
91      catch (final MissingResourceException e)
92      {
93        return '#' + key + '#';
94      }
95    }
96  
97    /**
98     * Returns the message for the given key.
99     * 
100    * @param key the key to lookup the localized message.
101    * @param params the parameter to the message.
102    * @return the localized message.
103    */
104   public static String getString(final String key, final Object[] params)
105   {
106     try
107     {
108       return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
109     }
110     catch (MissingResourceException e)
111     {
112       return '#' + key + '#';
113     }
114   }
115 
116   /**
117    * Convenience method if there is just one parameter.
118    * 
119    * @param key the key to lookup the localized message.
120    * @param param the parameter to the message.
121    * @return the localized message.
122    */
123   public static String getString(final String key, final Object param)
124   {
125     return getString(key, new Object[]
126     { param });
127   }
128 
129   /**
130    * Convenience method if there is just two parameters.
131    * 
132    * @param key the key to lookup the localized message.
133    * @param param1 the first parameter to the message.
134    * @param param2 the second parameter to the message.
135    * @return the localized message.
136    */
137   public static String getString(final String key, final Object param1,
138       final Object param2)
139   {
140     return getString(key, new Object[]
141     { param1, param2 });
142   }
143 
144   // --- business -------------------------------------------------------------
145 
146   // --- object basics --------------------------------------------------------
147 
148 }