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