Example #1
0
  public static void parse(URL url, PrintStream statusMsgStream, AppletViewerFactory factory)
      throws IOException {
    // <OBJECT> <EMBED> tag flags
    boolean isAppletTag = false;
    boolean isObjectTag = false;
    boolean isEmbedTag = false;

    // warning messages
    String requiresNameWarning = amh.getMessage("parse.warning.requiresname");
    String paramOutsideWarning = amh.getMessage("parse.warning.paramoutside");
    String appletRequiresCodeWarning = amh.getMessage("parse.warning.applet.requirescode");
    String appletRequiresHeightWarning = amh.getMessage("parse.warning.applet.requiresheight");
    String appletRequiresWidthWarning = amh.getMessage("parse.warning.applet.requireswidth");
    String objectRequiresCodeWarning = amh.getMessage("parse.warning.object.requirescode");
    String objectRequiresHeightWarning = amh.getMessage("parse.warning.object.requiresheight");
    String objectRequiresWidthWarning = amh.getMessage("parse.warning.object.requireswidth");
    String embedRequiresCodeWarning = amh.getMessage("parse.warning.embed.requirescode");
    String embedRequiresHeightWarning = amh.getMessage("parse.warning.embed.requiresheight");
    String embedRequiresWidthWarning = amh.getMessage("parse.warning.embed.requireswidth");
    String appNotLongerSupportedWarning = amh.getMessage("parse.warning.appnotLongersupported");

    j86.java.net.URLConnection conn = url.openConnection();
    Reader in = makeReader(conn.getInputStream());
    /* The original URL may have been redirected - this
     * sets it to whatever URL/codebase we ended up getting
     */
    url = conn.getURL();

    int ydisp = 1;
    Hashtable atts = null;

    while (true) {
      c = in.read();
      if (c == -1) break;

      if (c == '<') {
        c = in.read();
        if (c == '/') {
          c = in.read();
          String nm = scanIdentifier(in);
          if (nm.equalsIgnoreCase("applet")
              || nm.equalsIgnoreCase("object")
              || nm.equalsIgnoreCase("embed")) {

            // We can't test for a code tag until </OBJECT>
            // because it is a parameter, not an attribute.
            if (isObjectTag) {
              if (atts.get("code") == null && atts.get("object") == null) {
                statusMsgStream.println(objectRequiresCodeWarning);
                atts = null;
              }
            }

            if (atts != null) {
              // XXX 5/18 In general this code just simply
              // shouldn't be part of parsing.  It's presence
              // causes things to be a little too much of a
              // hack.
              factory.createAppletViewer(x, y, url, atts);
              x += XDELTA;
              y += YDELTA;
              // make sure we don't go too far!
              Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
              if ((x > d.width - 300) || (y > d.height - 300)) {
                x = 0;
                y = 2 * ydisp * YDELTA;
                ydisp++;
              }
            }
            atts = null;
            isAppletTag = false;
            isObjectTag = false;
            isEmbedTag = false;
          }
        } else {
          String nm = scanIdentifier(in);
          if (nm.equalsIgnoreCase("param")) {
            Hashtable t = scanTag(in);
            String att = (String) t.get("name");
            if (att == null) {
              statusMsgStream.println(requiresNameWarning);
            } else {
              String val = (String) t.get("value");
              if (val == null) {
                statusMsgStream.println(requiresNameWarning);
              } else if (atts != null) {
                atts.put(att.toLowerCase(), val);
              } else {
                statusMsgStream.println(paramOutsideWarning);
              }
            }
          } else if (nm.equalsIgnoreCase("applet")) {
            isAppletTag = true;
            atts = scanTag(in);
            if (atts.get("code") == null && atts.get("object") == null) {
              statusMsgStream.println(appletRequiresCodeWarning);
              atts = null;
            } else if (atts.get("width") == null) {
              statusMsgStream.println(appletRequiresWidthWarning);
              atts = null;
            } else if (atts.get("height") == null) {
              statusMsgStream.println(appletRequiresHeightWarning);
              atts = null;
            }
          } else if (nm.equalsIgnoreCase("object")) {
            isObjectTag = true;
            atts = scanTag(in);
            // The <OBJECT> attribute codebase isn't what
            // we want. If its defined, remove it.
            if (atts.get("codebase") != null) {
              atts.remove("codebase");
            }

            if (atts.get("width") == null) {
              statusMsgStream.println(objectRequiresWidthWarning);
              atts = null;
            } else if (atts.get("height") == null) {
              statusMsgStream.println(objectRequiresHeightWarning);
              atts = null;
            }
          } else if (nm.equalsIgnoreCase("embed")) {
            isEmbedTag = true;
            atts = scanTag(in);

            if (atts.get("code") == null && atts.get("object") == null) {
              statusMsgStream.println(embedRequiresCodeWarning);
              atts = null;
            } else if (atts.get("width") == null) {
              statusMsgStream.println(embedRequiresWidthWarning);
              atts = null;
            } else if (atts.get("height") == null) {
              statusMsgStream.println(embedRequiresHeightWarning);
              atts = null;
            }
          } else if (nm.equalsIgnoreCase("app")) {
            statusMsgStream.println(appNotLongerSupportedWarning);
            Hashtable atts2 = scanTag(in);
            nm = (String) atts2.get("class");
            if (nm != null) {
              atts2.remove("class");
              atts2.put("code", nm + ".class");
            }
            nm = (String) atts2.get("src");
            if (nm != null) {
              atts2.remove("src");
              atts2.put("codebase", nm);
            }
            if (atts2.get("width") == null) {
              atts2.put("width", "100");
            }
            if (atts2.get("height") == null) {
              atts2.put("height", "100");
            }
            printTag(statusMsgStream, atts2);
            statusMsgStream.println();
          }
        }
      }
    }
    in.close();
  }
Example #2
0
  /** Handle events. */
  public void processUserAction(ActionEvent evt) {

    String label = ((MenuItem) evt.getSource()).getLabel();

    if (amh.getMessage("menuitem.restart").equals(label)) {
      appletRestart();
      return;
    }

    if (amh.getMessage("menuitem.reload").equals(label)) {
      appletReload();
      return;
    }

    if (amh.getMessage("menuitem.clone").equals(label)) {
      appletClone();
      return;
    }

    if (amh.getMessage("menuitem.stop").equals(label)) {
      appletStop();
      return;
    }

    if (amh.getMessage("menuitem.save").equals(label)) {
      appletSave();
      return;
    }

    if (amh.getMessage("menuitem.start").equals(label)) {
      appletStart();
      return;
    }

    if (amh.getMessage("menuitem.tag").equals(label)) {
      appletTag();
      return;
    }

    if (amh.getMessage("menuitem.info").equals(label)) {
      appletInfo();
      return;
    }

    if (amh.getMessage("menuitem.encoding").equals(label)) {
      appletCharacterEncoding();
      return;
    }

    if (amh.getMessage("menuitem.edit").equals(label)) {
      appletEdit();
      return;
    }

    if (amh.getMessage("menuitem.print").equals(label)) {
      appletPrint();
      return;
    }

    if (amh.getMessage("menuitem.props").equals(label)) {
      networkProperties();
      return;
    }

    if (amh.getMessage("menuitem.close").equals(label)) {
      appletClose();
      return;
    }

    if (factory.isStandalone() && amh.getMessage("menuitem.quit").equals(label)) {
      appletQuit();
      return;
    }
    // statusMsgStream.println("evt = " + evt);
  }
Example #3
0
 /** Clone the viewer and the applet. */
 void appletClone() {
   Point p = location();
   updateAtts();
   factory.createAppletViewer(
       p.x + XDELTA, p.y + YDELTA, panel.documentURL, (Hashtable) panel.atts.clone());
 }
Example #4
0
 /** Exit the program. Exit from the program (if not stand alone) - do no clean-up */
 private void appletSystemExit() {
   if (factory.isStandalone()) System.exit(0);
 }
Example #5
0
  /** Create the applet viewer */
  public AppletViewer(
      int x,
      int y,
      URL doc,
      Hashtable atts,
      PrintStream statusMsgStream,
      AppletViewerFactory factory) {
    this.factory = factory;
    this.statusMsgStream = statusMsgStream;
    setTitle(amh.getMessage("tool.title", atts.get("code")));

    MenuBar mb = factory.getBaseMenuBar();

    Menu m = new Menu(amh.getMessage("menu.applet"));

    addMenuItem(m, "menuitem.restart");
    addMenuItem(m, "menuitem.reload");
    addMenuItem(m, "menuitem.stop");
    addMenuItem(m, "menuitem.save");
    addMenuItem(m, "menuitem.start");
    addMenuItem(m, "menuitem.clone");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.tag");
    addMenuItem(m, "menuitem.info");
    addMenuItem(m, "menuitem.edit").disable();
    addMenuItem(m, "menuitem.encoding");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.print");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.props");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.close");
    if (factory.isStandalone()) {
      addMenuItem(m, "menuitem.quit");
    }

    mb.add(m);

    setMenuBar(mb);

    add("Center", panel = new AppletViewerPanel(doc, atts));
    add("South", label = new Label(amh.getMessage("label.hello")));
    panel.init();
    appletPanels.addElement(panel);

    pack();
    move(x, y);
    setVisible(true);

    WindowListener windowEventListener =
        new WindowAdapter() {

          public void windowClosing(WindowEvent evt) {
            appletClose();
          }

          public void windowIconified(WindowEvent evt) {
            appletStop();
          }

          public void windowDeiconified(WindowEvent evt) {
            appletStart();
          }
        };

    class AppletEventListener implements AppletListener {
      final Frame frame;

      public AppletEventListener(Frame frame) {
        this.frame = frame;
      }

      public void appletStateChanged(AppletEvent evt) {
        AppletPanel src = (AppletPanel) evt.getSource();

        switch (evt.getID()) {
          case AppletPanel.APPLET_RESIZE:
            {
              if (src != null) {
                resize(preferredSize());
                validate();
              }
              break;
            }
          case AppletPanel.APPLET_LOADING_COMPLETED:
            {
              Applet a = src.getApplet(); // j86.sun.applet.AppletPanel

              // Fixed #4754451: Applet can have methods running on main
              // thread event queue.
              //
              // The cause of this bug is that the frame of the applet
              // is created in main thread group. Thus, when certain
              // AWT/Swing events are generated, the events will be
              // dispatched through the wrong event dispatch thread.
              //
              // To fix this, we rearrange the AppContext with the frame,
              // so the proper event queue will be looked up.
              //
              // Swing also maintains a Frame list for the AppContext,
              // so we will have to rearrange it as well.
              //
              if (a != null)
                AppletPanel.changeFrameAppContext(frame, SunToolkit.targetToAppContext(a));
              else AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext());

              break;
            }
        }
      }
    };

    addWindowListener(windowEventListener);
    panel.addAppletListener(new AppletEventListener(this));

    // Start the applet
    showStatus(amh.getMessage("status.start"));
    initEventQueue();
  }