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