package yi.net;

import java.applet.Applet;
import java.net.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** A Netscape3-specific way to generate an HTML page
 *  on-the-fly and pass it to the browser. Simply
 *  generate a URL of the form
 *  "javascript:'[Entire HTML Page]'"
 *  and call showDocument on it. Note that there should
 *  not be any carriage returns or single quotes in
 *  the string. Using netscape.javascript.JSObject is
 *  a much more robust approach.
 */

public class ShowHTML {

  /** Show in full page. */
  
  public static void showPage(Applet app, String html) {
    URL page = makeJavascriptURL(html);
    app.getAppletContext().showDocument(page);
  }

  /** Show in particular frame. */
  
  public static void showPage(Applet app, String html,
                              String frameName) {
    URL page = makeJavascriptURL(html);
    app.getAppletContext().showDocument(page, frameName);
  }

  /** No \n's or single quotes in the String! */
  
  public static URL makeJavascriptURL(String html) {
    try {
      URL page = new URL("javascript:'" + html + "'");
      return(page);
    } catch(MalformedURLException mue) {
      System.out.println("Illegal URL: " + mue);
      return(null);
    }
  }
}