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 | /** | |
18 | * The PowerpointStamper class implements the OfficeStamper interface | |
19 | * to provide functionality for stamping Powerpoint presentations with | |
20 | * context and writing the result to an OutputStream. | |
21 | */ | |
22 | public class PowerpointStamper | |
23 | implements OfficeStamper<PresentationMLPackage> { | |
24 | ||
25 | @Override | |
26 | public void stamp( | |
27 | PresentationMLPackage template, | |
28 | Object context, | |
29 | OutputStream outputStream | |
30 | ) | |
31 | throws OfficeStamperException { | |
32 | Class<CTTextParagraph> ctTextParagraphClass = CTTextParagraph.class; | |
33 | List<CTTextParagraph> ctTextParagraphs = PowerpointCollector.collect(template, | |
34 | 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 |
|
47 |
1.1 |
|
52 |
1.1 |