Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletMessageHandler.java
38829 views
/*1* Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.applet;2627import java.util.ResourceBundle;28import java.util.MissingResourceException;29import java.text.MessageFormat;3031/**32* An hanlder of localized messages.33*34* @author Koji Uno35*/36class AppletMessageHandler {37private static ResourceBundle rb;38private String baseKey = null;3940static {41try {42rb = ResourceBundle.getBundle43("sun.applet.resources.MsgAppletViewer");44} catch (MissingResourceException e) {45System.out.println(e.getMessage());46System.exit(1);47}48}4950AppletMessageHandler(String baseKey) {51this.baseKey = baseKey;52}5354String getMessage(String key) {55return (String)rb.getString(getQualifiedKey(key));56}5758String getMessage(String key, Object arg){59String basemsgfmt = (String)rb.getString(getQualifiedKey(key));60MessageFormat msgfmt = new MessageFormat(basemsgfmt);61Object msgobj[] = new Object[1];62if (arg == null) {63arg = "null"; // mimic java.io.PrintStream.print(String)64}65msgobj[0] = arg;66return msgfmt.format(msgobj);67}6869String getMessage(String key, Object arg1, Object arg2) {70String basemsgfmt = (String)rb.getString(getQualifiedKey(key));71MessageFormat msgfmt = new MessageFormat(basemsgfmt);72Object msgobj[] = new Object[2];73if (arg1 == null) {74arg1 = "null";75}76if (arg2 == null) {77arg2 = "null";78}79msgobj[0] = arg1;80msgobj[1] = arg2;81return msgfmt.format(msgobj);82}8384String getMessage(String key, Object arg1, Object arg2, Object arg3) {85String basemsgfmt = (String)rb.getString(getQualifiedKey(key));86MessageFormat msgfmt = new MessageFormat(basemsgfmt);87Object msgobj[] = new Object[3];88if (arg1 == null) {89arg1 = "null";90}91if (arg2 == null) {92arg2 = "null";93}94if (arg3 == null) {95arg3 = "null";96}97msgobj[0] = arg1;98msgobj[1] = arg2;99msgobj[2] = arg3;100return msgfmt.format(msgobj);101}102103String getMessage(String key, Object arg[]) {104String basemsgfmt = (String)rb.getString(getQualifiedKey(key));105MessageFormat msgfmt = new MessageFormat(basemsgfmt);106return msgfmt.format(arg);107}108109String getQualifiedKey(String subKey) {110return baseKey + "." + subKey;111}112}113114115