Index: modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java (revision 616183) +++ modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java (working copy) @@ -24,6 +24,7 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.net.URLClassLoader; +import java.net.URL; import java.util.HashSet; import javax.swing.AbstractAction; @@ -45,33 +46,45 @@ public AppletFrame(AppletInfo appletInfo) throws Exception { this.appletInfo = appletInfo; + String code = this.appletInfo.getCode(); + if(code == null || code.equals("")){ + System.err.println("Warning: <" + appletInfo.getTag() +"> tag requires code attribute."); + System.exit(0); + } + shutdownHandler.addFrame(this); // Load applet class + if(appletInfo.getCodeBase() == null){ + appletInfo.setCodeBase(new URL(appletInfo.getDocumentBase(), "./")); + } + URLClassLoader cl = new URLClassLoader(appletInfo.getClassLoaderURLs()); - Class clz = cl.loadClass(this.appletInfo.getCode()); + Class clz = cl.loadClass(code); applet = (Applet)clz.newInstance(); applet.setStub(new ViewerAppletStub(applet, appletInfo)); + applet.setPreferredSize(new Dimension(appletInfo.getWidth(), appletInfo.getHeight())); + // Create menu bar + setJMenuBar(createMenu()); + // Create applet pane setLayout(new BorderLayout()); JPanel appletPanel = new JPanel(); appletPanel.add(applet); - add(appletPanel, BorderLayout.CENTER); - applet.setPreferredSize(new Dimension(appletInfo.getWidth(), appletInfo.getHeight())); + add(appletPanel, BorderLayout.NORTH); - // Create menu bar - setJMenuBar(createMenu()); - // Create status pane JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.setMinimumSize(new Dimension(100, 15)); + panel.setPreferredSize(new Dimension(100, 15)); statusLabel = new JLabel(); - panel.add(statusLabel); + statusLabel.setMinimumSize(new Dimension(100, 15)); + statusLabel.setHorizontalAlignment(SwingConstants.LEFT); + panel.add(statusLabel, BorderLayout.WEST); add(panel, BorderLayout.SOUTH); appletInfo.setStatusLabel(statusLabel); - - statusLabel.setMinimumSize(new Dimension(100, 40)); - statusLabel.setHorizontalAlignment(SwingConstants.LEFT); // Start applet and make frame visible // Init should be called after pack to make components displayable @@ -99,44 +112,44 @@ private class StartAction extends AbstractAction { public StartAction() { - super("Start"); + super("Start"); } - public void actionPerformed(final ActionEvent e) { - applet.start(); - applet.setEnabled(true); - } + public void actionPerformed(final ActionEvent e) { + applet.start(); + applet.setEnabled(true); + } } private class StopAction extends AbstractAction { - public StopAction() { - super("Stop"); - } + public StopAction() { + super("Stop"); + } - public void actionPerformed(ActionEvent e) { - applet.stop(); - applet.setEnabled(false); - } + public void actionPerformed(ActionEvent e) { + applet.stop(); + applet.setEnabled(false); + } } private class CloseAction extends AbstractAction { - public CloseAction() { - super("Close"); - } + public CloseAction() { + super("Close"); + } - public void actionPerformed(ActionEvent e) { - setVisible(false); - } + public void actionPerformed(ActionEvent e) { + setVisible(false); + } } private class ExitAction extends AbstractAction { - public ExitAction() { - super("Exit"); - } + public ExitAction() { + super("Exit"); + } - public void actionPerformed(ActionEvent e) { - System.exit(0); - } + public void actionPerformed(ActionEvent e) { + System.exit(0); + } } private static class ShutdownHandler implements WindowListener { Index: modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java (revision 616183) +++ modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java (working copy) @@ -31,6 +31,7 @@ private URL codeBase; private URL archive; private String code; + private String tagName; private int width; private int height; private HashMap params; @@ -129,4 +130,12 @@ } return res; } + + public void setTag(String tagName){ + this.tagName = tagName; + } + + public String getTag(){ + return tagName; + } } Index: modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java (revision 616183) +++ modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java (working copy) @@ -32,7 +32,8 @@ import javax.swing.text.html.parser.TagElement; class HTMLParser { - private final ParserImpl parser; + + private final ParserImpl parser; HTMLParser() throws IOException { DTD dtd = DTD.getDTD("reader"); @@ -49,14 +50,14 @@ } private class ParserImpl extends javax.swing.text.html.parser.Parser { - private URL documentBase; - private ArrayList list; + private URL documentBase; + private ArrayList list; private AppletInfo appletInfo = null; private HTML.Tag startElement = null; public ParserImpl(DTD dtd) { - super(dtd); - } + super(dtd); + } public void parse(String url, ArrayList list) throws IOException { try { @@ -72,57 +73,71 @@ parse(isr); } - @Override - protected void handleStartTag(TagElement tag) { - if (tag == null) - return; - HTML.Tag htmlTag = tag.getHTMLTag(); + @Override + protected void handleStartTag(TagElement tag) { + if (tag == null) + return; + + HTML.Tag htmlTag = tag.getHTMLTag(); + if (htmlTag == HTML.Tag.APPLET || htmlTag == HTML.Tag.OBJECT) { + if (startElement != null) { throw new RuntimeException(htmlTag+" inside "+startElement); } startElement = htmlTag; appletInfo = new AppletInfo(); + appletInfo.setTag(htmlTag.toString()); + list.add(appletInfo); + appletInfo.setDocumentBase(documentBase); + SimpleAttributeSet attributes = getAttributes(); - appletInfo.setCode((String)attributes.getAttribute(HTML.Attribute.CODE)); - try { - appletInfo.setCodeBase((String)attributes.getAttribute(HTML.Attribute.CODEBASE)); - } catch (Exception e) { - appletInfo.setCodeBase((URL)null); - } - try { - appletInfo.setArchive((String)attributes.getAttribute(HTML.Attribute.ARCHIVE)); - } catch (MalformedURLException e) { - appletInfo.setArchive((URL)null); - } appletInfo.setWidth((String)attributes.getAttribute(HTML.Attribute.WIDTH)); appletInfo.setHeight((String)attributes.getAttribute(HTML.Attribute.HEIGHT)); - list.add(appletInfo); - return; - } - if (appletInfo != null && htmlTag == HTML.Tag.PARAM) { - SimpleAttributeSet attributes = getAttributes(); - appletInfo.setParameter((String)attributes.getAttribute(HTML.Attribute.NAME), (String)attributes.getAttribute(HTML.Attribute.VALUE)); - } - } + try { + appletInfo.setArchive((String)attributes.getAttribute(HTML.Attribute.ARCHIVE)); + } catch (MalformedURLException e) { + appletInfo.setArchive((URL)null); + } - @Override - protected void handleEndTag(TagElement tag) { - if (tag != null && tag.getHTMLTag() == startElement) + try { + appletInfo.setCode((String)attributes.getAttribute(HTML.Attribute.CODE)); + } catch (Exception e) {} + + if (htmlTag == HTML.Tag.APPLET) { + try { + appletInfo.setCodeBase((String)attributes.getAttribute(HTML.Attribute.CODEBASE)); + } catch (Exception e) { + appletInfo.setCodeBase((URL)null); + } + } + + + } + } + + @Override + protected void handleEndTag(TagElement tag) { + if (tag != null && tag.getHTMLTag() == startElement) startElement = null; - } + } - @Override - protected void handleEmptyTag(TagElement tag) - throws ChangedCharSetException { - HTML.Tag htmlTag = tag.getHTMLTag(); + @Override + protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException { + + HTML.Tag htmlTag = tag.getHTMLTag(); if (appletInfo != null && htmlTag == HTML.Tag.PARAM) { SimpleAttributeSet attributes = getAttributes(); - appletInfo.setParameter((String)attributes.getAttribute(HTML.Attribute.NAME), (String)attributes.getAttribute(HTML.Attribute.VALUE)); + String name = (String)attributes.getAttribute(HTML.Attribute.NAME); + if(name.equalsIgnoreCase("code")){ + appletInfo.setCode((String)attributes.getAttribute(HTML.Attribute.VALUE)); + } else { + appletInfo.setParameter(name, (String)attributes.getAttribute(HTML.Attribute.VALUE)); + } } - } + } } }