From: PJ Fanning Date: Thu, 18 Nov 2021 11:38:56 +0000 (+0000) Subject: try to make CommentsTable more extensible X-Git-Tag: REL_5_2_0~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=14480be6deb9ae82738c99f4cdc70ca417076b81;p=poi.git try to make CommentsTable more extensible git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895146 13f79535-47bb-0310-9956-ffa450edef68 --- 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 1341de6561..d40be0f5db 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 @@ -17,7 +17,9 @@ package org.apache.poi.xssf.model; import org.apache.poi.ss.util.CellAddress; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFComment; +import org.apache.poi.xssf.usermodel.XSSFSheet; import java.util.Iterator; @@ -58,4 +60,28 @@ public interface Comments { * @since 4.0.0 */ Iterator getCellAddresses(); + + /** + * @return iterator of comments (without their VML Shapes set) + * @since POI 5.2.0 + */ + Iterator commentIterator(); + + /** + * Create a new comment and add to the CommentTable. + * @param sheet sheet to add comment to + * @param clientAnchor the anchor for this comment + * @return new XSSFComment + * @since POI 5.2.0 + */ + XSSFComment createNewComment(XSSFSheet sheet, XSSFClientAnchor clientAnchor); + + /** + * Called after the reference is updated, so that + * 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 + * @since POI 5.2.0 + */ + void referenceUpdated(CellAddress oldReference, 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 876028a579..a47557013a 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 @@ -100,6 +100,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { * @return iterator of comments (without their VML Shapes set) * @since POI 5.2.0 */ + @Override public Iterator commentIterator() { final CommentsTable table = this; return new Iterator() { @@ -142,6 +143,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { * @param comment the comment to replace in the commentRefs map * @since POI 5.2.0 */ + @Override public void referenceUpdated(CellAddress oldReference, XSSFComment comment) { if(commentRefs != null) { commentRefs.remove(oldReference); @@ -239,6 +241,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { * @return new XSSFComment * @since POI 5.2.0 */ + @Override public XSSFComment createNewComment(XSSFSheet sheet, XSSFClientAnchor clientAnchor) { XSSFVMLDrawing vml = sheet.getVMLDrawing(true); com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape(); 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 96920c2345..93ae75fa69 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 @@ -25,6 +25,7 @@ import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.model.Comments; import org.apache.poi.xssf.model.CommentsTable; import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; @@ -36,7 +37,7 @@ import com.microsoft.schemas.vml.CTShape; public class XSSFComment implements Comment { private final CTComment _comment; - private final CommentsTable _comments; + private final Comments _comments; private final CTShape _vmlShape; /** @@ -49,6 +50,15 @@ public class XSSFComment implements Comment { * low level comment object. */ public XSSFComment(CommentsTable comments, CTComment comment, CTShape vmlShape) { + this((Comments)comments, comment, vmlShape); + } + + /** + * Creates a new XSSFComment, associated with a given + * low level comment object. + * @since POI 5.2.0 + */ + public XSSFComment(Comments comments, CTComment comment, CTShape vmlShape) { _comment = comment; _comments = comments; _vmlShape = vmlShape; @@ -60,7 +70,7 @@ public class XSSFComment implements Comment { CTClientData clientData = vmlShape.getClientDataArray(0); clientData.setRowArray(0, new BigInteger(String.valueOf(ref.getRow()))); clientData.setColumnArray(0, new BigInteger(String.valueOf(ref.getCol()))); - + avoidXmlbeansCorruptPointer(vmlShape); } }