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
|
131
|
15 import dwtx.jface.internal.text.html.HTML2TextReader; // packageimport
|
|
16 import dwtx.jface.internal.text.html.HTMLPrinter; // packageimport
|
|
17 import dwtx.jface.internal.text.html.BrowserInformationControl; // packageimport
|
|
18 import dwtx.jface.internal.text.html.SubstitutionTextReader; // packageimport
|
|
19 import dwtx.jface.internal.text.html.HTMLTextPresenter; // packageimport
|
|
20 import dwtx.jface.internal.text.html.BrowserInput; // packageimport
|
|
21 import dwtx.jface.internal.text.html.SingleCharReader; // packageimport
|
|
22 import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport
|
|
23
|
|
24
|
129
|
25 import dwt.dwthelper.utils;
|
|
26
|
|
27 import java.util.MissingResourceException;
|
|
28 import java.util.ResourceBundle;
|
|
29
|
|
30 import com.ibm.icu.text.MessageFormat;
|
|
31
|
|
32
|
|
33 /**
|
|
34 * Helper class to get NLSed messages.
|
|
35 *
|
|
36 * @since 3.3
|
|
37 */
|
|
38 class HTMLMessages {
|
|
39
|
|
40 private static final String RESOURCE_BUNDLE= HTMLMessages.class.getName();
|
|
41
|
|
42 private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
|
43
|
|
44 private HTMLMessages() {
|
|
45 }
|
|
46
|
|
47 /**
|
|
48 * Gets a string from the resource bundle.
|
|
49 *
|
|
50 * @param key the string used to get the bundle value, must not be null
|
|
51 * @return the string from the resource bundle
|
|
52 */
|
|
53 public static String getString(String key) {
|
|
54 try {
|
|
55 return fgResourceBundle.getString(key);
|
|
56 } catch (MissingResourceException e) {
|
|
57 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
58 }
|
|
59 }
|
|
60
|
|
61 /**
|
|
62 * Gets a string from the resource bundle and formats it with the given arguments.
|
|
63 *
|
|
64 * @param key the string used to get the bundle value, must not be null
|
|
65 * @param args the arguments used to format the string
|
|
66 * @return the formatted string
|
|
67 */
|
|
68 public static String getFormattedString(String key, Object[] args) {
|
|
69 String format= null;
|
|
70 try {
|
|
71 format= fgResourceBundle.getString(key);
|
|
72 } catch (MissingResourceException e) {
|
|
73 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
74 }
|
|
75 return MessageFormat.format(format, args);
|
|
76 }
|
|
77
|
|
78 /**
|
|
79 * Gets a string from the resource bundle and formats it with the given argument.
|
|
80 *
|
|
81 * @param key the string used to get the bundle value, must not be null
|
|
82 * @param arg the argument used to format the string
|
|
83 * @return the formatted string
|
|
84 */
|
|
85 public static String getFormattedString(String key, Object arg) {
|
|
86 String format= null;
|
|
87 try {
|
|
88 format= fgResourceBundle.getString(key);
|
|
89 } catch (MissingResourceException e) {
|
|
90 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
|
|
91 }
|
|
92 if (arg is null)
|
|
93 arg= ""; //$NON-NLS-1$
|
|
94 return MessageFormat.format(format, new Object[] { arg });
|
|
95 }
|
|
96 }
|