PowerpointStamper.java

1
package pro.verron.officestamper.experimental;
2
3
import org.docx4j.dml.CTRegularTextRun;
4
import org.docx4j.dml.CTTextParagraph;
5
import org.docx4j.openpackaging.exceptions.Docx4JException;
6
import org.docx4j.openpackaging.packages.PresentationMLPackage;
7
import org.springframework.expression.spel.SpelParserConfiguration;
8
import org.springframework.expression.spel.standard.SpelExpressionParser;
9
import org.springframework.expression.spel.support.StandardEvaluationContext;
10
import pro.verron.officestamper.api.OfficeStamper;
11
import pro.verron.officestamper.api.OfficeStamperException;
12
import pro.verron.officestamper.core.Placeholders;
13
14
import java.io.OutputStream;
15
import java.util.List;
16
17
/// The PowerpointStamper class implements the OfficeStamper interface
18
/// to provide capability for stamping PowerPoint presentations with
19
/// context and writing the result to an OutputStream.
20
public class PowerpointStamper
21
        implements OfficeStamper<PresentationMLPackage> {
22
    /// Constructs a new instance of the PowerpointStamper class.
23
    /// This constructor initializes an instance of PowerpointStamper, which implements
24
    /// the OfficeStamper interface. The class provides functionality to apply variable-based
25
    /// stamping on PowerPoint templates and outputs the modified presentation.
26
    public PowerpointStamper() {
27
        // Explicit default constructor for Javadoc
28
    }
29
30
    @Override
31
    public void stamp(PresentationMLPackage template, Object context, OutputStream outputStream)
32
            throws OfficeStamperException {
33
        Class<CTTextParagraph> ctTextParagraphClass = CTTextParagraph.class;
34
        List<CTTextParagraph> ctTextParagraphs = PowerpointCollector.collect(template, ctTextParagraphClass);
35
        for (CTTextParagraph paragraph : ctTextParagraphs) {
36
            PowerpointParagraph paragraph1 = new PowerpointParagraph(new PptxPart(), paragraph);
37
            String string = paragraph1.asString();
38
            for (var variable : Placeholders.findVariables(string)) {
39
                var replacement = new CTRegularTextRun();
40
                var evaluationContext = new StandardEvaluationContext(context);
41
                var parserConfiguration = new SpelParserConfiguration();
42
                var parser = new SpelExpressionParser(parserConfiguration);
43
                var expression = parser.parseExpression(variable.content());
44
                var value = expression.getValue(evaluationContext);
45
46 1 1. stamp : removed call to org/docx4j/dml/CTRegularTextRun::setT → KILLED
                replacement.setT((String) value);
47 1 1. stamp : removed call to pro/verron/officestamper/experimental/PowerpointParagraph::replace → KILLED
                paragraph1.replace(variable, replacement);
48
            }
49
50
        }
51
        try {
52 1 1. stamp : removed call to org/docx4j/openpackaging/packages/PresentationMLPackage::save → KILLED
            template.save(outputStream);
53
        } catch (Docx4JException e) {
54
            throw new OfficeStamperException(e);
55
        }
56
    }
57
}

Mutations

46

1.1
Location : stamp
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
removed call to org/docx4j/dml/CTRegularTextRun::setT → KILLED

47

1.1
Location : stamp
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
removed call to pro/verron/officestamper/experimental/PowerpointParagraph::replace → KILLED

52

1.1
Location : stamp
Killed by : pro.verron.officestamper.test.BasicPowerpointTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicPowerpointTest]/[method:testStamper()]
removed call to org/docx4j/openpackaging/packages/PresentationMLPackage::save → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0