Search in sources :

Example 66 with Element

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

the class ItemPageParser method parseItemSection.

private Item parseItemSection(Element itemSection) {
    Item ret = null;
    try {
        _item = null;
        Element itemTooltip = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemSection, HTMLElementName.TABLE, "class", "tooltip");
        if (itemTooltip != null) {
            parseItemDescription(itemTooltip);
        }
        ret = _item;
    } catch (Exception e) {
        ret = null;
        _logger.error("Item [" + _key + "]. Cannot parse item section!", e);
    }
    return ret;
}
Also used : Item(delta.games.lotro.lore.items.Item) Element(net.htmlparser.jericho.Element)

Example 67 with Element

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

the class ItemPageParser method parseResourceSection.

private Item parseResourceSection(Element resourceSection) {
    Item ret = null;
    try {
        Element officialSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(resourceSection, HTMLElementName.DIV, "class", "officialsection");
        if (officialSection != null) {
            ret = new Item();
            // Name
            String name = null;
            Element nameElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(officialSection, HTMLElementName.DIV, "class", "lorebooktitle");
            if (nameElement != null) {
                name = CharacterReference.decodeCollapseWhiteSpace(nameElement.getContent());
                if (name != null) {
                    if (name.startsWith(RESOURCE_SEED)) {
                        name = name.substring(RESOURCE_SEED.length()).trim();
                    }
                }
            }
            ret.setName(name);
            // Description
            List<Element> divs = JerichoHtmlUtils.findElementsByTagName(officialSection, HTMLElementName.DIV);
            if ((divs != null) && (divs.size() >= 4)) {
                Element div = divs.get(3);
                String description = CharacterReference.decodeCollapseWhiteSpace(div.getContent());
                ret.setDescription(description);
            }
        }
    } catch (Exception e) {
        ret = null;
        _logger.error("Item [" + _key + "]. Cannot parse item section!", e);
    }
    return ret;
}
Also used : Item(delta.games.lotro.lore.items.Item) Element(net.htmlparser.jericho.Element)

Example 68 with Element

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

the class LotroWikiDeedCategoryPageParser method parseTables.

private void parseTables(Source source, List<String> deedIds) {
    List<Element> tables = JerichoHtmlUtils.findElementsByTagName(source, HTMLElementName.TABLE);
    for (Element table : tables) {
        boolean ok = checkTable(table);
        if (!ok) {
            continue;
        }
        List<Element> rows = JerichoHtmlUtils.findElementsByTagName(table, HTMLElementName.TR);
        rows.remove(0);
        for (Element row : rows) {
            String deedId = handleRow(row);
            if (deedId != null) {
                deedIds.add(deedId);
            }
        }
    }
}
Also used : Element(net.htmlparser.jericho.Element)

Example 69 with Element

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

the class LotroWikiDeedCategoryPageParser method handleRow.

private String handleRow(Element row) {
    String deedId = null;
    List<Element> cells = JerichoHtmlUtils.findElementsByTagName(row, HTMLElementName.TD);
    if (cells.size() >= 1) {
        Element deedCell = cells.get(0);
        Element anchor = JerichoHtmlUtils.findElementByTagName(deedCell, HTMLElementName.A);
        if (anchor != null) {
            // String title=anchor.getAttributeValue("title");
            String href = anchor.getAttributeValue("href");
            // System.out.println(href + "  ==>  "+title);
            if (href.startsWith(INDEX)) {
                deedId = href.substring(INDEX.length());
            }
        }
    }
    return deedId;
}
Also used : Element(net.htmlparser.jericho.Element)

Example 70 with Element

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

the class LotroWikiDeedCategoryPageParser method checkTable.

private boolean checkTable(Element table) {
    List<Element> rows = JerichoHtmlUtils.findElementsByTagName(table, HTMLElementName.TR);
    if (rows.size() >= 1) {
        Element header = rows.get(0);
        List<Element> cells = JerichoHtmlUtils.findElementsByTagName(header, HTMLElementName.TH);
        if (cells.size() >= 1) {
            String text = JerichoHtmlUtils.getTextFromTag(cells.get(0));
            return text.contains("Deed");
        }
    }
    return false;
}
Also used : Element(net.htmlparser.jericho.Element)

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