corba/src/share/classes/com/sun/tools/corba/se/idl/som/cff/Messages.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997,1998
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *  Defect History
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
 *  #26964 LKR 11/25/96 \u0020 at end-of-message not handled properly by Java.
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
 *  #31840 LKR 06/05/97 Replace \n in templates with Java's line separator.
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
package com.sun.tools.corba.se.idl.som.cff;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.lang.String;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.lang.System;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * This class provides messaging services for accessing, and merging
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 * parameters into, translatable message text.  The text is presumed
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 * to reside in a .properties file.  A "cff.properties" file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * contains all of the message text needed for the CFF framework itself
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * is loaded during class initialization.  All of the messages in the
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * cff.properties file that are needed by the CFF framework contain keys
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * that begin with the string "cff.".
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * The static method Messages.msgLoad may be used to merge additional
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * message text .properties files needed by other frameworks or user
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 * programs.
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 * @see com.sun.tools.corba.se.idl.som.cff.Messages#msgLoad
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
 * @author      Larry K. Raper
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
public abstract class Messages {
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    /* Class variables */
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    /* Metasymbol for leading or trailing blank */
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    private static final String LTB = "%B";
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    /* Metasymbol for line separator */
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    private static final char NL  = '\n';
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    private static final String lineSeparator =
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        System.getProperty ("line.separator");
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    private static final Properties m = new Properties ();
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    private static boolean loadNeeded = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    /* Class methods for message loading and formatting */
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    private static final synchronized void loadDefaultProperties () {
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        if (!loadNeeded)
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            m.load (FileLocator.locateLocaleSpecificFileInClassPath (
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
                "com/sun/tools/corba/se/idl/som/cff/cff.properties"));
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        } catch (IOException ioe) { }
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        fixMessages (m);  /* #26964 Replace any metasymbols */
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        loadNeeded = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
     * This method was introduced to fix defect #26964.  For Java 1.0.2
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
     * on Win NT, the escape sequence \u0020 was not being handled
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
     * correctly by the Java Properties class when it was the final
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
     * character of a line.  Instead the trailing blank was dropped
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
     * and the next line was swallowed as a continuation.  To work
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
     * around the problem, we introduced our own metasymbol to represent
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
     * a trailing blank.  Hence:
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
     * Performs substitution for any metasymbols in the message
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
     * templates.  So far only %B is needed.  This was introduced
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
     * to make it more convenient for .properties files to
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
     * contain message templates with leading or trailing blanks
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
     * (although %B may actually occur anywhere in a template).
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * Subsequently, checking for '\n' has also been added.  Now,
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     * wherever '\n' occurs in a message template, it is replaced
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     * with the value of System.getProperty ("line.separator").
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    private static final void fixMessages (Properties p) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
        Enumeration keys = p.keys ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        Enumeration elems = p.elements ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        while (keys.hasMoreElements ()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            String key = (String) keys.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            String elem = (String) elems.nextElement ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            int i = elem.indexOf (LTB);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            boolean changed = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            while (i != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                if (i == 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
                    elem = " " + elem.substring (2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                    elem = elem.substring (0, i) + " " + elem.substring (i+2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
                changed = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                i = elem.indexOf (LTB);
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            int lsIncr = lineSeparator.length () - 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            for (i=0; i<elem.length (); i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
                if (elem.charAt (i) == NL) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
                    elem = elem.substring (0, i) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
                        lineSeparator + elem.substring (i+1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                    i += lsIncr;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
                    changed = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
            if (changed)
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
                p.put (key, elem);
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
     * Loads additional message keys and text found in the passed
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
     * properties file.  The specified properties file is assumed to
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
     * reside in the CLASSPATH. An IOException is thrown if the loading fails.
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    public static final synchronized void msgLoad (String propertyFileName)
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        m.load (FileLocator.locateLocaleSpecificFileInClassPath (
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
            propertyFileName));
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        fixMessages (m);   /* #26964 Replace any metasymbols */
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        loadNeeded = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * string.  If the msgkey cannot be found, its value is returned
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * as the output message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    public static final String msg (String msgkey) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        if (loadNeeded)
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
            loadDefaultProperties ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        String msgtext = m.getProperty (msgkey, msgkey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        return msgtext;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
     * of a single argument, supplied by the "parm" parameter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
     * If the message text does not contain the meta characters "%1"
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
     * that indicate where to place the argument, the passed argument
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
     * is appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    public static final String msg (String msgkey, String parm) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        if (loadNeeded)
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
            loadDefaultProperties ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
        String msgtext = m.getProperty (msgkey, msgkey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
        int i = msgtext.indexOf ("%1");
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
        if (i >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
            String ending = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            if ((i+2) < msgtext.length ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                ending = msgtext.substring (i+2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            return msgtext.substring (0, i) + parm + ending;
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
            msgtext += " " + parm;
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        return msgtext;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
     * of a single argument, supplied by the "parm" parameter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * If the message text does not contain the meta characters "%1"
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     * that indicate where to place the argument, the passed argument
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
     * is appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    public static final String msg (String msgkey, int parm) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        return msg (msgkey, String.valueOf (parm));
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
     * of two arguments, supplied by the "parm1" and "parm2" parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
     * If the message text does not contain the meta characters "%1" and
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
     * "%2" that indicate where to place the arguments, the passed arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
     * are appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    public static final String msg (String msgkey, String parm1, String parm2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        if (loadNeeded)
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            loadDefaultProperties ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        String result = m.getProperty (msgkey, msgkey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        String ending = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        int i = result.indexOf ("%1");
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        if (i >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
            if ((i+2) < result.length ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
                ending = result.substring (i+2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
            result = result.substring (0, i) + parm1 + ending;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            result += " " + parm1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        i = result.indexOf ("%2");
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        if (i >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            ending = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            if ((i+2) < result.length ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                ending = result.substring (i+2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            result = result.substring (0, i) + parm2 + ending;
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            result += " " + parm2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
     * of two arguments, supplied by the "parm1" and "parm2" parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
     * If the message text does not contain the meta characters "%1" and
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
     * "%2" that indicate where to place the arguments, the passed arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
     * are appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    public static final String msg (String msgkey, int parm1, String parm2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        return msg (msgkey, String.valueOf (parm1), parm2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
     * of two arguments, supplied by the "parm1" and "parm2" parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
     * If the message text does not contain the meta characters "%1" and
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
     * "%2" that indicate where to place the arguments, the passed arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
     * are appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    public static final String msg (String msgkey, String parm1, int parm2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        return msg (msgkey, parm1, String.valueOf (parm2));
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
     * of two arguments, supplied by the "parm1" and "parm2" parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
     * If the message text does not contain the meta characters "%1" and
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
     * "%2" that indicate where to place the arguments, the passed arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
     * are appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    public static final String msg (String msgkey, int parm1, int parm2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        return msg (msgkey, String.valueOf (parm1), String.valueOf (parm2));
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
     * Returns the message text corresponding to the passed msgkey
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
     * string.  The message text is assumed to require the insertion
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
     * of three arguments, supplied by the "parm1", "parm2" and "parm3"
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
     *  parameters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
     * If the message text does not contain the meta characters "%1" and
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
     * "%2" that indicate where to place the arguments, the passed arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
     * are appended at the end of the message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
     * If the msgkey cannot be found, its value is used as the
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
     * message text.
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    public static final String msg (String msgkey, String parm1,
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
                            String parm2, String parm3) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        if (loadNeeded)
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
            loadDefaultProperties ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        String result = m.getProperty (msgkey, msgkey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        result = substituteString(result, 1, parm1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        result = substituteString(result, 2, parm2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        result = substituteString(result, 3, parm3);
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    /* helper function for string substition.
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
     @return the substituted string, it substitution is possible.
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
       Otherwise, return a new string with subst at the end.
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
     @orig: original string
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
     @paramNum the parameter number to search. For example,
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
         paramNam == 1 means search for "%1".
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
     @subst: string for the substitution.
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    private static String substituteString(String orig, int paramNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
                     String subst){
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        String result = orig;
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        String paramSubst = "%"+ paramNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        int len = paramSubst.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
        int index = result.indexOf (paramSubst);
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        String ending = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        if (index >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            if ((index+len) < result.length ())
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
                ending = result.substring (index+len);
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            result = result.substring (0, index) + subst + ending;
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        else result += " " + subst;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
         return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
}