/** * SystemPropertyInfo lists all properties available from * the System class. * * Copyright &copy; 1996-1998 Martin Minow. All Rights Reserved.<p> * * Permission to use, copy, modify, and redistribute this software and its * documentation for personal, non-commercial use is hereby granted provided that * this copyright notice and appropriate documentation appears in all copies. This * software may not be distributed for fee or as part of commercial, "shareware," * and/or not-for-profit endevors including, but not limited to, CD-ROM collections, * online databases, and subscription services without specific license.<p> * * @author <a href="mailto:minow@apple.com">Martin Minow</a> * @version 1.0.1 * Edit History: * 1998.03.29 MM Redo property list as an Enumeration, including *		the properties listed in Jef Poskanzer's StatusProperties *		applet. See <http://acme.com/> for his source distribution. * * Set tabs every 4 characters. * */import java.awt.*;import java.util.*;public class SystemPropertyInfo extends SystemInfo{	/*	 * This is a default list of system properties that we will use	 * if the Security Manager doesn't let us extract the "real" list.	 */	public static final String defaultProperties =			""			+ "browser "			+ "file.separator "			+ "java.class.version "			+ "java.vendor "			+ "java.vendor.url "			+ "java.version "			+ "line.separator "			+ "os.arch "			+ "os.name "			+ "os.version "			+ "path.separator ";	public static final String hexPropertyNames =			  " file.separator "			+ "line.separator "			+ "path.separator ";	public static final String urlPropertyNames =			  " browser.vendor.url "			+ " java.class.path "			+ "java.home "			+ "user.dir "			+ "user.home "			+ "user.name ";					public SystemPropertyInfo(			EtchedBorder		border		)	{		super(border);		try {			Properties props = System.getProperties();			/*			 * Unfortunately, enumerating System.getProperties() returns			 * them in an unsatisfactory order. To make the display			 * esthetically pleasing, we'll extract the property names			 * (i.e. the keys) into a vector, then sort the vector, then			 * use the vector as an enumeration. props.size() is not			 * trustworthy (bug in MRJ?)			 */			setBorderText("System Properties");			/*			 * Count the actual size of the System property list.			 */			int size = 0;			Enumeration enum = props.propertyNames();			while (enum.hasMoreElements()) {				++size;				enum.nextElement();			}			String[] names = new String[size];			enum = props.propertyNames();			for (int i = 0; enum.hasMoreElements(); i++) {				names[i] = (String) enum.nextElement();			}			if (size < 1) {				append("No System Properties");			}			else {				JavaInfo.quickSort(names, 0, names.length - 1);				for (int i = 0; i < size; i++) {					addOneSystemProperty(names[i]);				}			}		}		catch (SecurityException e) {			setBorderText("Default Applet Properties");			StringTokenizer t = new StringTokenizer(defaultProperties, " ");			while (t.hasMoreElements()) {				addOneSystemProperty(t.nextToken());			}		}		catch (Exception e) {			append("Strange Exception getting system properties: " + e);		}	}	public void addOneSystemProperty(			String			name		)	{		try {			String propValue	= System.getProperty(name);			/*			 * On the Macintosh (under MRJ), a bunch of font names			 * are loaded into the property list. We toss them			 * to avoid confusion.			 */			if (propValue != null && name.equals(propValue) == false) {				append(name + ":");				boolean isReadable = true;				for (int i = 0; i < propValue.length(); i++) {					char	c	= propValue.charAt(i);					if (isControlCharacter(c)) {						isReadable = false;						break;					}				}				if (isReadable == false) {					for (int i = 0; i < propValue.length(); i++) {						char	c	= propValue.charAt(i);						if (Character.isLetterOrDigit(c)) {							append(" '" + c + "'");						}						else {							append(" 0x");							if (c < 0x10) {								append("0");							}							append(Integer.toHexString(c));						}					}				}				else if (isURLProperty(name)) {					StringBuffer	fixed = new StringBuffer();					int		start	= 0;					int		hit		= 0;					while ((hit = propValue.indexOf('%', start)) >= 0) {						fixed.append(propValue.substring(start, hit));						int		value	=							Integer.parseInt(propValue.substring(hit + 1, hit + 3), 16);						fixed.append(((char) value));						start = hit + 3;					}					append(" \"" + fixed + "\"");				}				else {					append(" " + propValue);				}				append("\n");			} /* If the property name was found */		} /* Try to fetch the property name */		catch (SecurityException e) {			append(name + ": Security Exception\n"	);		}		catch (Exception e) {			append(name 	+ ": " + e + "\n");		}	}	protected boolean isHexProperty(			String			thisName		)	{		int	index	= hexPropertyNames.indexOf(" " + thisName + " ");		return (index >= 0);	}	protected boolean isURLProperty(			String			thisName		)	{		int	index	= urlPropertyNames.indexOf(" " + thisName + " ");		return (index >= 0);	}	/**	 * Replicate the Java 1.1 isISOControl method (for Java 1.0.2 compatibility)	 */	private boolean isControlCharacter(			char			c		)	{		return ((c >= '\u0000' && c <= '\u001f')			 || (c >= '\u007f' && c <= '\u009f')); 	}}