src/share/classes/sun/applet/Main.java

Print this page
rev 10175 : 8042872: Fix raw and unchecked warnings in sun.applet
Reviewed-by:


  67         userHome.canWrite();
  68 
  69         theUserPropertiesFile = new File(userHome, ".appletviewer");
  70     }
  71 
  72     // i18n
  73     private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer");
  74 
  75     /**
  76      * Member variables set according to options passed in to AppletViewer.
  77      */
  78     private boolean debugFlag = false;
  79     private boolean helpFlag  = false;
  80     private String  encoding  = null;
  81     private boolean noSecurityFlag  = false;
  82     private static boolean cmdLineTestFlag = false;
  83 
  84     /**
  85      * The list of valid URLs passed in to AppletViewer.
  86      */
  87     private static Vector urlList = new Vector(1);
  88 
  89     // This is used in init().  Getting rid of this is desirable but depends
  90     // on whether the property that uses it is necessary/standard.
  91     public static final String theVersion = System.getProperty("java.version");
  92 
  93     /**
  94      * The main entry point into AppletViewer.
  95      */
  96     public static void main(String [] args) {
  97         Main m = new Main();
  98         int ret = m.run(args);
  99 
 100         // Exit immediately if we got some sort of error along the way.
 101         // For debugging purposes, if we have passed in "-XcmdLineTest" we
 102         // force a premature exit.
 103         if ((ret != 0) || (cmdLineTestFlag))
 104             System.exit(ret);
 105     }
 106 
 107     private int run(String [] args) {


 136         }
 137 
 138         if (debugFlag) {
 139             // START A DEBUG SESSION
 140             // Given the current architecture, we will end up decoding the
 141             // arguments again, but at least we are guaranteed to have
 142             // arguments which are valid.
 143             return invokeDebugger(args);
 144         }
 145 
 146         // INSTALL THE SECURITY MANAGER (if necessary)
 147         if (!noSecurityFlag && (System.getSecurityManager() == null))
 148             init();
 149 
 150         // LAUNCH APPLETVIEWER FOR EACH URL
 151         for (int i = 0; i < urlList.size(); i++) {
 152             try {
 153                 // XXX 5/17 this parsing method should be changed/fixed so that
 154                 // it doesn't do both parsing of the html file and launching of
 155                 // the AppletPanel
 156                 AppletViewer.parse((URL) urlList.elementAt(i), encoding);
 157             } catch (IOException e) {
 158                 System.err.println(lookup("main.err.io", e.getMessage()));
 159                 return 1;
 160             }
 161         }
 162         return 0;
 163     }
 164 
 165     private static void usage() {
 166         System.out.println(lookup("usage"));
 167     }
 168 
 169     /**
 170      * Decode a single argument in an array and return the number of elements
 171      * used.
 172      *
 173      * @param args The array of arguments.
 174      * @param i    The argument to decode.
 175      * @return     The number of array elements used when the argument was
 176      *             decoded.


 290 
 291         // Appletviewer's main class is the debuggee
 292         newArgs[current++] = "sun.applet.Main";
 293 
 294         // Append all the of the original appletviewer arguments,
 295         // leaving out the "-debug" option.
 296         for (int i = 0; i < args.length; i++) {
 297             if (!("-debug".equals(args[i]))) {
 298                 newArgs[current++] = args[i];
 299             }
 300         }
 301 
 302         // LAUNCH THE DEBUGGER
 303         // Reflection is used for two reasons:
 304         // 1) The debugger classes are on classpath and thus must be loaded
 305         // by the application class loader. (Currently, appletviewer are
 306         // loaded through the boot class path out of rt.jar.)
 307         // 2) Reflection removes any build dependency between appletviewer
 308         // and jdb.
 309         try {
 310             Class c = Class.forName("com.sun.tools.example.debug.tty.TTY", true,
 311                                     ClassLoader.getSystemClassLoader());
 312             Method m = c.getDeclaredMethod("main",
 313                                            new Class[] { String[].class });
 314             m.invoke(null, new Object[] { newArgs });
 315         } catch (ClassNotFoundException cnfe) {
 316             System.err.println(lookup("main.debug.cantfinddebug"));
 317             return 1;
 318         } catch (NoSuchMethodException nsme) {
 319             System.err.println(lookup("main.debug.cantfindmain"));
 320             return 1;
 321         } catch (InvocationTargetException ite) {
 322             System.err.println(lookup("main.debug.exceptionindebug"));
 323             return 1;
 324         } catch (IllegalAccessException iae) {
 325             System.err.println(lookup("main.debug.cantaccess"));
 326             return 1;
 327         }
 328         return 0;
 329     }
 330 
 331     private void init() {
 332         // GET APPLETVIEWER USER-SPECIFIC PROPERTIES
 333         Properties avProps = getAVProps();


 350         // Define which properties can be read by applets.
 351         // A property named by "key" can be read only when its twin
 352         // property "key.applet" is true.  The following ten properties
 353         // are open by default.  Any other property can be explicitly
 354         // opened up by the browser user by calling appletviewer with
 355         // -J-Dkey.applet=true
 356         avProps.put("java.version.applet", "true");
 357         avProps.put("java.vendor.applet", "true");
 358         avProps.put("java.vendor.url.applet", "true");
 359         avProps.put("java.class.version.applet", "true");
 360         avProps.put("os.name.applet", "true");
 361         avProps.put("os.version.applet", "true");
 362         avProps.put("os.arch.applet", "true");
 363         avProps.put("file.separator.applet", "true");
 364         avProps.put("path.separator.applet", "true");
 365         avProps.put("line.separator.applet", "true");
 366 
 367         // Read in the System properties.  If something is going to be
 368         // over-written, warn about it.
 369         Properties sysProps = System.getProperties();
 370         for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements(); ) {
 371             String key = (String) e.nextElement();
 372             String val = sysProps.getProperty(key);
 373             String oldVal;
 374             if ((oldVal = (String) avProps.setProperty(key, val)) != null)
 375                 System.err.println(lookup("main.warn.prop.overwrite", key,
 376                                           oldVal, val));
 377         }
 378 
 379         // INSTALL THE PROPERTY LIST
 380         System.setProperties(avProps);
 381 
 382         // Create and install the security manager
 383         if (!noSecurityFlag) {
 384             System.setSecurityManager(new AppletSecurity());
 385         } else {
 386             System.err.println(lookup("main.nosecmgr"));
 387         }
 388 
 389         // REMIND: Create and install a socket factory!
 390     }




  67         userHome.canWrite();
  68 
  69         theUserPropertiesFile = new File(userHome, ".appletviewer");
  70     }
  71 
  72     // i18n
  73     private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer");
  74 
  75     /**
  76      * Member variables set according to options passed in to AppletViewer.
  77      */
  78     private boolean debugFlag = false;
  79     private boolean helpFlag  = false;
  80     private String  encoding  = null;
  81     private boolean noSecurityFlag  = false;
  82     private static boolean cmdLineTestFlag = false;
  83 
  84     /**
  85      * The list of valid URLs passed in to AppletViewer.
  86      */
  87     private static Vector<URL> urlList = new Vector<>(1);
  88 
  89     // This is used in init().  Getting rid of this is desirable but depends
  90     // on whether the property that uses it is necessary/standard.
  91     public static final String theVersion = System.getProperty("java.version");
  92 
  93     /**
  94      * The main entry point into AppletViewer.
  95      */
  96     public static void main(String [] args) {
  97         Main m = new Main();
  98         int ret = m.run(args);
  99 
 100         // Exit immediately if we got some sort of error along the way.
 101         // For debugging purposes, if we have passed in "-XcmdLineTest" we
 102         // force a premature exit.
 103         if ((ret != 0) || (cmdLineTestFlag))
 104             System.exit(ret);
 105     }
 106 
 107     private int run(String [] args) {


 136         }
 137 
 138         if (debugFlag) {
 139             // START A DEBUG SESSION
 140             // Given the current architecture, we will end up decoding the
 141             // arguments again, but at least we are guaranteed to have
 142             // arguments which are valid.
 143             return invokeDebugger(args);
 144         }
 145 
 146         // INSTALL THE SECURITY MANAGER (if necessary)
 147         if (!noSecurityFlag && (System.getSecurityManager() == null))
 148             init();
 149 
 150         // LAUNCH APPLETVIEWER FOR EACH URL
 151         for (int i = 0; i < urlList.size(); i++) {
 152             try {
 153                 // XXX 5/17 this parsing method should be changed/fixed so that
 154                 // it doesn't do both parsing of the html file and launching of
 155                 // the AppletPanel
 156                 AppletViewer.parse(urlList.elementAt(i), encoding);
 157             } catch (IOException e) {
 158                 System.err.println(lookup("main.err.io", e.getMessage()));
 159                 return 1;
 160             }
 161         }
 162         return 0;
 163     }
 164 
 165     private static void usage() {
 166         System.out.println(lookup("usage"));
 167     }
 168 
 169     /**
 170      * Decode a single argument in an array and return the number of elements
 171      * used.
 172      *
 173      * @param args The array of arguments.
 174      * @param i    The argument to decode.
 175      * @return     The number of array elements used when the argument was
 176      *             decoded.


 290 
 291         // Appletviewer's main class is the debuggee
 292         newArgs[current++] = "sun.applet.Main";
 293 
 294         // Append all the of the original appletviewer arguments,
 295         // leaving out the "-debug" option.
 296         for (int i = 0; i < args.length; i++) {
 297             if (!("-debug".equals(args[i]))) {
 298                 newArgs[current++] = args[i];
 299             }
 300         }
 301 
 302         // LAUNCH THE DEBUGGER
 303         // Reflection is used for two reasons:
 304         // 1) The debugger classes are on classpath and thus must be loaded
 305         // by the application class loader. (Currently, appletviewer are
 306         // loaded through the boot class path out of rt.jar.)
 307         // 2) Reflection removes any build dependency between appletviewer
 308         // and jdb.
 309         try {
 310             Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY", true,
 311                                     ClassLoader.getSystemClassLoader());
 312             Method m = c.getDeclaredMethod("main",
 313                                            new Class<?>[] { String[].class });
 314             m.invoke(null, new Object[] { newArgs });
 315         } catch (ClassNotFoundException cnfe) {
 316             System.err.println(lookup("main.debug.cantfinddebug"));
 317             return 1;
 318         } catch (NoSuchMethodException nsme) {
 319             System.err.println(lookup("main.debug.cantfindmain"));
 320             return 1;
 321         } catch (InvocationTargetException ite) {
 322             System.err.println(lookup("main.debug.exceptionindebug"));
 323             return 1;
 324         } catch (IllegalAccessException iae) {
 325             System.err.println(lookup("main.debug.cantaccess"));
 326             return 1;
 327         }
 328         return 0;
 329     }
 330 
 331     private void init() {
 332         // GET APPLETVIEWER USER-SPECIFIC PROPERTIES
 333         Properties avProps = getAVProps();


 350         // Define which properties can be read by applets.
 351         // A property named by "key" can be read only when its twin
 352         // property "key.applet" is true.  The following ten properties
 353         // are open by default.  Any other property can be explicitly
 354         // opened up by the browser user by calling appletviewer with
 355         // -J-Dkey.applet=true
 356         avProps.put("java.version.applet", "true");
 357         avProps.put("java.vendor.applet", "true");
 358         avProps.put("java.vendor.url.applet", "true");
 359         avProps.put("java.class.version.applet", "true");
 360         avProps.put("os.name.applet", "true");
 361         avProps.put("os.version.applet", "true");
 362         avProps.put("os.arch.applet", "true");
 363         avProps.put("file.separator.applet", "true");
 364         avProps.put("path.separator.applet", "true");
 365         avProps.put("line.separator.applet", "true");
 366 
 367         // Read in the System properties.  If something is going to be
 368         // over-written, warn about it.
 369         Properties sysProps = System.getProperties();
 370         for (Enumeration<?> e = sysProps.propertyNames(); e.hasMoreElements(); ) {
 371             String key = (String) e.nextElement();
 372             String val = sysProps.getProperty(key);
 373             String oldVal;
 374             if ((oldVal = (String) avProps.setProperty(key, val)) != null)
 375                 System.err.println(lookup("main.warn.prop.overwrite", key,
 376                                           oldVal, val));
 377         }
 378 
 379         // INSTALL THE PROPERTY LIST
 380         System.setProperties(avProps);
 381 
 382         // Create and install the security manager
 383         if (!noSecurityFlag) {
 384             System.setSecurityManager(new AppletSecurity());
 385         } else {
 386             System.err.println(lookup("main.nosecmgr"));
 387         }
 388 
 389         // REMIND: Create and install a socket factory!
 390     }