You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/21 13:46:43 UTC
svn commit: r1895230 - in /poi/trunk/poi-ooxml/src: main/java/org/apache/poi/xssf/model/ main/java/org/apache/poi/xssf/usermodel/ test/java/org/apache/poi/xssf/usermodel/
Author: fanningpj
Date: Sun Nov 21 13:46:42 2021
New Revision: 1895230
URL: http://svn.apache.org/viewvc?rev=1895230&view=rev
Log:
set sheet on comments table
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java?rev=1895230&r1=1895229&r2=1895230&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java Sun Nov 21 13:46:42 2021
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.model;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellAddress;
+import org.apache.poi.util.Internal;
import org.apache.poi.xssf.usermodel.XSSFComment;
import java.util.Iterator;
@@ -30,6 +31,15 @@ import java.util.Iterator;
*/
public interface Comments {
+ /**
+ * This method is for internal POI use only. POI uses it to link the sheet and comments table.
+ * This method will not move comments from one sheet to another (if a user tries to use this method for that purpose).
+ * @param sheet the sheet that this comments table is associated with
+ * @since POI 5.2.0
+ */
+ @Internal
+ void setSheet(Sheet sheet);
+
int getNumberOfComments();
int getNumberOfAuthors();
@@ -48,18 +58,6 @@ public interface Comments {
XSSFComment findCellComment(CellAddress cellAddress);
/**
- * Finds the cell comment at cellAddress, if one exists
- *
- * @param sheet the sheet to check for comments (used to find drawing/shape data for comments) - set to null
- * if you don't need the drawing/shape data
- * @param cellAddress the address of the cell to find a comment
- * @return cell comment if one exists, otherwise returns null
- * @see #findCellComment(CellAddress)
- * @since POI 5.2.0
- */
- public XSSFComment findCellComment(Sheet sheet, CellAddress cellAddress);
-
- /**
* Remove the comment at cellRef location, if one exists
*
* @param cellRef the location of the comment to remove
@@ -76,12 +74,11 @@ public interface Comments {
/**
* 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(Sheet sheet, ClientAnchor clientAnchor);
+ XSSFComment createNewComment(ClientAnchor clientAnchor);
/**
* Called after the reference is updated, so that
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java?rev=1895230&r1=1895229&r2=1895230&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java Sun Nov 21 13:46:42 2021
@@ -51,6 +51,8 @@ public class CommentsTable extends POIXM
public static final String DEFAULT_AUTHOR = "";
public static final int DEFAULT_AUTHOR_ID = 0;
+ private Sheet sheet;
+
/**
* Underlying XML Beans CTComment list.
*/
@@ -93,6 +95,12 @@ public class CommentsTable extends POIXM
}
@Override
+ @Internal
+ public void setSheet(Sheet sheet) {
+ this.sheet = sheet;
+ }
+
+ @Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
try (OutputStream out = part.getOutputStream()) {
@@ -175,26 +183,9 @@ public class CommentsTable extends POIXM
*
* @param cellAddress the address of the cell to find a comment
* @return cell comment if one exists, otherwise returns null
- * @see #findCellComment(Sheet, CellAddress)
*/
@Override
public XSSFComment findCellComment(CellAddress cellAddress) {
- CTComment ct = getCTComment(cellAddress);
- return ct == null ? null : new XSSFComment(this, ct, null);
- }
-
- /**
- * Finds the cell comment at cellAddress, if one exists
- *
- * @param sheet the sheet to check for comments (used to find drawing/shape data for comments) - set to null
- * if you don't need the drawing/shape data
- * @param cellAddress the address of the cell to find a comment
- * @return cell comment if one exists, otherwise returns null
- * @see #findCellComment(CellAddress)
- * @since POI 5.2.0
- */
- @Override
- public XSSFComment findCellComment(Sheet sheet, CellAddress cellAddress) {
CTComment ctComment = getCTComment(cellAddress);
if(ctComment == null) {
return null;
@@ -204,7 +195,7 @@ public class CommentsTable extends POIXM
return new XSSFComment(this, ctComment,
vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn()));
}
-
+
/**
* Get the underlying CTComment xmlbean for a comment located at cellRef, if it exists
*
@@ -233,13 +224,12 @@ public class CommentsTable extends POIXM
/**
* 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
*/
@Override
- public XSSFComment createNewComment(Sheet sheet, ClientAnchor clientAnchor) {
+ public XSSFComment createNewComment(ClientAnchor clientAnchor) {
XSSFVMLDrawing vml = getVMLDrawing(sheet, true);
CTShape vmlShape = vml == null ? null : vml.newCommentShape();
if (vmlShape != null && clientAnchor instanceof XSSFClientAnchor && ((XSSFClientAnchor)clientAnchor).isSet()) {
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=1895230&r1=1895229&r2=1895230&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Sun Nov 21 13:46:42 2021
@@ -380,11 +380,10 @@ public final class XSSFDrawing extends P
*/
@Override
public XSSFComment createCellComment(ClientAnchor anchor) {
- XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet();
Comments comments = sheet.getCommentsTable(true);
- return comments.createNewComment(getSheet(), ca);
+ return comments.createNewComment(anchor);
}
/**
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1895230&r1=1895229&r2=1895230&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sun Nov 21 13:46:42 2021
@@ -165,6 +165,7 @@ public class XSSFSheet extends POIXMLDoc
POIXMLDocumentPart p = rp.getDocumentPart();
if(p instanceof Comments) {
sheetComments = (Comments)p;
+ sheetComments.setSheet(this);
}
if(p instanceof XSSFTable) {
tables.put( rp.getRelationship().getId(), (XSSFTable)p );
@@ -755,7 +756,7 @@ public class XSSFSheet extends POIXMLDoc
* Return cell comment at row, column, if one exists. Otherwise returns null.
*
* @param address the location of the cell comment
- * @return the cell comment, if one exists. Otherwise return null.
+ * @return the cell comment, if one exists. Otherwise, return null.
*/
@Override
public XSSFComment getCellComment(CellAddress address) {
@@ -763,7 +764,7 @@ public class XSSFSheet extends POIXMLDoc
return null;
}
- return sheetComments.findCellComment(this, address);
+ return sheetComments.findCellComment(address);
}
/**
@@ -3120,7 +3121,7 @@ public class XSSFSheet extends POIXMLDoc
// is this comment part of the current row?
if(cellAddress.getRow() == rownum) {
- XSSFComment oldComment = sheetComments.findCellComment(this, cellAddress);
+ XSSFComment oldComment = sheetComments.findCellComment(cellAddress);
if (oldComment != null) {
XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
oldComment.getCTShape());
@@ -3208,7 +3209,7 @@ public class XSSFSheet extends POIXMLDoc
int columnIndex = oldCommentAddress.getColumn();
int newColumnIndex = shiftedRowNum(startColumnIndex, endColumnIndex, n, columnIndex);
if(newColumnIndex != columnIndex) {
- XSSFComment oldComment = sheetComments.findCellComment(this, oldCommentAddress);
+ XSSFComment oldComment = sheetComments.findCellComment(oldCommentAddress);
if (oldComment != null) {
XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
oldComment.getCTShape());
@@ -3523,6 +3524,7 @@ public class XSSFSheet extends POIXMLDoc
sheetComments = (Comments)createRelationship(
XSSFRelation.SHEET_COMMENTS, getWorkbook().getXssfFactory(), -1);
}
+ sheetComments.setSheet(this);
}
return sheetComments;
}
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java?rev=1895230&r1=1895229&r2=1895230&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java Sun Nov 21 13:46:42 2021
@@ -362,6 +362,7 @@ public final class TestXSSFComment exten
try (SXSSFWorkbook workbook = new SXSSFWorkbook()) {
CreationHelper factory = workbook.getCreationHelper();
SXSSFSheet sheet = workbook.createSheet();
+ commentsTable.setSheet(sheet);
SXSSFRow row = sheet.createRow(0);
SXSSFCell cell = row.createCell(0);
ClientAnchor anchor = factory.createClientAnchor();
@@ -369,7 +370,7 @@ public final class TestXSSFComment exten
anchor.setCol2(1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum());
- XSSFComment comment = commentsTable.createNewComment(sheet, anchor);
+ XSSFComment comment = commentsTable.createNewComment(anchor);
String uniqueText = UUID.randomUUID().toString();
comment.setString(uniqueText);
comment.setAuthor("author" + uniqueText);
@@ -392,6 +393,7 @@ public final class TestXSSFComment exten
try (SXSSFWorkbook workbook = new SXSSFWorkbook()) {
CreationHelper factory = workbook.getCreationHelper();
SXSSFSheet sheet = workbook.createSheet();
+ commentsTable.setSheet(sheet);
SXSSFRow row = sheet.createRow(0);
SXSSFCell cell = row.createCell(0);
ClientAnchor anchor = factory.createClientAnchor();
@@ -399,7 +401,7 @@ public final class TestXSSFComment exten
anchor.setCol2(1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum());
- XSSFComment comment = commentsTable.createNewComment(sheet, anchor);
+ XSSFComment comment = commentsTable.createNewComment(anchor);
String uniqueText = UUID.randomUUID().toString();
comment.setString(uniqueText);
comment.setAuthor("author" + uniqueText);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org