| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.devacfr.maven.skins.reflow; |
| 17 |
|
|
| 18 |
|
import static java.util.Objects.requireNonNull; |
| 19 |
|
|
| 20 |
|
import java.nio.charset.StandardCharsets; |
| 21 |
|
import javax.annotation.Nonnull; |
| 22 |
|
import org.jsoup.Jsoup; |
| 23 |
|
import org.jsoup.nodes.Document; |
| 24 |
|
import org.jsoup.nodes.Element; |
| 25 |
|
import org.jsoup.nodes.Node; |
| 26 |
|
import org.jsoup.parser.Parser; |
| 27 |
|
import org.jsoup.parser.Tag; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| |
|
| 44,7% |
Uncovered Elements: 47 (85) |
Complexity: 31 |
Complexity Density: 0,6 |
|
| 47 |
|
public final class JsoupUtils { |
| 48 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 49 |
0 |
private JsoupUtils() {... |
| 50 |
|
|
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@param |
| 57 |
|
|
| 58 |
|
@return |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 60 |
188 |
@Nonnull... |
| 61 |
|
public static Document createHtmlDocument(@Nonnull String html) { |
| 62 |
188 |
requireNonNull(html); |
| 63 |
188 |
Document doc = Jsoup.parse(html, "", createHtmlParser()); |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
188 |
return doc; |
| 71 |
|
} |
| 72 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 73 |
0 |
@Nonnull... |
| 74 |
|
public static Document createXmlDocument(@Nonnull String html) { |
| 75 |
0 |
requireNonNull(html); |
| 76 |
0 |
Document doc = Jsoup.parse(html, "", createXmlParser()); |
| 77 |
0 |
doc.outputSettings() |
| 78 |
|
.outline(false) |
| 79 |
|
.syntax(Document.OutputSettings.Syntax.xml) |
| 80 |
|
.prettyPrint(false) |
| 81 |
|
.escapeMode(org.jsoup.nodes.Entities.EscapeMode.xhtml) |
| 82 |
|
.charset(StandardCharsets.UTF_8); |
| 83 |
0 |
return doc; |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
| 86 |
188 |
@Nonnull... |
| 87 |
|
public static Parser createHtmlParser() { |
| 88 |
188 |
Parser parser = Parser.htmlParser(); |
| 89 |
188 |
parser.tagSet().onNewTag(tag -> { |
| 90 |
1030 |
if (!tag.isKnownTag()) |
| 91 |
125 |
tag.set(Tag.SelfClose); |
| 92 |
|
}); |
| 93 |
188 |
return parser; |
| 94 |
|
} |
| 95 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 96 |
0 |
@Nonnull... |
| 97 |
|
public static Parser createXmlParser() { |
| 98 |
0 |
Parser parser = Parser.xmlParser(); |
| 99 |
0 |
return parser; |
| 100 |
|
} |
| 101 |
|
|
| |
|
| 53,1% |
Uncovered Elements: 15 (32) |
Complexity: 13 |
Complexity Density: 0,65 |
|
| 102 |
6 |
public static Element link(Document doc,... |
| 103 |
|
String href, |
| 104 |
|
String name, |
| 105 |
|
String target, |
| 106 |
|
String img, |
| 107 |
|
String icon, |
| 108 |
|
String className) { |
| 109 |
6 |
Element a = doc.createElement("a"); |
| 110 |
6 |
if (href != null && !href.isEmpty()) { |
| 111 |
6 |
a.attr("href", href); |
| 112 |
|
} |
| 113 |
6 |
if (name != null && !name.isEmpty()) { |
| 114 |
6 |
a.attr("title", name); |
| 115 |
|
} |
| 116 |
6 |
if (target != null && !target.isEmpty()) { |
| 117 |
0 |
a.attr("target", target); |
| 118 |
|
} |
| 119 |
6 |
if (className != null && !className.isEmpty()) { |
| 120 |
0 |
a.addClass(className); |
| 121 |
|
} |
| 122 |
6 |
if (img != null && !img.isEmpty()) { |
| 123 |
|
|
| 124 |
0 |
Element image = image(doc, img, "", "", "", ""); |
| 125 |
0 |
a.appendChild(image); |
| 126 |
0 |
a.appendText(name); |
| 127 |
6 |
} else if (icon != null && !icon.isEmpty()) { |
| 128 |
|
|
| 129 |
0 |
a.appendText(name); |
| 130 |
0 |
Element i = doc.createElement("i"); |
| 131 |
0 |
i.addClass(icon); |
| 132 |
0 |
a.appendChild(i); |
| 133 |
|
} else { |
| 134 |
|
|
| 135 |
6 |
a.appendText(name); |
| 136 |
|
} |
| 137 |
6 |
return a; |
| 138 |
|
} |
| 139 |
|
|
| |
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 9 |
Complexity Density: 0,75 |
|
| 140 |
0 |
public static Element image(Document doc, String src, String alt, String border, String width, String height) {... |
| 141 |
0 |
Element image = doc.createElement("img"); |
| 142 |
0 |
image.addClass("image-link"); |
| 143 |
0 |
image.attr("src", src); |
| 144 |
0 |
if (alt != null && !alt.isEmpty()) { |
| 145 |
0 |
image.attr("alt", alt); |
| 146 |
|
} |
| 147 |
0 |
if (border != null && !border.isEmpty()) { |
| 148 |
0 |
image.attr("border", border); |
| 149 |
|
} |
| 150 |
0 |
if (width != null && !width.isEmpty()) { |
| 151 |
0 |
image.attr("width", width); |
| 152 |
|
} |
| 153 |
0 |
if (height != null && !height.isEmpty()) { |
| 154 |
0 |
image.attr("height", height); |
| 155 |
|
} |
| 156 |
0 |
return image; |
| 157 |
|
} |
| 158 |
|
|
| |
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
| 159 |
17968 |
public static String getNodeName(Node node) {... |
| 160 |
17968 |
if (node instanceof Element) { |
| 161 |
17968 |
return ((Element) node).tagName(); |
| 162 |
|
} else { |
| 163 |
0 |
return node.nodeName(); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 167 |
66 |
public static boolean hasTextNode(Node node) {... |
| 168 |
66 |
return node.childNodes().stream().anyMatch(n -> { |
| 169 |
22 |
boolean match = n.nodeName().equals("#text") && !n.toString().trim().isEmpty(); |
| 170 |
22 |
return match; |
| 171 |
|
}); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
} |