< prev index next >

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

Print this page




 212             return 1;
 213         } else if (arg.startsWith("-")) {
 214             throw new ParseException(lookup("main.err.unsupportedopt", arg));
 215         } else {
 216             // we found what we hope is a url
 217             URL url = parseURL(arg);
 218             if (url != null) {
 219                 urlList.addElement(url);
 220                 return 1;
 221             }
 222         }
 223         return 0;
 224     }
 225 
 226     /**
 227      * Following the relevant RFC, construct a valid URL based on the passed in
 228      * string.
 229      *
 230      * @param url  a string which represents either a relative or absolute URL.
 231      * @return     a URL when the passed in string can be interpreted according
 232      *             to the RFC, <code>null</code> otherwise.
 233      * @exception  ParseException
 234      *             Thrown when we are unable to construct a proper URL from the
 235      *             passed in string.
 236      */
 237     private URL parseURL(String url) throws ParseException {
 238         URL u = null;
 239         // prefix of the urls with 'file' scheme
 240         String prefix = "file:";
 241 
 242         try {
 243             if (url.indexOf(':') <= 1)
 244             {
 245                 // appletviewer accepts only unencoded filesystem paths
 246                 u = ParseUtil.fileToEncodedURL(new File(url));
 247             } else if (url.startsWith(prefix) &&
 248                        url.length() != prefix.length() &&
 249                        !(new File(url.substring(prefix.length())).isAbsolute()))
 250             {
 251                 // relative file URL, like this "file:index.html"
 252                 // ensure that this file URL is absolute
 253                 // ParseUtil.fileToEncodedURL should be done last (see 6329251)
 254                 String path = ParseUtil.fileToEncodedURL(new File(System.getProperty("user.dir"))).getPath() +
 255                     url.substring(prefix.length());
 256                 u = new URL("file", "", path);
 257             } else {
 258                 // appletviewer accepts only encoded urls
 259                 u = new URL(url);
 260             }
 261         } catch (MalformedURLException e) {
 262             throw new ParseException(lookup("main.err.badurl",
 263                                             url, e.getMessage()));
 264         }
 265 
 266         return u;
 267     }
 268 
 269     /**
 270      * Invoke the debugger with the arguments passed in to appletviewer.
 271      *
 272      * @param args The arguments passed into the debugger.
 273      * @return     <code>0</code> if the debugger is invoked successfully,
 274      *             <code>1</code> otherwise.
 275      */
 276     private int invokeDebugger(String [] args) {
 277         // CONSTRUCT THE COMMAND LINE
 278         String [] newArgs = new String[args.length + 1];
 279         int current = 0;
 280 
 281         // Add a -classpath argument that prevents
 282         // the debugger from launching appletviewer with the default of
 283         // ".". appletviewer's classpath should never contain valid
 284         // classes since they will result in security exceptions.
 285         // Ideally, the classpath should be set to "", but the VM won't
 286         // allow an empty classpath, so a phony directory name is used.
 287         String phonyDir = System.getProperty("java.home") +
 288                           File.separator + "phony";
 289         newArgs[current++] = "-Djava.class.path=" + phonyDir;
 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,




 212             return 1;
 213         } else if (arg.startsWith("-")) {
 214             throw new ParseException(lookup("main.err.unsupportedopt", arg));
 215         } else {
 216             // we found what we hope is a url
 217             URL url = parseURL(arg);
 218             if (url != null) {
 219                 urlList.addElement(url);
 220                 return 1;
 221             }
 222         }
 223         return 0;
 224     }
 225 
 226     /**
 227      * Following the relevant RFC, construct a valid URL based on the passed in
 228      * string.
 229      *
 230      * @param url  a string which represents either a relative or absolute URL.
 231      * @return     a URL when the passed in string can be interpreted according
 232      *             to the RFC, {@code null} otherwise.
 233      * @exception  ParseException
 234      *             Thrown when we are unable to construct a proper URL from the
 235      *             passed in string.
 236      */
 237     private URL parseURL(String url) throws ParseException {
 238         URL u = null;
 239         // prefix of the urls with 'file' scheme
 240         String prefix = "file:";
 241 
 242         try {
 243             if (url.indexOf(':') <= 1)
 244             {
 245                 // appletviewer accepts only unencoded filesystem paths
 246                 u = ParseUtil.fileToEncodedURL(new File(url));
 247             } else if (url.startsWith(prefix) &&
 248                        url.length() != prefix.length() &&
 249                        !(new File(url.substring(prefix.length())).isAbsolute()))
 250             {
 251                 // relative file URL, like this "file:index.html"
 252                 // ensure that this file URL is absolute
 253                 // ParseUtil.fileToEncodedURL should be done last (see 6329251)
 254                 String path = ParseUtil.fileToEncodedURL(new File(System.getProperty("user.dir"))).getPath() +
 255                     url.substring(prefix.length());
 256                 u = new URL("file", "", path);
 257             } else {
 258                 // appletviewer accepts only encoded urls
 259                 u = new URL(url);
 260             }
 261         } catch (MalformedURLException e) {
 262             throw new ParseException(lookup("main.err.badurl",
 263                                             url, e.getMessage()));
 264         }
 265 
 266         return u;
 267     }
 268 
 269     /**
 270      * Invoke the debugger with the arguments passed in to appletviewer.
 271      *
 272      * @param args The arguments passed into the debugger.
 273      * @return     {@code 0} if the debugger is invoked successfully,
 274      *             {@code 1} otherwise.
 275      */
 276     private int invokeDebugger(String [] args) {
 277         // CONSTRUCT THE COMMAND LINE
 278         String [] newArgs = new String[args.length + 1];
 279         int current = 0;
 280 
 281         // Add a -classpath argument that prevents
 282         // the debugger from launching appletviewer with the default of
 283         // ".". appletviewer's classpath should never contain valid
 284         // classes since they will result in security exceptions.
 285         // Ideally, the classpath should be set to "", but the VM won't
 286         // allow an empty classpath, so a phony directory name is used.
 287         String phonyDir = System.getProperty("java.home") +
 288                           File.separator + "phony";
 289         newArgs[current++] = "-Djava.class.path=" + phonyDir;
 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,


< prev index next >