ShowProps.java

Download ShowProps.java

 1: // Property and environment lister demo (WebStart+ runnable Jar), as a
 2: // Simple AWT app.
 3: // Shows all system properties that an Applet/WebStaret app can look at.
 4: // Can use this to experiment with Policy Files:  Run, then
 5: // re-run after granting this app read permission on some
 6: // normally forbidden System Property.  This program can also be downloaded
 7: // and is a runnable Jar; in that mode, no properties are forbidden.  Finally,
 8: // We also show all accessible environment variables.
 9: //
10: // (C) 2000-2018 by Wayne Pollock, Tampa Florida USA.  All Rights Reserved.
11: 
12: import java.awt.*;
13: import java.awt.event.*;
14: import java.util.*;
15: 
16: public class ShowProps
17: {
18:    private static final java.util.List<String> defaultListOfSystemProperties =
19:    Arrays.asList(
20:      "awt.toolkit", "file.encoding", "file.encoding.pkg", "file.separator",
21:      "java.awt.graphicsenv", "java.awt.printerjob", "java.class.path",
22:      "java.class.version", "java.home", "java.io.tmpdir",
23:      "java.library.path", "java.runtime.name", "java.runtime.version",
24:      "java.specification.name", "java.specification.vendor",
25:      "java.specification.version", "java.vendor", "java.vendor.url",
26:      "java.vendor.url.bug", "java.version", "java.vm.compressedOopsMode",
27:      "java.vm.info", "java.vm.name",
28:      "java.vm.specification.name", "java.vm.specification.vendor",
29:      "java.vm.specification.version", "java.vm.vendor", "java.vm.version",
30:      "jdk.debug", "line.separator", "os.arch", "os.name", "os.version",
31:      "path.separator", "sun.arch.data.model", "sun.awt.enableExtraMouseButtons",
32:      "sun.boot.library.path", "sun.cpu.endian", "sun.cpu.isalist",
33:      "sun.desktop", "sun.io.unicode.encoding", "sun.java.command",
34:      "sun.java.launcher", "sun.jnu.encoding", "sun.management.compiler",
35:      "sun.os.patch.level", "sun.stderr.encoding", "sun.stdout.encoding",
36:      "user.country", "user.dir", "user.home", "user.language",
37:      "user.name", "user.script", "user.timezone", "user.variant"
38:    );
39: 
40: 
41:    public static void main ( String[] args) {
42:       // Set up GUI:
43:       Frame f = new Frame( "ShowProps" );
44:       TextArea ta;
45:       f.setLayout( new BorderLayout() );
46:       f.setBackground( Color.white );
47:       ta = new TextArea();
48:       f.addWindowListener( new WindowAdapter() {
49:          public void windowClosing ( WindowEvent we ) {
50:             System.exit( 0 );
51:          }
52:       });
53:       f.add( ta, BorderLayout.CENTER );
54:       ta.setEditable( false );
55:       f.setSize( 900, 800 );  // Height is a guess to fit on most monitors
56:       f.setLocationRelativeTo(null);  // Center on screen
57: 
58:       ta.append(  "======= System property list =======\n\n" );
59: 
60:       // Obtain a sorted list of property names:
61:       java.util.List<String> props = new ArrayList<>();
62:       try {
63:           Set<String> propNames= System.getProperties().stringPropertyNames();
64:           for ( final String name : propNames ) {
65:              props.add( name );
66:           }
67:       }
68:       catch ( SecurityException se )
69:       {  ta.append( " (Using default property list)\n\n" );
70:          props = defaultListOfSystemProperties;
71:       }
72: 
73:       props.sort( String::compareToIgnoreCase );
74: 
75:       // Add each property name and value (if not restricted) to the output:
76:       for ( final String prop: props ) {
77:          String value;
78:          try { value = System.getProperty( prop ); }
79:          catch ( SecurityException se ) { value = "***Restricted***"; }
80: 
81:          ta.append( prop + " = \"" + value + "\"\n" );
82:       }
83: 
84:       // Append list of environment variables and their values
85:       // (note these are sorted case-sensitively):
86:       ta.append(  "\n\n=======Environment variable list=======\n\n" );
87:       try {
88:          SortedMap<String,String> env = new TreeMap<>( System.getenv() );
89:          for ( final String name : env.keySet() ) {
90:             ta.append( name + " = \"" + env.get( name ) + "\"\n" );
91:          }
92:       } catch ( Exception e ) { ta.append( "\n***Restricted***\n" ); }
93:       ta.append( "\n" );
94: 
95:       ta.setCaretPosition( 0 );  // Scroll back to top
96:       f.setVisible( true );
97:    }
98: }