c7536eda8083307a45b26f555845aa43bc81bb26
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / HTMLUIMessages.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: HTMLUIMessages.java,v 1.1 2004-09-02 18:25:05 jsurfer 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 HTMLUIMessages {
24
25         // Constants ---------------------------------------------------------------
26
27         /**
28          * Qualified name of the resource bundle containing the localized messages.
29          */
30         private static final String RESOURCE_BUNDLE =
31                 "net.sourceforge.phpdt.smarty.ui.internal.HTMLUIMessages"; //$NON-NLS-1$
32
33         // Class Variables ---------------------------------------------------------
34
35         /**
36          * The resource bundle.
37          */
38         private static ResourceBundle resourceBundle =
39                 ResourceBundle.getBundle(RESOURCE_BUNDLE);
40
41         // Constructors ------------------------------------------------------------
42
43         /**
44          * Hidden constructor.
45          */
46         private HTMLUIMessages() {
47                 // Hidden
48         }
49
50         // Public Methods ----------------------------------------------------------
51
52         /**
53          * Returns the resource bundle.
54          * 
55          * @return the resource bundle
56          */
57         public static ResourceBundle getResourceBundle() {
58                 return resourceBundle;
59         }
60
61         /**
62          * Returns the message identified by the specified key.
63          * 
64          * @param key 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 the message key
81          * @param arg the parameter value
82          * @return the formatted string, or the key enclosed by exclamation marks
83          *         if no message was found for the key
84          */
85         public static String getString(String key, String arg) {
86                 return getString(key, new String[] { arg });
87         }
88
89         /**
90          * Returns the message identified by the specified key, replacing all
91          * parameters with the provided values.
92          * 
93          * @param key the message key
94          * @param args the parameter values
95          * @return the formatted string, or the key enclosed by exclamation marks
96          *         if no message was found for the key
97          */
98         public static String getString(String key, String[] args) {
99                 return MessageFormat.format(getString(key), args);      
100         }
101
102 }