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
9 * Christopher Lenz - initial API and implementation
11 * $Id: HTMLUIMessages.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $
14 package net.sourceforge.phpdt.smarty.ui.internal;
16 import java.text.MessageFormat;
17 import java.util.MissingResourceException;
18 import java.util.ResourceBundle;
21 * Utility class that provides easy access to externalized strings.
23 public final class HTMLUIMessages {
25 // Constants ---------------------------------------------------------------
28 * Qualified name of the resource bundle containing the localized messages.
30 private static final String RESOURCE_BUNDLE =
31 "net.sourceforge.phpdt.smarty.ui.internal.HTMLUIMessages"; //$NON-NLS-1$
33 // Class Variables ---------------------------------------------------------
36 * The resource bundle.
38 private static ResourceBundle resourceBundle =
39 ResourceBundle.getBundle(RESOURCE_BUNDLE);
41 // Constructors ------------------------------------------------------------
46 private HTMLUIMessages() {
50 // Public Methods ----------------------------------------------------------
53 * Returns the resource bundle.
55 * @return the resource bundle
57 public static ResourceBundle getResourceBundle() {
58 return resourceBundle;
62 * Returns the message identified by the specified key.
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
68 public static String getString(String key) {
70 return resourceBundle.getString(key);
71 } catch (MissingResourceException e) {
72 return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
77 * Returns the message identified by the specified key, replacing a single
78 * parameter with the provided value.
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
85 public static String getString(String key, String arg) {
86 return getString(key, new String[] { arg });
90 * Returns the message identified by the specified key, replacing all
91 * parameters with the provided values.
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
98 public static String getString(String key, String[] args) {
99 return MessageFormat.format(getString(key), args);