/** * Scan tag */ public static Hashtable scanTag(Reader in) throws IOException { Hashtable atts = new Hashtable(); skipSpace(in); while (c >= 0 && c != '>') { String att = scanIdentifier(in); String val = ""; skipSpace(in); if (c == '=') { int quote = -1; c = in.read(); skipSpace(in); if ((c == '\'') || (c == '\"')) { quote = c; c = in.read(); } StringBuffer buf = new StringBuffer(); while ((c > 0) && (((quote < 0) && (c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '>')) || ((quote >= 0) && (c != quote)))) { buf.append((char)c); c = in.read(); } if (c == quote) { c = in.read(); } skipSpace(in); val = buf.toString(); } //statusMsgStream.println("PUT " + att + " = '" + val + "'"); if (! val.equals("")) { atts.put(att.toLowerCase(java.util.Locale.ENGLISH), val); } while (true) { if ((c == '>') || (c < 0) || ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_')) break; c = in.read(); } //skipSpace(in); } return atts; } /* values used for placement of AppletViewer's frames */ private static int x = 0; private static int y = 0; private static final int XDELTA = 30; private static final int YDELTA = XDELTA; static String encoding = null; static private Reader makeReader(InputStream is) { if (encoding != null) { try { return new BufferedReader(new InputStreamReader(is, encoding)); } catch (IOException x) { } } InputStreamReader r = new InputStreamReader(is); encoding = r.getEncoding(); return new BufferedReader(r); } /** * Scan an html file for <applet> tags */ public static void parse(URL url, String enc) throws IOException { encoding = enc; parse(url, System.out, new StdAppletViewerFactory()); } public static void parse(URL url) throws IOException { parse(url, System.out, new StdAppletViewerFactory()); } 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"); 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(); } /** * Old main entry point. * * @deprecated */ @Deprecated public static void main(String argv[]) { // re-route everything to the new main entry point Main.main(argv); } private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer"); private static void checkConnect(URL url) { SecurityManager security = System.getSecurityManager(); if (security != null) { try { java.security.Permission perm = url.openConnection().getPermission(); if (perm != null) security.checkPermission(perm); else security.checkConnect(url.getHost(), url.getPort()); } catch (java.io.IOException ioe) { security.checkConnect(url.getHost(), url.getPort()); } } }}Lines 1001–1278 of 1278. Previous lines
/** * Scan tag */ public static Hashtable scanTag(Reader in) throws IOException { Hashtable atts = new Hashtable(); skipSpace(in); while (c >= 0 && c != '>') { String att = scanIdentifier(in); String val = ""; skipSpace(in); if (c == '=') { int quote = -1; c = in.read(); skipSpace(in); if ((c == '\'') || (c == '\"')) { quote = c; c = in.read(); } StringBuffer buf = new StringBuffer(); while ((c > 0) && (((quote < 0) && (c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '>')) || ((quote >= 0) && (c != quote)))) { buf.append((char)c); c = in.read(); } if (c == quote) { c = in.read(); } skipSpace(in); val = buf.toString(); } //statusMsgStream.println("PUT " + att + " = '" + val + "'"); if (! val.equals("")) { atts.put(att.toLowerCase(java.util.Locale.ENGLISH), val); } while (true) { if ((c == '>') || (c < 0) || ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_')) break; c = in.read(); } //skipSpace(in); } return atts; } /* values used for placement of AppletViewer's frames */ private static int x = 0; private static int y = 0; private static final int XDELTA = 30; private static final int YDELTA = XDELTA; static String encoding = null; static private Reader makeReader(InputStream is) { if (encoding != null) { try { return new BufferedReader(new InputStreamReader(is, encoding)); } catch (IOException x) { } } InputStreamReader r = new InputStreamReader(is); encoding = r.getEncoding(); return new BufferedReader(r); } /** * Scan an html file for <applet> tags */ public static void parse(URL url, String enc) throws IOException { encoding = enc; parse(url, System.out, new StdAppletViewerFactory()); } public static void parse(URL url) throws IOException { parse(url, System.out, new StdAppletViewerFactory()); } 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"); 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(); } /** * Old main entry point. * * @deprecated */ @Deprecated public static void main(String argv[]) { // re-route everything to the new main entry point Main.main(argv); } private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer"); private static void checkConnect(URL url) { SecurityManager security = System.getSecurityManager(); if (security != null) { try { java.security.Permission perm = url.openConnection().getPermission(); if (perm != null) security.checkPermission(perm); else security.checkConnect(url.getHost(), url.getPort()); } catch (java.io.IOException ioe) { security.checkConnect(url.getHost(), url.getPort()); } } } }