import java.util.Hashtable; import java.net.*; import java.io.IOException; public class AppletTag { String code; URL codebase; int width; int height; String name = null; Hashtable params; String alt = ""; public AppletTag(String s) throws IOException { String temp; String at = s.substring(0, s.indexOf('>')); code = readParameter(at, "code"); if (code.endsWith(".class")) code = code.substring(0,code.length()-6); try { temp = readParameter(at, "codebase"); // need to handle relative URLs if (temp == null) codebase = null; else codebase = new URL(temp); } catch (MalformedURLException e) { codebase = null; } name = readParameter(at, "name"); alt = readParameter(at, "alt"); try { width = Integer.parseInt(readParameter(at, "width")); height = Integer.parseInt(readParameter(at, "height")); } catch (NumberFormatException e) { throw new IOException("The tag must have height and width parameters."); } catch (NullPointerException e) { throw new IOException("The tag must have height and width parameters."); } int nextParam = -1; String ucs = s.toUpperCase(); while ((nextParam = ucs.indexOf("")), "name"); String value = readParameter(s.substring(nextParam, s.indexOf("\\>")), "value"); params.put(name, value); } } String readParameter(String tag, String key) { key = key.toLowerCase(); String ltag = tag.toLowerCase(); int e1; int k1 = ltag.indexOf(key + '='); if (k1 == -1) { k1 = ltag.indexOf(key + ' '); if (k1 == -1) return null; int k2 = ltag.indexOf(' ', k1); while (ltag.charAt(k2) == ' ') k2++; if (ltag.charAt(k2) != '=') return null; e1 = k2; } else { e1=ltag.indexOf('=', k1); } // e1 is now positioned on the equals sign // skip spaces, if any int v1 = e1+1; while (tag.charAt(v1) == ' ') v1++; int v2; try { char c = tag.charAt(v1); if (c == '"') { v1 = v1 + 1; v2 = tag.indexOf('"', v1+1); } else v2 = tag.indexOf(' ', v1); if (v2 == -1) v2 = tag.indexOf('>', v1); if (v2 == -1) return tag.substring(v1); return tag.substring(v1,v2); } catch (StringIndexOutOfBoundsException e) { System.err.println(key + "=" + tag.substring(v1)); System.err.println(e); return null; } } public URL codebase() { return codebase; } public String code() { return code; } public int width() { return width; } public int height() { return height; } public String name() { return name; } public String alt() { return alt; } public Hashtable params() { return params; } public String toString() { String s = "