public void tail(Node source, int depth) { if (source == elementToSkip) { elementToSkip = null; } else if (source instanceof Element && isSafeTag(source)) { destination = destination.parent(); } }
@Override public boolean matches(Element root, Element element) { final Element p = element.parent(); if (p == null || (p instanceof Document)) return false; final int pos = calculatePosition(root, element); if (a == 0) return pos == b; return (pos-b)*a >= 0 && (pos-b)%a==0; }
@Override public boolean matches(Element root, Element element) { final Element p = element.parent(); return p!=null && !(p instanceof Document) && element.siblingElements().size() == 0; } @Override
@Override public boolean matches(Element root, Element element) { final Element p = element.parent(); return p != null && !(p instanceof Document) && element.elementSiblingIndex() == 0; }
/** * Gets the first element sibling of this element. * @return the first sibling that is an element (aka the parent's first element child) */ public Element firstElementSibling() { // todo: should firstSibling() exclude this? List<Element> siblings = parent().childElementsList(); return siblings.size() > 1 ? siblings.get(0) : null; }
/** * Gets the last element sibling of this element * @return the last sibling that is an element (aka the parent's last element child) */ public Element lastElementSibling() { List<Element> siblings = parent().childElementsList(); return siblings.size() > 1 ? siblings.get(siblings.size() - 1) : null; }
public boolean matches(Element root, Element element) { if (root == element) return false; Element parent = element.parent(); return parent != null && evaluator.matches(root, parent); }
@Override public List<String> getURLsFromPage(Document doc) { List<String> result = new ArrayList<String>(); for (Element el : doc.select("#contentMain img")) { String url = "https://jabarchives.com" + el.attr("src").replace("thumb", "large"); result.add(url); String title = el.parent().attr("title"); itemPrefixes.put(url, getSlug(title) + "_"); } return result; }
static boolean preserveWhitespace(Node node) { // looks only at this element and five levels up, to prevent recursion & needless stack searches if (node != null && node instanceof Element) { Element el = (Element) node; int i = 0; do { if (el.tag.preserveWhitespace()) return true; el = el.parent(); i++; } while (i < 6 && el != null); } return false; }
@Override public List<String> getURLsFromPage(Document doc) { List<String> result = new ArrayList<>(); for (Element e : doc.select("img.img")) { String imageName = e.parent().attr("href"); LOGGER.info(getFullSizedImageFromURL(imageName.split("/")[2])); result.add(getFullSizedImageFromURL(imageName.split("/")[2])); } return result; }
@Override public boolean matches(Element root, Element element) { final Element p = element.parent(); return p != null && !(p instanceof Document) && element.elementSiblingIndex() == p.children().size()-1; }
@Override protected int calculatePosition(Element root, Element element) { return element.parent().children().size() - element.elementSiblingIndex(); }
public void tail(Node source, int depth) { if (source instanceof Element && whitelist.isSafeTag(source.nodeName())) { destination = destination.parent(); // would have descended, so pop destination stack } } }
private static void accumulateParents(Element el, Elements parents) { Element parent = el.parent(); if (parent != null && !parent.tagName().equals("#root")) { parents.add(parent); accumulateParents(parent, parents); } }
/** * Gets the previous element sibling of this element. * @return the previous element, or null if there is no previous element * @see #nextElementSibling() */ public Element previousElementSibling() { if (parentNode == null) return null; List<Element> siblings = parent().childElementsList(); Integer index = indexInList(this, siblings); Validate.notNull(index); if (index > 0) return siblings.get(index-1); else return null; }
@Override protected int calculatePosition(Element root, Element element) { int pos = 0; Elements family = element.parent().children(); for (int i = element.elementSiblingIndex(); i < family.size(); i++) { if (family.get(i).tag().equals(element.tag())) pos++; } return pos; }
protected int calculatePosition(Element root, Element element) { int pos = 0; Elements family = element.parent().children(); for (Element el : family) { if (el.tag().equals(element.tag())) pos++; if (el == element) break; } return pos; }
@Override public boolean matches(Element root, Element element) { final Element p = element.parent(); if (p==null || p instanceof Document) return false; int pos = 0; Elements family = p.children(); for (Element el : family) { if (el.tag().equals(element.tag())) pos++; } return pos == 1; } @Override