001: /*
002: * Copyright 1996-1997 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.applet;
027:
028: import java.util.ResourceBundle;
029: import java.util.MissingResourceException;
030: import java.text.MessageFormat;
031:
032: /**
033: * An hanlder of localized messages.
034: *
035: * @version 1.24, 05/05/07
036: * @author Koji Uno
037: */
038: class AppletMessageHandler {
039: private static ResourceBundle rb;
040: private String baseKey = null;
041:
042: static {
043: try {
044: rb = ResourceBundle
045: .getBundle("sun.applet.resources.MsgAppletViewer");
046: } catch (MissingResourceException e) {
047: System.out.println(e.getMessage());
048: System.exit(1);
049: }
050: }
051:
052: AppletMessageHandler(String baseKey) {
053: this .baseKey = baseKey;
054: }
055:
056: String getMessage(String key) {
057: return (String) rb.getString(getQualifiedKey(key));
058: }
059:
060: String getMessage(String key, Object arg) {
061: String basemsgfmt = (String) rb.getString(getQualifiedKey(key));
062: MessageFormat msgfmt = new MessageFormat(basemsgfmt);
063: Object msgobj[] = new Object[1];
064: if (arg == null) {
065: arg = "null"; // mimic java.io.PrintStream.print(String)
066: }
067: msgobj[0] = arg;
068: return msgfmt.format(msgobj);
069: }
070:
071: String getMessage(String key, Object arg1, Object arg2) {
072: String basemsgfmt = (String) rb.getString(getQualifiedKey(key));
073: MessageFormat msgfmt = new MessageFormat(basemsgfmt);
074: Object msgobj[] = new Object[2];
075: if (arg1 == null) {
076: arg1 = "null";
077: }
078: if (arg2 == null) {
079: arg2 = "null";
080: }
081: msgobj[0] = arg1;
082: msgobj[1] = arg2;
083: return msgfmt.format(msgobj);
084: }
085:
086: String getMessage(String key, Object arg1, Object arg2, Object arg3) {
087: String basemsgfmt = (String) rb.getString(getQualifiedKey(key));
088: MessageFormat msgfmt = new MessageFormat(basemsgfmt);
089: Object msgobj[] = new Object[3];
090: if (arg1 == null) {
091: arg1 = "null";
092: }
093: if (arg2 == null) {
094: arg2 = "null";
095: }
096: if (arg3 == null) {
097: arg3 = "null";
098: }
099: msgobj[0] = arg1;
100: msgobj[1] = arg2;
101: msgobj[2] = arg3;
102: return msgfmt.format(msgobj);
103: }
104:
105: String getMessage(String key, Object arg[]) {
106: String basemsgfmt = (String) rb.getString(getQualifiedKey(key));
107: MessageFormat msgfmt = new MessageFormat(basemsgfmt);
108: return msgfmt.format(arg);
109: }
110:
111: String getQualifiedKey(String subKey) {
112: return baseKey + "." + subKey;
113: }
114: }
|