KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > DrJava


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava;
35
36 import static edu.rice.cs.drjava.config.OptionConstants.*;
37
38 import java.io.File JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.io.ByteArrayOutputStream JavaDoc;
41 import java.net.MalformedURLException JavaDoc;
42 import java.net.URL JavaDoc;
43 import java.net.URLClassLoader JavaDoc;
44 import java.util.ArrayList JavaDoc;
45 import java.util.LinkedList JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.jar.JarFile JavaDoc;
48 import java.util.jar.Manifest JavaDoc;
49
50 import javax.swing.JFileChooser JavaDoc;
51 import javax.swing.JOptionPane JavaDoc;
52 import javax.swing.SwingUtilities JavaDoc;
53
54 import edu.rice.cs.drjava.config.FileConfiguration;
55 import edu.rice.cs.drjava.config.FileOption;
56 import edu.rice.cs.drjava.platform.PlatformFactory;
57 import edu.rice.cs.drjava.ui.DrJavaErrorHandler;
58 import edu.rice.cs.drjava.ui.ClassPathFilter;
59 import edu.rice.cs.drjava.ui.SplashScreen;
60 import edu.rice.cs.util.ArgumentTokenizer;
61 import edu.rice.cs.util.FileOps;
62 import edu.rice.cs.util.Log;
63 import edu.rice.cs.util.classloader.ToolsJarClassLoader;
64 import edu.rice.cs.util.newjvm.ExecJVM;
65
66 /** Startup class for DrJava consisting entirely of static members. The main method reads the .drjava file (creating
67  * one if none exists) to get the critical information required to start the main JVM for DrJava:
68  * (i) the location of tools.jar in the Java JDK installed on this machine (so DrJava can invoke the javac compiler
69  * stored in tools.jar)
70  * (ii) the argument string for invoking the main JVM (notably -X options used to determine maximum heap size, etc.)
71  * @version $Id: DrJava.java 4079 2007-01-22 20:20:33Z dlsmith $
72  */

73 public class DrJava {
74   
75   private static Log _log = new Log("DrJava.txt", false);
76   
77   /** Class to probe to see if the debugger is available */
78   public static final String JavaDoc TEST_DEBUGGER_CLASS = "com.sun.jdi.Bootstrap";
79   /** Class to probe to see if the 1.4 compiler is available */
80   public static final String JavaDoc TEST_14_COMPILER_CLASS = "com.sun.tools.javac.v8.JavaCompiler";
81   /** Class to probe to see if the 1.5/1.6 compiler is available */
82   public static final String JavaDoc TEST_15_16_COMPILER_CLASS = "com.sun.tools.javac.main.JavaCompiler";
83   
84   /** Class to probe to see if the compiler is available; either TEST_14_COMPILER_CLASS or TEST_15_16_COMPILER_CLASS. */
85   public static final String JavaDoc TEST_COMPILER_CLASS;
86   static {
87     if (System.getProperty("java.version").startsWith("1.4")) {
88       TEST_COMPILER_CLASS = TEST_14_COMPILER_CLASS;
89     }
90     else {
91       TEST_COMPILER_CLASS = TEST_15_16_COMPILER_CLASS;
92     }
93   }
94   
95   private static final String JavaDoc DEFAULT_MAX_HEAP_SIZE_ARG = "-Xmx128M";
96   
97   private static final ArrayList JavaDoc<String JavaDoc> _filesToOpen = new ArrayList JavaDoc<String JavaDoc>();
98   private static final ArrayList JavaDoc<String JavaDoc> _jvmArgs = new ArrayList JavaDoc<String JavaDoc>();
99
100   static volatile boolean _showDebugConsole = false;
101   
102   /* Config objects can't be public static final, since we have to delay construction until we know the
103    * config file's location. (Might be specified on command line.) Instead, use accessor methods to
104    * prevent others from assigning new values. */

105
106   /** Default properties file used by the configuration object, i.e. ".drjava" in the user's home directory. */
107   public static final File JavaDoc DEFAULT_PROPERTIES_FILE = new File JavaDoc(System.getProperty("user.home"), ".drjava");
108   
109   /** Properties file used by the configuration object. Defaults to DEFAULT_PROPERTIES_FILE. */
110   private static volatile File JavaDoc _propertiesFile = DEFAULT_PROPERTIES_FILE;
111   
112   /** Configuration object with all customized and default values. Initialized from _propertiesFile. */
113   private static volatile FileConfiguration _config = _initConfig();
114   
115   private static ToolsJarClassLoader _toolsLoader = new ToolsJarClassLoader(getConfig().getSetting(JAVAC_LOCATION));
116   private static final ClassLoader JavaDoc _thisLoader = DrJava.class.getClassLoader();
117
118   /** Returns the properties file used by the configuration object. */
119   public static File JavaDoc getPropertiesFile() { return _propertiesFile; }
120
121   /** Returns the configuration object with all customized and default values. */
122   public static FileConfiguration getConfig() { return _config; }
123
124   /** @return an array of the files that were passed on the command line. */
125   public static String JavaDoc[] getFilesToOpen() { return _filesToOpen.toArray(new String JavaDoc[0]); }
126   
127   /** @return true if the debug console should be enabled */
128   public static boolean getShowDebugConsole() { return _showDebugConsole; }
129   
130   /** Starts running DrJava.
131    * @param args Command line argument array
132    */

133   public static void main(final String JavaDoc[] args) {
134     // Platform-specific UI setup.
135
PlatformFactory.ONLY.beforeUISetup();
136     
137     new SplashScreen().flash();
138 // Utilities.showDebug("Calling configureAndLoadDrJavaRoot with args = " + args);
139
configureAndLoadDrJavaRoot(args);
140   }
141   
142   public static void configureAndLoadDrJavaRoot(String JavaDoc[] args) {
143     try {
144       // handleCommandLineArgs will return true if the DrJava should be loaded
145
if (handleCommandLineArgs(args)) {
146         
147         // Check that compiler and debugger are available on classpath (including tools.jar location)
148
boolean restart = !checkForCompilersAndDebugger(args);
149         
150         // Restart if there are custom JVM args
151
restart |= getConfig().getSetting(MASTER_JVM_ARGS).length() > 0;
152         
153         LinkedList JavaDoc<String JavaDoc> classArgsList = new LinkedList JavaDoc<String JavaDoc>();
154         classArgsList.addAll(_filesToOpen);
155
156         // Add the parameters "-debugConsole" to classArgsList if _showDebugConsole is true
157
if (_showDebugConsole) { classArgsList.addFirst("-debugConsole"); }
158         
159         if (!_propertiesFile.equals(DEFAULT_PROPERTIES_FILE)) {
160           // Placed in reversed order to get "-config filename"
161
classArgsList.addFirst(_propertiesFile.getAbsolutePath());
162           classArgsList.addFirst("-config");
163         }
164
165         String JavaDoc[] classArgs = classArgsList.toArray(new String JavaDoc[0]);
166         
167         if (restart) {
168           // Determine classpath
169
String JavaDoc pathSep = System.getProperty("path.separator");
170           String JavaDoc classPath = System.getProperty("java.class.path");
171           
172           // Include both the javac location stored in .drjava prefences and the path proposed by ToolsJarClassLoader
173
File JavaDoc toolsFromConfig = getConfig().getSetting(JAVAC_LOCATION);
174           classPath += pathSep + ToolsJarClassLoader.getToolsJarClassPath(toolsFromConfig);
175         
176           // Run a new copy of DrJava and exit
177
try {
178 // Utilities.showDebug("Starting DrJavaRoot with classArgs = " + Arrays.toString(classArgs) + "; classPath = " + classPath +
179
// "; jvmArgs = " + _jvmArgs + "; workDir = " + workDir);
180
ExecJVM.runJVM("edu.rice.cs.drjava.DrJavaRoot", classArgs, classPath, _jvmArgs.toArray(new String JavaDoc[0]), null);
181           }
182           catch (IOException JavaDoc ioe) {
183             // Display error
184
final String JavaDoc[] text = {
185               "DrJava was unable to load its compiler and debugger. Would you ",
186               "like to start DrJava without a compiler and debugger?", "\nReason: " + ioe.toString()
187             };
188             int result = JOptionPane.showConfirmDialog(null, text, "Could Not Load Compiler and Debugger",
189                                                        JOptionPane.YES_NO_OPTION);
190             if (result != JOptionPane.YES_OPTION) { System.exit(0); }
191           }
192         }
193         
194         else {
195           // No restart -- just invoke DrJavaRoot.main.
196
DrJavaRoot.main(classArgs);
197         }
198       }
199     }
200     catch (Throwable JavaDoc t) {
201       // Show any errors to the System.err and in an DrJavaErrorHandler
202
System.out.println(t.getClass().getName() + ": " + t.getMessage());
203       t.printStackTrace(System.err);System.out.println("error thrown");
204       new DrJavaErrorHandler().handle(t);
205     }
206   }
207   
208   /** Handles any command line arguments that have been specified.
209    * @return true if DrJava should load, false if not
210    */

211   static boolean handleCommandLineArgs(String JavaDoc[] args) {
212     boolean heapSizeGiven = false; // indicates whether args includes an argument of the form -Xmx<number>
213

214     // Loop through arguments looking for known options
215
int argIndex = 0;
216     int len = args.length;
217     _filesToOpen.clear();
218     
219     while(argIndex < len) {
220       String JavaDoc arg = args[argIndex++];
221       
222       if (arg.equals("-config")) {
223         if (len == argIndex) {
224           // config option is missing file name; should we generate an error?
225
return true;
226         }
227         // arg.length > i+1 implying args list incudes config file name and perhaps files to open
228
setPropertiesFile(args[argIndex++]);
229         _config = _initConfig(); // read specified .djrava file into _config
230
_toolsLoader = new ToolsJarClassLoader(getConfig().getSetting(JAVAC_LOCATION));
231       }
232       
233       else if (arg.startsWith("-X") || arg.startsWith("-D")) {
234         if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
235         _jvmArgs.add(arg);
236       }
237       
238       else if (arg.equals("-debugConsole")) _showDebugConsole = true;
239       
240       else if (arg.equals("-help") || arg.equals("-?")) {
241         displayUsage();
242         return false;
243       }
244       else {
245         // this is the first file to open, do not consume
246
--argIndex;
247         break;
248       }
249     }
250     
251     List JavaDoc<String JavaDoc> configArgs = ArgumentTokenizer.tokenize(getConfig().getSetting(MASTER_JVM_ARGS));
252     for (String JavaDoc arg : configArgs) {
253       if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
254       _jvmArgs.add(arg);
255     }
256
257     if (PlatformFactory.ONLY.isMacPlatform()) {
258       String JavaDoc iconLoc = System.getProperty("edu.rice.cs.drjava.icon");
259       if (iconLoc != null) { // we are running inside the Mac app wrapper
260
_jvmArgs.add("-Xdock:name=DrJava");
261         _jvmArgs.add("-Xdock:icon=" + iconLoc);
262       }
263     }
264     
265     if (!heapSizeGiven) { _jvmArgs.add(DEFAULT_MAX_HEAP_SIZE_ARG); }
266         
267     _log.log("_jvmArgs = " + _jvmArgs);
268
269     // Open the remaining args as filenames
270

271     for (int i = argIndex; i < len; i++) { _filesToOpen.add(args[i]); }
272     return true;
273   }
274
275   /** Displays a usage message about the available options. */
276   static void displayUsage() {
277     final StringBuilder JavaDoc buf = new StringBuilder JavaDoc();
278     buf.append("Usage: java -jar drjava.jar [OPTIONS] [FILES]\n\n");
279     buf.append("where options include:\n");
280     buf.append(" -config [FILE] use a custom config file\n");
281     buf.append(" -help | -? print this help message\n");
282     buf.append(" -X<jvmOption> specify a JVM configuration option for the master DrJava JVM\n");
283     buf.append(" -D<name>[=<value>] set a Java property for the master DrJava JVM\n");
284     System.out.print(buf.toString());
285   }
286   
287    /** Check to see if a compiler and the debugger are available in a tools.jar file. If it can't find them, it
288     * prompts the user to optionally specify the location of a propert tools.jar file.
289     * @param args Command line argument array, in case we need to restart
290     * @return {@code true} iff the compiler and debugger are available without restarting
291     */

292   static boolean checkForCompilersAndDebugger(String JavaDoc[] args) {
293     if (canLoad(_thisLoader, TEST_COMPILER_CLASS) && canLoad(_thisLoader, TEST_DEBUGGER_CLASS)) {
294       return true;
295     }
296     else {
297       boolean haveCompiler = canLoad(_thisLoader, TEST_COMPILER_CLASS) ||
298                              canLoad(_toolsLoader, TEST_COMPILER_CLASS);
299       boolean haveDebugger = canLoad(_thisLoader, TEST_DEBUGGER_CLASS) ||
300                              canLoad(_toolsLoader, TEST_DEBUGGER_CLASS);
301       if (!haveCompiler || !haveDebugger) { promptForToolsJar(!haveCompiler, !haveDebugger); }
302       return false;
303     }
304   }
305
306   /** Returns whether the debugger will be able to load successfully. Checks for the ability to load the
307    * com.sun.jdi.Bootstrap class.
308    */

309   public static boolean hasAvailableDebugger() {
310     return canLoad(_thisLoader, TEST_DEBUGGER_CLASS) || canLoad(_toolsLoader, TEST_DEBUGGER_CLASS);
311   }
312   
313   public static boolean hasAvailableCompiler() {
314    return canLoad(_thisLoader, TEST_COMPILER_CLASS) || canLoad(_toolsLoader, TEST_COMPILER_CLASS);
315   }
316   
317   /* Tests whether the specified class loader can load the specifed class */
318    public static boolean canLoad(ClassLoader JavaDoc cl, String JavaDoc className) {
319     try {
320       cl.loadClass(className);
321       return true;
322     }
323     catch(ClassNotFoundException JavaDoc e) { return false; }
324     catch(UnsupportedClassVersionError JavaDoc e) { return false; }
325     catch(RuntimeException JavaDoc e) { return false; }
326   }
327   
328   /** Prompts the user that the location of tools.jar needs to be specified to be able to use the compiler and/or the
329    * debugger.
330    * @param needCompiler whether DrJava needs tools.jar for a compiler
331    * @param needDebugger whether DrJava needs tools.jar for the debugger
332    */

333   public static void promptForToolsJar(boolean needCompiler, boolean needDebugger) {
334     File JavaDoc selectedFile = getConfig().getSetting(JAVAC_LOCATION);
335     String JavaDoc selectedVersion = _getToolsJarVersion(selectedFile);
336     
337     final String JavaDoc[] text;
338     if (selectedVersion==null) {
339       text = new String JavaDoc[] {
340         "DrJava cannot find a 'tools.jar' file for the version of Java ",
341         "that is being used to run DrJava (Java version "+System.getProperty("java.version")+").",
342         "Would you like to specify the location of the requisite 'tools.jar' file?",
343         "If you say 'No', DrJava might be unable to compile or debug Java programs."
344       };
345     }
346     else {
347       text = new String JavaDoc[] {
348         "DrJava cannot find a 'tools.jar' file for the version of Java ",
349         "that is being used to run DrJava (Java version "+System.getProperty("java.version")+").",
350         "The file you have selected appears to be for version "+selectedVersion+".",
351         "Would you like to specify the ocation of the requisite 'tools.jar' file?",
352         "If you say 'No', DrJava might be unable to compile or debug Java programs.)"
353       };
354     }
355     
356     int result = JOptionPane.showConfirmDialog(null, text, "Locate 'tools.jar'?", JOptionPane.YES_NO_OPTION);
357
358     if (result == JOptionPane.YES_OPTION) {
359       JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
360       chooser.setFileFilter(new ClassPathFilter() {
361         public boolean accept(File JavaDoc f) {
362           if (f.isDirectory()) return true;
363           String JavaDoc ext = getExtension(f);
364           return ext != null && ext.equals("jar");
365         }
366         public String JavaDoc getDescription() { return "Jar Files"; }
367       });
368
369       // Loop until we find a good tools.jar or the user gives up
370
do {
371         if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
372           File JavaDoc jar = chooser.getSelectedFile();
373
374           if (jar != null) {
375             // set the tools.jar property
376
getConfig().setSetting(JAVAC_LOCATION, jar);
377
378             // Adjust if we needed a compiler
379
if (needCompiler && classLoadersCanFind(TEST_COMPILER_CLASS)) needCompiler = false;
380
381             // Adjust if we need a debugger
382
if (needDebugger && classLoadersCanFind(TEST_DEBUGGER_CLASS)) needDebugger = false;
383           }
384         }
385 // Utilities.showDebug("need Compiler = " + needCompiler + "; needDebugger = " + needDebugger);
386
}
387       while ((needCompiler || needDebugger) && _userWantsToPickAgain());
388       
389       // Save config with good tools.jar if available
390
if ((! needCompiler) && (! needDebugger)) _saveConfig();
391     }
392   }
393   
394  
395   /** Returns whether the debugger will be able to load successfully when we start the DrJava master JVM with
396    * tools.jar on the classpath. Uses ToolsJarClassLoader to try to load com.sun.jdi.Bootstrap.
397    */

398   public static boolean classLoadersCanFind(String JavaDoc className) {
399     // First check the specified location
400
File JavaDoc jar = getConfig().getSetting(JAVAC_LOCATION);
401     if (jar != FileOption.NULL_FILE) {
402       try {
403         URL JavaDoc[] urls = new URL JavaDoc[] { FileOps.toURL(jar) };
404         URLClassLoader JavaDoc loader = new URLClassLoader JavaDoc(urls);
405         if (canLoad(loader, className)) return true;
406       }
407       catch(MalformedURLException JavaDoc e) { /* fall through */ }
408     }
409     return canLoad(_toolsLoader, className);
410   }
411     
412   /** Switches the config object to use a custom config file. Ensures that Java source files aren't
413    * accidentally used.
414    */

415   static void setPropertiesFile(String JavaDoc fileName) {
416     if (!fileName.endsWith(".java")) _propertiesFile = new File JavaDoc(fileName);
417   }
418   
419   /** Initializes the configuration object with the current notion of the properties file.
420    * @throws IllegalStateException if config has already been assigned
421    */

422   static FileConfiguration _initConfig() throws IllegalStateException JavaDoc {
423 // // Make sure someone doesn't try to change the config object.
424
// if (_config != null) throw new IllegalStateException("Can only call initConfig once!");
425

426     FileConfiguration config;
427
428     try { _propertiesFile.createNewFile(); } // be nice and ensure a config file if there isn't one
429
catch (IOException JavaDoc e) { /* IOException occurred, continue without a real file */ }
430     
431     config = new FileConfiguration(_propertiesFile);
432     try { config.loadConfiguration(); }
433     catch (Exception JavaDoc e) {
434       // Problem parsing the config file. Use defaults and remember what happened (for the UI).
435
config.resetToDefaults();
436       config.storeStartupException(e);
437     }
438     _config = config; // required to support calls on DrJava._initConfig() in unit tests
439
return config;
440   }
441
442   /** Saves the contents of the config file. TO DO: log any IOExceptions that occur. */
443   protected static void _saveConfig() {
444     try { getConfig().saveConfiguration(); }
445     catch(IOException JavaDoc e) {
446       JOptionPane.showMessageDialog(null,
447                                     "Could not save the location of tools.jar in \n" +
448                                     "the '.drjava' file in your home directory. \n" +
449                                     "Another process may be using the file.\n\n" + e,
450                                     "Could Not Save Changes",
451                                     JOptionPane.ERROR_MESSAGE);
452       // TODO: log this error
453
}
454   }
455
456   /** Displays a prompt to the user indicating that tools.jar could not be found in the specified location, and asks
457    * if he would like to specify a new location.
458    */

459   private static boolean _userWantsToPickAgain() {
460     File JavaDoc selectedFile = getConfig().getSetting(JAVAC_LOCATION);
461     String JavaDoc selectedVersion = _getToolsJarVersion(selectedFile);
462     
463     final String JavaDoc[] text;
464     if (selectedVersion==null) {
465       text = new String JavaDoc[] {
466         "The file you chose did not appear to be the correct 'tools.jar'",
467         "that is compatible with the version of Java that is used to",
468         "run DrJava (Java version "+System.getProperty("java.version")+").",
469         "Your choice might be an incompatible version of the file.",
470         "Would you like to pick again? The 'tools.jar' file is ",
471         "generally located in the 'lib' subdirectory under your ",
472         "JDK installation directory.",
473         "(If you say 'No', DrJava might be unable to compile or ",
474         "debug programs.)"
475       };
476     }
477     else {
478       text = new String JavaDoc[] {
479         "The file you chose did not appear to be the correct 'tools.jar'",
480         "that is compatible with the version of Java that is used to",
481         "run DrJava (Java version "+System.getProperty("java.version")+").",
482         "The file you have selected appears to be for",
483         "Java version "+selectedVersion+".",
484         "Your choice might be an incompatible version of the file.",
485         "Would you like to pick again? The 'tools.jar' file is ",
486         "generally located in the 'lib' subdirectory under your ",
487         "JDK installation directory.",
488         "If you say 'No', DrJava might be unable to compile or ",
489         "debug programs."
490       };
491     }
492
493     int result = JOptionPane.showConfirmDialog(null, text, "Locate 'tools.jar'?", JOptionPane.YES_NO_OPTION);
494     return result == JOptionPane.YES_OPTION;
495   }
496   
497   /** @return a string with the suspected version of the tools.jar file, or null if an error occurred. */
498   private static String JavaDoc _getToolsJarVersion(File JavaDoc toolsJarFile) {
499     try {
500       JarFile JavaDoc jf = new JarFile JavaDoc(toolsJarFile);
501       Manifest JavaDoc mf = jf.getManifest();
502       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
503       mf.write(baos);
504       String JavaDoc str = baos.toString();
505       // the expected format of str is:
506
// Manifest-Version: 1.0
507
// Created-By: 1.5.0_07 (Sun Microsystems Inc.)
508
//
509
final String JavaDoc CB = "Created-By: ";
510       int beginPos = str.indexOf(CB);
511       if (beginPos >= 0) {
512         beginPos += CB.length();
513         int endPos = str.indexOf(System.getProperty("line.separator"), beginPos);
514         if (endPos >= 0) return str.substring(beginPos, endPos);
515         else {
516           endPos = str.indexOf(' ', beginPos);
517           if (endPos >= 0) return str.substring(beginPos, endPos);
518           else {
519             endPos = str.indexOf('\t', beginPos);
520             if (endPos >= 0) return str.substring(beginPos, endPos);
521           }
522         }
523       }
524     }
525     catch(Exception JavaDoc rte) { /* ignore, just return null */ }
526     return null;
527   }
528 }
529
530
Popular Tags