A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / SmartyUIMessages.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: SmartyUIMessages.java,v 1.2 2006-10-21 23:19:32 pombredanne Exp $
12  */
13
14 package net.sourceforge.phpdt.smarty.ui.internal;
15
16 import java.text.MessageFormat;
17 import java.util.MissingResourceException;
18 import java.util.ResourceBundle;
19
20 /**
21  * Utility class that provides easy access to externalized strings.
22  */
23 public final class SmartyUIMessages {
24
25         // Constants ---------------------------------------------------------------
26
27         /**
28          * Qualified name of the resource bundle containing the localized messages.
29          */
30         private static final String RESOURCE_BUNDLE = "net.sourceforge.phpdt.smarty.ui.internal.SmartyUIMessages"; //$NON-NLS-1$
31
32         // Class Variables ---------------------------------------------------------
33
34         /**
35          * The resource bundle.
36          */
37         private static ResourceBundle resourceBundle = ResourceBundle
38                         .getBundle(RESOURCE_BUNDLE);
39
40         // Constructors ------------------------------------------------------------
41
42         /**
43          * Hidden constructor.
44          */
45         private SmartyUIMessages() {
46                 // Hidden
47         }
48
49         // Public Methods ----------------------------------------------------------
50
51         /**
52          * Returns the resource bundle.
53          * 
54          * @return the resource bundle
55          */
56         public static ResourceBundle getResourceBundle() {
57                 return resourceBundle;
58         }
59
60         /**
61          * Returns the message identified by the specified key.
62          * 
63          * @param key
64          *            the message key
65          * @return the localized message, or the key enclosed by exclamation marks
66          *         if no message was found for the key
67          */
68         public static String getString(String key) {
69                 try {
70                         return resourceBundle.getString(key);
71                 } catch (MissingResourceException e) {
72                         return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
73                 }
74         }
75
76         /**
77          * Returns the message identified by the specified key, replacing a single
78          * parameter with the provided value.
79          * 
80          * @param key
81          *            the message key
82          * @param arg
83          *            the parameter value
84          * @return the formatted string, or the key enclosed by exclamation marks if
85          *         no message was found for the key
86          */
87         public static String getString(String key, String arg) {
88                 return getString(key, new String[] { arg });
89         }
90
91         /**
92          * Returns the message identified by the specified key, replacing all
93          * parameters with the provided values.
94          * 
95          * @param key
96          *            the message key
97          * @param args
98          *            the parameter values
99          * @return the formatted string, or the key enclosed by exclamation marks if
100          *         no message was found for the key
101          */
102         public static String getString(String key, String[] args) {
103                 return MessageFormat.format(getString(key), args);
104         }
105
106 }