(! line.trim().equals("")) &&
(! line.startsWith("#"))) {
StringTokenizer st = new StringTokenizer(line);
// we need at least 2 tokens
if (st.countTokens() < 2) {
throw new IOException("line "+lineno+" has less then 2 fields");
}
String allowStr = st.nextToken();
boolean allow = true;
String mime = st.nextToken();
// allow or deny ?
if (allowStr.equalsIgnoreCase("allow")) {
allow=true;
} else if (allowStr.equalsIgnoreCase("deny")) {
allow=false;
} else {
throw new IOException("first token in line "+lineno+
" has to be allow or deny");
}
DownloadRule r = new DownloadRule();
r.setAllow(allow);
try {
r.setMimeType(mime);
} catch (IllegalArgumentException e) {
throw new IOException(e.getMessage());
}
// parse < and > rules
while (st.hasMoreTokens()) {
boolean isMin=true;
String descr=st.nextToken();
if (descr.startsWith("<")) {
// it is a maximum value
isMin=false;
} else if (descr.startsWith(">")) {
isMin=true;
} else {
throw new IOException("can't understand "+descr+
" in line "+lineno);
}
int size=0;
try {
size = Integer.parseInt(descr.substring(1));
} catch (NumberFormatException e) {
throw new IOException("no numerical value "+descr+
" in line "+lineno);
}
if (isMin) {
r.setMinSize(size);