author | ohair |
Tue, 25 May 2010 15:54:51 -0700 | |
changeset 5520 | 86e4b9a9da40 |
parent 2212 | 1d3dc0e0ba0c |
child 14258 | 8d2148961366 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
26 |
||
27 |
import com.sun.javadoc.*; |
|
28 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
29 |
import java.util.*; |
|
30 |
import java.text.MessageFormat; |
|
31 |
||
32 |
||
33 |
/** |
|
34 |
* Retrieve and format messages stored in a resource. |
|
35 |
* |
|
36 |
* This code is not part of an API. |
|
37 |
* It is implementation that is subject to change. |
|
38 |
* Do not use it as an API |
|
39 |
* |
|
40 |
* @since 1.2 |
|
41 |
* @author Atul M Dambalkar |
|
42 |
* @author Robert Field |
|
43 |
*/ |
|
44 |
public class MessageRetriever { |
|
45 |
/** |
|
46 |
* The global configuration information for this run. |
|
47 |
*/ |
|
48 |
private final Configuration configuration; |
|
49 |
||
50 |
/** |
|
51 |
* The location from which to lazily fetch the resource.. |
|
52 |
*/ |
|
53 |
private final String resourcelocation; |
|
54 |
||
55 |
/** |
|
56 |
* The lazily fetched resource.. |
|
57 |
*/ |
|
58 |
private ResourceBundle messageRB; |
|
59 |
||
60 |
/** |
|
61 |
* Initilize the ResourceBundle with the given resource. |
|
62 |
* |
|
63 |
* @param rb the esource bundle to read. |
|
64 |
*/ |
|
65 |
public MessageRetriever(ResourceBundle rb) { |
|
66 |
this.configuration = null; |
|
67 |
this.messageRB = rb; |
|
68 |
this.resourcelocation = null; |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Initilize the ResourceBundle with the given resource. |
|
73 |
* |
|
74 |
* @param configuration the configuration |
|
75 |
* @param resourcelocation Resource. |
|
76 |
*/ |
|
77 |
public MessageRetriever(Configuration configuration, |
|
78 |
String resourcelocation) { |
|
79 |
this.configuration = configuration; |
|
80 |
this.resourcelocation = resourcelocation; |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Get and format message string from resource |
|
85 |
* |
|
86 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
87 |
* @param args arguments to be replaced in the message. |
10 | 88 |
* @throws MissingResourceException when the key does not |
89 |
* exist in the properties file. |
|
90 |
*/ |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
91 |
public String getText(String key, Object... args) throws MissingResourceException { |
10 | 92 |
if (messageRB == null) { |
93 |
try { |
|
94 |
messageRB = ResourceBundle.getBundle(resourcelocation); |
|
95 |
} catch (MissingResourceException e) { |
|
96 |
throw new Error("Fatal: Resource (" + resourcelocation + |
|
97 |
") for javadoc doclets is missing."); |
|
98 |
} |
|
99 |
} |
|
100 |
String message = messageRB.getString(key); |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
101 |
return MessageFormat.format(message, args); |
10 | 102 |
} |
103 |
||
104 |
/** |
|
105 |
* Print error message, increment error count. |
|
106 |
* |
|
107 |
* @param pos the position of the source |
|
108 |
* @param msg message to print |
|
109 |
*/ |
|
110 |
private void printError(SourcePosition pos, String msg) { |
|
111 |
configuration.root.printError(pos, msg); |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Print error message, increment error count. |
|
116 |
* |
|
117 |
* @param msg message to print |
|
118 |
*/ |
|
119 |
private void printError(String msg) { |
|
120 |
configuration.root.printError(msg); |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* Print warning message, increment warning count. |
|
125 |
* |
|
126 |
* @param pos the position of the source |
|
127 |
* @param msg message to print |
|
128 |
*/ |
|
129 |
private void printWarning(SourcePosition pos, String msg) { |
|
130 |
configuration.root.printWarning(pos, msg); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Print warning message, increment warning count. |
|
135 |
* |
|
136 |
* @param msg message to print |
|
137 |
*/ |
|
138 |
private void printWarning(String msg) { |
|
139 |
configuration.root.printWarning(msg); |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Print a message. |
|
144 |
* |
|
145 |
* @param pos the position of the source |
|
146 |
* @param msg message to print |
|
147 |
*/ |
|
148 |
private void printNotice(SourcePosition pos, String msg) { |
|
149 |
configuration.root.printNotice(pos, msg); |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Print a message. |
|
154 |
* |
|
155 |
* @param msg message to print |
|
156 |
*/ |
|
157 |
private void printNotice(String msg) { |
|
158 |
configuration.root.printNotice(msg); |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* Print error message, increment error count. |
|
163 |
* |
|
164 |
* @param pos the position of the source |
|
165 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
166 |
* @param args arguments to be replaced in the message. |
10 | 167 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
168 |
public void error(SourcePosition pos, String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
169 |
printError(pos, getText(key, args)); |
10 | 170 |
} |
171 |
||
172 |
/** |
|
173 |
* Print error message, increment error count. |
|
174 |
* |
|
175 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
176 |
* @param args arguments to be replaced in the message. |
10 | 177 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
178 |
public void error(String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
179 |
printError(getText(key, args)); |
10 | 180 |
} |
181 |
||
182 |
/** |
|
183 |
* Print warning message, increment warning count. |
|
184 |
* |
|
185 |
* @param pos the position of the source |
|
186 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
187 |
* @param args arguments to be replaced in the message. |
10 | 188 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
189 |
public void warning(SourcePosition pos, String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
190 |
printWarning(pos, getText(key, args)); |
10 | 191 |
} |
192 |
||
193 |
/** |
|
194 |
* Print warning message, increment warning count. |
|
195 |
* |
|
196 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
197 |
* @param args arguments to be replaced in the message. |
10 | 198 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
199 |
public void warning(String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
200 |
printWarning(getText(key, args)); |
10 | 201 |
} |
202 |
||
203 |
/** |
|
204 |
* Print a message. |
|
205 |
* |
|
206 |
* @param pos the position of the source |
|
207 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
208 |
* @param args arguments to be replaced in the message. |
10 | 209 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
210 |
public void notice(SourcePosition pos, String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
211 |
printNotice(pos, getText(key, args)); |
10 | 212 |
} |
213 |
||
214 |
/** |
|
215 |
* Print a message. |
|
216 |
* |
|
217 |
* @param key selects message from resource |
|
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
218 |
* @param args arguments to be replaced in the message. |
10 | 219 |
*/ |
1864
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
220 |
public void notice(String key, Object... args) { |
c17be9084212
6794520: MessageRetriever should be upgraded to use varargs Object...
jjg
parents:
10
diff
changeset
|
221 |
printNotice(getText(key, args)); |
10 | 222 |
} |
223 |
} |