String response = FileTools.getFileContentsAsString(cacheFile);
if (response == null) {
response = WebTools.getURLAsString(url);
file(cacheFile, response);
}
Crew crew = new Crew();
crew.setName(getTableValue("Name", response));
crew.setPoints(Integer.parseInt(getTableValue("Point Value", response)));
String number = getTableValue("Collector's Number", response);
// if(number.indexOf("-")>0) {
// int base = -1;
// if(number.startsWith("PS")) {
// base = 0;
// }
// if(number.startsWith("ES")) {
// base = 40;
// }
// if(number.startsWith("SS")) {
// base = 68;
// }
// String remainder = number.substring(number.indexOf("-")+1);
// if(base>=0) {
// number = "" + (Integer.parseInt(remainder) + base);
// }
// }
crew.setNumber(number);
crew.setRarity(getTableValue("Rarity", response));
crew.setRank(getTableValue("Rank", response));
crew.setLink(getTableValue("Link", response));
String marker = "<td><strong>";
if (response.indexOf(marker) > -1) {
int start = response.indexOf(marker);
int end = response.indexOf("</td>", start);
String cell = response.substring(start + 12, end - 4);
cell = cell.trim();
cell = cell.replaceAll("<P>", "<p>");
cell = cell.replaceAll("</strong>", "");
cell = cell.replaceAll("^ *<p>", "");
cell = cell.trim();
cell = cell.replaceAll("^<p>", "");
String[] parts = cell.trim().split("<p>");
if (parts.length == 1) {
crew.setRules("");
crew.setFlavor(parts[0].trim());
} else {
crew.setRules(fixRules(parts[0].trim()));
crew.setFlavor(parts[1].trim());
}
}
if (response.indexOf("src=\"images/Release") > -1) {
int start = response.indexOf("src=\"images/Release");
int end = response.indexOf("width", start);
String set = response.substring(start, end);
set = set.replaceAll(".*alt=\"(.*)\"", "$1");
crew.setExpansion(set.trim());
}
if (response.indexOf("src=\"images/faction") > -1) {
int start = response.indexOf("src=\"images/faction");
int end = response.indexOf("width", start);
String faction = response.substring(start, end);
faction = faction.replaceAll(".*alt=\"(.*)\"", "$1");
crew.setFaction(faction.trim());
}
return crew;
}