ImageInlineUtils.java

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

Mutations

35

1.1
Location : isInlineModeAllowed
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
negated conditional → KILLED

2.2
Location : isInlineModeAllowed
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : isInlineModeAllowed
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.differentImageFormats(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
negated conditional → KILLED

36

1.1
Location : isInlineModeAllowed
Killed by : none
replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → NO_COVERAGE

2.2
Location : isInlineModeAllowed
Killed by : oghamcore.it.html.translator.InlineImageTranslatorTest.oghamAttributesShoulBeRemoved(oghamcore.it.html.translator.InlineImageTranslatorTest)
replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → KILLED

39

1.1
Location : isInlineModeAllowed
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : isInlineModeAllowed
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.differentImageFormats(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
negated conditional → KILLED

3.3
Location : isInlineModeAllowed
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
negated conditional → KILLED

4.4
Location : isInlineModeAllowed
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipAttach(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
negated conditional → KILLED

5.5
Location : isInlineModeAllowed
Killed by : none
negated conditional → NO_COVERAGE

6.6
Location : isInlineModeAllowed
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.skipInline(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
negated conditional → KILLED

40

1.1
Location : isInlineModeAllowed
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipAttach(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → KILLED

2.2
Location : isInlineModeAllowed
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.skipInline(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → KILLED

3.3
Location : isInlineModeAllowed
Killed by : none
replaced boolean return with true for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → NO_COVERAGE

44

1.1
Location : isInlineModeAllowed
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → KILLED

2.2
Location : isInlineModeAllowed
Killed by : none
replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → NO_COVERAGE

3.3
Location : isInlineModeAllowed
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.differentImageFormats(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
replaced boolean return with false for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::isInlineModeAllowed → KILLED

65

1.1
Location : removeOghamAttributes
Killed by : oghamall.it.html.translator.JsoupInlineImageTranslatorTest.skipExternalImages(oghamall.it.html.translator.JsoupInlineImageTranslatorTest)
replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::removeOghamAttributes → KILLED

2.2
Location : removeOghamAttributes
Killed by : oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest.differentImageFormats(oghamcore.ut.html.inliner.impl.JsoupBase64ImageInlinerTest)
replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::removeOghamAttributes → KILLED

3.3
Location : removeOghamAttributes
Killed by : none
replaced return value with "" for fr/sii/ogham/html/inliner/impl/jsoup/ImageInlineUtils::removeOghamAttributes → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM