1 | package pro.verron.officestamper.experimental; | |
2 | ||
3 | import org.xlsx4j.sml.CTRst; | |
4 | import pro.verron.officestamper.api.Placeholder; | |
5 | ||
6 | /** | |
7 | * The ExcelParagraph class represents a paragraph in an Excel document. | |
8 | * It provides methods to replace expressions and retrieve the aggregated text over all runs. | |
9 | */ | |
10 | public class ExcelParagraph { | |
11 | private final CTRst paragraph; | |
12 | ||
13 | /** | |
14 | * Constructs a new ParagraphWrapper for the given paragraph. | |
15 | * | |
16 | * @param paragraph the paragraph to wrap. | |
17 | */ | |
18 | public ExcelParagraph(CTRst paragraph) { | |
19 | this.paragraph = paragraph; | |
20 | } | |
21 | ||
22 | /** | |
23 | * Replaces the given expression with the replacement object within | |
24 | * the paragraph. | |
25 | * The replacement object must be a valid DOCX4J Object. | |
26 | * | |
27 | * @param placeholder the expression to be replaced. | |
28 | * @param replacement the object to replace the expression. | |
29 | */ | |
30 | public void replace(Placeholder placeholder, String replacement) { | |
31 | var ctXstringWhitespace = paragraph.getT(); | |
32 | var string = ctXstringWhitespace.getValue(); | |
33 | var start = string.indexOf(placeholder.expression()); | |
34 | var end = start + placeholder.expression() | |
35 |
1
1. replace : Replaced integer addition with subtraction → KILLED |
.length(); |
36 | var next = string.substring(0, start) + replacement + string.substring(end); | |
37 |
1
1. replace : removed call to org/xlsx4j/sml/CTXstringWhitespace::setValue → KILLED |
ctXstringWhitespace.setValue(next); |
38 | } | |
39 | ||
40 | /** | |
41 | * {@inheritDoc} | |
42 | */ | |
43 | @Override | |
44 | public String toString() { | |
45 |
1
1. toString : replaced return value with "" for pro/verron/officestamper/experimental/ExcelParagraph::toString → NO_COVERAGE |
return asString(); |
46 | } | |
47 | ||
48 | /** | |
49 | * Returns the aggregated text over all runs. | |
50 | * | |
51 | * @return the text of all runs. | |
52 | */ | |
53 | ||
54 | public String asString() { | |
55 |
1
1. asString : replaced return value with "" for pro/verron/officestamper/experimental/ExcelParagraph::asString → KILLED |
return paragraph.getR() + ": " + paragraph.getT() |
56 | .getValue(); | |
57 | } | |
58 | } | |
Mutations | ||
35 |
1.1 |
|
37 |
1.1 |
|
45 |
1.1 |
|
55 |
1.1 |