// Return a vector of Tags, given a URL name import java.net.*; import java.io.*; import java.util.*; public class TagsVector extends Vector { TagsVector(URL context, String URLName) { try { URL url = new URL(context, URLName); try { DataInputStream stream = new DataInputStream(url.openStream()); try { for (String line ; (line = stream.readLine()) != null ; ) parseLine(line); } catch (Exception e) {System.out.println("reading: " + e);} addItem(text); } catch (Exception e) {System.out.println(e);} } catch (MalformedURLException e) {System.out.println(e);} } private void addItem(String item) { // ADD ITEM ONLY IF IT for (int i = 0 ; i < item.length() ; i++) // CONTAINS NONSPACE if (item.charAt(i) != ' ') { // CHARACTERS addElement(item); return; } } private String text = ""; private boolean untagged = true, quoted; private void parseLine(String line) { for (int i = 0 ; i < line.length() ; i++) if (line.charAt(i) == '<') { // START A TAG addItem(text); text = ""; addItem("<"); untagged = false; } else if (untagged) // ADD TO UNTAGGED TEXT text += line.substring(i, i+1); else { // PARSE TAGGED TEXT for ( ; i < line.length() ; i++) // SKIP OVER SPACE if (line.charAt(i) != ' ' && line.charAt(i) != '=') break; if (i < line.length()) if (untagged = (line.charAt(i) == '>')) // END THE TAG addItem(">"); else { // GET NEXT TAG ITEM if (quoted = (line.charAt(i) == '"')) i++; int j = i; for ( ; j < line.length() ; j++) { int c = line.charAt(j); if (c == '"' || (!quoted && (c==' ' || c=='=' || c=='>'))) break; } addItem(line.substring(i, j)); i = quoted ? j : j-1; } } } }