home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 2.9 KB | 94 lines |
- /*
- * @(#)MessageUtils.java 1.6 96/02/27 Herb Jellinek
- *
- * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package sun.misc;
-
- /**
- * MessageUtils: miscellaneous utilities for handling error and status
- * properties and messages.
- *
- * @version 1.6, 02/27/96
- * @author Herb Jellinek
- */
-
- public class MessageUtils {
- // can instantiate it for to allow less verbose use - via instance
- // instead of classname
-
- public MessageUtils() { }
-
- public static String subst(String patt, String arg) {
- String args[] = { arg };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String arg1, String arg2) {
- String args[] = { arg1, arg2 };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String arg1, String arg2,
- String arg3) {
- String args[] = { arg1, arg2, arg3 };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String args[]) {
- StringBuffer result = new StringBuffer();
- int len = patt.length();
- for (int i = 0; i >= 0 && i < len; i++) {
- char ch = patt.charAt(i);
- if (ch == '%') {
- if (i != len) {
- int index = Character.digit(patt.charAt(i + 1), 10);
- if (index == -1) {
- result.append(patt.charAt(i + 1));
- i++;
- } else if (index < args.length) {
- result.append(args[index]);
- i++;
- }
- }
- } else {
- result.append(ch);
- }
- }
- return result.toString();
- }
-
- public static String substProp(String propName, String arg) {
- return subst(System.getProperty(propName), arg);
- }
-
- public static String substProp(String propName, String arg1, String arg2) {
- return subst(System.getProperty(propName), arg1, arg2);
- }
-
- public static String substProp(String propName, String arg1, String arg2,
- String arg3) {
- return subst(System.getProperty(propName), arg1, arg2, arg3);
- }
-
- public static void main(String args[]) {
- String stringArgs[] = new String[args.length - 1];
- System.arraycopy(args, 1, stringArgs, 0, args.length - 1);
- System.out.println("> result = "+subst(args[0], stringArgs));
- }
- }
-