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>
*/
}
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">
5
<img class="coin" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/currency/copper.gif">
</div>
</div>
*/
}
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>
*/
}
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;
}
Aggregations