Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  public static Image getImage(JopSession session, String image) {
    String fullName;
    if (session.getRoot() instanceof JopApplet) {
      String name;
      try {
        URL current = ((JApplet) session.getRoot()).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);
        String url_str;

        //        String url_str = new String( path + name);
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("jar:" + path + "pwr_" + name + ".jar!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("jar:" + path + "pwrp_" + systemName + "_web.jar!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
      return null;
    } else {
      // Add default directory /pwrp/img
      System.out.println("Image: " + image);

      //      int idx = image.lastIndexOf('/');
      //      if ( idx == -1)
      //  fullName = new String("/pwrp/img/" + image);
      // else
      fullName = new String(image);
      //      return Toolkit.getDefaultToolkit().getImage( fullName);

      try {
        String name;
        String url_str;
        int idx;
        String path = new String("file://");
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("$pwr_lib/pwr_" + name + ".jar");
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("$pwrp_lib/pwrp_" + systemName + ".jar");
          System.out.println("java: " + url_str);
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
    }
    return null;
  }