home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-05-02 | 13.7 KB | 482 lines |
- /* Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved. */
-
- /*
- * Demo.java
- *
- * Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved.
- *
- * Oracle grants you ("Licensee") a non-exclusive, royalty free, license
- * to use, modify and redistribute this software in source and binary code
- * form, provided that i) this copyright notice and license appear on all
- * copies of the software; and ii) Licensee does not utilize the software
- * in a manner which is disparaging to Oracle.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ORACLE AND ITS LICENSORS SHALL NOT BE
- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL ORACLE OR ITS
- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
- * OR INABILITY TO USE SOFTWARE, EVEN IF ORACLE HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * This software is not designed or intended for use in on-line control of
- * aircraft, air traffic, aircraft navigation or aircraft communications; or in
- * the design, construction, operation or maintenance of any nuclear
- * facility. Licensee represents and warrants that it will not use or
- * redistribute the Software for such purposes.
- */
-
-
- import oracle.help.Help;
- import oracle.help.library.Book;
- import oracle.help.library.helpset.HelpSet;
- import oracle.help.library.helpbook.HelpBook;
-
- import java.net.URL;
- import java.util.Enumeration;
- import java.util.Vector;
- import java.lang.Class;
-
- //Launch OracleHelp
- public class HelpLauncher
- {
- public HelpLauncher(String a_strHelpSet, String a_strHelpId)
- {
- //HelpLauncher31(a_strHelpSet, String a_strHelpId);
- // HelpLauncher32(a_strHelpSet,a_strHelpId);
- HelpLauncher322(a_strHelpSet, a_strHelpId);
- }
-
- //Help Launcher for OracleHelp 3.2.2/4.1.2
- public boolean HelpLauncher322(String a_strHelpSet, String a_strHelpId)
- {
- Help help = null;
- HelpSet helpset = null;
- String strHsUrl = "";
- String strJarName = "";
-
-
- //make help which can shut down JVM..
- Class htmlBrowserClass = null;
- try
- {
- htmlBrowserClass = Class.forName("oracle.help.htmlBrowser.ICEBrowser");
- }
- catch (Exception e)
- {
- htmlBrowserClass = null;
- System.err.println("HelpLauncher : Failed to load ICEBrowser");
- }
- help = new Help(htmlBrowserClass, false, true, true);
-
- boolean bSuccess = true;
-
- if (a_strHelpSet.endsWith(".jar"))
- {
- //Compressed help in jar, the class inside the jar should be "FileName"+"DocHelpSet"
- //and located either in "FileName".toLowCase() package or Unnamed Package
- strJarName = new String("");
- strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
- }
- else if (a_strHelpSet.endsWith(".hs"))
- {
- //Helpset file
- if (a_strHelpSet.charAt(0) == '/')
- strHsUrl = "file:" + a_strHelpSet;
- else
- strHsUrl = "file:/" + a_strHelpSet;
- }
- else
- {
- System.out.println("Unknown file extension name.");
- bSuccess = false;
- }
-
- //Build helpset object
- if (bSuccess)
- {
- try
- {
- if (strHsUrl.length () != 0)
- {
- //a hs file
- helpset = new HelpSet(new URL(strHsUrl));
- }
- else if (strJarName.length() != 0)
- {
- //a jar file
- String strPackageName = strJarName;
- String strClsName = "";
-
- //try to find the class in package
- Class clsName = null;
- boolean bFindClass = false;
- try
- {
- strClsName = strPackageName +"." + strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
-
- if (!bFindClass)
- {
- //try to find the class in unnamed package
- try
- {
- strClsName = strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
- }
-
- if (bFindClass)
- {
- String strHsName = strJarName + ".hs";
- helpset = new HelpSet(clsName, strHsName);
- }
- else
- {
- System.out.println("Can not find class in jar file:" + strJarName + ".class" );
- bSuccess = false;
- }
- }
- else
- {
- System.out.println("No file name ?!");
- bSuccess = false;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- bSuccess = false;
- }
- }
-
- if (!bSuccess)
- {
- System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
- }
- else
- {
- Book book = (Book)helpset;
- help.addBook(book);
- help.showNavigatorWindow();
-
- }
- return bSuccess;
- }
-
-
- //Use same command line parameter as JavaHelp Launch
- public static void main(String[] args)
- {
- String strHelpset = "";
- String strHelpPath = "";
- String strHelpsetUrl= "";
- String strHelpId = "";
- String strSize = "";
-
- while (args.length > 0)
- {
- if (args[0].equals("-helpset"))
- {
- // Name of HelpSet. Look for it in the classpath
- args = shiftArgs(args, 1);
- strHelpset = args[0];
- args = shiftArgs(args, 1);
- } else if (args[0].equals("-helppath")) {
- // This is a 1.2-only feature
- args = shiftArgs(args, 1);
- strHelpPath = args[0];
- args = shiftArgs(args, 1);
- } else if (args[0].equals("-hsURL")) {
- // This is the given URL for the HelpSet
- args = shiftArgs(args, 1);
- strHelpsetUrl = args[0];
- args = shiftArgs(args, 1);
- } else if (args[0].equals("-id")) {
- // This is the given ID in a HelpSet to display
- args = shiftArgs(args, 1);
- strHelpId = args[0];
- args = shiftArgs(args, 1);
- } else if (args[0].equals("-size")) {
- // This is the given ID in a HelpSet to display
- args = shiftArgs(args, 1);
- strSize = args[0];
- args = shiftArgs(args, 1);
- } else if (args[0].equals("-debug")) {
- args = shiftArgs(args, 1);
- } else {
- usage(null);
- }
- }
- HelpLauncher demo = new HelpLauncher(strHelpset, strHelpId);
- }
-
- //Usage: Same as JavaHelp
- protected static void usage(String msg) {
- if (msg != null) {
- System.err.println("HelpLauncher: " + msg);
- }
- System.err.println("Usage: HelpLauncher [-helpset name | -helppath path | -hsURL spec | -id target | -size width,height ]");
- System.exit(1);
- }
-
- //Shift argv
- private static String[] shiftArgs(String args[], int step) {
- int count = args.length;
- String back[] = new String[count-step];
- for (int i=0; i<count-step; i++) {
- back[i] = args[i+step];
- }
- return back;
- }
-
-
-
- /*
- //Help Launcher for OracleHelp 3.1.x
- public boolean HelpLauncher31(String a_strHelpSet, String a_strHelpId)
- {
- Help help = new Help();
- HelpSetFile helpset = null;
- String strHsUrl = "";
- String strJarName = "";
-
- boolean bSuccess = true;
-
- if (a_strHelpSet.endsWith(".jar"))
- {
- //Compressed help in jar, the class inside the jar should be "FileName"+"DocHelpSet"
- //and located either in "FileName".toLowCase() package or Unnamed Package
- strJarName = new String("");
- strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
- }
- else if (a_strHelpSet.endsWith(".hs"))
- {
- //Helpset file
- if (a_strHelpSet.charAt(0) == '/')
- strHsUrl = "file:" + a_strHelpSet;
- else
- strHsUrl = "file:/" + a_strHelpSet;
- }
- else
- {
- System.out.println("Unknown file extension name.");
- bSuccess = false;
- }
-
- //Build helpset object
- if (bSuccess)
- {
- try
- {
- if (strHsUrl.length () != 0)
- {
- //a hs file
- String strHsWorkingFolder = new String("");
- strHsWorkingFolder = strHsUrl.substring(0, strHsUrl.lastIndexOf('/'));
- helpset = new HelpSetFile(help, new URL(strHsUrl), new URL(strHsWorkingFolder));
- }
- else if (strJarName.length() != 0)
- {
- //a jar file
- String strPackageName = strJarName;
- String strClsName = "";
-
- //try to find the class in package
- Class clsName = null;
- boolean bFindClass = false;
- try
- {
- strClsName = strPackageName +"." + strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
-
- if (!bFindClass)
- {
- //try to find the class in unnamed package
- try
- {
- strClsName = strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
- }
-
- if (bFindClass)
- {
- String strHsName = strJarName + ".hs";
- helpset = new HelpSetFile(help, clsName, strHsName);
- }
- else
- {
- System.out.println("Can not find class in jar file:" + strJarName + ".class" );
- bSuccess = false;
- }
- }
- else
- {
- System.out.println("No file name ?!");
- bSuccess = false;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- bSuccess = false;
- }
- }
-
- if (!bSuccess)
- {
- System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
- }
- else
- {
- help.showContents();
- }
- return bSuccess;
- }
- */
-
- /*
- //Help Launcher for OracleHelp 3.2.0~3.2.1 /4.1.0~4.1.1
- public boolean HelpLauncher32(String a_strHelpSet, String a_strHelpId)
- {
- Help help = new Help();
- HelpSet helpset = null;
- String strHsUrl = "";
- String strJarName = "";
-
- boolean bSuccess = true;
-
- if (a_strHelpSet.endsWith(".jar"))
- {
- //Compressed help in jar, the class inside the jar should be "FileName"+"DocHelpSet"
- //and located either in "FileName".toLowCase() package or Unnamed Package
- strJarName = new String("");
- strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
- }
- else if (a_strHelpSet.endsWith(".hs"))
- {
- //Helpset file
- if (a_strHelpSet.charAt(0) == '/')
- strHsUrl = "file:" + a_strHelpSet;
- else
- strHsUrl = "file:/" + a_strHelpSet;
- }
- else
- {
- System.out.println("Unknown file extension name.");
- bSuccess = false;
- }
-
- //Build helpset object
- if (bSuccess)
- {
- try
- {
- if (strHsUrl.length () != 0)
- {
- //a hs file
- helpset = new HelpSet(new URL(strHsUrl));
- }
- else if (strJarName.length() != 0)
- {
- //a jar file
- String strPackageName = strJarName;
- String strClsName = "";
-
- //try to find the class in package
- Class clsName = null;
- boolean bFindClass = false;
- try
- {
- strClsName = strPackageName +"." + strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
-
- if (!bFindClass)
- {
- //try to find the class in unnamed package
- try
- {
- strClsName = strJarName + "DocHelpSet";
- clsName = Class.forName(strClsName);
- bFindClass = true;
- }
- catch(Exception e)
- {
- //Ignore
- }
- }
-
- if (bFindClass)
- {
- String strHsName = strJarName + ".hs";
- helpset = new HelpSet(clsName, strHsName);
- }
- else
- {
- System.out.println("Can not find class in jar file:" + strJarName + ".class" );
- bSuccess = false;
- }
- }
- else
- {
- System.out.println("No file name ?!");
- bSuccess = false;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- bSuccess = false;
- }
- }
-
- if (!bSuccess)
- {
- System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
- }
- else
- {
- Book book = (Book)helpset;
- help.addBook(book);
- help.showNavigatorWindow();
-
- }
- return bSuccess;
- }
- */
- }
-
-