// Find if the redirect is already taken into account
boolean exists = false;
Iterator<Page> itPage = p.getRedirectIteratorWithPage();
while (itPage.hasNext()) {
Page tmp = itPage.next();
String title = getNormalizedTitle(tmp.getTitle(), normalization);
if (Page.areSameTitle(title, toPage)) {
exists = true;
}
}
// Add the redirect if needed
itPage = p.getRedirectIteratorWithPage();
while (itPage.hasNext()) {
Page tmp = itPage.next();
String title = getNormalizedTitle(tmp.getTitle(), normalization);
if (!exists && Page.areSameTitle(title, fromPage)) {
XPath xpaPage = createXPath("page", "title", toPage);
List listTo = xpaPage.selectNodes(listPages);
if (!listTo.isEmpty()) {
Element to = (Element) listTo.get(0);
Page pageTo = DataManager.getPage(
p.getWikipedia(), xpaTitle.valueOf(to), null, null, null);
pageTo.setNamespace(xpaNamespace.valueOf(to));
pageTo.setPageId(xpaPageId.valueOf(to));
p.addRedirect(pageTo);
}
}
}
}
}
// Analyzing missing pages
for (Page p : pages) {
Iterator<Page> itPage = p.getRedirectIteratorWithPage();
while (itPage.hasNext()) {
Page tmp = itPage.next();
String title = getNormalizedTitle(tmp.getTitle(), normalization);
XPath xpaPage = createXPath("page", "title", title);
Element page = (Element) xpaPage.selectSingleNode(listPages);
if (page != null) {
List pageId = xpaPageId.selectNodes(page);
if ((pageId != null) && (!pageId.isEmpty())) {
tmp.setExisting(Boolean.TRUE);
} else {
Attribute attrMissing = page.getAttribute("missing");
if (attrMissing != null) {
tmp.setExisting(Boolean.FALSE);
}
}
}
}
}