use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.
the class AreaPageParser method parseAreaPage.
/**
* Parse the region page at the given URL.
* @param identifier Identifier of the area.
* @return An area or <code>null</code> if an error occurred.
*/
public Area parseAreaPage(String identifier) {
Area ret = null;
String url = "http://lorebook.lotro.com/wiki/Area:" + identifier;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <div class="lorebooktitle">Area: Bindbole Wood</div>
Element titleTag = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "lorebooktitle");
String name = "";
if (titleTag != null) {
name = CharacterReference.decodeCollapseWhiteSpace(titleTag.getContent());
if (name.startsWith(TITLE_SEED)) {
name = name.substring(TITLE_SEED.length()).trim();
}
}
_area = new Area(identifier, name);
// <div id="regionQuests"
Element questsTable = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "id", "region_quests_table");
if (questsTable != null) {
parseQuests(questsTable);
}
ret = _area;
_area = null;
} catch (Exception e) {
_logger.error("Cannot parse region page [" + url + "]", e);
}
return ret;
}
use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.
the class RegionPageParser method parseRegionPage.
/**
* Parse a region page.
* @param identifier Identifier of the region.
* @return A region or <code>null</code> if an error occurred.
*/
public Region parseRegionPage(String identifier) {
Region ret = null;
String url = "http://lorebook.lotro.com/wiki/Region:" + identifier;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <div class="lorebooktitle">Region: The Shire</div>
Element titleTag = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "lorebooktitle");
String name = "";
if (titleTag != null) {
name = CharacterReference.decodeCollapseWhiteSpace(titleTag.getContent());
if (name.startsWith(TITLE_SEED)) {
name = name.substring(TITLE_SEED.length()).trim();
}
}
_region = new Region(identifier, name);
// <div class="regionAreas widget ui-corner-all">
Element regionAreas = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "regionAreas widget ui-corner-all");
if (regionAreas != null) {
parseAreas(regionAreas);
}
ret = _region;
_region = null;
} catch (Exception e) {
_logger.error("Cannot parse region page [" + url + "]", e);
}
return ret;
}
use of delta.games.lotro.utils.DownloadService in project lotro-tools by dmorcellet.
the class ItemPageParser method findIdentifiers.
private void findIdentifiers(List<Item> items) {
String url = "http://lorebook.lotro.com/index.php?title=" + _key + "&action=edit";
DownloadService downloader = DownloadService.getInstance();
try {
String page = downloader.getPage(url);
Source s = new Source(page);
// <textarea id="wpTextbox1"
Element pageSource = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(s, HTMLElementName.TEXTAREA, "id", "wpTextbox1");
if (pageSource != null) {
String text = JerichoHtmlUtils.getTextFromTag(pageSource);
parsePageSource(text, items);
} else {
_logger.warn("Cannot find identifiers!");
}
} catch (Exception e) {
_logger.error("Parsing error", e);
}
}
use of delta.games.lotro.utils.DownloadService 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 delta.games.lotro.utils.DownloadService 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;
}
Aggregations