src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MessageRetriever.java

changeset 1
9a66ca7c79fa
child 192
42f9d392159d
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
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
87 */
88 public String getText(String key) {
89 return getText(key, (String)null);
90 }
91
92 /**
93 * Get and format message string from resource
94 *
95 * @param key selects message from resource
96 * @param a1 Argument, to be repalced in the message.
97 */
98 public String getText(String key, String a1) {
99 return getText(key, a1, null);
100 }
101
102 /**
103 * Get and format message string from resource
104 *
105 * @param key selects message from resource
106 * @param a1 first argument to be replaced in the message.
107 * @param a2 second argument to be replaced in the message.
108 */
109 public String getText(String key, String a1, String a2) {
110 return getText(key, a1, a2, null);
111 }
112
113 /**
114 * Get and format message string from resource
115 *
116 * @param key selects message from resource
117 * @param a1 first argument to be replaced in the message.
118 * @param a2 second argument to be replaced in the message.
119 * @param a3 third argument to be replaced in the message.
120 * @throws MissingResourceException when the key does not
121 * exist in the properties file.
122 */
123 public String getText(String key, String a1, String a2, String a3) throws MissingResourceException {
124 if (messageRB == null) {
125 try {
126 messageRB = ResourceBundle.getBundle(resourcelocation);
127 } catch (MissingResourceException e) {
128 throw new Error("Fatal: Resource (" + resourcelocation +
129 ") for javadoc doclets is missing.");
130 }
131 }
132 String message = messageRB.getString(key);
133 return MessageFormat.format(message, a1, a2, a3);
134 }
135
136 /**
137 * Print error message, increment error count.
138 *
139 * @param pos the position of the source
140 * @param msg message to print
141 */
142 private void printError(SourcePosition pos, String msg) {
143 configuration.root.printError(pos, msg);
144 }
145
146 /**
147 * Print error message, increment error count.
148 *
149 * @param msg message to print
150 */
151 private void printError(String msg) {
152 configuration.root.printError(msg);
153 }
154
155 /**
156 * Print warning message, increment warning count.
157 *
158 * @param pos the position of the source
159 * @param msg message to print
160 */
161 private void printWarning(SourcePosition pos, String msg) {
162 configuration.root.printWarning(pos, msg);
163 }
164
165 /**
166 * Print warning message, increment warning count.
167 *
168 * @param msg message to print
169 */
170 private void printWarning(String msg) {
171 configuration.root.printWarning(msg);
172 }
173
174 /**
175 * Print a message.
176 *
177 * @param pos the position of the source
178 * @param msg message to print
179 */
180 private void printNotice(SourcePosition pos, String msg) {
181 configuration.root.printNotice(pos, msg);
182 }
183
184 /**
185 * Print a message.
186 *
187 * @param msg message to print
188 */
189 private void printNotice(String msg) {
190 configuration.root.printNotice(msg);
191 }
192
193 /**
194 * Print error message, increment error count.
195 *
196 * @param pos the position of the source
197 * @param key selects message from resource
198 */
199 public void error(SourcePosition pos, String key) {
200 printError(pos, getText(key));
201 }
202
203 /**
204 * Print error message, increment error count.
205 *
206 * @param key selects message from resource
207 */
208 public void error(String key) {
209 printError(getText(key));
210 }
211
212 /**
213 * Print error message, increment error count.
214 *
215 * @param pos the position of the source
216 * @param key selects message from resource
217 * @param a1 first argument to be replaced in the message.
218 */
219 public void error(SourcePosition pos, String key, String a1) {
220 printError(pos, getText(key, a1));
221 }
222
223 /**
224 * Print error message, increment error count.
225 *
226 * @param key selects message from resource
227 * @param a1 first argument to be replaced in the message.
228 */
229 public void error(String key, String a1) {
230 printError(getText(key, a1));
231 }
232
233 /**
234 * Print error message, increment error count.
235 *
236 * @param pos the position of the source
237 * @param key selects message from resource
238 * @param a1 first argument to be replaced in the message.
239 * @param a2 second argument to be replaced in the message.
240 */
241 public void error(SourcePosition pos, String key, String a1, String a2) {
242 printError(pos, getText(key, a1, a2));
243 }
244
245 /**
246 * Print error message, increment error count.
247 *
248 * @param key selects message from resource
249 * @param a1 first argument to be replaced in the message.
250 * @param a2 second argument to be replaced in the message.
251 */
252 public void error(String key, String a1, String a2) {
253 printError(getText(key, a1, a2));
254 }
255
256 /**
257 * Print error message, increment error count.
258 *
259 * @param pos the position of the source
260 * @param key selects message from resource
261 * @param a1 first argument to be replaced in the message.
262 * @param a2 second argument to be replaced in the message.
263 * @param a3 third argument to be replaced in the message.
264 */
265 public void error(SourcePosition pos, String key, String a1, String a2, String a3) {
266 printError(pos, getText(key, a1, a2, a3));
267 }
268
269 /**
270 * Print error message, increment error count.
271 *
272 * @param key selects message from resource
273 * @param a1 first argument to be replaced in the message.
274 * @param a2 second argument to be replaced in the message.
275 * @param a3 third argument to be replaced in the message.
276 */
277 public void error(String key, String a1, String a2, String a3) {
278 printError(getText(key, a1, a2, a3));
279 }
280
281 /**
282 * Print warning message, increment warning count.
283 *
284 * @param pos the position of the source
285 * @param key selects message from resource
286 */
287 public void warning(SourcePosition pos, String key) {
288 printWarning(pos, getText(key));
289 }
290
291 /**
292 * Print warning message, increment warning count.
293 *
294 * @param key selects message from resource
295 */
296 public void warning(String key) {
297 printWarning(getText(key));
298 }
299
300 /**
301 * Print warning message, increment warning count.
302 *
303 * @param pos the position of the source
304 * @param key selects message from resource
305 * @param a1 first argument to be replaced in the message.
306 */
307 public void warning(SourcePosition pos, String key, String a1) {
308 printWarning(pos, getText(key, a1));
309 }
310
311 /**
312 * Print warning message, increment warning count.
313 *
314 * @param key selects message from resource
315 * @param a1 first argument to be replaced in the message.
316 */
317 public void warning(String key, String a1) {
318 printWarning(getText(key, a1));
319 }
320
321 /**
322 * Print warning message, increment warning count.
323 *
324 * @param pos the position of the source
325 * @param key selects message from resource
326 * @param a1 first argument to be replaced in the message.
327 * @param a2 second argument to be replaced in the message.
328 */
329 public void warning(SourcePosition pos, String key, String a1, String a2) {
330 printWarning(pos, getText(key, a1, a2));
331 }
332
333 /**
334 * Print warning message, increment warning count.
335 *
336 * @param key selects message from resource
337 * @param a1 first argument to be replaced in the message.
338 * @param a2 second argument to be replaced in the message.
339 */
340 public void warning(String key, String a1, String a2) {
341 printWarning(getText(key, a1, a2));
342 }
343
344 /**
345 * Print warning message, increment warning count.
346 *
347 * @param pos the position of the source
348 * @param key selects message from resource
349 * @param a1 first argument to be replaced in the message.
350 * @param a2 second argument to be replaced in the message.
351 * @param a3 third argument to be replaced in the message.
352 */
353 public void warning(SourcePosition pos, String key, String a1, String a2, String a3) {
354 printWarning(pos, getText(key, a1, a2, a3));
355 }
356
357 /**
358 * Print warning message, increment warning count.
359 *
360 * @param key selects message from resource
361 * @param a1 first argument to be replaced in the message.
362 * @param a2 second argument to be replaced in the message.
363 * @param a3 third argument to be replaced in the message.
364 */
365 public void warning(String key, String a1, String a2, String a3) {
366 printWarning(getText(key, a1, a2, a3));
367 }
368
369 /**
370 * Print a message.
371 *
372 * @param pos the position of the source
373 * @param key selects message from resource
374 */
375 public void notice(SourcePosition pos, String key) {
376 printNotice(pos, getText(key));
377 }
378
379 /**
380 * Print a message.
381 *
382 * @param key selects message from resource
383 */
384 public void notice(String key) {
385 printNotice(getText(key));
386 }
387
388 /**
389 * Print a message.
390 * @param pos the position of the source
391 * @param key selects message from resource
392 * @param a1 first argument to be replaced in the message.
393 */
394 public void notice(SourcePosition pos, String key, String a1) {
395 printNotice(pos, getText(key, a1));
396 }
397
398 /**
399 * Print a message.
400 *
401 * @param key selects message from resource
402 * @param a1 first argument to be replaced in the message.
403 */
404 public void notice(String key, String a1) {
405 printNotice(getText(key, a1));
406 }
407
408 /**
409 * Print a message.
410 *
411 * @param pos the position of the source
412 * @param key selects message from resource
413 * @param a1 first argument to be replaced in the message.
414 * @param a2 second argument to be replaced in the message.
415 */
416 public void notice(SourcePosition pos, String key, String a1, String a2) {
417 printNotice(pos, getText(key, a1, a2));
418 }
419
420 /**
421 * Print a message.
422 *
423 * @param key selects message from resource
424 * @param a1 first argument to be replaced in the message.
425 * @param a2 second argument to be replaced in the message.
426 */
427 public void notice(String key, String a1, String a2) {
428 printNotice(getText(key, a1, a2));
429 }
430
431 /**
432 * Print a message.
433 *
434 * @param pos the position of the source
435 * @param key selects message from resource
436 * @param a1 first argument to be replaced in the message.
437 * @param a2 second argument to be replaced in the message.
438 * @param a3 third argument to be replaced in the message.
439 */
440 public void notice(SourcePosition pos, String key, String a1, String a2, String a3) {
441 printNotice(pos, getText(key, a1, a2, a3));
442 }
443
444 /**
445 * Print a message.
446 *
447 * @param key selects message from resource
448 * @param a1 first argument to be replaced in the message.
449 * @param a2 second argument to be replaced in the message.
450 * @param a3 third argument to be replaced in the message.
451 */
452 public void notice(String key, String a1, String a2, String a3) {
453 printNotice(getText(key, a1, a2, a3));
454 }
455 }

mercurial