1 | package fr.sii.ogham.html.inliner.impl.jsoup; | |
2 | ||
3 | ||
4 | import static fr.sii.ogham.html.inliner.CssInlinerConstants.INLINED_ATTR; | |
5 | import static fr.sii.ogham.html.inliner.CssInlinerConstants.INLINE_MODE_ATTR; | |
6 | ||
7 | import org.jsoup.Jsoup; | |
8 | import org.jsoup.nodes.Document; | |
9 | import org.jsoup.nodes.Element; | |
10 | import org.jsoup.select.Elements; | |
11 | ||
12 | import fr.sii.ogham.html.inliner.CssInlinerConstants; | |
13 | import fr.sii.ogham.html.inliner.CssInlinerConstants.InlineMode; | |
14 | ||
15 | ||
16 | /** | |
17 | * Helper class that factorizes code for classes that are using Jsoup inliners. | |
18 | * | |
19 | * @author Aurélien Baudet | |
20 | * | |
21 | */ | |
22 | public final class CssInlineUtils { | |
23 | /** | |
24 | * Checks if inlining mode is allowed on the provided element. | |
25 | * | |
26 | * @param node | |
27 | * the node to check if the actual inlining mode is | |
28 | * allowed | |
29 | * @param mode | |
30 | * the actual mode | |
31 | * @return true if this mode is allowed, false otherwise | |
32 | */ | |
33 | @SuppressWarnings("squid:S1126") | |
34 | public static boolean isInlineModeAllowed(Element node, InlineMode mode) { | |
35 | // if already inlined => reject (do not inline twice) | |
36 |
3
1. isInlineModeAllowed : negated conditional → NO_COVERAGE 2. isInlineModeAllowed : negated conditional → KILLED 3. isInlineModeAllowed : negated conditional → KILLED |
if (!node.attr(INLINED_ATTR).isEmpty()) { |
37 |
1
1. isInlineModeAllowed : replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → NO_COVERAGE |
return false; |
38 | } | |
39 | // if inline mode defined but not the wanted mode => reject | |
40 |
5
1. isInlineModeAllowed : negated conditional → NO_COVERAGE 2. isInlineModeAllowed : negated conditional → NO_COVERAGE 3. isInlineModeAllowed : negated conditional → KILLED 4. isInlineModeAllowed : negated conditional → KILLED 5. isInlineModeAllowed : negated conditional → KILLED |
if (!node.attr(INLINE_MODE_ATTR).isEmpty() && !mode.is(node.attr(INLINE_MODE_ATTR))) { |
41 |
2
1. isInlineModeAllowed : replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → NO_COVERAGE 2. isInlineModeAllowed : replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → KILLED |
return false; |
42 | } | |
43 | // if inline mode defined and matches the wanted mode => allow | |
44 | // if no inline mode defined => allow (any mode allowed) | |
45 |
3
1. isInlineModeAllowed : replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → NO_COVERAGE 2. isInlineModeAllowed : replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → KILLED 3. isInlineModeAllowed : replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::isInlineModeAllowed → KILLED |
return true; |
46 | } | |
47 | ||
48 | /** | |
49 | * Remove attributes that are used only by Ogham: | |
50 | * <ul> | |
51 | * <li>{@link CssInlinerConstants#INLINE_MODE_ATTR}</li> | |
52 | * <li>{@link CssInlinerConstants#INLINED_ATTR}</li> | |
53 | * </ul> | |
54 | * | |
55 | * @param html | |
56 | * the html to clean | |
57 | * @return the cleaned html | |
58 | */ | |
59 | public static String removeOghamAttributes(String html) { | |
60 | Document doc = Jsoup.parse(html); | |
61 | Elements nodes = doc.select("["+INLINE_MODE_ATTR+"], ["+INLINED_ATTR+"]"); | |
62 | for (Element node : nodes) { | |
63 | node.removeAttr(INLINE_MODE_ATTR); | |
64 | node.removeAttr(INLINED_ATTR); | |
65 | } | |
66 |
3
1. removeOghamAttributes : replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::removeOghamAttributes → NO_COVERAGE 2. removeOghamAttributes : replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::removeOghamAttributes → KILLED 3. removeOghamAttributes : replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/CssInlineUtils::removeOghamAttributes → KILLED |
return doc.outerHtml(); |
67 | } | |
68 | ||
69 | private CssInlineUtils() { | |
70 | super(); | |
71 | } | |
72 | } | |
Mutations | ||
36 |
1.1 2.2 3.3 |
|
37 |
1.1 |
|
40 |
1.1 2.2 3.3 4.4 5.5 |
|
41 |
1.1 2.2 |
|
45 |
1.1 2.2 3.3 |
|
66 |
1.1 2.2 3.3 |