use of delta.games.lotro.lore.region.Region 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.lore.region.Region in project lotro-tools by dmorcellet.
the class MainTestRegionParsing method main.
/**
* Basic main method for test.
* @param args Not used.
*/
public static void main(String[] args) {
RegionPageParser regionParser = new RegionPageParser();
Region shire = regionParser.parseRegionPage("The_Shire");
if (shire != null) {
AreaPageParser areaParser = new AreaPageParser();
System.out.println(shire.dump());
Area[] areas = shire.getAreas();
for (Area area : areas) {
String identifier = area.getIdentifier();
Area a = areaParser.parseAreaPage(identifier);
System.out.println(a.dump());
String[] questIdentifiers = a.getQuestIdentifiers();
System.out.println(Arrays.deepToString(questIdentifiers));
}
}
}
Aggregations