import java.util.Vector;
import java.util.StringTokenizer;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
/**
*
tag. */
void analyzeAnchor(String anchor) {
String href = extract(anchor, "href");
if (href == null) return;
try {
addURL(new URL(base, href));
} catch (MalformedURLException e) {
anchor = anchor.toLowerCase();
// java doesn't understand mailto and will throw an exception
if (!href.startsWith("mailto:")) {
e.printStackTrace();
}
}
}
/** Analyzes the tag. */
void analyzeFrame(String frame) {
String src = extract(frame, "src");
if (src == null) return;
try {
addURL(new URL(base, src));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/** Extracts the base URL from the tag. */
void extractBase(String b) {
String b2 = extract(b, "href");
if (b2 != null) {
try {
base = new URL(base, b2);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
/** Adds "url" to the list of URLs. */
public void addURL(URL url) {
urls.addElement(url);
url_count++;
}
public boolean hasMoreElements() {
return url_count != next_url;
}
public Object nextElement() {
Object ob = urls.elementAt(next_url);
next_url++;
return ob;
}
/** Resets this enumeration. */
public void reset() {
next_url = 0;
}
/** Returns the value in "line" associated with "key", or null if "key"
* is not found. For instance, if line were "a href="blah blah blah"
* and "key" were "href" this method would return "blah blah blah".
*
* Keys are case insensitive.
*/
String extract(String line, String key) {
try {
key = key.toLowerCase();
String lower_case = line.toLowerCase();
int i = lower_case.indexOf(key);
if (i < 0) return null;
i += key.length();
if (line.charAt(i) != '=') return null;
i++;
int i2;
if (line.charAt(i) == '"') {
i++;
i2 = line.indexOf('"', i);
if (i2 < 0) {
return line.substring(i);
} else {
return line.substring(i, i2);
}
} else {
int targ = line.length();
for (i2 = i; i < targ; i++) {
if (Character.isSpace(line.charAt(i))) break;
}
return line.substring(i, i2);
}
} catch (StringIndexOutOfBoundsException e) {}
return null;
}
}