From 1f595aba1e38b1a0113f45492288e22d3fa90799 Mon Sep 17 00:00:00 2001 From: Adam Domurad Date: Tue, 4 Dec 2012 10:43:59 -0500 Subject: Remove redundant HTML-tag scanner from ITW. Do not reconstruct tags. --- .../java/sun/applet/PluginAppletViewer.java | 534 ++------------------- .../java/sun/applet/PluginParameterParser.java | 90 ++++ 2 files changed, 119 insertions(+), 505 deletions(-) create mode 100644 plugin/icedteanp/java/sun/applet/PluginParameterParser.java (limited to 'plugin/icedteanp/java/sun/applet') diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java index f9d9422..611ed56 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -70,7 +70,6 @@ import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.Insets; -import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; @@ -87,6 +86,7 @@ import java.lang.reflect.InvocationTargetException; import java.net.SocketPermission; import java.net.URI; import java.net.URL; +import java.net.URLConnection; import java.security.AccessController; import java.security.AllPermission; import java.security.PrivilegedAction; @@ -107,6 +107,7 @@ import java.util.concurrent.locks.ReentrantLock; import javax.swing.SwingUtilities; import net.sourceforge.jnlp.NetxPanel; +import net.sourceforge.jnlp.PluginParameters; import net.sourceforge.jnlp.runtime.JNLPClassLoader; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -129,14 +130,14 @@ class PluginAppletPanelFactory { public AppletPanel createPanel(PluginStreamHandler streamhandler, final int identifier, - final long handle, int x, int y, + final long handle, final URL doc, - final Hashtable atts) { + final PluginParameters params) { final NetxPanel panel = AccessController.doPrivileged(new PrivilegedAction() { public NetxPanel run() { - NetxPanel panel = new NetxPanel(doc, atts, false); + NetxPanel panel = new NetxPanel(doc, params, false); NetxPanel.debug("Using NetX panel"); - PluginDebug.debug(atts.toString()); + PluginDebug.debug(params.toString()); return panel; } }); @@ -146,14 +147,13 @@ class PluginAppletPanelFactory { // isn't the case, the awt eventqueue thread's context classloader // won't be set to a JNLPClassLoader, and when an applet class needs // to be loaded from the awt eventqueue, it won't be found. - final int width = Integer.parseInt(atts.get("width")); - final int height = Integer.parseInt(atts.get("height")); Thread panelInit = new Thread(panel.getThreadGroup(), new Runnable() { @Override public void run() { panel.createNewAppContext(); // create the frame. - PluginDebug.debug("X and Y are: " + width + " " + height); - panel.setAppletViewerFrame(PluginAppletViewer.framePanel(identifier,handle, width, height, panel)); + PluginDebug.debug("X and Y are: " + params.getWidth() + " " + params.getHeight()); + panel.setAppletViewerFrame(PluginAppletViewer.framePanel(identifier, handle, + params.getWidth(), params.getHeight(), panel)); panel.init(); // Start the applet @@ -194,7 +194,7 @@ class PluginAppletPanelFactory { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { - panel.getParent().setSize(width, height); + panel.getParent().setSize(params.getWidth(), params.getHeight()); } }); } catch (InvocationTargetException ite) { @@ -599,18 +599,28 @@ public class PluginAppletViewer extends XEmbeddedFrame int spaceLocation = message.indexOf(' ', "tag".length() + 1); String documentBase = UrlUtil.decode(message.substring("tag".length() + 1, spaceLocation)); - String tag = message.substring(spaceLocation + 1); + String paramString = message.substring(spaceLocation + 1); PluginDebug.debug("Handle = ", handle, "\n", "Width = ", width, "\n", "Height = ", height, "\n", "DocumentBase = ", documentBase, "\n", - "Tag = ", tag); + "Params = ", paramString); - PluginAppletViewer.parse - (identifier, handle, width, height, - new StringReader(tag), - new URL(documentBase)); + PluginAppletPanelFactory factory = new PluginAppletPanelFactory(); + AppletMessageHandler amh = new AppletMessageHandler("appletviewer"); + URL url = new URL(documentBase); + URLConnection conn = url.openConnection(); + /* The original URL may have been redirected - this + * sets it to whatever URL/codebase we ended up getting + */ + url = conn.getURL(); + + PluginParameters params = new PluginParameterParser().parse(width, height, paramString); + + // Let user know we are starting up + streamhandler.write("instance " + identifier + " status " + amh.getMessage("status.start")); + factory.createPanel(streamhandler, identifier, handle, url, params); long maxTimeToSleep = APPLET_TIMEOUT; appletsLock.lock(); @@ -1545,24 +1555,6 @@ public class PluginAppletViewer extends XEmbeddedFrame return null; } - /** - * Decodes the string (converts html escapes into proper characters) - * - * @param toDecode The string to decode - * @return The decoded string - */ - public static String decodeString(String toDecode) { - - toDecode = toDecode.replace(">", ">"); - toDecode = toDecode.replace("<", "<"); - toDecode = toDecode.replace("&", "&"); - toDecode = toDecode.replace(" ", "\n"); - toDecode = toDecode.replace(" ", "\r"); - toDecode = toDecode.replace(""", "\""); - - return toDecode; - } - /** * System parameters. */ @@ -1579,77 +1571,15 @@ public class PluginAppletViewer extends XEmbeddedFrame systemParam.put("hspace", "hspace"); } - /** - * Print the HTML tag. - */ - public static void printTag(PrintStream out, Hashtable atts) { - out.print(""); - - // A very slow sorting algorithm - int len = atts.size(); - String params[] = new String[len]; - len = 0; - for (Enumeration e = atts.keys(); e.hasMoreElements();) { - String param = e.nextElement(); - int i = 0; - for (; i < len; i++) { - if (params[i].compareTo(param) >= 0) { - break; - } - } - System.arraycopy(params, i, params, i + 1, len - i); - params[i] = param; - len++; - } - - for (int i = 0; i < len; i++) { - String param = params[i]; - if (systemParam.get(param) == null) { - out.println(""); - } - } - out.println(""); - } - /** * Make sure the atrributes are uptodate. */ public void updateAtts() { Dimension d = panel.getSize(); Insets in = panel.getInsets(); - panel.atts.put("width", - Integer.valueOf(d.width - (in.left + in.right)).toString()); - panel.atts.put("height", - Integer.valueOf(d.height - (in.top + in.bottom)).toString()); + int width = d.width - (in.left + in.right); + int height = d.height - (in.top + in.bottom); + panel.updateSizeInAtts(height, width); } /** @@ -1796,412 +1726,6 @@ public class PluginAppletViewer extends XEmbeddedFrame return appletPanels.size(); } - /** - * Scan spaces. - */ - public static void skipSpace(int[] c, Reader in) throws IOException { - while ((c[0] >= 0) && - ((c[0] == ' ') || (c[0] == '\t') || (c[0] == '\n') || (c[0] == '\r'))) { - c[0] = in.read(); - } - } - - /** - * Scan identifier - */ - public static String scanIdentifier(int[] c, Reader in) throws IOException { - StringBuilder buf = new StringBuilder(); - - if (c[0] == '!') { - // Technically, we should be scanning for '!--' but we are reading - // from a stream, and there is no way to peek ahead. That said, - // a ! at this point can only mean comment here afaik, so we - // should be okay - skipComment(c, in); - return ""; - } - - while (true) { - if (((c[0] >= 'a') && (c[0] <= 'z')) || - ((c[0] >= 'A') && (c[0] <= 'Z')) || - ((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '_')) { - buf.append((char) c[0]); - c[0] = in.read(); - } else { - return buf.toString(); - } - } - } - - public static void skipComment(int[] c, Reader in) throws IOException { - StringBuilder buf = new StringBuilder(); - boolean commentHeaderPassed = false; - c[0] = in.read(); - buf.append((char) c[0]); - - while (true) { - if (c[0] == '-' && (c[0] = in.read()) == '-') { - buf.append((char) c[0]); - if (commentHeaderPassed) { - // -- encountered ... is > next? - if ((c[0] = in.read()) == '>') { - buf.append((char) c[0]); - - PluginDebug.debug("Comment skipped: ", buf.toString()); - - // comment skipped. - return; - } - } else { - // first -- is part of