package com.digi.config.util; import java.io.*; import java.applet.*; import java.net.*; /** * HelpDisplay is a utility class to display html help text based on a key to a help bundle. */ public class HelpDisplay { static Applet applet = null; public static void setApplet(Applet applet) { HelpDisplay.applet = applet; } /** * This method shows the html file in a new browser window *
* @param key Key for the resource file, the value will be the html file to display */ public static void showHelp(String key) { // Determine which help file to show String helpFileName=ConfigResource.getHelpRbString(key); if (applet!=null) { // Running as an applet... Display help using applet context try { URL docBase = applet.getDocumentBase(); //System.out.println("Doc base = "+docBase.toString()); int fileNamePos = docBase.getPath().lastIndexOf("/"); String path = docBase.getPath().substring(0, fileNamePos); //System.out.println("path = "+path); if (!path.endsWith("/")) { path += "/"; } URL helpUrl = new URL(docBase.getProtocol(), docBase.getHost(), path+helpFileName); applet.getAppletContext().showDocument(helpUrl, "Configuration Help"); } catch (MalformedURLException e) { SystemLog.log("InvalidHelpURL", new Serializable[] {helpFileName}, e); } } else { // Running as an application... display help in browser window String fullHelpFileName=PathLocater.locateFile(helpFileName); if (fullHelpFileName!=null) { // If we found the help file, then define the url and display it String url=fullHelpFileName; String cmd; try { String osname=System.getProperty("os.name"); if (osname.startsWith("Win")) { cmd="rundll32" +" " + "url.dll,FileProtocolHandler" +" " +url; } else { // Apple cmd="open" +" " +url; } SystemLog.debug("OS name is : " +osname); SystemLog.debug("Cmd is : " +cmd); Runtime.getRuntime().exec(cmd); } catch (Exception ex) { SystemLog.log(ex); } } else { SystemLog.log("MissingHelpFile", new Serializable[] { helpFileName }, new Serializable[] { key, helpFileName }); } } } }