harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r616348 - in /harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer: AppletFrame.java AppletInfo.java HTMLParser.java
Date Tue, 29 Jan 2008 14:39:16 GMT
Author: apetrenko
Date: Tue Jan 29 06:39:15 2008
New Revision: 616348

URL: http://svn.apache.org/viewvc?rev=616348&view=rev
Log:
Patch for HARMONY-5440 "[jdktools][appletviewer] appletviewer doesn't 
"understand" <object> tag"

Modified:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java?rev=616348&r1=616347&r2=616348&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
Tue Jan 29 06:39:15 2008
@@ -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()));
-        
-        // Create menu bar
-        setJMenuBar(createMenu());
+        add(appletPanel, BorderLayout.NORTH);
         
         // 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 void actionPerformed(ActionEvent e) {
-			applet.stop();
-			applet.setEnabled(false);
-		}
+        public StopAction() {
+            super("Stop");
+        }
+    	
+        public void actionPerformed(ActionEvent e) {
+            applet.stop();
+            applet.setEnabled(false);
+        }
     }
     
     private class CloseAction extends  AbstractAction {
-    	public CloseAction() {
-    		super("Close");
-    	}
-    	
-		public void actionPerformed(ActionEvent e) {
-			setVisible(false);
-		}
+        public CloseAction() {
+            super("Close");
+        }
+    	
+        public void actionPerformed(ActionEvent e) {
+            setVisible(false);
+        }
     }
     
     private class ExitAction extends  AbstractAction {
-    	public ExitAction() {
-    		super("Exit");
-    	}
-    	
-		public void actionPerformed(ActionEvent e) {
-			System.exit(0);
-		}
+        public ExitAction() {
+            super("Exit");
+        }
+    	
+        public void actionPerformed(ActionEvent e) {
+            System.exit(0);
+        }
     }
     
     private static class ShutdownHandler implements WindowListener {

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java?rev=616348&r1=616347&r2=616348&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
Tue Jan 29 06:39:15 2008
@@ -31,6 +31,7 @@
     private URL codeBase;
     private URL archive;
     private String code;
+    private String tagName;
     private int width;
     private int height;
     private HashMap<String, String> params;
@@ -128,5 +129,13 @@
     		case 1: res[0] = codeBase;
     	}
     	return res;
+    }
+
+    public void setTag(String tagName){
+        this.tagName = tagName;
+    }
+
+    public String getTag(){
+        return tagName;
     }
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java?rev=616348&r1=616347&r2=616348&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
Tue Jan 29 06:39:15 2008
@@ -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<AppletInfo> list;
+        private URL documentBase;
+        private ArrayList<AppletInfo> list;
         private AppletInfo appletInfo = null;
         private HTML.Tag startElement = null;
     	
     	public ParserImpl(DTD dtd) {
-    		super(dtd);
-		}
+            super(dtd);
+        }
     	
     	public void parse(String url, ArrayList<AppletInfo> list) throws IOException {
             try  {
@@ -72,57 +73,69 @@
             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);
+                }
+
+                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)
+        @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));
+                }
             }
-		}
+        }
     }
 }



Mime
View raw message