}
private void parseMovieQueue(Node queue, List<MovieItem> items) {
NodeFilter discFilter = new CssClassFilter("disc");
NodeCollector infoCollector = new NodeCollector(new NodeFilter[] {
new CssClassFilter("bvr-qremove"),
new AndFilter(new NodeClassFilter(LinkTag.class),
new HasParentFilter(new CssClassFilter("title"))),
new CssClassFilter("mpaa"),
new CssClassFilter("bvr-rating"),
new AndFilter(new NodeClassFilter(LinkTag.class),
new CssClassFilter("availability")),
new CssClassFilter("shipped"),
new CssClassFilter("arrival")
});
Pattern ratingPattern = Pattern.compile(RATING_IMG_EXPR);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
NodeList discs = new NodeList();
queue.collectInto(discs, discFilter);
int index;
NodeList all = new NodeList();
SimpleNodeIterator iter = discs.elements();
while (iter.hasMoreNodes()) {
all.removeAll();
infoCollector.clear();
Node disc = iter.nextNode();
//collect all the nodes for the movie items
disc.collectInto(all, infoCollector);
int i=0;
//parse out all the information
String queueId = null;
boolean discSet = false;
LinkTag removeNode = (LinkTag)infoCollector.getNode(i++);
if (removeNode != null) {
queueId = removeNode.getLink();
discSet = queueId.indexOf("setId") != -1;
index = queueId.lastIndexOf('=');
if (index != -1) {
queueId = queueId.substring(index+1);
}
}
LinkTag titleNode = (LinkTag)infoCollector.getNode(i++);
String movieId = titleNode.getLink();
index = movieId.lastIndexOf('/');
if (index != -1) {
movieId = movieId.substring(index+1);
}
String title = NodeUtils.getTextData(titleNode);
String mpaa = NodeUtils.getTextData(infoCollector.getNode(i++));
int rating = -1;
boolean myRating = false;
Node ratingNode = infoCollector.getNode(i++);
if (ratingNode != null) {
String ratingStr = ((Tag)ratingNode).getAttribute("src");
Matcher matcher = ratingPattern.matcher(ratingStr);
if (matcher.matches()) {
myRating = "rt".equals(matcher.group(1));
rating = Integer.parseInt(matcher.group(2));
}
}
String availability = NodeUtils.getTextData(infoCollector.getNode(i++));
Node node;
Date shippedDate = null;
Date arrivalDate = null;
try {
node = infoCollector.getNode(i++);
if (node != null) {
shippedDate = dateFormat.parse(NodeUtils.getTextData(node));
}
} catch (ParseException e) {}
try {
node = infoCollector.getNode(i++);
if (node != null) {
arrivalDate = dateFormat.parse(NodeUtils.getTextData(node));
}
} catch (ParseException e) {}