use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class RewardsHTMLParser method parseTraitReward.
private void parseTraitReward(Element rewardDiv, Rewards rewards) {
List<Element> as = rewardDiv.getAllElements(HTMLElementName.A);
int size = (as != null) ? as.size() : 0;
if (size == 2) {
Element secondA = as.get(1);
String name = CharacterReference.decodeCollapseWhiteSpace(secondA.getContent());
// String iconURL=null;
Element firstA = as.get(0);
String url = firstA.getAttributeValue("href");
if ((url != null) && (url.startsWith(URL_SEED))) {
String qualifiedIdentifier = url.substring(URL_SEED.length()).trim();
if (qualifiedIdentifier.startsWith(TRAIT_URL_SEED)) {
String identifier = qualifiedIdentifier.substring(TRAIT_URL_SEED.length()).trim();
if ((identifier.startsWith(EMOTE_SEED)) && (name.startsWith(EMOTE_SEED))) {
// identifier=identifier.substring(EMOTE_SEED.length()).trim();
name = name.substring(EMOTE_SEED.length()).trim();
Emote emote = new Emote(/*identifier,*/
name);
rewards.addEmote(emote);
// System.out.println(emote.dump());
} else {
Trait trait = new Trait(/*identifier,*/
name);
rewards.addTrait(trait);
// System.out.println(trait.dump());
}
} else if (qualifiedIdentifier.startsWith(PASSIVE_SKILL_URL_SEED)) {
// String identifier=qualifiedIdentifier.substring(PASSIVE_SKILL_URL_SEED.length()).trim();
Skill skill = new Skill(/*SkillType.PASSIVE,identifier,*/
name);
rewards.addSkill(skill);
// System.out.println(skill.dump());
} else {
_logger.warn(_objectId + ": unmanaged trait/skill identifier [" + qualifiedIdentifier + "]");
}
/*
List<Element> imgs=firstA.getAllElements(HTMLElementName.IMG);
if ((imgs!=null) && (imgs.size()>=1))
{
Element img=imgs.get(0);
iconURL=img.getAttributeValue("src");
}
*/
} else {
_logger.warn(_objectId + ": malformed URL [" + url + "]");
}
} else {
_logger.warn(_objectId + ": trait reward with " + size + " anchor tags!");
}
/*
<div class="questReward">
<div>
<strong>Traits:</strong>
</div>
<div>
<a href="/wiki/Trait:Expert_Woodworker_Proficiency">
<img class="icon" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/trait/trait_c_craft_woodworker_complete_proficiency_3.png">
</a>
<a href="/wiki/Trait:Expert_Woodworker_Proficiency">Expert Woodworker Proficiency</a>
</div>
</div>
*/
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class RewardsHTMLParser method parseVirtuesReward.
private void parseVirtuesReward(Element rewardDiv, Rewards rewards) {
List<Element> as = rewardDiv.getAllElements(HTMLElementName.A);
int size = (as != null) ? as.size() : 0;
int nbItems = size / 2;
if (nbItems * 2 == size) {
for (int i = 0; i < nbItems; i++) {
String name = null;
String virtueIdentifier = null;
// String iconURL=null;
Element firstA = as.get(2 * i + 1);
String url = firstA.getAttributeValue("href");
if ((url != null) && (url.startsWith(VIRTUE_URL_SEED))) {
virtueIdentifier = url.substring(VIRTUE_URL_SEED.length()).trim();
}
name = CharacterReference.decodeCollapseWhiteSpace(firstA.getContent());
if ((name != null) && (virtueIdentifier != null)) {
VirtueId virtueId = VirtueId.valueOf(virtueIdentifier.toUpperCase());
Virtue virtue = new Virtue(virtueId, 1);
rewards.addVirtue(virtue);
}
}
} else {
_logger.warn(_objectId + ": virtue with " + size + " anchor tags!");
}
/*
<div class="questReward">
<div>
<strong>Virtues:</strong>
</div>
<div>
<a href="/wiki/Trait:Patience">
<img class="icon" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/trait/trait_virtue_patience.png">
</a>
<a href="/wiki/Trait:Patience">Patience</a>
</div>
</div>
*/
}
use of net.htmlparser.jericho.Element 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;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class ItemPageParser method parseItemsSet.
private ItemsSet parseItemsSet(Element itemTooltip) {
ItemsSet ret = null;
Element itemsSet = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemTooltip, HTMLElementName.DIV, "class", "itemset");
if (itemsSet != null) {
ret = new ItemsSet();
String setKey = null;
String setName = "";
String setURL = null;
Element itemsSetName = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemsSet, HTMLElementName.DIV, "class", "itemsn");
if (itemsSetName != null) {
Element aElement = itemsSetName.getFirstElement(HTMLElementName.A);
if (aElement != null) {
setURL = aElement.getAttributeValue("href");
if ((setURL != null) && (setURL.startsWith(WIKI_SEED))) {
setKey = setURL.substring(WIKI_SEED.length());
int index = setKey.indexOf(":");
if (index != -1) {
setKey = setKey.substring(index + 1);
}
}
setName = JerichoHtmlUtils.getTagContents(itemsSetName, HTMLElementName.A);
}
}
// System.out.println("Set name: "+setName);
// System.out.println("Set URL: "+setURL);
ret.setName(setName);
ret.setKey(setKey);
// Set items
Element setItemsElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemsSet, HTMLElementName.DIV, "class", "itemsps");
if (setItemsElement != null) {
List<Element> setItemElements = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(itemsSet, HTMLElementName.DIV, "class", "itemsp");
for (Element setItemElement : setItemElements) {
String itemKey = null;
String itemURL = null;
// String itemName=null;
Element aElement = setItemElement.getFirstElement(HTMLElementName.A);
if (aElement != null) {
itemURL = aElement.getAttributeValue("href");
if ((itemURL != null) && (itemURL.startsWith(WIKI_SEED))) {
itemKey = itemURL.substring(WIKI_SEED.length());
}
// itemName=JerichoHtmlUtils.getTagContents(setItemElement,HTMLElementName.A);
}
if (itemKey != null) {
ret.addItem(0, itemKey);
}
// System.out.println("Item ["+itemName+"]. URL=["+itemURL+"]");
}
}
// Set effects
Element setEffectsElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemsSet, HTMLElementName.DIV, "class", "itemseteff");
if (setEffectsElement != null) {
List<Element> divs = setEffectsElement.getAllElements(HTMLElementName.DIV);
// Remove self
divs.remove(0);
int nbOfItems = 0;
for (Element div : divs) {
String effectLine = JerichoHtmlUtils.getTagContents(div, HTMLElementName.DIV);
// System.out.println("Effect line ["+effectLine+"]");
effectLine = effectLine.trim();
if (effectLine.length() > 0) {
if ((effectLine.startsWith(SET_NUMBER_SEED)) && (effectLine.endsWith(SET_NUMBER_END))) {
String nbStr = TextTools.findBetween(effectLine, SET_NUMBER_SEED, SET_NUMBER_END);
nbOfItems = NumericTools.parseInt(nbStr, 0);
} else {
if (nbOfItems != 0) {
ret.addBonus(nbOfItems, effectLine);
}
}
}
}
}
}
/*
<div class="itemset">
<div class="itemsn"><a href="/wiki/Item:Armaments_of_the_Impossible_Shot">Armaments of the Impossible Shot</a></div>
<div class="itemsps">
<div class="itemsp"><a href="/wiki/Armour:Helm_of_the_Impossible_Shot">Helm of the Impossible Shot</a></div>
<div class="itemsp"><a href="/wiki/Armour:Shoulder_guards_of_Impossible_Shot">Shoulder guards of Impossible Shot</a></div>
<div class="itemsp"><a href="/wiki/Armour:Jacket_of_the_Impossible_Shot">Jacket of the Impossible Shot</a></div>
<div class="itemsp"><a href="/wiki/Armour:Leggings_of_the_Impossible_Shot">Leggings of the Impossible Shot</a></div>
<div class="itemsp"><a href="/wiki/Armour:Gloves_of_the_Impossible_Shot">Gloves of the Impossible Shot</a></div>
<div class="itemsp"><a href="/wiki/Armour:Boots_of_the_Impossible_Shot">Boots of the Impossible Shot</a></div>
</div>
<div class="itemseteff">
<div>Set (2):</div>
<div>+52.8 in-Combat Power Regen</div>
<div>Set (3):</div>
<div>+10% Heart Seeker Damage</div>
<div>Set (4):</div>
<div>+600 Physical Mastery Rating</div>
<div> </div>
<div>Set (5):</div>
<div>Intent Concentration recovers all Archer's Art skills</div>
</div>
<div class="itemsd"></div>
</div>
*/
return ret;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class ItemPageParser method internalParseItemPage.
/**
* Parse the item page at the given URL.
* @param url URL of item page.
* @return An item or <code>null</code> if an error occurred.
*/
private List<Item> internalParseItemPage(String url) {
List<Item> items = null;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <div id="lorebookNoedit">
// Element lorebook=JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source,HTMLElementName.DIV,"id","lorebookNoedit");
// if (lorebook!=null)
{
items = new ArrayList<Item>();
// Fetch identifier
List<Element> itemSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "tooltip");
if ((itemSections != null) && (itemSections.size() > 0)) {
String key = fetchItemKey(source);
_key = key;
for (Element itemSection : itemSections) {
Item item = parseItemSection(itemSection);
if (item != null) {
items.add(item);
item.setKey(key);
}
}
findIdentifiers(items);
}
List<Element> resourceSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(source, HTMLElementName.DIV, "class", "lorebookresource");
if ((resourceSections != null) && (resourceSections.size() > 0)) {
String key = fetchItemKey(source);
_key = key;
for (Element resourceSection : resourceSections) {
Item item = parseResourceSection(resourceSection);
if (item != null) {
items.add(item);
item.setKey(key);
}
}
findIdentifiers(items);
}
}
} catch (Exception e) {
items = null;
_logger.error("Cannot parse item page [" + url + "]", e);
}
return items;
}
Aggregations