1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugin.ide;
20
21 import java.text.MessageFormat;
22 import java.util.MissingResourceException;
23 import java.util.ResourceBundle;
24
25 /**
26 * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
27 * @version $Id: Messages.java 595476 2007-11-15 22:21:55Z aheritier $
28 */
29 class Messages
30 {
31
32 /**
33 * bundle filename.
34 */
35 private static final String BUNDLE_NAME = "org.apache.maven.plugin.ide.messages"; //$NON-NLS-1$
36
37 /**
38 * Static resource bundle.
39 */
40 private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );
41
42 /**
43 * Don't instantiate.
44 */
45 private Messages()
46 {
47 }
48
49 /**
50 * Returns a string from the bundle.
51 *
52 * @param key message key
53 * @return message value or <code>!key!</code> if key is not found
54 */
55 public static String getString( String key )
56 {
57 try
58 {
59 return RESOURCE_BUNDLE.getString( key );
60 }
61 catch ( MissingResourceException e )
62 {
63 return '!' + key + '!';
64 }
65 }
66
67 /**
68 * Returns a string from the bundle, formatting it using provided params.
69 *
70 * @param key message key
71 * @param params MessageFormat arguments
72 * @return message value or <code>!key!</code> if key is not found
73 */
74 public static String getString( String key, Object[] params )
75 {
76 try
77 {
78 return MessageFormat.format( RESOURCE_BUNDLE.getString( key ), params );
79 }
80 catch ( MissingResourceException e )
81 {
82 return '!' + key + '!';
83 }
84 }
85
86 /**
87 * Returns a string from the bundle, formatting it using provided param.
88 *
89 * @param key message key
90 * @param param MessageFormat arguments
91 * @return message value or <code>!key!</code> if key is not found
92 */
93 public static String getString( String key, Object param )
94 {
95 return getString( key, new Object[] { param } );
96 }
97 }