View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
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.mybatis.generator.internal.util.messages;
17  
18  import java.text.MessageFormat;
19  import java.util.MissingResourceException;
20  import java.util.ResourceBundle;
21  
22  /**
23   * @author Jeff Butler
24   */
25  public class Messages {
26      private static final String BUNDLE_NAME = "org.mybatis.generator.internal.util.messages.messages"; //$NON-NLS-1$
27  
28      private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
29              .getBundle(BUNDLE_NAME);
30  
31      private Messages() {
32      }
33  
34      public static String getString(String key) {
35          try {
36              return RESOURCE_BUNDLE.getString(key);
37          } catch (MissingResourceException e) {
38              return '!' + key + '!';
39          }
40      }
41  
42      public static String getString(String key, String parm1) {
43          try {
44              return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
45                      new Object[] { parm1 });
46          } catch (MissingResourceException e) {
47              return '!' + key + '!';
48          }
49      }
50  
51      public static String getString(String key, String parm1, String parm2) {
52          try {
53              return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
54                      new Object[] { parm1, parm2 });
55          } catch (MissingResourceException e) {
56              return '!' + key + '!';
57          }
58      }
59  
60      public static String getString(String key, String parm1, String parm2,
61              String parm3) {
62          try {
63              return MessageFormat.format(RESOURCE_BUNDLE.getString(key),
64                      new Object[] { parm1, parm2, parm3 });
65          } catch (MissingResourceException e) {
66              return '!' + key + '!';
67          }
68      }
69  }