Interface ICommentProcessor
- All Known Implementing Classes:
BaseCommentProcessor,DisplayIfProcessor,ParagraphRepeatProcessor,RepeatDocPartProcessor,RepeatProcessor,ReplaceWithProcessor,TableResolver
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:
- Create an interface that defines the custom method(s) you want to expose to the expression language used in .docx comments
- Create an implementation of your interface
- Register your comment processor with DocxStamper
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 setCurrentParagraph() 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 DocxStamperConfiguration#addCommentProcessor().
- Version:
- ${version}
- Author:
- Joseph Verron
-
Method Summary
Modifier and TypeMethodDescriptionvoidcommitChanges(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) This method is called after all comments in the .docx template have been passed to the comment processor.voidreset()Resets all state in the comment processor so that it can be re-used in another stamping process.voidsetCurrentCommentWrapper(CommentWrapper commentWrapper) Passes the comment range wrapper that is currently being processed (i.e.voidsetCurrentRun(org.docx4j.wml.R run) Passes the run that is currently being processed (i.e.voidsetDocument(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Deprecated, for removal: This API element is subject to removal in a future version.the document is passed to the processor through the commitChange method now, and will probably pe passed through the constructor in the futurevoidsetParagraph(org.docx4j.wml.P paragraph) Passes the paragraph that is currently being processed (i.e.
-
Method Details
-
commitChanges
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. All manipulations of the .docx document SHOULD BE done in this method. If certain manipulations are already done within in the custom methods of a comment processor, the ongoing iteration over the paragraphs in the document may be disturbed.- Parameters:
document- The Word document that can be manipulated by using the DOCX4J api.
-
setParagraph
void setParagraph(org.docx4j.wml.P paragraph) Passes the paragraph that is currently being processed (i.e. the paragraph that is commented in the .docx template). This method is always called BEFORE the custom methods of the custom comment processor interface are called.- Parameters:
paragraph- coordinates of the currently processed paragraph within the template.
-
setCurrentRun
void setCurrentRun(org.docx4j.wml.R run) Passes the run that is currently being processed (i.e. the run that is commented in the .docx template). This method is always called BEFORE the custom methods of the custom comment processor interface are called.- Parameters:
run- coordinates of the currently processed run within the template.
-
setCurrentCommentWrapper
Passes the comment range wrapper that is currently being processed (i.e. the start and end of comment that in the .docx template). This method is always called BEFORE the custom methods of the custom comment processor interface are called.- Parameters:
commentWrapper- of the currently processed comment within the template.
-
setDocument
@Deprecated(since="1.6.5", forRemoval=true) void setDocument(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Deprecated, for removal: This API element is subject to removal in a future version.the document is passed to the processor through the commitChange method now, and will probably pe passed through the constructor in the futurePasses the processed document, in order to make all linked data (images, etc.) available to processors that need it (example : repeatDocPart)- Parameters:
document- DocX template being processed.
-
reset
void reset()Resets all state in the comment processor so that it can be re-used in another stamping process.
-