### Minimal End-to-End Example Source: https://office-stamper.verron.pro/engine/how-does-it-works.html This snippet shows the basic setup for using the Office Stamper. It configures standard settings, adds a comment processor and a resolver, and then stamps a document. ```java var cfg = standard() .addCommentProcessor(HideIfProcessor.class, HideIfProcessor::new) .addResolver(new MoneyResolver()); new DocxStamper(cfg).stamp(templateInputStream, model, outputStream); ``` -------------------------------- ### Create and Customize Standard Configuration Source: https://office-stamper.verron.pro/engine/how-does-it-works.html Demonstrates how to create a standard configuration and set a default evaluation context factory. This is a common starting point for most Office Stamper setups. ```java import static pro.verron.officestamper.preset.OfficeStamperConfigurations.standard; import static pro.verron.officestamper.preset.EvaluationContextFactories.defaultFactory(); var cfg = standard() .setEvaluationContextFactory(defaultFactory()); ``` -------------------------------- ### Basic Office-stamper Usage Example Source: https://office-stamper.verron.pro/engine/getting-started.html This example demonstrates how to stamp a DOCX document using Office-stamper with a provided context and template. ```java void main() { // a java Bean, a record, or a map to use as context for the expressions found in the template. var context = Map.of( "company", Map.of("name", "Duff"), "customer", Map.of("name", "Homer"), "order", Map.of("id", "123", "date", "2023-01-01") ); // an instance of the stamper var stamper = OfficeStampers.docxStamper(); try( // Path to the .docx template file var template = Files.newInputStream(Paths.get("your/docx/template/file.docx")), // Path to write the resulting .docx document var output = Files.newOutputStream(Paths.get("your/desired/output/path.docx")) ) { stamper.stamp(template, context, output); } } ``` -------------------------------- ### Customizing Configuration Presets Source: https://office-stamper.verron.pro/cli/index.html Illustrates how to start with a standard configuration preset and add custom resolvers. ```java var configuration = OfficeStamperConfigurations.standard() .addResolver(new MyCustomResolver()); ``` -------------------------------- ### Example DOCX Template Content Source: https://office-stamper.verron.pro/engine/getting-started.html This is a sample template showing how to use placeholders for dynamic content insertion. ```plaintext Dear ${customer.name}, Thank you for your order #${order.id} placed on ${order.date}. Your order details: ${order.description} Total amount: $${order.amount} Sincerely, ${company.name} ``` -------------------------------- ### Configure DocxStamper with Custom Resolvers and Processors Source: https://office-stamper.verron.pro/engine/how-to-custom.html Set up the DocxStamperConfiguration by adding custom comment processors and resolvers, and configuring exception handling for template expressions. This example demonstrates a comprehensive setup for advanced document generation. ```java var configuration = new pro.verron.officestamper.core.DocxStamperConfiguration() // Custom comment processors .addCommentProcessor(IWatermarkProcessor.class, WatermarkProcessor::new) .addCommentProcessor(IHighlightProcessor.class, HighlightProcessor::new) // Custom resolvers (ordering matters: specific before generic) .addResolver(new MoneyResolver()) .addResolver(new PhoneNumberResolver()) // Exception behavior for expressions .setExceptionResolver(pro.verron.officestamper.preset.ExceptionResolvers.throwing()); var stamper = new pro.verron.officestamper.core.DocxStamper(configuration); try (var in = Files.newInputStream(templateDocx); var out = Files.newOutputStream(stampedDocx)) { stamper.stamp(in, context, out); } ``` -------------------------------- ### Get Preprocessors Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/DocxStamperConfiguration.html Retrieves the list of preprocessors configured for the stamper. ```APIDOC ## Method getPreprocessors ### Description Retrieves the list of preprocessors that will be applied before document processing. ### Method Signature `List getPreprocessors()` ### Returns A list of `PreProcessor` instances. ``` -------------------------------- ### Get Comment Range Start Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Returns the starting point of the comment range. ```Java public CommentRangeStart getCommentRangeStart() { return commentRangeStart; } ``` -------------------------------- ### Get Run Start Index Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.wml/WmlUtils.java.html Returns the starting index of the current run relative to its containing paragraph. ```Java @Override public int startIndex() {return startIndex;} ``` -------------------------------- ### Get Preprocessors List Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.core/DocxStamperConfiguration.java.html Retrieves the list of preprocessors. Returns an empty list if no preprocessors are configured. ```java public List getPreprocessors() { return preprocessors; } ``` -------------------------------- ### Get Parent Element Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Finds the smallest common parent element for the comment's start and end ranges. ```Java public ContentAccessor getParent() { return DocumentUtil.findSmallestCommonParent(commentRangeStart, commentRangeEnd); } ``` -------------------------------- ### Create Standard Configuration and Docx Stamper Source: https://office-stamper.verron.pro/engine/presets.html This snippet shows how to create a configuration using the 'standard' preset and then initialize a DOCX stamper with that configuration. ```javascript // Create a configuration with standard settings var configuration = OfficeStamperConfigurations.standard(); // Create a stamper with the custom configuration var stamper = OfficeStampers.docxStamper(configuration); ``` -------------------------------- ### Tweak Standard Configuration Source: https://office-stamper.verron.pro/engine/how-does-it-works.html Modifies the standard Office-stamper configuration by adding a specific preprocessor. This allows for adjustments to the default setup without starting from scratch. ```java var std = OfficeStamperConfigurations.standard(); // ...std.getPreprocessors() lists them; you can start from raw if you need full control. ``` -------------------------------- ### full() Source: https://office-stamper.verron.pro/engine/apidocs/index-all.html Creates a full OfficeStamperConfiguration with standard configurations, supplemented with additional pre- and post-processors for enhanced document handling. ```APIDOC ## full() ### Description Creates a full `OfficeStamperConfiguration` with standard configurations, supplemented with additional pre- and post-processors for enhanced document handling. ### Method Static method ### Class pro.verron.officestamper.preset.OfficeStamperConfigurations ``` -------------------------------- ### Slice ResetableIterator Elements Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.iterator/ResetableIterator.java.html Creates a new iterator that wraps the current one, providing only elements between the specified start and end (inclusive). Use this to get a sub-sequence of elements. ```java default ResetableIterator slice(T start, T end) { return new SlicingIterator<>(this, start, end); } ``` -------------------------------- ### Clone Repository and Build Project Source: https://office-stamper.verron.pro/engine/contributing.html Clone the Office-stamper repository and build the project using Maven. This is the initial setup step for development. ```bash git clone https://github.com/yourusername/office-stamper.git cd office-stamper mvn clean install ``` -------------------------------- ### Full Configuration Factory Method Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.preset/OfficeStamperConfigurations.java.html Creates a fully configured OfficeStamperConfiguration with standard processors and additional pre/post-processors for enhanced document handling. ```java public static OfficeStamperConfiguration full() { var configuration = standard(); configuration.addPreprocessor(Preprocessors.removeLanguageProof()); configuration.addPreprocessor(Preprocessors.removeLanguageInfo()); configuration.addPreprocessor(Preprocessors.mergeSimilarRuns()); configuration.addPostprocessor(Postprocessors.removeOrphanedFootnotes()); configuration.addPostprocessor(Postprocessors.removeOrphanedEndnotes()); return configuration; } ``` -------------------------------- ### Get Affected Runs in PowerpointParagraph Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.experimental/PowerpointParagraph.java.html Retrieves a list of PowerpointRun objects that are affected by a given range of start and end indices. It filters the available runs based on whether they are touched by the specified range. ```java private List getAffectedRuns(int startIndex, int endIndex) { return runs.stream() .filter(run -> run.isTouchedByRange(startIndex, endIndex)) .toList(); } ``` -------------------------------- ### raw() Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/preset/OfficeStamperConfigurations.html Creates an OfficeStamperConfiguration instance without any configuration or resolvers, processors, preprocessors or postprocessors applied. This provides a basic instance for custom setup. ```APIDOC ## raw() ### Description Creates a `OfficeStamperConfiguration` instance without any configuration or resolvers, processors, preprocessors or postprocessors applied. ### Method static OfficeStamperConfiguration ### Parameters None ### Response - `OfficeStamperConfiguration` - a basic `OfficeStamperConfiguration` instance with no extra configurations. ``` -------------------------------- ### Full OfficeStamperConfiguration Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.preset/OfficeStamperConfigurations.java.html Creates a comprehensive configuration with standard settings plus preprocessors for language cleanup and postprocessors for orphaned notes. ```java public static OfficeStamperConfiguration full() { var configuration = standard(); configuration.addPreprocessor(Preprocessors.removeLanguageProof()); configuration.addPreprocessor(Preprocessors.removeLanguageInfo()); configuration.addPreprocessor(Preprocessors.mergeSimilarRuns()); configuration.addPostprocessor(Postprocessors.removeOrphanedFootnotes()); configuration.addPostprocessor(Postprocessors.removeOrphanedEndnotes()); return configuration; } ``` -------------------------------- ### Get Elements within Comment Range Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Retrieves all elements within the parent that fall between the comment's start and end ranges. It iterates through siblings and uses depth-first search to identify elements within the specified range. ```Java public List getElements() { List elements = new ArrayList<>(); boolean startFound = false; boolean endFound = false; var siblings = getParent().getContent(); for (Object element : siblings) { startFound = startFound || DocumentUtil.depthElementSearch(commentRangeStart, element); if (startFound && !endFound) elements.add(element); endFound = endFound || DocumentUtil.depthElementSearch(commentRangeEnd, element); } return elements; } ``` -------------------------------- ### OfficeStamperConfigurations.standard Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/OfficeStamperConfiguration.html Creates a standard OfficeStamperConfiguration instance with predefined processors, resolvers, and preprocessors. ```APIDOC ## OfficeStamperConfigurations.standard ### Description Creates a standard `OfficeStamperConfiguration` instance with a set of predefined comment processors, resolvers, and preprocessors. ### Method static ### Parameters #### Path Parameters - **fallback** (ObjectResolver) - Required - The fallback resolver to use. ### Response #### Success Response - **OfficeStamperConfiguration** - A new instance of `OfficeStamperConfiguration`. ``` -------------------------------- ### Conditional Check: Expression at Start of Run Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.wml/WmlUtils.java.html Checks if an expression starts at the beginning of the first run. ```java boolean expressionAtStartOfRun = startIndex == firstRun.startIndex(); ``` -------------------------------- ### Main Method Entry Point Source: https://office-stamper.verron.pro/cli/jacoco/pro.verron.officestamper/Main.java.html The main method initializes the CommandLine object and executes the application with provided arguments, exiting with the determined status code. ```Java static void main(String[] args) { var main = new Main(); var cli = new CommandLine(main); int exitCode = cli.execute(args); System.exit(exitCode); } ``` -------------------------------- ### OfficeStamperConfigurations Standard Methods Source: https://office-stamper.verron.pro/engine/apidocs/index-all.html Static methods for creating standard OfficeStamperConfiguration instances. ```APIDOC ## OfficeStamperConfigurations Standard Methods ### Description Creates a standard `OfficeStamperConfiguration` instance with predefined settings or custom processors, resolvers, and preprocessors. ### Static Methods - **standard()** Creates a standard `OfficeStamperConfiguration` instance with predefined settings. - **standard(ObjectResolver)** Creates a standard `OfficeStamperConfiguration` instance with a set of predefined comment processors, resolvers, and preprocessors. ``` -------------------------------- ### Get SpEL Security Mode Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/DocxStamperConfiguration.html Gets the current SpEL security mode, which controls the security settings for SpEL expression evaluation. ```APIDOC ## Method getSpelSecurityMode ### Description Gets the current SpEL security mode, which controls the security settings for SpEL expression evaluation. ### Method Signature `SecurityMode getSpelSecurityMode()` ### Returns The current `SecurityMode` for SpEL. ``` -------------------------------- ### create Source: https://office-stamper.verron.pro/utils/apidocs/pro.verron.officestamper.utils/pro/verron/officestamper/utils/wml/WmlUtils.html Creates a new run with specified text and run style. ```APIDOC ## create ### Description Creates a new run with the specified text, and the specified run style. ### Method public static org.docx4j.wml.R create(String text, org.docx4j.wml.RPr rPr) ### Parameters #### Path Parameters - **text** (String) - the initial text of the `R`. - **rPr** (org.docx4j.wml.RPr) - the `RPr` to apply to the run ### Response #### Success Response - **org.docx4j.wml.R** - a new run with the specified text and run style. ``` -------------------------------- ### StandardParagraph.replace (start, end) Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/Insert.html Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. ```APIDOC ## StandardParagraph.replace (start, end) ### Description Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. ### Method `replace(Object start, Object end, Insert insert)` ### Parameters * **start** (Object) - The starting object defining the section to replace. * **end** (Object) - The ending object defining the section to replace. * **insert** (Insert) - The Insert object containing the elements to replace the section with. ``` -------------------------------- ### Visit Method Entry Point Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.experimental/PowerpointVisitor.java.html The main entry point for visiting an object. It calls the 'before' method and then dispatches to specific visit methods based on the object's type. ```java public final void visit(@Nullable Object object) { before(object); try { switch (object) { case PresentationMLPackage element -> visit(element.getParts()); case PartName ignored -> ignore(ignored); case Parts element -> visit(element.getParts()); case SlideLayoutPart ignored -> ignore(ignored); case ImageJpegPart ignored -> ignore(ignored); case ThemePart ignored -> ignore(ignored); case DocPropsCorePart ignored -> ignore(ignored); case DocPropsExtendedPart ignored -> ignore(ignored); case SlideMasterPart ignored -> ignore(ignored); case ViewPropertiesPart ignored -> ignore(ignored); } } catch (Exception e) { unexpectedVisit(object); } } ``` -------------------------------- ### Paragraph.replace (start, end) Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/Insert.html Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. ```APIDOC ## Paragraph.replace (start, end) ### Description Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. ### Method `replace(Object start, Object end, Insert insert)` ### Parameters * **start** (Object) - The starting object defining the section to replace. * **end** (Object) - The ending object defining the section to replace. * **insert** (Insert) - The Insert object containing the elements to replace the section with. ``` -------------------------------- ### StandardComment Constructor Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Initializes a StandardComment with DOCX part, start tag run, comment range start and end, comment object, and comment reference. ```java public StandardComment( DocxPart part, CTSmartTagRun startTagRun, CommentRangeStart commentRangeStart, CommentRangeEnd commentRangeEnd, Comments.Comment comment, @Nullable CommentReference commentReference ) { this.part = part; this.startTagRun = startTagRun; this.commentRangeStart = commentRangeStart; this.commentRangeEnd = commentRangeEnd; this.comment = comment; this.commentReference = commentReference; } ``` -------------------------------- ### AsciiDoc Preview Command Implementation Source: https://office-stamper.verron.pro/cli/jacoco/pro.verron.officestamper/Main.java.html This class implements the 'preview' subcommand for generating a preview image from an AsciiDoc file. It accepts input file, output file, theme, DPI, and format options. The run method reads the AsciiDoc content, converts it to a model, and injects theme attributes. ```Java public static class Preview implements Runnable { @Option(names = {"-i", "--input"}, required = true, description = "Input AsciiDoc file") private Path input; @Option(names = {"-o", "--output"}, defaultValue = "preview.png", description = "Output file (PNG or SVG)") private Path output; @Option(names = "--theme", defaultValue = "word", description = "Theme: word, gdocs, libre") private String theme; @Option(names = "--dpi", defaultValue = "96", description = "DPI for PNG output") private int dpi; @Option(names = "--format", description = "Output format: png, svg (auto-detected if " + "omitted)") private String format; /// Default constructor. public Preview() {} @Override public void run() { try { String asciidoc = Files.readString(input); var model = AsciiDocCompiler.toModel(asciidoc); // Inject theme attribute into model var attributes = new java.util.HashMap<>(model.getAttributes()); attributes.put("theme", theme); model = AsciiDocModel.of(attributes, model.getBlocks()); } catch (IOException e) { throw new OfficeStamperException(e); } } } ``` -------------------------------- ### Template Snippet Example Source: https://office-stamper.verron.pro/engine/how-does-it-works.html These are examples of template snippets that can be used within documents. They demonstrate conditional logic and data binding using expression language. ```template ${hideParagraphIf(order.total == 0)} ${order.total} ``` -------------------------------- ### Check if Run Starts in Range Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.wml/WmlUtils.java.html Helper method to check if the start index of the run falls within the specified global range. Used internally by `isTouchedByRange`. ```java private boolean startsInRange( int globalStartIndex, int globalEndIndex ) { return globalStartIndex < startIndex && startIndex <= globalEndIndex; } ``` -------------------------------- ### show Source: https://office-stamper.verron.pro/engine/testapidocs/pro.verron.officestamper.test/pro/verron/officestamper/test/utils/ContextFactory.html Creates a show context. This is an instance method on the ContextFactory interface. ```APIDOC ## show ### Description Creates a show context. ### Method instance ### Returns - show context ``` -------------------------------- ### full() Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/preset/OfficeStamperConfigurations.html Creates a full OfficeStamperConfiguration with standard configurations, supplemented with additional pre- and post-processors for enhanced document handling. This includes processors for removing language markings, merging text runs, and handling orphaned footnotes/endnotes. ```APIDOC ## full() ### Description Creates a full `OfficeStamperConfiguration` with standard configurations, supplemented with additional pre- and post-processors for enhanced document handling. ### Method static OfficeStamperConfiguration ### Parameters None ### Response - `OfficeStamperConfiguration` - a fully configured `OfficeStamperConfiguration` instance with the additional processors applied. ``` -------------------------------- ### Get Aggregated Text from Runs Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.experimental/PowerpointParagraph.java.html Retrieves the combined text content from all runs within the paragraph. This method is used to get the full text representation of the paragraph. ```java public String asString() { return runs.stream() .map(PowerpointRun::run) .map(CTRegularTextRun::getT) .collect(joining()) + "\n"; } ``` -------------------------------- ### minimal() Source: https://office-stamper.verron.pro/engine/apidocs/index-all.html Creates a minimal `OfficeStamperConfiguration` instance with essential settings for basic placeholder processing and fallback resolvers. This is a static method in the OfficeStamperConfigurations class. ```APIDOC ## minimal() ### Description Creates a minimal `OfficeStamperConfiguration` instance with essential settings to provide basic placeholder processing and fallback resolvers. ### Method Static method ### Class pro.verron.officestamper.preset.OfficeStamperConfigurations ``` -------------------------------- ### Check if WML Run Starts within a Range Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.wml/WmlUtils.java.html Helper method to check if the start index of the run falls within the specified global range. Used by `isTouchedByRange`. ```java private boolean startsInRange( int globalStartIndex, int globalEndIndex ) { return globalStartIndex < startIndex && startIndex <= globalEndIndex; } ``` -------------------------------- ### Replace Content Between Start and End Elements Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.core/StandardParagraph.java.html Replaces content within a paragraph that lies between specified start and end elements. It validates the order and presence of these elements before proceeding with the replacement. ```Java @Override public void replace(Object start, Object end, Insert insert) { var content = contents.getContent(); var fromIndex = content.indexOf(start); var toIndex = content.indexOf(end); if (fromIndex < 0) { var msg = "The start element (%s) is not in the paragraph (%s)"; throw new OfficeStamperException(msg.formatted(start, this)); } if (toIndex < 0) { var msg = "The end element (%s) is not in the paragraph (%s)"; throw new OfficeStamperException(msg.formatted(end, this)); } if (fromIndex > toIndex) { var msg = "The start element (%s) is after the end element (%s)"; throw new OfficeStamperException(msg.formatted(end, this)); } var expression = extractExpression(start, end); var newContents = WmlUtils.replaceExpressionWithRun(() -> p, expression, insert.elements(), insert::setRPr); content.clear(); content.addAll(newContents); } ``` -------------------------------- ### show Source: https://office-stamper.verron.pro/engine/testapidocs/pro.verron.officestamper.test/pro/verron/officestamper/test/utils/ObjectContextFactory.html Creates a show context. ```APIDOC ## show ### Description Creates a show context. ### Method `public Object show()` ### Response #### Success Response - **Object** - The created show context. ``` -------------------------------- ### setupRelationship(Part, Part, String) Source: https://office-stamper.verron.pro/utils/apidocs/index-all.html Establishes a relationship between two parts in an Open Packaging structure. ```APIDOC ## setupRelationship(Part, Part, String) ### Description Establishes a relationship between a source part and a target part using the specified relationship ID. ### Method Static method ### Endpoint N/A ### Parameters - **sourcePart** (Part) - Required - The source part. - **targetPart** (Part) - Required - The target part. - **relationshipId** (String) - Required - The ID for the relationship. ### Request Example None ### Response None ``` -------------------------------- ### Get Last Index of Run Text Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.experimental/PowerpointRun.java.html Helper method to get the index of the last character in the run's text content. It delegates to an overloaded method with the actual string. ```java private int lastIndex() { return lastIndex(run.getT()); } ``` -------------------------------- ### Localize Global Index within Run Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.wml/WmlUtils.java.html Converts a global index to a local index relative to the start of the current run. Handles indices outside the run's bounds by clamping them to the run's start or end. ```java private int localize(int globalIndex) { if (globalIndex < startIndex) return 0; else if (globalIndex > endIndex()) return length(); else return globalIndex - startIndex; } ``` -------------------------------- ### Custom Placeholder Preprocessor Source: https://office-stamper.verron.pro/engine/how-does-it-works.html Starts from a raw configuration and adds a custom preprocessor for placeholder detection. Use this when you need full control over the preprocessor chain. ```java var cfg = OfficeStamperConfigurations.raw(); cfg.addPreprocessor(Preprocessors.preparePlaceholders("(\\\$\\{(.+?)\")", "placeholder")); ``` -------------------------------- ### OpenPackage Constructor Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.openpackaging/OpenPackage.java.html Constructs a new OpenPackage instance, initializing it with the provided OpcPackage document and a specific Part. It also hashes all parts within the document for potential future lookup. ```APIDOC ## OpenPackage(T document, Part part) ### Description Constructs a new instance of OpenPackage with the specified document and part. ### Parameters #### Path Parameters - **document** (T extends OpcPackage) - The document object associated with this package. - **part** (Part) - The Part object representing a specific part of the document. ``` -------------------------------- ### replace(Object start, Object end, Insert insert) Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/Paragraph.html Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. This allows for targeted replacement of content blocks. ```APIDOC ## replace(Object start, Object end, Insert insert) ### Description Replaces a section of elements within the document, defined by the start and end objects, with the elements provided by the given insert. ### Method void ### Parameters #### Path Parameters - **start** (Object) - Required - the starting object marking the beginning of the section to replace. - **end** (Object) - Required - the ending object marking the end of the section to replace. - **insert** (Insert) - Required - the insert containing the elements that will replace the specified section. ``` -------------------------------- ### getStartTagRun Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/StandardComment.html Retrieves the CTSmartTagRun object associated with the start of this comment. ```APIDOC ## getStartTagRun ### Description Retrieves the CTSmartTagRun object associated with the start of this comment. ### Method org.docx4j.wml.CTSmartTagRun ### Returns the `CTSmartTagRun` object representing the start tag run of the comment ### Specified by `getStartTagRun` in interface `Comment` ``` -------------------------------- ### Raw OfficeStamperConfiguration Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.preset/OfficeStamperConfigurations.java.html Creates a basic OfficeStamperConfiguration instance without any additional configurations, resolvers, processors, or postprocessors. This serves as a starting point for custom configurations. ```java var defaultFactory = EvaluationContextFactories.defaultFactory(); var defaultExceptionResolver = ExceptionResolvers.throwing(); var configuration = new DocxStamperConfiguration(defaultFactory, defaultExceptionResolver); // Honor system property: officestamper.spel.mode = restricted|permissive (default: restricted) var spelModeProp = System.getProperty("officestamper.spel.mode"); var spelPermissive = spelModeProp != null && spelModeProp.equalsIgnoreCase("permissive"); configuration.setSpelSecurityMode(spelPermissive ? SecurityMode.PERMISSIVE : SecurityMode.RESTRICTED); if (spelPermissive) { configuration.setEvaluationContextFactory(EvaluationContextFactories.noopFactory()); } // Honor system property: officestamper.svg.mode = restricted|permissive (default: restricted) var svgModeProp = System.getProperty("officestamper.svg.mode"); configuration.setSvgSecurityMode(svgModeProp != null && svgModeProp.equalsIgnoreCase("permissive") ? SecurityMode.PERMISSIVE : SecurityMode.RESTRICTED); return configuration; ``` -------------------------------- ### minimal() Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/preset/OfficeStamperConfigurations.html Creates a minimal OfficeStamperConfiguration instance with essential settings for basic placeholder processing and fallback resolvers. It includes a fallback resolver with a newline character as the default value and a placeholder preprocessor. ```APIDOC ## minimal() ### Description Creates a minimal `OfficeStamperConfiguration` instance with essential settings to provide basic placeholder processing and fallback resolvers. ### Method static OfficeStamperConfiguration ### Parameters None ### Response - `OfficeStamperConfiguration` - a minimally configured `OfficeStamperConfiguration` instance. ``` -------------------------------- ### getStartTagRun Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/StandardComment.html Retrieves the CTSmartTagRun object associated with the start of this comment. ```APIDOC ## getStartTagRun ### Description Retrieves the CTSmartTagRun object associated with the start of this comment. ### Returns * **org.docx4j.wml.CTSmartTagRun** - The start tag run object. ``` -------------------------------- ### PptxPart Constructor Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/experimental/PptxPart.html Creates an instance of a PptxPart record class, initializing it with a presentation document. ```APIDOC ## PptxPart(PresentationMLPackage document) ### Description Creates an instance of a `PptxPart` record class. ### Parameters * **document** (PresentationMLPackage) - The value for the `document` record component. ``` -------------------------------- ### Get Parent Content Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.wml/WmlUtils.java.html Retrieves the content of the parent of a run. ```java var firstSiblings = ((ContentAccessor) firstR.getParent()).getContent(); ``` -------------------------------- ### Get Run Object Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.wml/WmlUtils.java.html Obtains the run object from a StandardRun. ```java var firstR = firstRun.run(); ``` -------------------------------- ### OfficeStamperConfigurations Factory Methods Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/OfficeStamperConfiguration.html Factory methods for creating pre-configured OfficeStamperConfiguration instances. ```APIDOC ## OfficeStamperConfigurations ### Description Provides static factory methods to create various `OfficeStamperConfiguration` instances. ### Factory Methods #### `static OfficeStamperConfiguration full()` Creates a full `OfficeStamperConfiguration` with standard configurations, supplemented with additional pre- and post-processors for enhanced document handling. #### `static OfficeStamperConfiguration minimal()` Creates a minimal `OfficeStamperConfiguration` instance with essential settings to provide basic placeholder processing and fallback resolvers. #### `static OfficeStamperConfiguration raw()` Creates a `OfficeStamperConfiguration` instance without any configuration or resolvers, processors, preprocessors or postprocessors applied. #### `static OfficeStamperConfiguration standard()` Creates a standard `OfficeStamperConfiguration` instance with predefined settings. ``` -------------------------------- ### standard() Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/preset/OfficeStamperConfigurations.html Creates a standard OfficeStamperConfiguration instance with predefined settings, including custom comment processing, resolvers, and additional preprocessors. It sets up a fallback resolver with a newline character as the default value. ```APIDOC ## standard() ### Description Creates a standard `OfficeStamperConfiguration` instance with predefined settings. The configuration is extended with custom comment processing, resolvers, and additional preprocessors. ### Method static OfficeStamperConfiguration ### Parameters None ### Response - `OfficeStamperConfiguration` - a standard `OfficeStamperConfiguration` instance with pre-configured resolvers and processors. ``` -------------------------------- ### get Source: https://office-stamper.verron.pro/excel-context/apidocs/pro.verron.officestamper.excel/pro/verron/officestamper/excel/ExcelContext.html Retrieves the value associated with the specified key from the ExcelContext. ```APIDOC ## get ### Description Retrieves the value associated with the specified key from the `ExcelContext`. ### Method `Object get(Object key)` ### Parameters #### Path Parameters - **key** (Object) - Required - The key whose associated value is to be returned. ### Returns - `Object` - The value to which the specified key is mapped, or `null` if this map contains no mapping for the key. ``` -------------------------------- ### run Method Source: https://office-stamper.verron.pro/cli/apidocs/pro.verron.officestamper.cli/pro/verron/officestamper/Main.ReportView.html Executes the ReportView subcommand to generate an HTML viewer for a traceability report. ```APIDOC ## run() ### Description Generates an HTML viewer for a traceability report. ### Method void ### Endpoint N/A (This is a method call, not an HTTP endpoint) ### Parameters None ### Response None (void method) ### Specified by `run` in interface `Runnable` ``` -------------------------------- ### Get Filename Hint Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.preset/Image.java.html Returns the filename hint for the image. ```java public String getFilenameHint() { return filenameHint; } ``` -------------------------------- ### Initialize DocxStamperConfiguration Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/DocxStamperConfiguration.java.html Constructs a new DocxStamperConfiguration with default settings. Initializes internal collections and sets up default behaviors for expression handling, evaluation, and exception resolution. ```java public DocxStamperConfiguration( EvaluationContextFactory evaluationContextFactory, ExceptionResolver exceptionResolver ) { this.commentProcessors = new HashMap<>(); this.resolvers = new ArrayList<>(); this.expressionFunctions = new HashMap<>(); this.preprocessors = new ArrayList<>(); this.postprocessors = new ArrayList<>(); this.functions = new ArrayList<>(); this.evaluationContextFactory = evaluationContextFactory; this.parserConfiguration = new SpelParserConfiguration(); this.exceptionResolver = exceptionResolver; } ``` -------------------------------- ### Get Comment ID Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Returns the unique identifier for the comment. ```Java public BigInteger getId() { return comment.getId(); } ``` -------------------------------- ### OpenPackage Constructor Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.openpackaging/OpenPackage.java.html Constructs an OpenPackage instance, initializing the document and part, and populating the image parts cache by hashing all parts within the document. ```java public OpenPackage(T document, Part part) { this.document = document; this.part = part; part.getPackage() .getParts() .getParts() .values() .forEach(this::hash); } ``` -------------------------------- ### Get Comment Reference Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Returns the associated comment reference, if any. ```Java public @Nullable CommentReference getCommentReference() { return commentReference; } ``` -------------------------------- ### ProofErr List Initialization Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.preset.preprocessors.prooferror/ProofErrVisitor.java.html Initializes a list to store collected ProofErr elements. ```java private final List proofErrs = new ArrayList<>(); ``` -------------------------------- ### Create Run with Text and Run Properties Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.wml/WmlUtils.java.html Creates a new WML run with specified text and run properties. This is useful when you need to define the exact styling for a piece of text. ```java public static R create(String text, RPr rPr) { R newStartRun = newRun(text); newStartRun.setRPr(rPr); return newStartRun; } ``` -------------------------------- ### Get Postprocessors Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/DocxStamperConfiguration.html Retrieves the list of postprocessors configured for the stamper. ```APIDOC ## Method getPostprocessors ### Description Retrieves the list of postprocessors that will be applied after document processing. ### Method Signature `List getPostprocessors()` ### Returns A list of `PostProcessor` instances. ``` -------------------------------- ### Get User Preferences Source: https://office-stamper.verron.pro/cli/jacoco/pro.verron.officestamper/Diagnostic.java.html Retrieves the map of user preferences. ```java private Map userPreferences() { return userPreferences; } ``` -------------------------------- ### standard(ObjectResolver fallback) Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/ObjectResolver.html Creates a standard OfficeStamperConfiguration instance with a set of predefined comment processors, resolvers, and preprocessors. ```APIDOC ## standard(ObjectResolver fallback) ### Description Creates a standard `OfficeStamperConfiguration` instance with a set of predefined comment processors, resolvers, and preprocessors. ### Method static ### Endpoint OfficeStamperConfigurations.standard(ObjectResolver fallback) ### Parameters #### Path Parameters - **fallback** (ObjectResolver) - Required - The `ObjectResolver` to use as a fallback. ### Response #### Success Response - **OfficeStamperConfiguration** (OfficeStamperConfiguration) - A standard `OfficeStamperConfiguration` instance. ### Response Example ```json { "example": "OfficeStamperConfiguration instance" } ``` ``` -------------------------------- ### Get JVM Properties Source: https://office-stamper.verron.pro/cli/jacoco/pro.verron.officestamper/Diagnostic.java.html Retrieves the map of JVM properties. ```java private Map jvmProperties() { return jvmProperties; } ``` -------------------------------- ### Prepare Sample JSON Data Source: https://office-stamper.verron.pro/cli/quickstart-windows.html Example of a JSON file used to provide data for stamping a document template. ```json { "customer": { "name": "Ada Lovelace" }, "items": [ {"name": "Consulting", "qty": 1, "price": 1000 } ] } ``` -------------------------------- ### Constructor Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.experimental/PowerpointParagraph.java.html Initializes a new PowerpointParagraph with the given part and paragraph. ```java public PowerpointParagraph(PptxPart part, CTTextParagraph paragraph) { this.part = part; this.paragraph = paragraph; recalculateRuns(); } ``` -------------------------------- ### Get Document Object Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.openpackaging/OpenPackage.java.html Retrieves the document object associated with this package. ```java public T document() {return document;} ``` -------------------------------- ### Get Alternative Text Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.preset/Image.java.html Returns the alternative text associated with the image. ```java public String getAltText() { return altText; } ``` -------------------------------- ### Implement and Add Custom Post-Processor Source: https://office-stamper.verron.pro/engine/advanced-features.html Demonstrates how to create a custom post-processor by implementing the PostProcessor interface and adding it to the Office-Stamper configuration. Also shows how to add a standard post-processor to remove specific tags. ```java void main(String[] args){ // Create a custom post processor class CustomPostProcessor implements PostProcessor { @Override public void process(WordprocessingMLPackage document) { // Perform operations on the document after stamping } } // Add the post-processor to the configuration var configuration = OfficeStamperConfigurations.standard(); configuration.addPostProcessor(new CustomPostProcessor()); // Use a standard post-processor to remove engine-specific tags configuration.addPostProcessor(Postprocessors.removeTags("placeholder")); } ``` -------------------------------- ### Get Resolvers Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/DocxStamperConfiguration.html Retrieves the list of object resolvers configured for the stamper. ```APIDOC ## Method getResolvers ### Description Retrieves the list of object resolvers used for resolving objects within the expression language. ### Method Signature `List getResolvers()` ### Returns A list of `ObjectResolver` instances. ``` -------------------------------- ### Engine Constructor Source: https://office-stamper.verron.pro/engine/apidocs/index-all.html Constructs an Engine instance with the specified configuration and context. ```APIDOC ## Engine Constructor ### Description Constructs an Engine with the provided SpelParserConfiguration, ExceptionResolver, ObjectResolverRegistry, ProcessorContext, and TraceabilityReporter. ### Method Constructor ### Endpoint N/A ### Parameters - **SpelParserConfiguration** (SpelParserConfiguration) - The configuration for the SpEL parser. - **ExceptionResolver** (ExceptionResolver) - The resolver for handling exceptions. - **ObjectResolverRegistry** (ObjectResolverRegistry) - The registry for object resolvers. - **ProcessorContext** (ProcessorContext) - The context for the processor. - **TraceabilityReporter** (TraceabilityReporter) - The reporter for traceability. ### Request Example None ### Response #### Success Response - **Engine** (Engine) - A new Engine instance. #### Response Example None ``` -------------------------------- ### DocxIterator Initialization Logic Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.wml/DocxIterator.java.html Sets up the iterator queue and determines the initial next element upon instantiation or reset. ```java private void initialize() { var startingIterator = supplier.get(); this.iteratorQueue = Collections.asLifoQueue(new ArrayDeque<>()); this.iteratorQueue.add(startingIterator); this.next = startingIterator.hasNext() ? unwrap(startingIterator.next()) : null; } ``` -------------------------------- ### Get Exception Resolver Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/core/DocxStamperConfiguration.html Retrieves the exception resolver configured for the stamper. ```APIDOC ## Method getExceptionResolver ### Description Retrieves the exception resolver for handling exceptions during the stamping process. ### Method Signature `ExceptionResolver getExceptionResolver()` ### Returns The configured `ExceptionResolver` instance. ``` -------------------------------- ### SpEL Collection Projection Example Source: https://office-stamper.verron.pro/engine/template-expressions.html Extract a specific property from each element in a collection. ```java ${orders.![total]} ``` -------------------------------- ### DisplayIfProcessor Constructor Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.preset.processors.displayif/DisplayIfProcessor.java.html Initializes the DisplayIfProcessor with the given ProcessorContext. This is the standard way to create an instance of this processor. ```Java public DisplayIfProcessor(ProcessorContext processorContext) { super(processorContext); } ``` -------------------------------- ### Setup Relationship in Open Packaging Source: https://office-stamper.verron.pro/utils/pit-reports/pro.verron.officestamper.utils.openpackaging/OpenpackagingFactory.java.html Establishes a relationship between two parts with a specified relationship ID. Handles potential InvalidFormatException by re-throwing as UtilsException. ```Java public static Relationship setupRelationship(Part sourcePart, Part targetPart, String relationshipId) { try { var reuseExisting = RelationshipsPart.AddPartBehaviour.REUSE_EXISTING; return sourcePart.addTargetPart(targetPart, reuseExisting, relationshipId); } catch (InvalidFormatException e) { throw new UtilsException(e); } } ``` -------------------------------- ### SpEL Operator Example Source: https://office-stamper.verron.pro/engine/template-expressions.html Perform arithmetic operations on values within the context. ```java ${price * quantity} ``` -------------------------------- ### SpEL Array/List Access Example Source: https://office-stamper.verron.pro/engine/template-expressions.html Access elements in arrays or lists by their index. ```java ${orders[0].id} ``` -------------------------------- ### Pre-configured Preprocessors Source: https://office-stamper.verron.pro/engine/apidocs/pro.verron.officestamper/pro/verron/officestamper/api/class-use/PreProcessor.html Static methods providing pre-configured `PreProcessor` instances for common document manipulation tasks. ```APIDOC ## Preprocessors.mergeSimilarRuns() ### Description Returns a `PreProcessor` object that merges same style runs that are next to each other in a `WordprocessingMLPackage` document. ### Method GET ### Endpoint N/A (Method Call) ### Returns `PreProcessor` - A `PreProcessor` for merging similar runs. ## Preprocessors.prepareCommentProcessor() ### Description Returns a `PreProcessor` object that prepares comment processors for use with the stamper. ### Method GET ### Endpoint N/A (Method Call) ### Returns `PreProcessor` - A `PreProcessor` for preparing comment processors. ## Preprocessors.preparePlaceholders(String regex, String element) ### Description Returns a `PreProcessor` object that prepares inline placeholders based on the provided regex and element name. ### Method GET ### Endpoint N/A (Method Call) ### Parameters #### Query Parameters - **regex** (`String`) - Required - The regular expression to match placeholders. - **element** (`String`) - Required - The name of the element containing the placeholders. ### Returns `PreProcessor` - A `PreProcessor` for preparing inline placeholders. ## Preprocessors.removeLanguageInfo() ### Description Returns a `PreProcessor` object that removes all language informations such as grammatical and orthographics markers in a `WordprocessingMLPackage` document. ### Method GET ### Endpoint N/A (Method Call) ### Returns `PreProcessor` - A `PreProcessor` for removing language information. ## Preprocessors.removeLanguageProof() ### Description Returns a `PreProcessor` object that removes all `ProofErr` elements from the `WordprocessingMLPackage` document. ### Method GET ### Endpoint N/A (Method Call) ### Returns `PreProcessor` - A `PreProcessor` for removing language proofing elements. ## Preprocessors.removeMalformedComments() ### Description Returns a `PreProcessor` object that removes comments information that is not conforming to the expected patterns. ### Method GET ### Endpoint N/A (Method Call) ### Returns `PreProcessor` - A `PreProcessor` for removing malformed comments. ``` -------------------------------- ### Get Hooks Method Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.core/StandardRow.java.html Retrieves a list of all hooks present in the table row. ```java @Override public List hooks() { return Hooks.ofHooks(tr) .collect(toList()); } ``` -------------------------------- ### TraceabilityReport Constructor Source: https://office-stamper.verron.pro/cli/apidocs/pro.verron.officestamper.cli/pro/verron/officestamper/TraceabilityReport.html Initializes a new instance of the TraceabilityReport class with default settings. ```APIDOC ## TraceabilityReport() ### Description Default constructor for the TraceabilityReport class. ### Constructor `public TraceabilityReport()` ``` -------------------------------- ### Get Tag Expression Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/Tag.java.html Retrieves the expression string associated with the smart tag. ```java public String expression() { return asString(tag.getContent()); } ``` -------------------------------- ### toString Method Source: https://office-stamper.verron.pro/utils/apidocs/pro.verron.officestamper.utils/pro/verron/officestamper/utils/openpackaging/OpenPackage.html Returns a string representation of the OpenPackage object. ```APIDOC ## toString() ### Description Returns a string representation of the OpenPackage object. ### Overrides `toString` in class `Object` ``` -------------------------------- ### Get Comment Object Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Returns the main comment object associated with this range. ```Java public Comments.Comment getComment() { return comment; } ``` -------------------------------- ### Initialize Watch Mode Source: https://office-stamper.verron.pro/cli/jacoco/pro.verron.officestamper/Main.java.html Sets up and runs the watch mode for the Office Stamper CLI. It performs an initial run, logs any errors, and then starts a file system watch service to monitor for changes. ```java private void runWatch() { var lf = getLogFormat(); emit("INFO", "Watch mode enabled", null, lf); try { runOnce(); } catch (Exception e) { emit("ERROR", "Initial run failed", Map.of("error", String.valueOf(e.getMessage())), lf); } try ( var watchService = FileSystems.getDefault() .newWatchService() ) { var templateFile = "diagnostic".equals(templatePath) ? null : Path.of(templatePath) .toAbsolutePath(); var dataFile = (dataPath == null || "diagnostic".equals(dataPath)) ? null : Path.of(dataPath) .toAbsolutePath(); var pathsToWatch = new HashSet(); ``` -------------------------------- ### Get Comment Range End Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.core/StandardComment.java.html Returns the ending point of the comment range. ```Java public CommentRangeEnd getCommentRangeEnd() { return commentRangeEnd; } ``` -------------------------------- ### Get or Create OpenPackage Instance Source: https://office-stamper.verron.pro/utils/jacoco/pro.verron.officestamper.utils.openpackaging/OpenPackage.java.html Retrieves an existing OpenPackage instance for a given document and part from a pool, or creates a new one if it doesn't exist. This ensures efficient management and reuse of package wrappers. ```java public static OpenPackage getOrCreate( T document, Part part ) { //noinspection unchecked because the pool system ensure types respect return pool.computeIfAbsent(document, d -> new ConcurrentHashMap<>) .computeIfAbsent(part, p -> new OpenPackage<>(document, p)); } ``` -------------------------------- ### Get Expression Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.api/ProcessorContext.java.html Returns the expression or directive string that is currently being evaluated or processed. ```Java public String expression() {return expression;} ``` -------------------------------- ### Logger Initialization Source: https://office-stamper.verron.pro/engine/pit-reports/pro.verron.officestamper.experimental/PowerpointVisitor.java.html Initializes a static logger for the PowerpointVisitor class. ```java private static final Logger logger = LoggerFactory.getLogger(PowerpointVisitor.class); ``` -------------------------------- ### Get Paragraph Source: https://office-stamper.verron.pro/engine/jacoco/pro.verron.officestamper.api/ProcessorContext.java.html Returns the Paragraph object that is the focus of the current processing context. ```Java public Paragraph paragraph() {return paragraph;} ```