List of usage examples for org.jsoup.nodes Node attr
public Node attr(String attributeKey, String attributeValue)
From source file:com.screenslicer.core.util.Util.java
private static void markVisible(Node node) { if (node != null) { if (node.nodeName().equals("select")) { for (Node child : node.childNodes()) { child.attr("class", hiddenMarker.matcher(child.attr("class")).replaceAll("")); }//from w w w. j ava 2 s .c o m } node.attr("class", hiddenMarker.matcher(node.attr("class")).replaceAll("")); markVisible(node.parent()); } }
From source file:com.screenslicer.core.util.Util.java
private static void markFiltered(Node node, final boolean lenient) { if (lenient) { if (!isFilteredLenient(node)) { node.attr("class", node.attr("class") + " " + FILTERED_LENIENT_MARKER + " "); }/* w w w . ja v a 2s . c o m*/ } else { node.traverse(new NodeVisitor() { @Override public void tail(Node n, int d) { } @Override public void head(Node n, int d) { if (!isFiltered(n)) { n.attr("class", n.attr("class") + " " + FILTERED_MARKER + " "); } } }); } }
From source file:com.screenslicer.core.util.Util.java
public static Element markTestElement(Element element) { element.traverse(new NodeVisitor() { @Override/*from w w w . jav a2 s . c o m*/ public void tail(Node node, int level) { } @Override public void head(Node node, int level) { node.attr("class", nodeMarker.matcher(node.attr("class")).replaceAll("")); } }); element.traverse(new NodeVisitor() { int count = 0; @Override public void tail(Node node, int level) { } @Override public void head(Node node, int level) { ++count; node.attr("class", node.attr("class") + " " + NODE_MARKER + count + " "); } }); return element; }
From source file:com.aurel.track.exchange.docx.exporter.PreprocessImage.java
/** * Removes the HTML5 figure tag and saves the figcaption in the <img> tag's "alt" attribute for later use * @param htmlContent/*from ww w . ja v a2s . c o m*/ * @return */ private Document removeFigureSaveFigcaption(String htmlContent) { Document doc = Jsoup.parseBodyFragment(htmlContent); //figure is a HTML5 tag not accepted by Tidy, so it should be replaced by the content <img>-tag, and the figcaption is saved in the "alt" attribute Elements figureElements = doc.select("figure"); Element figcaptionNode = null; if (figureElements != null) { for (Iterator<Element> iterator = figureElements.iterator(); iterator.hasNext();) { Element figureElement = iterator.next(); Elements figureChildren = figureElement.getAllElements(); Node imageNode = null; if (figureChildren != null) { for (Element figureChild : figureChildren) { if ("img".equals(figureChild.nodeName())) { imageNode = figureChild; } else { if ("figcaption".equals(figureChild.nodeName())) { figcaptionNode = figureChild; //set "figcaption" text as value for "alt" attribute if (imageNode != null) { imageNode.attr("alt", figcaptionNode.text()); } } } } } if (imageNode != null) { figureElement.replaceWith(imageNode); } } } return doc; }