From b4f36926dc1d91374dbdc01e8f897f821e38eb86 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 19 Nov 2021 14:26:15 +0000 Subject: [PATCH] try to make CommentsTable more extensible git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895176 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/model/Comments.java | 10 ++++++++++ .../org/apache/poi/xssf/model/CommentsTable.java | 13 +++++++++++++ .../org/apache/poi/xssf/usermodel/XSSFComment.java | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java index ff8fad93ce..0223f60926 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java @@ -91,7 +91,17 @@ public interface Comments { * we can reflect that in our cache * @param oldReference the comment to remove from the commentRefs map * @param comment the comment to replace in the commentRefs map + * @see #commentUpdated(XSSFComment) * @since POI 5.2.0 */ void referenceUpdated(CellAddress oldReference, XSSFComment comment); + + /** + * Called after the comment is updated, so that + * we can reflect that in our cache + * @param comment the comment to replace in the commentRefs map + * @since POI 5.2.0 + * @see #referenceUpdated(CellAddress, XSSFComment) + */ + void commentUpdated(XSSFComment comment); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java index f4a5493436..9b3a2f888b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java @@ -141,6 +141,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { * we can reflect that in our cache * @param oldReference the comment to remove from the commentRefs map * @param comment the comment to replace in the commentRefs map + * @see #commentUpdated(XSSFComment) * @since POI 5.2.0 */ @Override @@ -151,6 +152,18 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { } } + /** + * Called after the comment is updated, so that + * we can reflect that in our cache + * @param comment the comment to replace in the commentRefs map + * @since POI 5.2.0 + * @see #referenceUpdated(CellAddress, XSSFComment) + */ + @Override + public void commentUpdated(XSSFComment comment) { + //no-op in this implementation + } + @Override public int getNumberOfComments() { return comments.getCommentList().sizeOfCommentArray(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java index 93ae75fa69..b0fb430712 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java @@ -92,6 +92,7 @@ public class XSSFComment implements Comment { @Override public void setAuthor(String author) { _comment.setAuthorId(_comments.findAuthor(author)); + _comments.commentUpdated(this); } /** @@ -152,6 +153,7 @@ public class XSSFComment implements Comment { } } } + _comments.commentUpdated(this); } @Override @@ -182,6 +184,7 @@ public class XSSFComment implements Comment { avoidXmlbeansCorruptPointer(_vmlShape); } + _comments.commentUpdated(this); } /** @@ -232,6 +235,7 @@ public class XSSFComment implements Comment { } _str = (XSSFRichTextString)string; _comment.setText(_str.getCTRst()); + _comments.commentUpdated(this); } public void setString(String string) { -- 2.39.5