home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / misc / MessageUtils.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.9 KB  |  94 lines

  1. /*
  2.  * @(#)MessageUtils.java    1.6 96/02/27 Herb Jellinek
  3.  *
  4.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.misc;
  21.  
  22. /**
  23.  * MessageUtils: miscellaneous utilities for handling error and status
  24.  * properties and messages.
  25.  *
  26.  * @version 1.6, 02/27/96
  27.  * @author Herb Jellinek
  28.  */
  29.  
  30. public class MessageUtils {
  31.     // can instantiate it for to allow less verbose use - via instance
  32.     // instead of classname
  33.     
  34.     public MessageUtils() { }
  35.  
  36.     public static String subst(String patt, String arg) {
  37.     String args[] = { arg };
  38.     return subst(patt, args);
  39.     }
  40.  
  41.     public static String subst(String patt, String arg1, String arg2) {
  42.     String args[] = { arg1, arg2 };
  43.     return subst(patt, args);
  44.     }
  45.  
  46.     public static String subst(String patt, String arg1, String arg2,
  47.                    String arg3) {
  48.     String args[] = { arg1, arg2, arg3 };
  49.     return subst(patt, args);
  50.     }
  51.  
  52.     public static String subst(String patt, String args[]) {
  53.     StringBuffer result = new StringBuffer();
  54.     int len = patt.length();
  55.     for (int i = 0; i >= 0 && i < len; i++) {
  56.         char ch = patt.charAt(i);
  57.         if (ch == '%') {
  58.         if (i != len) {
  59.             int index = Character.digit(patt.charAt(i + 1), 10);
  60.             if (index == -1) {
  61.             result.append(patt.charAt(i + 1));
  62.             i++;
  63.             } else if (index < args.length) {
  64.             result.append(args[index]);
  65.             i++;
  66.             }
  67.         }
  68.         } else {
  69.         result.append(ch);
  70.         }
  71.     }
  72.     return result.toString();
  73.     }
  74.  
  75.     public static String substProp(String propName, String arg) {
  76.     return subst(System.getProperty(propName), arg);
  77.     }
  78.  
  79.     public static String substProp(String propName, String arg1, String arg2) {
  80.     return subst(System.getProperty(propName), arg1, arg2);
  81.     }
  82.  
  83.     public static String substProp(String propName, String arg1, String arg2,
  84.                    String arg3) {
  85.     return subst(System.getProperty(propName), arg1, arg2, arg3);
  86.     }
  87.  
  88.     public static void main(String args[]) {
  89.     String stringArgs[] = new String[args.length - 1];
  90.     System.arraycopy(args, 1, stringArgs, 0, args.length - 1);
  91.     System.out.println("> result = "+subst(args[0], stringArgs));
  92.     }
  93. }
  94.