Search in sources :

Example 16 with Element

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

the class ItemPageParser method fetchItemKey.

private String fetchItemKey(Segment root) {
    String id = null;
    Element articleTop = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(root, HTMLElementName.DIV, "id", "article_top");
    if (articleTop != null) {
        Element article = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(articleTop, HTMLElementName.A, "class", "lorebook_action_link");
        if (article != null) {
            String href = article.getAttributeValue("href");
            if (href != null) {
                if (href.startsWith(HREF_IDENTIFIER_SEED)) {
                    id = href.substring(HREF_IDENTIFIER_SEED.length());
                    // explicit copy to trim underlying char[]
                    id = new String(id);
                }
            }
        }
    }
    return id;
}
Also used : Element(net.htmlparser.jericho.Element)

Example 17 with Element

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

Example 18 with Element

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

the class ItemPageParser method getIconURL.

private String getIconURL(Element itemTooltip) {
    String url = null;
    Element iconElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemicon");
    if (iconElement != null) {
        Element imgElement = iconElement.getFirstElement(HTMLElementName.IMG);
        url = imgElement.getAttributeValue("src");
    }
    return url;
}
Also used : Element(net.htmlparser.jericho.Element)

Example 19 with Element

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

the class ItemPageParser method parseItemDescription.

private void parseItemDescription(Element itemTooltip) {
    // Name
    String name = findName(itemTooltip);
    // Find out type of item
    Armour armour = null;
    // Armor?
    // <div class="itemarmor">1130 Armour Value</div>
    String armorStr = getTagContent(itemTooltip, "itemarmor");
    Weapon weapon = null;
    // Weapon?
    // <div class="itemdps">126.5 DPS</div>
    String dpsStr = getTagContent(itemTooltip, "itemdps");
    if (armorStr != null) {
        // Armour!
        armour = new Armour();
        _item = armour;
        Integer armourValue = getArmour(armorStr);
        if (armourValue != null) {
            armour.setArmourValue(armourValue.intValue());
        }
        String armourTypeStr = getTagContent(itemTooltip, "itemtype");
        ArmourType armourType = ArmourType.getArmourTypeByName(armourTypeStr);
        if (armourType == null) {
            // Assume light armour...
            armourType = ArmourType.LIGHT;
            _logger.warn("Unknown armour type: " + armourTypeStr + " (name=" + name + ")");
        }
        armour.setArmourType(armourType);
    } else if (dpsStr != null) {
        // Weapon!
        weapon = new Weapon();
        _item = weapon;
        Float dpsValue = getDPS(dpsStr);
        if (dpsValue != null) {
            weapon.setDPS(dpsValue.floatValue());
        }
        String weaponTypeStr = getTagContent(itemTooltip, "itemtype");
        if (weaponTypeStr != null) {
            WeaponType type = WeaponType.getWeaponTypeByName(weaponTypeStr);
            if (type != null) {
                weapon.setWeaponType(type);
            } else {
                _logger.warn("Unknown weapon type: " + weaponTypeStr + " (name=" + name + ")");
            }
        }
    } else {
        _item = new Item();
    }
    // Icon
    // <div class="itemicon"><img src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/item/tool/eq_c_craft_tool_voc_explorer_tier6.png"></div>
    String url = getIconURL(itemTooltip);
    // Name
    _item.setName(name);
    if (url != null) {
        _item.setIconURL(url);
    }
    // Item sub-category
    // <div class="itemtype">Craft Tool</div>
    // TODO: duplicated with weapon type and armor type...
    String subCategory = getTagContent(itemTooltip, "itemtype");
    _item.setSubCategory(subCategory);
    // Uniqueness
    // <div class="itemunique"></div>
    String uniqueStr = getTagContent(itemTooltip, "itemunique");
    if ("Unique".equalsIgnoreCase(uniqueStr)) {
        _item.setUnique(true);
    }
    // Item bind
    // <div class="itembind">Bind on Equip</div>
    String itemBindStr = getTagContent(itemTooltip, "itembind");
    ItemBinding binding = getBinding(itemBindStr);
    _item.setBinding(binding);
    // Damage:
    // <div class="itemdamage">197 - 359 Common Damage</div>
    String damage = getTagContent(itemTooltip, "itemdamage");
    if (damage != null) {
        try {
            if (damage.endsWith("Damage")) {
                String tmp = damage.substring(0, damage.length() - 6).trim();
                String[] split = tmp.split(" ", 4);
                int minDamage = Integer.parseInt(split[0]);
                int maxDamage = Integer.parseInt(split[2]);
                String typeStr = split[3];
                DamageType type = DamageType.getDamageTypeByName(typeStr);
                if (type == null) {
                    type = DamageType.COMMON;
                    _logger.warn("Unmanaged damage type [" + typeStr + "]");
                }
                weapon.setMinDamage(minDamage);
                weapon.setMaxDamage(maxDamage);
                weapon.setDamageType(type);
            }
        } catch (Exception e) {
            _logger.error("Damage parsing exception on [" + damage + "]", e);
        }
    }
    // Bonuses
    // <div class="itemes">
    // <div class="iteme">
    // <div>-3s Forester Chopping Duration</div>
    // </div>
    // ...
    // </div>
    List<String> bonuses = new ArrayList<String>();
    Element itemsContainer = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemes");
    if (itemsContainer != null) {
        List<Element> itemsList = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(itemsContainer, HTMLElementName.DIV, "class", "iteme");
        for (Element item : itemsList) {
            List<Element> children = item.getChildElements();
            if (children != null) {
                for (Element child : children) {
                    String line = JerichoHtmlUtils.getTagContents(child, HTMLElementName.DIV);
                    bonuses.add(line);
                }
            }
        }
    }
    _item.setBonus(bonuses);
    // TODO <div class="itemmsi">+5 Damage to The Dead</div>
    String msi = getTagContent(itemTooltip, "itemmsi");
    if ((msi != null) && (msi.length() > 0)) {
        _logger.warn("Unmanaged itemmsi [" + msi + "] for " + _item.getName());
    }
    // Item set
    ItemsSet set = parseItemsSet(itemTooltip);
    if (set != null) {
        _item.setSetKey(set.getKey());
        _item.setItemsSet(set);
    }
    // Possible legacies TODO
    /*
<div class="itemes">Possible Initial Legacies:</div>
  <div>Focus Bow Critical Multiplier (Tier(s):
    <span class="legacytier rare">4</span>
    ,
    <span class="legacytier incomparable">5</span>
    ,
    <span class="legacytier incomparable">6</span>
    )
  </div>
  <div>Focus Bow Power Cost (Tier(s):
    <span class="legacytier rare">4</span>
    ,
    <span class="legacytier incomparable">5</span>
    ,
    <span class="legacytier incomparable">6</span>
  )
  </div>
<div>
Induction Bow Critical Multiplier (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
<div>
<div>
Merciful Shot Cooldown (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
<div>
Quick Shot Critical Chance (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
<div>
Ranged Skill Block Chance Modifier (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
<div>
Ranged Skill Evade Chance Modifier (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
<div>
Strength Quick Shot Slow (Tier(s):
<span class="legacytier rare">4</span>
,
<span class="legacytier incomparable">5</span>
,
<span class="legacytier incomparable">6</span>
)
</div>
     * 
     */
    // Item durability:
    // - durability
    // <div class="itemdurability">Durability 60 / 60</div>
    String durabilityStr = getTagContent(itemTooltip, "itemdurability");
    Integer durability = getDurability(durabilityStr);
    _item.setDurability(durability);
    // - sturdiness
    // <div class="itemsturdiness">Tough</div>
    String sturdinessStr = getTagContent(itemTooltip, "itemsturdiness");
    ItemSturdiness sturdiness = getSturdiness(sturdinessStr);
    _item.setSturdiness(sturdiness);
    // Item requirements
    List<Element> requirements = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemrequirement");
    for (Element requirement : requirements) {
        // String contents=getTagContent(requirement,"itemrequirement");
        String contents = CharacterReference.decodeCollapseWhiteSpace(requirement.getContent());
        if (contents.contains("Minimum Level")) {
            // - minimum level
            // <div class="itemrequirement">Minimum Level: 55</div>
            String minLevelStr = getTagContent(itemTooltip, "itemrequirement");
            Integer minLevel = getMinLevel(minLevelStr);
            _item.setMinLevel(minLevel);
        } else if (contents.contains("Class")) {
            // - class
            String className = parseClassRequirement(requirement);
            if (className != null) {
                CharacterClass cClass = CharacterClass.getByName(className);
                _item.setRequiredClass(cClass);
            }
        }
    }
    // Description
    // <div class="itemdescription">A collection of indispensable tools for tailors, foresters, and prospectors.</div>
    // String description=getTagContent(itemTooltip,"");
    Element element = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemdescription");
    if (element != null) {
        String description = JerichoHtmlUtils.getTextFromTag(element);
        _item.setDescription(description);
    }
    // Money
    // <div class="itemworth">
    Element worth = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemworth");
    if (worth != null) {
        Money m = parseMoneyReward(worth);
        _item.setValue(m);
    }
    // Stackability
    // <div class="itemstacksize">Stacks to 100</div>
    String stackabilityStr = getTagContent(itemTooltip, "itemstacksize");
    Integer stackSize = getStackSize(stackabilityStr);
    _item.setStackMax(stackSize);
/*
    // Item category: Armour, Tool, ...
    private ItemCategory _category;
    // Item identifier: "Jacket_of_the_Impossible_Shot", ...
    private String _id;
    */
}
Also used : ArmourType(delta.games.lotro.lore.items.ArmourType) Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList) Weapon(delta.games.lotro.lore.items.Weapon) DamageType(delta.games.lotro.lore.items.DamageType) CharacterClass(delta.games.lotro.common.CharacterClass) Item(delta.games.lotro.lore.items.Item) ItemBinding(delta.games.lotro.lore.items.ItemBinding) Money(delta.games.lotro.common.Money) Armour(delta.games.lotro.lore.items.Armour) ItemsSet(delta.games.lotro.lore.items.ItemsSet) WeaponType(delta.games.lotro.lore.items.WeaponType) ItemSturdiness(delta.games.lotro.lore.items.ItemSturdiness)

Example 20 with Element

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

the class LotroWikiDeedCategoryPageParser method parseIndex.

private void parseIndex(Source source, List<String> deedIds) {
    Element indexSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "mw-pages");
    if (indexSection != null) {
        List<Element> anchors = JerichoHtmlUtils.findElementsByTagName(indexSection, HTMLElementName.A);
        for (Element anchor : anchors) {
            // String title=anchor.getAttributeValue("title");
            String href = anchor.getAttributeValue("href");
            // System.out.println(href + "  ==>  "+title);
            if (href.startsWith(INDEX)) {
                String deedId = href.substring(INDEX.length());
                deedIds.add(deedId);
            }
        }
    }
}
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