129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.internal.text.html.HTMLMessages;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.MissingResourceException;
|
|
18 import java.util.ResourceBundle;
|
|
19
|
|
20 import com.ibm.icu.text.MessageFormat;
|
|
21
|
|
22
|
|
23 /**
|
|
24 * Helper class to get NLSed messages.
|
|
25 *
|
|
26 * @since 3.3
|
|
27 */
|
|
28 class HTMLMessages {
|
|
29
|
|
30 private static final String RESOURCE_BUNDLE= HTMLMessages.class.getName();
|
|
31
|
|
32 private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
|
33
|
|
34 private HTMLMessages() {
|
|
35 }
|
|
36
|
|
37 /**
|
|
38 * Gets a string from the resource bundle.
|
|
39 *
|
|
40 * @param key the string used to get the bundle value, must not be null
|
|
41 * @return the string from the resource bundle
|
|
42 */
|
|
43 public static String getString(String key) {
|
|
44 try {
|
|
45 return fgResourceBundle.getString(key);
|
|
46 } catch (MissingResourceException e) {
|
|
47 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
48 }
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * Gets a string from the resource bundle and formats it with the given arguments.
|
|
53 *
|
|
54 * @param key the string used to get the bundle value, must not be null
|
|
55 * @param args the arguments used to format the string
|
|
56 * @return the formatted string
|
|
57 */
|
|
58 public static String getFormattedString(String key, Object[] args) {
|
|
59 String format= null;
|
|
60 try {
|
|
61 format= fgResourceBundle.getString(key);
|
|
62 } catch (MissingResourceException e) {
|
|
63 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
64 }
|
|
65 return MessageFormat.format(format, args);
|
|
66 }
|
|
67
|
|
68 /**
|
|
69 * Gets a string from the resource bundle and formats it with the given argument.
|
|
70 *
|
|
71 * @param key the string used to get the bundle value, must not be null
|
|
72 * @param arg the argument used to format the string
|
|
73 * @return the formatted string
|
|
74 */
|
|
75 public static String getFormattedString(String key, Object arg) {
|
|
76 String format= null;
|
|
77 try {
|
|
78 format= fgResourceBundle.getString(key);
|
|
79 } catch (MissingResourceException e) {
|
|
80 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
81 }
|
|
82 if (arg is null)
|
|
83 arg= ""; //$NON-NLS-1$
|
|
84 return MessageFormat.format(format, new Object[] { arg });
|
|
85 }
|
|
86 }
|