Search in sources :

Example 6 with Segment

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

the class RewardsHTMLParser method parseReputationReward.

private Reputation parseReputationReward(Element rewardDiv) {
    // System.out.println("Reputation reward!");
    Reputation r = new Reputation();
    List<Element> elements = rewardDiv.getChildElements();
    if ((elements != null) && (elements.size() == 2)) {
        Element reputationNode = elements.get(1);
        List<Segment> nodes = JerichoHtmlUtils.getChildNodes(reputationNode);
        int nbNodes = nodes.size();
        int nbItems = nbNodes / 4;
        for (int i = 0; i < nbItems; i++) {
            Segment valueNode = nodes.get(i * 4 + 1);
            Segment factionNode = nodes.get(i * 4 + 3);
            if ((valueNode.getClass() == Segment.class) && (factionNode.getClass() == Segment.class)) {
                String valueStr = valueNode.toString();
                valueStr = valueStr.replace("with", "").trim();
                valueStr = valueStr.replace("+", "").trim();
                int reputation = NumericTools.parseInt(valueStr, 0);
                String factionName = factionNode.toString().trim();
                Faction faction = FactionsRegistry.getInstance().getByName(factionName);
                if (faction != null) {
                    ReputationItem item = new ReputationItem(faction);
                    item.setAmount(reputation);
                    r.add(item);
                } else {
                    _logger.error("Cannot get faction [" + factionName + "]!");
                }
            }
        }
    }
    return r;
/*
<div class="questReward">
<div>
<strong>Reputation:</strong>
</div>
<div>
<img class="icon" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/reputation_increase.gif">
+700 with
<a href="/wiki/Faction:Malledhrim">Malledhrim</a>
</div>
</div>
     */
}
Also used : Element(net.htmlparser.jericho.Element) Reputation(delta.games.lotro.common.Reputation) ReputationItem(delta.games.lotro.common.ReputationItem) Segment(net.htmlparser.jericho.Segment) Faction(delta.games.lotro.lore.reputation.Faction)

Example 7 with Segment

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

the class RewardsHTMLParser method parseMoneyReward.

private Money parseMoneyReward(Element rewardDiv) {
    // System.out.println("Money reward!");
    Money m = new Money();
    List<Element> elements = rewardDiv.getChildElements();
    if ((elements != null) && (elements.size() == 2)) {
        Element moneyNode = elements.get(1);
        List<Segment> nodes = JerichoHtmlUtils.getChildNodes(moneyNode);
        int nb = nodes.size();
        for (int i = 0; i < nb; i++) {
            Segment s = nodes.get(i);
            if (s.getClass() == Segment.class) {
                int nbCoins = NumericTools.parseInt(s.toString(), 0);
                if ((nbCoins > 0) && (i < nb - 1)) {
                    Segment tmp = nodes.get(i + 1);
                    if (tmp instanceof StartTag) {
                        String className = ((StartTag) tmp).getAttributeValue("class");
                        if ("coin".equals(className)) {
                            String type = ((StartTag) tmp).getAttributeValue("src");
                            if (type != null) {
                                if (type.contains("silver")) {
                                    m.setSilverCoins(nbCoins);
                                } else if (type.contains("copper")) {
                                    m.setCopperCoins(nbCoins);
                                } else if (type.contains("gold")) {
                                    m.setGoldCoins(nbCoins);
                                } else {
                                    _logger.warn(_objectId + ": unknown coin type [" + type + "]");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return m;
/*
    <div class="questReward">
    <div>
    <strong>Money:</strong>
    </div>
    <div>
    29
    <img class="coin" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/currency/silver.gif">
    &nbsp;5
    <img class="coin" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/currency/copper.gif">
    </div>
    </div>
    */
}
Also used : Money(delta.games.lotro.common.Money) Element(net.htmlparser.jericho.Element) Segment(net.htmlparser.jericho.Segment) StartTag(net.htmlparser.jericho.StartTag)

Example 8 with Segment

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

the class RewardsHTMLParser method parseDestinyPoints.

private int parseDestinyPoints(Element rewardDiv) {
    int nbDestinyPoints = 0;
    List<Element> elements = rewardDiv.getChildElements();
    if ((elements != null) && (elements.size() == 2)) {
        Element moneyNode = elements.get(1);
        List<Segment> nodes = JerichoHtmlUtils.getChildNodes(moneyNode);
        int nb = nodes.size();
        for (int i = 0; i < nb; i++) {
            Segment s = nodes.get(i);
            if (s.getClass() == Segment.class) {
                nbDestinyPoints = NumericTools.parseInt(s.toString(), 0);
            }
        }
    }
    return nbDestinyPoints;
/*
<div class="questReward">
<div>
<strong>Destiny Points:</strong>
</div>
<div>
250
<img class="icon" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/icon_destiny_points_15.png">
</div>
</div>
 */
}
Also used : Element(net.htmlparser.jericho.Element) Segment(net.htmlparser.jericho.Segment)

Example 9 with Segment

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

the class LotroWikiDeedPageParser method parseDeeds.

/**
 * Parse the lotro wiki deed page for the given deed ID.
 * @param from Source page.
 * @param deedId Deed ID.
 * @return A deed or <code>null</code> if an error occurred.
 */
public List<DeedDescription> parseDeeds(File from, String deedId) {
    _currentFile = from;
    List<DeedDescription> deeds = null;
    try {
        FileInputStream inputStream = new FileInputStream(from);
        Source source = new Source(inputStream);
        String name = null;
        Element backElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "contentSub");
        if (backElement != null) {
            Element a = JerichoHtmlUtils.findElementByTagName(backElement, HTMLElementName.A);
            if (a != null) {
                name = a.getAttributeValue("title");
            }
        }
        Element deedSource = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TEXTAREA, "id", "wpTextbox1");
        if (deedSource != null) {
            Segment content = deedSource.getContent();
            String text = content.toString();
            deeds = buildDeeds(text, name);
        }
        if (deeds != null) {
            // Fixes
            for (DeedDescription deed : deeds) {
                handleFixes(deed);
            }
        }
    } catch (Exception e) {
        _logger.error("Cannot parse deed page [" + from + "]", e);
    }
    return deeds;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) Element(net.htmlparser.jericho.Element) FileInputStream(java.io.FileInputStream) Source(net.htmlparser.jericho.Source) Segment(net.htmlparser.jericho.Segment)

Aggregations

Segment (net.htmlparser.jericho.Segment)9 Element (net.htmlparser.jericho.Element)6 Money (delta.games.lotro.common.Money)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Source (net.htmlparser.jericho.Source)2 StartTag (net.htmlparser.jericho.StartTag)2 Prop (com.axellience.vuegwt.core.annotations.component.Prop)1 TemplateParserContext (com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext)1 LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)1 LocalComponentProp (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp)1 TemplateParserLoggerProvider (com.axellience.vuegwt.processors.component.template.parser.jericho.TemplateParserLoggerProvider)1 TemplateExpression (com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression)1 TemplateParserResult (com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult)1 LocalVariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo)1 VariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo)1 GeneratorsNameUtil.propNameToAttributeName (com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.propNameToAttributeName)1 GeneratorsUtil.stringTypeToTypeName (com.axellience.vuegwt.processors.utils.GeneratorsUtil.stringTypeToTypeName)1 JavaParser (com.github.javaparser.JavaParser)1 ParseProblemException (com.github.javaparser.ParseProblemException)1