public static boolean isEmpty(Node node, boolean doFilter) { return node == null || node.nodeName().equals("#comment") || node.nodeName().equals("#data") || node.nodeName().equals("style") || node.nodeName().equals("script") || isHidden(node) || (doFilter && isFiltered(node)) || (node.nodeName().equals("#text") && CommonUtil.isEmpty(node.toString(), true)); }
private Element cleanupElement(Element el) { Tag newTag = null; String newText = null; if (el.nodeName().equals("img")) { newTag = Tag.valueOf("x"); newText = el.attr("src"); } if (el.nodeName().equals("em")) { newTag = Tag.valueOf("b"); } if (el.nodeName().equals("a")) { String clazz = el.attr("class"); if (clazz.equals("user")) { newTag = Tag.valueOf("x"); newText = "@" + el.text().trim(); } else if (clazz.startsWith("postimg video")) { newTag = Tag.valueOf("x"); newText = "VIDEO: " + el.attr("href") + " THUMBNAIL: " + el.select("img").attr("src"); } else if (clazz.startsWith("postimg")) { newTag = Tag.valueOf("x"); } else if (clazz.equals("post")) { newTag = Tag.valueOf("x"); } else { newTag = Tag.valueOf("x"); newText = el.attr("href"); } } if (el.nodeName().equals("div")) { newTag = Tag.valueOf("x"); } Element nel; if (newTag == null) { // el = el; nel = new Element(el.tag(), ""); // for(List<Node> children = nel.childNodes(); children.size() > 0; children = // nel.childNodes()) { // children.get(0).remove(); // } } else { nel = new Element(newTag, ""); } if (newText != null) { nel.appendChild(new TextNode(newText, "")); } else { List<Node> children = el.childNodes(); for (Node child : children) { if (child instanceof Element) { nel.appendChild(cleanupElement((Element) child)); } else { nel.appendChild(new TextNode(child.toString(), "")); } } } return nel; }
private Elements parseNextNode(String query) { if (!NEXT_NODE_TAG.equals(query)) { throw new IllegalArgumentException("Argument selector part: " + query + " is illegal"); } else { Elements eles = new Elements(); if (elements.size() == 1) { Attributes attributes = new Attributes(); Node nextNode = elements.first().nextSibling(); if (nextNode == null) { return eles; } attributes.put("value", nextNode.toString()); eles.add(new Element(Tag.valueOf("nextnode"), "", attributes)); } else { eles = elements; } return eles; } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); String altText = ""; for (Node child : design.childNodes()) { if (child instanceof Element && ((Element) child).tagName().equals("source") && child.hasAttr("href")) { addSource(DesignAttributeHandler.readAttribute("href", child.attributes(), Resource.class)); } else { altText += child.toString(); } } altText = altText.trim(); if (!altText.isEmpty()) { setAltText(altText); } }
// hit when the node is first seen public void head(Node node, int depth) { String name = node.nodeName(); if (name.equals("li")) append('\n'); else if (node.toString().startsWith("<select")) { append1("[SELECT]"); append(tab); } else if (node.outerHtml().startsWith("<option")) { // append1(node.attr("value")+":");append1(" "); TextNodeVisitor textVisitor = new TextNodeVisitor(); node.traverse(textVisitor); append1("{" + textVisitor.toString() + "}"); } else if (node.outerHtml().startsWith("<input")) { if (node.attr("type").equals("input")) append1("[INPUT]" + node.attr("maxLength")); } else if (node.outerHtml().startsWith("<span")) { TextNodeVisitor textVisitor = new TextNodeVisitor(); node.traverse(textVisitor); append1(":" + textVisitor.toString() + " "); } }