Search in sources :

Example 1 with Area

use of delta.games.lotro.lore.region.Area 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;
}
Also used : Area(delta.games.lotro.lore.region.Area) Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source)

Example 2 with Area

use of delta.games.lotro.lore.region.Area in project lotro-tools by dmorcellet.

the class RegionPageParser method parseArea.

private void parseArea(Element area) {
    /*
<div>
<img id="1879064022" class="territoryMarker" src="http://content.turbine.com/sites/google_map/search_result_icon.gif" title="Highlight on Map">
<a href="/wiki/Area:Bindbole_Wood">Bindbole Wood</a>
</div>
     */
    String areaName = JerichoHtmlUtils.getTagContents(area, HTMLElementName.A);
    Element firstA = area.getFirstElement(HTMLElementName.A);
    if (firstA != null) {
        String url = firstA.getAttributeValue("href");
        if ((url != null) && (url.startsWith(AREA_URL_SEED))) {
            String areaIdentifier = url.substring(AREA_URL_SEED.length()).trim();
            Area a = new Area(areaIdentifier, areaName);
            _region.addArea(a);
        }
    // System.out.println("Area: ["+areaName+"], URL=["+url+"]");
    }
}
Also used : Area(delta.games.lotro.lore.region.Area) Element(net.htmlparser.jericho.Element)

Example 3 with Area

use of delta.games.lotro.lore.region.Area 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));
        }
    }
}
Also used : Area(delta.games.lotro.lore.region.Area) Region(delta.games.lotro.lore.region.Region)

Example 4 with Area

use of delta.games.lotro.lore.region.Area in project lotro-tools by dmorcellet.

the class MainTestAreaParsing method main.

/**
 * Basic main method for test.
 * @param args Not used.
 */
public static void main(String[] args) {
    AreaPageParser parser = new AreaPageParser();
    Area area = parser.parseAreaPage("Bindbole_Wood");
    if (area != null) {
        System.out.println(area.dump());
    }
}
Also used : Area(delta.games.lotro.lore.region.Area)

Aggregations

Area (delta.games.lotro.lore.region.Area)4 Element (net.htmlparser.jericho.Element)2 Region (delta.games.lotro.lore.region.Region)1 DownloadService (delta.games.lotro.utils.DownloadService)1 Source (net.htmlparser.jericho.Source)1