public interface ICommentProcessor
In a .docx template used by DocxStamper, you can comment paragraphs of text to manipulate them. The comments in the .docx template are passed to an implementation of ICommentProcessor that understands the expression used within the comment. Thus, you can implement your own ICommentProcessor to extend the expression language available in comments in the .docx template.
To implement a comment processor, you have to do the following steps:
1. Creating a comment processor interface
For example, if you want to create a comment processor that
makes a paragraph of text bold based on some condition, you would create an interface with the
method
boldIf(boolean condition).
2. Creating an implementation of your interface
Your implementation class must also implement the Interface
ICommentProcessor. To stay in the above example, when the boldIf method is called, simply keep
track of the paragraphs that are to be made bold.
The currently processed paragraph is passed into the method setCurrentParagraphCoordinates()
before your own method
(in this case boldIf()) is called.
Within the method commitChanges() you then do the manipulations on the word document, i.e. make
the paragraphs
that were commented bold.
3. Registering you comment processor with DocxStamper
Register your comment processor in DocxStamper by calling
DocxStamper#getCommentProcessorRegistry().registerCommentProcessor().
Modifier and Type | Method and Description |
---|---|
void |
commitChanges(org.docx4j.openpackaging.packages.WordprocessingMLPackage document)
This method is called after all comments in the .docx template
have been passed to the comment processor.
|
void |
setCurrentParagraphCoordinates(ParagraphCoordinates coordinates)
Passes the paragraph that is currently being processed (i.e. the
paragraph that is commented in the
.docx template.
|
void commitChanges(org.docx4j.openpackaging.packages.WordprocessingMLPackage document)
document
- The word document that can be manipulated by using the
DOCX4J api.
void setCurrentParagraphCoordinates(ParagraphCoordinates coordinates)
coordinates
- coordinates of the currently processed paragraph
within the template.
Copyright © 2016. All rights reserved.