use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class QuestPageParser method parseQuestPage.
/**
* Parse the quest page at the given URL.
* @param url URL of quest page.
* @return A list of quests or <code>null</code> if an error occurred.
*/
public List<QuestDescription> parseQuestPage(String url) {
List<QuestDescription> quests = null;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <div id="lorebookNoedit">
Element lorebook = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "lorebookNoedit");
if (lorebook != null) {
// identifier
// <a id="ca-nstab-quest" class="lorebook_action_link" href="/wiki/Quest:A_Feminine_Curve_to_the_Steel">Article</a>
_key = null;
Element articleLink = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.A, "id", "ca-nstab-quest");
if (articleLink != null) {
String thisURL = articleLink.getAttributeValue("href");
if ((thisURL != null) && (thisURL.startsWith(QUEST_URL_SEED))) {
_key = thisURL.substring(QUEST_URL_SEED.length()).trim();
}
}
quests = new ArrayList<QuestDescription>();
List<Element> questSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(lorebook, HTMLElementName.DIV, "class", "lorebookquest");
if ((questSections != null) && (questSections.size() > 0)) {
for (Element questSection : questSections) {
QuestDescription quest = parseQuestSection(questSection);
if (quest != null) {
// System.out.println(quest.dump());
quests.add(quest);
quest.setKey(_key);
}
}
}
findIdentifiers(quests);
}
} catch (Exception e) {
quests = null;
_logger.error("Cannot parse quest page [" + url + "]", e);
}
return quests;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class CharacterLogPageParser method parseFirstPage.
private int parseFirstPage(String rootUrl) {
int nbPages = 0;
String firstPageURL = rootUrl + "=1";
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(firstPageURL);
Source source = new Source(page);
// <div id="widget_" class="widget ui-widget ui-corner-all" type="activitylog">
Element activityLog = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "type", "activitylog");
if (activityLog != null) {
// Fetch page numbers
// <div class="pagination">
Element pagination = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "pagination");
if (pagination != null) {
// <td class="current"> Page 1 of 121 </td>
String pages = JerichoHtmlUtils.getTagContents(source, HTMLElementName.TD, "class", "current");
if (pages != null) {
String[] items = pages.split(" ");
if ((items != null) && (items.length == 4)) {
nbPages = NumericTools.parseInt(items[3], 0);
}
}
}
}
} catch (Exception e) {
_logger.error("Cannot parse character log page [" + firstPageURL + "]", e);
}
return nbPages;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class CharacterLogPageParser method parseLogPage.
private boolean parseLogPage(CharacterLog log, String rootURL, int pageNumber, int retryNumber) {
if (_logger.isInfoEnabled()) {
_logger.info("Page #" + pageNumber + ((retryNumber > 0) ? " try #" + retryNumber : ""));
}
boolean ret;
String url = rootURL + "=" + String.valueOf(pageNumber);
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <table class="gradient_table activitylog">
Element logTable = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "gradient_table activitylog");
if (logTable != null) {
List<Element> trs = logTable.getAllElements(HTMLElementName.TR);
if ((trs != null) && (trs.size() >= 1)) {
// ignore first (table headers)
trs.remove(0);
for (Element tr : trs) {
CharacterLogItem item = parseLogItem(tr);
if (item != null) {
boolean addIt = true;
long date = item.getDate();
if (_stopDate != null) {
if (date < _stopDate.longValue()) {
addIt = false;
_stop = true;
break;
}
}
if (addIt) {
log.addLogItem(item);
}
}
}
}
}
ret = true;
} catch (Exception e) {
_logger.warn("Cannot parse character page [" + url + "]", e);
ret = false;
}
return ret;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class RewardsHTMLParser method parseReward.
private void parseReward(Element rewardDiv, Rewards rewards) {
List<Element> strongs = rewardDiv.getAllElements(HTMLElementName.STRONG);
if ((strongs != null) && (strongs.size() >= 1)) {
Element strong = strongs.get(0);
String key = CharacterReference.decodeCollapseWhiteSpace(strong.getContent());
key = cleanupFieldName(key);
if ("Money".equals(key)) {
Money m = parseMoneyReward(rewardDiv);
rewards.getMoney().add(m);
} else if ("Reputation".equals(key)) {
Reputation r = parseReputationReward(rewardDiv);
rewards.getReputation().add(r);
} else if ((RECEIVE_KEY.equals(key)) || (SELECT_ONE_OF_KEY.equals(key))) {
parseItemReward(rewardDiv, rewards);
} else if ("IXP".equals(key)) {
boolean itemXP = parseItemXPReward(rewardDiv);
rewards.setHasItemXP(itemXP);
} else if ("Traits".equals(key)) {
parseTraitReward(rewardDiv, rewards);
} else if ("Titles".equals(key)) {
parseTitleReward(rewardDiv, rewards);
} else if ("Virtues".equals(key)) {
parseVirtuesReward(rewardDiv, rewards);
} else if ("Emotes".equals(key)) {
parseEmoteReward(rewardDiv, rewards);
} else if ("Destiny Points".equals(key)) {
int nb = parseDestinyPoints(rewardDiv);
rewards.setDestinyPoints(nb);
} else {
_logger.error(_objectId + ": unknown reward type: " + key);
}
}
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class RewardsHTMLParser method parseTitleReward.
private void parseTitleReward(Element rewardDiv, Rewards rewards) {
List<Element> as = rewardDiv.getAllElements(HTMLElementName.A);
int size = (as != null) ? as.size() : 0;
if (size == 1) {
String name = null;
String titleIdentifier = null;
// String iconURL=null;
Element firstA = as.get(0);
String url = firstA.getAttributeValue("href");
if ((url != null) && (url.startsWith(TITLE_URL_SEED))) {
titleIdentifier = url.substring(TITLE_URL_SEED.length()).trim();
}
name = CharacterReference.decodeCollapseWhiteSpace(firstA.getContent());
if ((name != null) && (titleIdentifier != null)) {
Title title = new Title(titleIdentifier, name);
rewards.addTitle(title);
}
} else {
_logger.warn(_objectId + ": title with " + size + " anchor tags!");
}
/*
<div class="questReward">
<div>
<strong>Titles:</strong>
</div>
<div>
<a href="/wiki/Title:_Honorary_Shirriff"> Honorary Shirriff</a>
</div>
</div>
*/
}
Aggregations