Class CommentUtil
java.lang.Object
org.wickedsource.docxstamper.util.CommentUtil
Utility class for working with comments in a DOCX document.
- Version:
- ${version}
- Author:
- Joseph Verron
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddeleteComment(CommentWrapper comment) Returns the string value of the specified comment object.static voiddeleteCommentFromElement(List<Object> items, BigInteger commentId) Returns the string value of the specified comment object.static Optional<org.docx4j.wml.Comments.Comment> findComment(org.docx4j.openpackaging.packages.WordprocessingMLPackage document, BigInteger id) Finds a comment with the given ID in the specified WordprocessingMLPackage document.static Optional<org.docx4j.wml.Comments.Comment> getCommentAround(org.docx4j.wml.R run, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the comment the given DOCX4J object is commented with.static Optional<org.docx4j.wml.Comments.Comment> getCommentFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the first comment found for the given docx object.static Map<BigInteger, CommentWrapper> getComments(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Extracts all comments from the given document.static StringgetCommentString(org.docx4j.wml.Comments.Comment comment) Returns the string value of the specified comment object.static StringgetCommentStringFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the comment the given DOCX4J object is commented with.
-
Method Details
-
getCommentAround
public static Optional<org.docx4j.wml.Comments.Comment> getCommentAround(org.docx4j.wml.R run, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the comment the given DOCX4J object is commented with.- Parameters:
run- the DOCX4J object whose comment to retrieve.document- the document that contains the object.- Returns:
- Optional of the comment, if found, Optional.empty() otherwise.
-
findComment
public static Optional<org.docx4j.wml.Comments.Comment> findComment(org.docx4j.openpackaging.packages.WordprocessingMLPackage document, BigInteger id) throws org.docx4j.openpackaging.exceptions.Docx4JException Finds a comment with the given ID in the specified WordprocessingMLPackage document.- Parameters:
document- the WordprocessingMLPackage document to search for the commentid- the ID of the comment to find- Returns:
- an Optional containing the Comment if found, or an empty Optional if not found
- Throws:
org.docx4j.openpackaging.exceptions.Docx4JException- if an error occurs while searching for the comment
-
getCommentStringFor
public static String getCommentStringFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the comment the given DOCX4J object is commented with.- Parameters:
object- the DOCX4J object whose comment to retrieve.document- the document that contains the object.- Returns:
- the comment, if found, null otherwise.
-
getCommentFor
public static Optional<org.docx4j.wml.Comments.Comment> getCommentFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Returns the first comment found for the given docx object. Note that an object is only considered commented if the comment STARTS within the object. Comments spanning several objects are not supported by this method.- Parameters:
object- the object whose comment to load.document- the document in which the object is embedded (needed to load the comment from the comments.xml part).- Returns:
- the concatenated string of all paragraphs of text within the comment or null if the specified object is not commented.
-
getCommentString
Returns the string value of the specified comment object.- Parameters:
comment- aComments.Commentobject- Returns:
- a
Stringobject
-
deleteComment
Returns the string value of the specified comment object.- Parameters:
comment- aCommentWrapperobject
-
deleteCommentFromElement
Returns the string value of the specified comment object.- Parameters:
items- aListobjectcommentId- aBigIntegerobject
-
getComments
public static Map<BigInteger,CommentWrapper> getComments(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Extracts all comments from the given document.- Parameters:
document- the document to extract comments from.- Returns:
- a map of all comments, with the key being the comment id.
-