Search in sources :

Example 51 with Element

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

the class QuestPageParser method parseQuestDescription.

private void parseQuestDescription(Element officialSection) {
    // Title
    String title = null;
    Element titleElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(officialSection, HTMLElementName.DIV, "class", "lorebooktitle");
    if (titleElement != null) {
        title = CharacterReference.decodeCollapseWhiteSpace(titleElement.getContent());
        if (title != null) {
            if (title.startsWith(QUEST_SEED)) {
                title = title.substring(QUEST_SEED.length()).trim();
            }
        }
    }
    _quest.setTitle(title);
    // Quest attributes
    // System.out.println("Title: "+title);
    List<Element> questFields = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(officialSection, HTMLElementName.DIV, "class", "questfield");
    for (Element questField : questFields) {
        parseQuestField(questField);
    }
    // Rewards
    // <table class="questrewards">
    Element rewardsTable = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(officialSection, HTMLElementName.TABLE, "class", "questrewards");
    if (rewardsTable != null) {
        Rewards rewards = _quest.getQuestRewards();
        RewardsHTMLParser parser = new RewardsHTMLParser("Quest [" + _key + "]");
        parser.parseRewards(rewardsTable, rewards);
    }
}
Also used : Element(net.htmlparser.jericho.Element) Rewards(delta.games.lotro.common.Rewards) RewardsHTMLParser(delta.games.lotro.tools.lore.common.RewardsHTMLParser)

Example 52 with Element

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

the class QuestPageParser method parseQuestField.

private void parseQuestField(Element questField) {
    List<Element> strongs = questField.getAllElements(HTMLElementName.STRONG);
    if ((strongs != null) && (strongs.size() == 1)) {
        List<Segment> nodes = JerichoHtmlUtils.getChildNodes(questField);
        Element strong = strongs.get(0);
        String key = CharacterReference.decodeCollapseWhiteSpace(strong.getContent());
        key = cleanupFieldName(key);
        if ("Category".equals(key)) {
            String value = nodes.get(3).toString().trim();
            _quest.setCategory(value);
        } else if ("Scope".equals(key)) {
            String value = nodes.get(3).toString().trim();
            if ("n/a".equals(value))
                value = "";
            _quest.setQuestScope(value);
        } else if ("Minimum Level".equals(key)) {
            String value = nodes.get(3).toString().trim();
            Integer minLevel = NumericTools.parseInteger(value);
            _quest.setMinimumLevel(minLevel);
        } else if ("Maximum Level".equals(key)) {
            String value = nodes.get(3).toString().trim();
            Integer maxLevel = NumericTools.parseInteger(value);
            _quest.setMaximumLevel(maxLevel);
        } else if ("Required Classes".equals(key)) {
            List<Element> as = questField.getAllElements(HTMLElementName.A);
            for (Element a : as) {
                String className = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
                _quest.addRequiredClass(className);
            }
        } else if ((PREREQUISITE_QUESTS.equals(key)) || (NEXT_QUESTS.equals(key))) {
            List<Element> dds = questField.getAllElements("dd");
            if ((dds != null) && (dds.size() == 1)) {
                parseQuestsList(dds.get(0), key);
            }
        } else if ("Arc(s)".equals(key)) {
            String value = nodes.get(5).toString().trim();
            _quest.setQuestArc(value);
        } else if ("Required Races".equals(key)) {
            List<Element> as = questField.getAllElements(HTMLElementName.A);
            for (Element a : as) {
                String race = CharacterReference.decodeCollapseWhiteSpace(a.getContent());
                _quest.addRequiredRace(race);
            }
        } else if ("Monster Play Quest".equals(key)) {
            _quest.setFaction(FACTION.MONSTER_PLAY);
        } else {
            _logger.warn("Quest [" + _key + "]. Unmanaged quest field key [" + key + "]");
        }
    } else {
        parseQuestIcons(questField);
    }
}
Also used : Element(net.htmlparser.jericho.Element) ArrayList(java.util.ArrayList) List(java.util.List) Segment(net.htmlparser.jericho.Segment)

Example 53 with Element

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

the class CharacterLogPageParser method parseLogItem.

private CharacterLogItem parseLogItem(Element tr) {
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_levelup.png">
Reached level 70
</td>
 */
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<a href="http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879208735">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_quest.png">
Completed 'The Practiced Arm'
</a>
</td>
 */
    CharacterLogItem ret = null;
    List<Element> tds = tr.getAllElements(HTMLElementName.TD);
    if ((tds != null) && (tds.size() == 3)) {
        if (_characterName == null) {
            Element charName = tds.get(0);
            _characterName = JerichoHtmlUtils.getTagContents(charName, HTMLElementName.A);
        }
        Element tdDate = tds.get(1);
        String dateStr = CharacterReference.decodeCollapseWhiteSpace(tdDate.getContent());
        LogItemType type = null;
        Element tdDetails = tds.get(2);
        List<Element> imgs = tdDetails.getAllElements(HTMLElementName.IMG);
        Element img = null;
        if ((imgs != null) && (imgs.size() == 1)) {
            img = imgs.get(0);
            String imgSrc = img.getAttributeValue("src");
            type = findType(imgSrc);
        }
        String url = null;
        Element a = tdDetails.getFirstElement(HTMLElementName.A);
        if (a != null) {
            url = a.getAttributeValue("href");
        }
        TextExtractor extractor = tdDetails.getTextExtractor();
        if (img != null)
            extractor.excludeElement(img.getStartTag());
        if (a != null)
            extractor.excludeElement(a.getStartTag());
        String label = extractor.toString().trim();
        if ((dateStr != null) && (type != null) && (label != null)) {
            try {
                Calendar c = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
                String[] items = dateStr.split("/");
                int year = Integer.parseInt(items[0]);
                int month = Integer.parseInt(items[1]);
                int day = Integer.parseInt(items[2]);
                label = tuneLabel(label);
                if (url != null) {
                    url = url.trim();
                }
                c.setTimeInMillis(0);
                c.set(year, month - 1, day);
                long date = c.getTimeInMillis();
                ret = new CharacterLogItem(date, type, label, url);
            } catch (Exception e) {
                _logger.error("Cannot parse LOTRO character log item!", e);
            }
        }
    }
    return ret;
}
Also used : Element(net.htmlparser.jericho.Element) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) TextExtractor(net.htmlparser.jericho.TextExtractor) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Example 54 with Element

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

the class CharacterPageParser method parseStats.

private void parseStats(Element charPanel) {
    BasicStatsSet stats = _character.getStats();
    // <table class="stat_list">
    List<Element> statsTables = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(charPanel, HTMLElementName.TABLE, "class", "stat_list");
    for (Element statsTable : statsTables) {
        List<Element> rows = statsTable.getAllElements(HTMLElementName.TR);
        for (Element row : rows) {
            String statName = JerichoHtmlUtils.getTagContents(row, HTMLElementName.TH);
            if (statName != null) {
                statName = statName.trim();
                if (statName.length() > 0) {
                    String statValue = JerichoHtmlUtils.getTagContents(row, HTMLElementName.TD);
                    STAT stat = getStatByName(statName);
                    if (stat != null) {
                        Integer value = null;
                        if (!"N/A".equals(statValue)) {
                            value = NumericTools.parseInteger(statValue);
                        }
                        if (value != null) {
                            stats.setStat(stat, value.intValue());
                        }
                    // System.out.println("Stat : name=["+statName+"], value=["+value+"]");
                    }
                }
            }
        }
    }
}
Also used : STAT(delta.games.lotro.character.stats.STAT) Element(net.htmlparser.jericho.Element) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet)

Example 55 with Element

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

the class CharacterPageParser method parseCharacterDescription.

private void parseCharacterDescription(Element charPanel) {
    // Character name
    // <div class="char_name header_color">Glumlug of Elendilmir</div>
    String charName = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_name header_color");
    if (charName != null) {
        int indexOf = charName.indexOf(OF);
        if (indexOf != -1) {
            String server = charName.substring(indexOf + OF.length());
            _character.setServer(server);
            charName = charName.substring(0, indexOf);
        }
        _character.setName(charName);
    }
    // System.out.println("Char name ["+charName+"]");
    // Character core:
    // <div class="char_core">
    Element charCore = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(charPanel, HTMLElementName.DIV, "class", "char_core");
    if (charCore != null) {
        // <div class="char_class header_color">Hunter</div>
        String charClassName = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_class header_color");
        CharacterClass cClass = CharacterClass.getByName(charClassName);
        _character.setCharacterClass(cClass);
        // <div class="char_race header_color">Dwarf</div>
        String charRace = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_race header_color");
        Race race = Race.getByLabel(charRace);
        _character.setRace(race);
        // <div class="char_nat header_color">Grey Mountains</div>
        String charNation = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_nat header_color");
        _character.setRegion(charNation);
        // <div class="char_level header_color">66</div>
        String charLevelStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_level header_color");
        int charLevel = NumericTools.parseInt(charLevelStr, 0);
        _character.setLevel(charLevel);
    // System.out.println("Class ["+charClassName+"], Race ["+charRace+"], Nation ["+charNation+"], Level="+charLevel);
    }
    // Character main stats:
    // <div class="core_stats header_color">
    Element charStats = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(charPanel, HTMLElementName.DIV, "class", "core_stats header_color");
    if (charStats != null) {
        // <div class="morale">4839</div>
        String moraleStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "morale");
        int morale = NumericTools.parseInt(moraleStr, 0);
        BasicStatsSet stats = _character.getStats();
        stats.setStat(STAT.MORALE, morale);
        // <div class="power">2243</div>
        String powerStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "power");
        int power = NumericTools.parseInt(powerStr, 0);
        stats.setStat(STAT.POWER, power);
        // <div class="armour">3213</div>
        String armourStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "armour");
        int armour = NumericTools.parseInt(armourStr, 0);
        stats.setStat(STAT.ARMOUR, armour);
    // System.out.println("Morale="+morale+", Power="+power+", Armour="+armour);
    }
    CharacterEquipment equipment = _character.getEquipment();
    // Object slots:
    // <a class="equipment_icon" href="http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879205751">
    // <img class="slot_2" src="http://lorebook.lotro.com/icon.php?id=1879205751&type=item">
    // </a>
    List<Element> objectSlots = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(charPanel, HTMLElementName.A, "class", "equipment_icon");
    for (Element objectSlot : objectSlots) {
        String objectPageURL = objectSlot.getAttributeValue("href");
        // System.out.println("Object ["+objectPageURL+"]");
        Element img = objectSlot.getFirstElement(HTMLElementName.IMG);
        if (img != null) {
            String slotName = img.getAttributeValue("class");
            Integer slotNumber = null;
            if ((slotName != null) && (slotName.startsWith(SLOT_SEED))) {
                slotName = slotName.substring(SLOT_SEED.length());
                slotNumber = NumericTools.parseInteger(slotName);
                if (slotNumber != null) {
                    // String iconURL=img.getAttributeValue("src");
                    EQUIMENT_SLOT slot = CharacterEquipment.getSlotByIndex(slotNumber.intValue());
                    SlotContents contents = equipment.getSlotContents(slot, true);
                    Integer itemId = CharacterXMLParser.idFromURL(objectPageURL);
                    contents.setItemId(itemId);
                // System.out.println("Slot ["+slotNumber+"], Icon URL ["+iconURL+"]");
                }
            }
        }
    }
}
Also used : SlotContents(delta.games.lotro.character.CharacterEquipment.SlotContents) CharacterEquipment(delta.games.lotro.character.CharacterEquipment) EQUIMENT_SLOT(delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT) Element(net.htmlparser.jericho.Element) Race(delta.games.lotro.common.Race) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet) CharacterClass(delta.games.lotro.common.CharacterClass)

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