java.lang.Object
pro.verron.officestamper.core.CommentUtil
- Direct Known Subclasses:
CommentUtil
Utility class for working with comments in a DOCX document.
- Since:
- 1.0.0
- Version:
- ${version}
- Author:
- Joseph Verron, Tom Hombergs
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUtility class for handling comments in a DOCX document. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.docx4j.openpackaging.packages.WordprocessingMLPackagecreateSubWordDocument(Comment comment) Creates a sub Word document by extracting a specified comment and its associated content from the original document.static voiddeleteComment(Comment comment) Returns the string value of the specified comment object.static voiddeleteCommentFromElements(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, Comment> getComments(org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Extracts all comments from the given document.static PlaceholdergetCommentString(org.docx4j.wml.Comments.Comment comment) Returns the string value of the specified comment object.static PlaceholdergetCommentStringFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Deprecated, for removal: This API element is subject to removal in a future version.This method's been deprecated since version 1.6.8 and will be removed in the future.
-
Constructor Details
-
CommentUtil
protected CommentUtil()Utility class for handling comments in a DOCX document.
-
-
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
@Deprecated(since="1.6.8", forRemoval=true) public static Placeholder getCommentStringFor(org.docx4j.wml.ContentAccessor object, org.docx4j.openpackaging.packages.WordprocessingMLPackage document) Deprecated, for removal: This API element is subject to removal in a future version.This method's been deprecated since version 1.6.8 and will be removed in the future.Returns the comment string for the given DOCX4J object and document.- Parameters:
object- the DOCX4J object whose comment to retrieve.document- the document that contains the object.- Returns:
- an Expression representing the comment string.
- Throws:
OfficeStamperException- if an error occurs while retrieving the comment.
-
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 text paragraphs 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- aCommentobject
-
getComments
public static Map<BigInteger,Comment> 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.
-
deleteCommentFromElements
Returns the string value of the specified comment object.- Parameters:
items- aListobjectcommentId- aBigIntegerobject
-
createSubWordDocument
public static org.docx4j.openpackaging.packages.WordprocessingMLPackage createSubWordDocument(Comment comment) throws org.docx4j.openpackaging.exceptions.InvalidFormatException Creates a sub Word document by extracting a specified comment and its associated content from the original document.- Parameters:
comment- The comment to be extracted from the original document.- Returns:
- The sub Word document containing the content of the specified comment.
- Throws:
org.docx4j.openpackaging.exceptions.InvalidFormatException- TODO_LATER: remove this explicit exception from public signature
-