use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class ItemPageParser method parseItemSection.
private Item parseItemSection(Element itemSection) {
Item ret = null;
try {
_item = null;
Element itemTooltip = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(itemSection, HTMLElementName.TABLE, "class", "tooltip");
if (itemTooltip != null) {
parseItemDescription(itemTooltip);
}
ret = _item;
} catch (Exception e) {
ret = null;
_logger.error("Item [" + _key + "]. Cannot parse item section!", e);
}
return ret;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class ItemPageParser method parseResourceSection.
private Item parseResourceSection(Element resourceSection) {
Item ret = null;
try {
Element officialSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(resourceSection, HTMLElementName.DIV, "class", "officialsection");
if (officialSection != null) {
ret = new Item();
// Name
String name = null;
Element nameElement = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(officialSection, HTMLElementName.DIV, "class", "lorebooktitle");
if (nameElement != null) {
name = CharacterReference.decodeCollapseWhiteSpace(nameElement.getContent());
if (name != null) {
if (name.startsWith(RESOURCE_SEED)) {
name = name.substring(RESOURCE_SEED.length()).trim();
}
}
}
ret.setName(name);
// Description
List<Element> divs = JerichoHtmlUtils.findElementsByTagName(officialSection, HTMLElementName.DIV);
if ((divs != null) && (divs.size() >= 4)) {
Element div = divs.get(3);
String description = CharacterReference.decodeCollapseWhiteSpace(div.getContent());
ret.setDescription(description);
}
}
} catch (Exception e) {
ret = null;
_logger.error("Item [" + _key + "]. Cannot parse item section!", e);
}
return ret;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class LotroWikiDeedCategoryPageParser method parseTables.
private void parseTables(Source source, List<String> deedIds) {
List<Element> tables = JerichoHtmlUtils.findElementsByTagName(source, HTMLElementName.TABLE);
for (Element table : tables) {
boolean ok = checkTable(table);
if (!ok) {
continue;
}
List<Element> rows = JerichoHtmlUtils.findElementsByTagName(table, HTMLElementName.TR);
rows.remove(0);
for (Element row : rows) {
String deedId = handleRow(row);
if (deedId != null) {
deedIds.add(deedId);
}
}
}
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class LotroWikiDeedCategoryPageParser method handleRow.
private String handleRow(Element row) {
String deedId = null;
List<Element> cells = JerichoHtmlUtils.findElementsByTagName(row, HTMLElementName.TD);
if (cells.size() >= 1) {
Element deedCell = cells.get(0);
Element anchor = JerichoHtmlUtils.findElementByTagName(deedCell, HTMLElementName.A);
if (anchor != null) {
// String title=anchor.getAttributeValue("title");
String href = anchor.getAttributeValue("href");
// System.out.println(href + " ==> "+title);
if (href.startsWith(INDEX)) {
deedId = href.substring(INDEX.length());
}
}
}
return deedId;
}
use of net.htmlparser.jericho.Element in project lotro-tools by dmorcellet.
the class LotroWikiDeedCategoryPageParser method checkTable.
private boolean checkTable(Element table) {
List<Element> rows = JerichoHtmlUtils.findElementsByTagName(table, HTMLElementName.TR);
if (rows.size() >= 1) {
Element header = rows.get(0);
List<Element> cells = JerichoHtmlUtils.findElementsByTagName(header, HTMLElementName.TH);
if (cells.size() >= 1) {
String text = JerichoHtmlUtils.getTextFromTag(cells.get(0));
return text.contains("Deed");
}
}
return false;
}
Aggregations