Mon, 02 May 2011 02:13:02 -0700
6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
24 */
25 package com.sun.tools.doclets.internal.toolkit.util;
27 import com.sun.javadoc.*;
28 import com.sun.tools.doclets.internal.toolkit.Configuration;
29 import java.util.*;
30 import java.text.MessageFormat;
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;
50 /**
51 * The location from which to lazily fetch the resource..
52 */
53 private final String resourcelocation;
55 /**
56 * The lazily fetched resource..
57 */
58 private ResourceBundle messageRB;
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 }
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 }
83 /**
84 * Get and format message string from resource
85 *
86 * @param key selects message from resource
87 * @param args arguments to be replaced in the message.
88 * @throws MissingResourceException when the key does not
89 * exist in the properties file.
90 */
91 public String getText(String key, Object... args) throws MissingResourceException {
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);
101 return MessageFormat.format(message, args);
102 }
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 }
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 }
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 }
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 }
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 }
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 }
161 /**
162 * Print error message, increment error count.
163 *
164 * @param pos the position of the source
165 * @param key selects message from resource
166 * @param args arguments to be replaced in the message.
167 */
168 public void error(SourcePosition pos, String key, Object... args) {
169 printError(pos, getText(key, args));
170 }
172 /**
173 * Print error message, increment error count.
174 *
175 * @param key selects message from resource
176 * @param args arguments to be replaced in the message.
177 */
178 public void error(String key, Object... args) {
179 printError(getText(key, args));
180 }
182 /**
183 * Print warning message, increment warning count.
184 *
185 * @param pos the position of the source
186 * @param key selects message from resource
187 * @param args arguments to be replaced in the message.
188 */
189 public void warning(SourcePosition pos, String key, Object... args) {
190 printWarning(pos, getText(key, args));
191 }
193 /**
194 * Print warning message, increment warning count.
195 *
196 * @param key selects message from resource
197 * @param args arguments to be replaced in the message.
198 */
199 public void warning(String key, Object... args) {
200 printWarning(getText(key, args));
201 }
203 /**
204 * Print a message.
205 *
206 * @param pos the position of the source
207 * @param key selects message from resource
208 * @param args arguments to be replaced in the message.
209 */
210 public void notice(SourcePosition pos, String key, Object... args) {
211 printNotice(pos, getText(key, args));
212 }
214 /**
215 * Print a message.
216 *
217 * @param key selects message from resource
218 * @param args arguments to be replaced in the message.
219 */
220 public void notice(String key, Object... args) {
221 printNotice(getText(key, args));
222 }
223 }