Search in sources :

Example 1 with Element

use of net.htmlparser.jericho.Element 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 Element

use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.

the class AreaPageParser method parseQuestRow.

private void parseQuestRow(Element questRow) {
    /*
    <tr>
    <td style="text-align: left;">
    <a href="/wiki/Quest:Bundle_for_Bywater">Bundle for Bywater</a>
    </td>
    <td>9</td>
    </tr>
     */
    // String questName=JerichoHtmlUtils.getTagContents(questRow,HTMLElementName.A);
    Element firstA = questRow.getFirstElement(HTMLElementName.A);
    if (firstA != null) {
        String url = firstA.getAttributeValue("href");
        if ((url != null) && (url.startsWith(QUEST_URL_SEED))) {
            String questIdentifier = url.substring(QUEST_URL_SEED.length()).trim();
            _area.addQuest(questIdentifier);
        }
    // System.out.println("Quest: ["+questName+"], URL=["+url+"]");
    }
}
Also used : Element(net.htmlparser.jericho.Element)

Example 3 with Element

use of net.htmlparser.jericho.Element 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 4 with Element

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

Example 5 with Element

use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.

the class RelicsIndexPageParser method handleTableRow.

private Relic handleTableRow(Element tr, Integer level, RelicType defaultType) {
    Relic relic = null;
    List<Element> tds = JerichoHtmlUtils.findElementsByTagName(tr, HTMLElementName.TD);
    if (tds.size() == 2) {
        // Icon & name
        Element iconAndNameElement = tds.get(0);
        List<Element> as = JerichoHtmlUtils.findElementsByTagName(iconAndNameElement, HTMLElementName.A);
        Element iconElement = as.get(0);
        String iconPath = extractIcon(iconElement);
        // Name
        Element nameElement = as.get(1);
        String name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.SPAN);
        if (name == null) {
            name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.A);
        }
        // Type
        RelicType type = getTypeFromName(name);
        relic = new Relic(name, type, level);
        relic.setIconFilename(iconPath);
        // Stats
        Element statsElement = tds.get(1);
        String statsStr = JerichoHtmlUtils.getTextFromTag(statsElement);
        statsStr = statsStr.replaceAll(",", "\n");
        BasicStatsSet stats = parseStats(statsStr);
        relic.getStats().setStats(stats);
    } else if (tds.size() == 3) {
        // Icon
        Element iconElement = tds.get(0);
        String iconPath = extractIcon(iconElement);
        // Name
        Element nameElement = tds.get(1);
        String name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.A);
        // Type
        RelicType type = getTypeFromName(name);
        relic = new Relic(name, type, level);
        relic.setIconFilename(iconPath);
        // Stats
        Element statsElement = tds.get(2);
        String statsStr = JerichoHtmlUtils.getTextFromTag(statsElement);
        BasicStatsSet stats = parseStats(statsStr);
        relic.getStats().setStats(stats);
    } else if (// Retired relics
    tds.size() == 4) {
        // Icon
        Element iconElement = tds.get(0);
        String iconPath = extractIcon(iconElement);
        // Name
        Element nameElement = tds.get(1);
        String name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.A);
        if (name == null) {
            name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.TD);
        }
        if (name.startsWith("Relic:")) {
            name = name.substring(6).trim();
        }
        // Tier
        /*
      Element tierElement=tds.get(2);
      String tierStr=JerichoHtmlUtils.getTextFromTag(tierElement);
      Integer tier=null;
      if (tierStr.length()>0)
      {
        tier=NumericTools.parseInteger(tierStr.trim());
      }
      else
      {
        tier=null;
      }
      */
        relic = new Relic(name, defaultType, level);
        relic.setIconFilename(iconPath);
        // Stats
        Element statsElements = tds.get(3);
        String statsStr = JerichoHtmlUtils.getTextFromTag(statsElements);
        statsStr = statsStr.replace(", ", "\n");
        BasicStatsSet stats = parseStats(statsStr);
        relic.getStats().setStats(stats);
    } else if (// Crafted relics
    tds.size() == 5) {
        // Icon
        Element iconElement = tds.get(0);
        String iconPath = extractIcon(iconElement);
        // Name
        Element nameElement = tds.get(1);
        String name = JerichoHtmlUtils.getTagContents(nameElement, HTMLElementName.A);
        // Type
        RelicType type = RelicType.CRAFTED_RELIC;
        // Level
        Element levelElement = tds.get(2);
        String levelStr = JerichoHtmlUtils.getTextFromTag(levelElement);
        if (levelStr.length() > 0) {
            level = NumericTools.parseInteger(levelStr.trim());
        } else {
            level = null;
        }
        relic = new Relic(name, type, level);
        relic.setIconFilename(iconPath);
        // Stats
        Element statsElements = tds.get(3);
        String statsStr = JerichoHtmlUtils.getTextFromTag(statsElements);
        BasicStatsSet stats = parseStats(statsStr);
        relic.getStats().setStats(stats);
    }
    // System.out.println(relic);
    return relic;
}
Also used : Relic(delta.games.lotro.lore.items.legendary.relics.Relic) RelicType(delta.games.lotro.lore.items.legendary.relics.RelicType) Element(net.htmlparser.jericho.Element) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet)

Aggregations

Element (net.htmlparser.jericho.Element)70 Source (net.htmlparser.jericho.Source)17 DownloadService (delta.games.lotro.utils.DownloadService)11 ArrayList (java.util.ArrayList)11 Segment (net.htmlparser.jericho.Segment)6 InputSource (org.xml.sax.InputSource)6 Context (com.cflint.plugins.Context)4 Matcher (java.util.regex.Matcher)4 StartTag (net.htmlparser.jericho.StartTag)4 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)3 Item (delta.games.lotro.lore.items.Item)3 List (java.util.List)3 Attribute (net.htmlparser.jericho.Attribute)3 CFScriptStatement (cfml.parsing.cfscript.script.CFScriptStatement)2 ParseException (cfml.parsing.reporting.ParseException)2 CFLintScanException (com.cflint.exception.CFLintScanException)2 ContextMessage (com.cflint.plugins.Context.ContextMessage)2 Money (delta.games.lotro.common.Money)2 CraftingResult (delta.games.lotro.lore.crafting.recipes.CraftingResult)2 Ingredient (delta.games.lotro.lore.crafting.recipes.Ingredient)2