1 | package pro.verron.officestamper.experimental; | |
2 | ||
3 | import org.docx4j.dml.CTRegularTextRun; | |
4 | import org.docx4j.dml.CTTextBody; | |
5 | import org.docx4j.dml.CTTextParagraph; | |
6 | import org.docx4j.openpackaging.exceptions.Docx4JException; | |
7 | import org.docx4j.openpackaging.packages.PresentationMLPackage; | |
8 | import org.docx4j.openpackaging.parts.*; | |
9 | import org.docx4j.openpackaging.parts.PresentationML.*; | |
10 | import org.docx4j.openpackaging.parts.WordprocessingML.ImageJpegPart; | |
11 | import org.pptx4j.pml.*; | |
12 | import org.slf4j.Logger; | |
13 | import org.slf4j.LoggerFactory; | |
14 | import org.springframework.lang.Nullable; | |
15 | import pro.verron.officestamper.api.OfficeStamperException; | |
16 | ||
17 | import java.util.List; | |
18 | import java.util.Map; | |
19 | import java.util.Set; | |
20 | ||
21 | import static java.util.Arrays.stream; | |
22 | ||
23 | abstract class PowerpointVisitor { | |
24 | ||
25 | private static final Logger logger = LoggerFactory.getLogger(PowerpointVisitor.class); | |
26 | ||
27 | private static void unexpectedVisit(Object object) { | |
28 | assert object != null : "Cannot visit a null object"; | |
29 | var env = System.getenv(); | |
30 | var throwOnUnexpectedVisit = Boolean.parseBoolean(env.getOrDefault("throw-on-unexpected-visit", "false")); | |
31 | var message = "Unknown case : %s %s".formatted(object, object.getClass()); | |
32 |
1
1. unexpectedVisit : negated conditional → NO_COVERAGE |
if (throwOnUnexpectedVisit) throw new OfficeStamperException(message); |
33 | else logger.debug(message); | |
34 | } | |
35 | ||
36 | private static void ignore(@Nullable Object ignored) { | |
37 | logger.trace("ignored visit of '{}' object", ignored); | |
38 | } | |
39 | ||
40 | /** | |
41 | * Signal the visited object through the before method, | |
42 | * then apply logic to know the visit next elements or ignore deeper nesting | |
43 | * based on the object type. | |
44 | * | |
45 | * @param object the object to visit | |
46 | */ | |
47 | public final void visit(@Nullable Object object) { | |
48 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::before → KILLED |
before(object); |
49 | try { | |
50 | switch (object) { | |
51 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case PresentationMLPackage element -> visit(element.getParts()); |
52 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case PartName ignored -> ignore(ignored); |
53 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case Parts element -> visit(element.getParts()); |
54 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case SlideLayoutPart ignored -> ignore(ignored); |
55 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case ImageJpegPart ignored -> ignore(ignored); |
56 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case ThemePart ignored -> ignore(ignored); |
57 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case DocPropsCorePart ignored -> ignore(ignored); |
58 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case DocPropsExtendedPart ignored -> ignore(ignored); |
59 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case SlideMasterPart ignored -> ignore(ignored); |
60 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case ViewPropertiesPart ignored -> ignore(ignored); |
61 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case PresentationPropertiesPart ignored -> ignore(ignored); |
62 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case TableStylesPart ignored -> ignore(ignored); |
63 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → SURVIVED |
case MainPresentationPart element -> visit(element.getContents()); |
64 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case SlidePart element -> visit(element.getContents()); |
65 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case Sld element -> visit(element.getCSld()); |
66 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case CommonSlideData element -> visit(element.getSpTree()); |
67 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case GroupShape element -> visit(element.getSpOrGrpSpOrGraphicFrame()); |
68 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case Shape element -> visit(element.getTxBody()); |
69 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case CTTextBody element -> visit(element.getP()); |
70 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → SURVIVED |
case CTTextParagraph element -> visit(element.getEGTextRun()); |
71 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case CTRegularTextRun ignored -> ignore(ignored); |
72 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → NO_COVERAGE |
case Presentation.SldSz ignored -> ignore(ignored); |
73 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → SURVIVED |
case Presentation ignored -> ignore(ignored); |
74 |
1
1. visit : removed call to java/util/List::forEach → KILLED |
case List<?> element -> element.forEach(this::visit); |
75 |
1
1. visit : removed call to java/util/Set::forEach → KILLED |
case Set<?> element -> element.forEach(this::visit); |
76 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case Map<?, ?> element -> visit(element.entrySet()); |
77 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::visit → KILLED |
case Map.Entry<?, ?> element -> visit(element.getKey(), element.getValue()); |
78 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::ignore → NO_COVERAGE |
case null -> ignore(null); |
79 |
1
1. visit : removed call to pro/verron/officestamper/experimental/PowerpointVisitor::unexpectedVisit → NO_COVERAGE |
default -> unexpectedVisit(object); |
80 | } | |
81 | } catch (Docx4JException e) { | |
82 | throw new OfficeStamperException(e); | |
83 | } | |
84 | } | |
85 | ||
86 | private void visit(Object... objs) { | |
87 |
1
1. visit : removed call to java/util/stream/Stream::forEach → KILLED |
stream(objs).forEach(this::visit); |
88 | } | |
89 | ||
90 | /** | |
91 | * This abstract method is responsible for executing some tasks before a specific operation. | |
92 | * It is intended to be implemented by subclasses. | |
93 | * | |
94 | * @param object The optional object that can be used as a parameter for the pre-operation tasks. | |
95 | */ | |
96 | protected abstract void before(@Nullable Object object); | |
97 | ||
98 | } | |
Mutations | ||
32 |
1.1 |
|
48 |
1.1 |
|
51 |
1.1 |
|
52 |
1.1 |
|
53 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
87 |
1.1 |