use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class CharacterPageParser method parseMainPage.
/**
* Parse the character page at the given URL.
* @param name Toon name.
* @param url URL of character page.
* @param retryNumber Number of previous tries.
* @return A character or <code>null</code> if an error occurred..
*/
private CharacterData parseMainPage(String name, String url, int retryNumber) {
if (_logger.isInfoEnabled()) {
_logger.info("Character description page parsing for toon [" + name + "] " + ((retryNumber > 0) ? " try #" + retryNumber : ""));
}
CharacterData ret = null;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
_character = null;
// <table class="char_panel freep">
Element charPanel = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "char_panel freep");
if (charPanel != null) {
_character = new CharacterData();
parseCharacterDescription(charPanel);
parseStats(charPanel);
}
ret = _character;
_character = null;
} catch (Exception e) {
if (_logger.isInfoEnabled()) {
_logger.info("Cannot parse character page [" + url + "]", e);
}
}
return ret;
}
use of net.htmlparser.jericho.Element 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.Element 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.Element in project lotro-tools by dmorcellet.
the class RewardsHTMLParser method parseItemReward.
private void parseItemReward(Element rewardDiv, Rewards rewards) {
ObjectsSet objects = null;
// System.out.println("Item reward!");
String key = "";
List<Element> divs = rewardDiv.getAllElements(HTMLElementName.DIV);
// remove reward div
divs.remove(0);
for (Element div : divs) {
List<Element> strongs = div.getAllElements(HTMLElementName.STRONG);
if (strongs.size() > 0) {
Element strong = strongs.get(0);
key = CharacterReference.decodeCollapseWhiteSpace(strong.getContent());
key = cleanupFieldName(key);
if (RECEIVE_KEY.equals(key)) {
objects = rewards.getObjects();
} else if (SELECT_ONE_OF_KEY.equals(key)) {
objects = rewards.getSelectObjects();
} else {
_logger.warn(_objectId + ": unmanaged object selection key [" + key + "]");
}
} else {
List<Element> as = div.getAllElements(HTMLElementName.A);
if ((as != null) && (as.size() == 2)) {
Element iconItem = as.get(0);
String iconURL = null;
List<Element> imgs = iconItem.getAllElements(HTMLElementName.IMG);
if ((imgs != null) && (imgs.size() == 1)) {
Element img = imgs.get(0);
iconURL = img.getAttributeValue("src");
// System.out.println("Icon: "+iconURL);
}
Element textItem = as.get(1);
String itemName = CharacterReference.decodeCollapseWhiteSpace(textItem.getContent());
String url = textItem.getAttributeValue("href");
ObjectItem item = new ObjectItem(itemName);
item.setObjectURL(url);
item.setIconURL(iconURL);
int quantity = 1;
TextExtractor extractor = div.getTextExtractor();
extractor.excludeElement(iconItem.getStartTag());
extractor.excludeElement(textItem.getStartTag());
String text = extractor.toString();
int factorIndex = text.indexOf("(x");
if (factorIndex != -1) {
int parenthesisIndex = text.indexOf(')', factorIndex + 2);
if (parenthesisIndex != -1) {
String factorStr = text.substring(factorIndex + 2, parenthesisIndex);
quantity = NumericTools.parseInt(factorStr, 1);
}
}
if (objects != null) {
objects.addObject(item, quantity);
} else {
_logger.warn(_objectId + ": ignored object [" + item + "], quantity=" + quantity);
}
// System.out.println("Item: "+itemName+", URL: "+url);
}
}
}
/*
<div class="questReward">
<div>
<strong>Receive:</strong>
</div>
<div>
<a href="/wiki/Item:Drownholt_Compass">
<img class="icon" rel="" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/item/device/it_tracking_mom_book9_chapter5.png">
</a>
<a href="/wiki/Item:Drownholt_Compass">Drownholt Compass</a>
(x5)
</div>
</div>
*/
}
use of net.htmlparser.jericho.Element 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>
*/
}
Aggregations