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