示例#1
0
  static void openURL(
      JopSession session, String name, boolean newFrame, String frameName, String bookmark) {
    System.out.println("openURL " + name);
    Object root = session.getRoot();

    // Replace any URL symbol
    name = replaceUrlSymbol(session, name);
    try {
      String url_str = null;
      if (name.substring(0, 5).equals("http:")) {
        url_str = name;
        if (url_str.lastIndexOf(".html") == -1
            && url_str.lastIndexOf(".shtml") == -1
            && url_str.lastIndexOf(".htm") == -1
            && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html";
      } else if (name.startsWith("$pwr_doc/")) {
        URL current = ((JApplet) root).getDocumentBase();
        String current_str = current.toString();
        int idx1 = current_str.indexOf('/');
        if (idx1 != -1 && current_str.length() > idx1 + 1) {
          idx1 = current_str.indexOf('/', idx1 + 1);
          if (idx1 != -1 && current_str.length() > idx1 + 1) {
            idx1 = current_str.indexOf('/', idx1 + 1);
            if (idx1 != -1 && current_str.length() > idx1 + 1) {
              url_str = current_str.substring(0, idx1 + 1) + "pwr_doc/" + name.substring(9);
              if (url_str.lastIndexOf(".html") == -1
                  && url_str.lastIndexOf(".shtml") == -1
                  && url_str.lastIndexOf(".htm") == -1
                  && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html";
            }
          }
        }
      } else {
        URL current = ((JApplet) root).getCodeBase();
        String current_str = current.toString();
        int idx1 = current_str.lastIndexOf('/');
        int idx2 = current_str.lastIndexOf(':');
        int idx = idx1;
        if (idx2 > idx) idx = idx2;
        String path = current_str.substring(0, idx + 1);
        if (name.lastIndexOf(".html") == -1
            && name.lastIndexOf(".shtml") == -1
            && name.lastIndexOf(".htm") == -1
            && name.lastIndexOf(".pdf") == -1) url_str = new String(path + name + ".html");
        else url_str = new String(path + name);
        if (bookmark != null) url_str += "#" + bookmark;
      }
      System.out.println("Opening URL: " + url_str);

      URL url = new URL(url_str);
      AppletContext appCtx = ((JApplet) root).getAppletContext();
      if (newFrame) appCtx.showDocument(url, "_blank");
      else if (frameName != null) appCtx.showDocument(url, frameName);
      else appCtx.showDocument(url, "_self");
    } catch (MalformedURLException e) {
      System.out.println("MalformedURL : " + name);
    }
  }
示例#2
0
  /**
   * Closes the applet. This method can be implemented by invoking <code>
   * getAppletContext().showDocument(...)</code>.
   */
  protected void close() {
    AppletContext appletContext;
    try {
      appletContext = getAppletContext();
    } catch (Throwable e) {
      appletContext = null;
    }

    if (appletContext == null) {
      System.exit(0);
    } else {
      getContentPane().removeAll();
      ((JComponent) getContentPane()).revalidate();
      try {
        appletContext.showDocument(new URL(getDocumentBase(), getParameter("PageURL")));
      } catch (MalformedURLException ex) {
        ex.printStackTrace();
      }
    }
  }