harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r606585 - in /harmony/enhanced/jdktools/trunk/modules: samsa/ tools/src/main/java/org/apache/harmony/tools/appletviewer/
Date Sun, 23 Dec 2007 18:02:15 GMT
Author: apetrenko
Date: Sun Dec 23 10:02:14 2007
New Revision: 606585

URL: http://svn.apache.org/viewvc?rev=606585&view=rev
Log:
Initial version of applet viewer

Added:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java
  (with props)
Modified:
    harmony/enhanced/jdktools/trunk/modules/samsa/build.xml

Modified: harmony/enhanced/jdktools/trunk/modules/samsa/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/samsa/build.xml?rev=606585&r1=606584&r2=606585&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/samsa/build.xml (original)
+++ harmony/enhanced/jdktools/trunk/modules/samsa/build.xml Sun Dec 23 10:02:14 2007
@@ -78,6 +78,9 @@
         <copy file="${hy.samsa.exe}" tofile="${hy.jdk}/bin/jarsigner${exe.suffix}" />
         <chmod file="${hy.jdk}/bin/jarsigner${exe.suffix}" perm="ugo+x" />
 
+        <copy file="${hy.samsa.exe}" tofile="${hy.jdk}/bin/appletviewer${exe.suffix}"
/>
+        <chmod file="${hy.jdk}/bin/appletviewer${exe.suffix}" perm="ugo+x" />
+
     </target>
 
     <!-- copy windows javaw executable -->

Added: 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=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.swing.JFrame;
+
+class AppletFrame extends JFrame {
+	private final AppletInfo appletInfo;
+	private final Applet applet;
+	
+	public AppletFrame(AppletInfo appletInfo) throws Exception {
+		this.appletInfo = appletInfo;
+		
+		// Load applet class
+		URL []urls = new URL[1];
+		urls[0] = appletInfo.getCodeBase();
+		URLClassLoader cl = new URLClassLoader(urls);
+		Class clz = cl.loadClass(this.appletInfo.getCode());
+		applet = (Applet)clz.newInstance();
+		applet.setStub(new ViewerAppletStub(applet, appletInfo));
+		
+		// Create applet pane
+		setLayout(new BorderLayout());
+		applet.setPreferredSize(new Dimension(appletInfo.getWidth(), appletInfo.getHeight()));
+		add(applet, BorderLayout.CENTER);
+
+		// Start applet
+		applet.init();
+		applet.start();
+
+		// Make frame visible
+		pack();
+		setVisible(true);		
+	}
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+
+public class AppletInfo {
+	private static final int DEFAULT_WIDTH=300;
+	private static final int DEFAULT_HEIGHT=200;	
+	
+	private URL documentBase;
+	private URL codeBase;
+	private String code;
+	private int width;
+	private int height;
+	private HashMap<String, String> params;
+	
+	public AppletInfo() {
+		params = new HashMap<String, String>();
+	}
+
+	public URL getDocumentBase() {
+		return documentBase;
+	}
+
+	public void setDocumentBase(URL documentBase) {
+		this.documentBase = documentBase;
+	}
+
+	public URL getCodeBase() {
+		return codeBase;
+	}
+
+	public void setCodeBase(URL codeBase) {
+		this.codeBase = codeBase;
+	}
+
+	public void setCodeBase(String codeBaseStr) throws MalformedURLException {
+		this.codeBase = new URL(this.documentBase, (codeBaseStr == null)?"./":codeBaseStr);
+	}
+
+	public String getParameter(String name) {
+		return params.get(name);
+	}
+
+	public void setParameter(String name, String value) {
+		params.put(name, value);
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = (code.endsWith(".class"))?code.substring(0, code.length()-6):code;
+	}
+
+	public int getWidth() {
+		return width;
+	}
+
+	public void setWidth(int width) {
+		this.width = width;
+	}
+
+	public void setWidth(String widthStr) {		
+		this.width = (widthStr == null)?DEFAULT_WIDTH:Integer.parseInt(widthStr);
+	}
+
+	public int getHeight() {
+		return height;
+	}
+
+	public void setHeight(int height) {
+		this.height = height;
+	}	
+
+	public void setHeight(String heightStr) {		
+		this.height = (heightStr == null)?DEFAULT_HEIGHT:Integer.parseInt(heightStr);
+	}
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,86 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+class HTMLParser {
+	HTMLParser() {
+	}
+	
+	Object []parse(String urls[], int start) throws ParserConfigurationException, SAXException,
IOException {
+		SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+		ArrayList<AppletInfo> list = new ArrayList<AppletInfo>(urls.length-start);
+		for (int i = start; i < urls.length; i++) {
+			AppletHTMLHandler handler = new AppletHTMLHandler(urls[i], list);
+			parser.parse(urls[i], handler);
+		}
+		return list.toArray();
+	}
+
+	private class AppletHTMLHandler extends DefaultHandler {
+		private final URL documentBase;
+		private final ArrayList<AppletInfo> list;
+		private AppletInfo appletInfo = null;
+		private String startElement = null;
+		
+		public AppletHTMLHandler(String url, ArrayList<AppletInfo> list) throws MalformedURLException
{
+			super();
+			this.documentBase = new URL(url);
+			this.list = list;
+		}
+
+		public void startElement(String uri, String lName, String qName, Attributes attrs) throws
SAXException {
+			if (qName.equalsIgnoreCase("APPLET") || qName.equalsIgnoreCase("OBJECT")) {
+				if (startElement != null) {
+					throw new SAXParseException(qName+" inside "+startElement, null);
+				}
+				
+				startElement = qName;
+				appletInfo = new AppletInfo();
+				appletInfo.setDocumentBase(documentBase);
+				appletInfo.setCode(attrs.getValue("code"));
+				try {
+					appletInfo.setCodeBase(attrs.getValue("codebase"));
+				} catch (Exception e) {
+					appletInfo.setCodeBase((URL)null);
+				}
+				appletInfo.setWidth(attrs.getValue("width"));
+				appletInfo.setHeight(attrs.getValue("height"));
+				list.add(appletInfo);
+			}			
+		}
+		
+		public void endElement(String uri, String lName, String qName) throws SAXException {
+			if (qName.equalsIgnoreCase(startElement))
+				startElement = null;
+		}
+	}
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java?rev=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+public class Main {
+    public static void main(String argv[]) throws Exception {
+    	if (argv.length == 0) {
+    		printHelp();
+    		return;
+    	}
+    	
+    	HTMLParser parser = new HTMLParser();
+    	Object []applets = parser.parse(argv, 0);
+    	
+    	// Start applets
+    	for (int i = 0; i < applets.length; i++)
+    		new AppletFrame((AppletInfo)applets[i]);
+    }
+
+	private static void printHelp() {
+		System.err.println("Applet viewer");
+		System.err.println("Usage: appletviewer urls");
+	}
+}
+

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java?rev=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.applet.AudioClip;
+import java.awt.Image;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+class ViewerAppletContext implements AppletContext {
+
+	public Applet getApplet(String name) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public Enumeration<Applet> getApplets() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public AudioClip getAudioClip(URL url) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public Image getImage(URL url) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public InputStream getStream(String key) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public Iterator<String> getStreamKeys() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void setStream(String key, InputStream stream) throws IOException {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void showDocument(URL url) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void showDocument(URL url, String target) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void showStatus(String status) {
+		// TODO Auto-generated method stub
+
+	}
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java?rev=606585&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java
Sun Dec 23 10:02:14 2007
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.tools.appletviewer;
+
+import java.applet.AppletContext;
+import java.applet.AppletStub;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.net.URL;
+
+class ViewerAppletStub implements AppletStub {
+    private final Component appletPane;
+    private final AppletInfo appletInfo;
+
+    ViewerAppletStub(Component appletPane, AppletInfo appletInfo) {
+        this.appletPane = appletPane;
+        this.appletInfo = appletInfo;
+    }
+    
+    public boolean isActive() {
+        return false;
+    }
+    
+    public URL getDocumentBase() {
+        return appletInfo.getDocumentBase();
+    }
+    
+    public URL getCodeBase() {
+        return appletInfo.getCodeBase();
+    }
+    
+    public String getParameter(String name) {
+        return appletInfo.getParameter(name);
+    }
+    
+    public AppletContext getAppletContext() {
+        return new ViewerAppletContext();
+    }
+    
+    public void appletResize(int width, int height) {
+        appletPane.setPreferredSize(new Dimension(width, height));
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletStub.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message