| 1 | package pro.verron.officestamper.api; | |
| 2 | ||
| 3 | import org.docx4j.wml.CTSmartTagRun; | |
| 4 | import org.docx4j.wml.ContentAccessor; | |
| 5 | import pro.verron.officestamper.utils.iterator.ResetableIterator; | |
| 6 | import pro.verron.officestamper.utils.wml.DocxIterator; | |
| 7 | import pro.verron.officestamper.utils.wml.WmlUtils; | |
| 8 | ||
| 9 | /// Provides utility methods for working with [Hook] instances in the context of a WordprocessingML-based document. The | |
| 10 | /// `Hooks` class contains static methods to create and manage [ResetableIterator] instances of hooks for a given | |
| 11 | /// document part. These hooks allow the customization or extension of document processing behavior in a flexible and | |
| 12 | /// context-driven manner. | |
| 13 | public class Hooks { | |
| 14 | ||
| 15 | private Hooks() { | |
| 16 | throw new IllegalStateException("Utility class"); | |
| 17 | } | |
| 18 | ||
| 19 | /// Creates a [ResetableIterator] of Hook instances for a specific document part, based on the provided content | |
| 20 | /// accessor. This method filters potential hooks from the content and maps them to Hook instances associated with | |
| 21 | /// the given document part. | |
| 22 | /// | |
| 23 | /// @param contentAccessor the content accessor providing access to the document's content | |
| 24 | /// | |
| 25 | /// @return a [ResetableIterator] of Hook instances for the specified document part | |
| 26 | public static ResetableIterator<Hook> ofHooks(ContentAccessor contentAccessor) { | |
| 27 |
1
1. ofHooks : replaced return value with null for pro/verron/officestamper/api/Hooks::ofHooks → KILLED |
return new DocxIterator(contentAccessor).filter(Hooks::isHook) |
| 28 | .map(Hooks::asHook); | |
| 29 | } | |
| 30 | ||
| 31 | private static boolean isHook(Object o) { | |
| 32 |
3
1. isHook : negated conditional → KILLED 2. isHook : negated conditional → KILLED 3. isHook : replaced boolean return with true for pro/verron/officestamper/api/Hooks::isHook → KILLED |
return o instanceof CTSmartTagRun tag && WmlUtils.isTagElement(tag, "officestamper"); |
| 33 | } | |
| 34 | ||
| 35 | private static Hook asHook(Object o) { | |
| 36 |
2
1. asHook : negated conditional → KILLED 2. asHook : negated conditional → KILLED |
if (o instanceof CTSmartTagRun tag && WmlUtils.isTagElement(tag, "officestamper")) |
| 37 |
2
1. lambda$asHook$0 : removed call to pro/verron/officestamper/utils/wml/WmlUtils::setTagAttribute → KILLED 2. asHook : replaced return value with null for pro/verron/officestamper/api/Hooks::asHook → KILLED |
return contextKey -> WmlUtils.setTagAttribute(tag, "context", contextKey); |
| 38 | throw new IllegalArgumentException("Unexpected value: " + o); | |
| 39 | } | |
| 40 | } | |
Mutations | ||
| 27 |
1.1 |
|
| 32 |
1.1 2.2 3.3 |
|
| 36 |
1.1 2.2 |
|
| 37 |
1.1 2.2 |