]> source.dussan.org Git - poi.git/commitdiff
Shift comments support over onto new style XSSFModel, in preparation for readings...
authorNick Burch <nick@apache.org>
Mon, 31 Mar 2008 23:15:38 +0000 (23:15 +0000)
committerNick Burch <nick@apache.org>
Mon, 31 Mar 2008 23:15:38 +0000 (23:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@643204 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/documentation/content/xdocs/spreadsheet/quick-guide.xml
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java [new file with mode: 0644]
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/SharedStringSource.java
src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFComments.java [deleted file]
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFSheetComments.java [deleted file]
src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFComments.java [deleted file]

index 76f3263fe5b87c273498712ced512f7f60f9c4d4..9ec268887f9e77bddcf0f39c425ce6a4b9dabac8 100644 (file)
@@ -1155,7 +1155,8 @@ Examples:
                 degenerate case of Named Range in that the 'group of cells' contains exactly one
                 cell. You can create as well as refer to cells in a workbook by their named range.
                 When working with Named Ranges, the classes: org.apache.poi.hssf.util.CellReference and
-                &amp; org.apache.poi.hssf.util.AreaReference are used.
+                &amp; org.apache.poi.hssf.util.AreaReference are used (these
+                work for both XSSF and HSSF, despite the package name).
             </p>
             <p>
             Creating Named Range / Named Cell
@@ -1163,28 +1164,27 @@ Examples:
             <source>
     // setup code
     String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
-    HSSFWorkbook wb = new HSSFWorkbook();
-    HSSFSheet sheet = wb.createSheet(sname);
+    Workbook wb = new HSSFWorkbook();
+    Sheet sheet = wb.createSheet(sname);
     sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);
 
     // 1. create named range for a single cell using areareference
-    HSSFName namedCell = wb.createName();
+    Name namedCell = wb.createName();
     namedCell.setNameName(cname);
     String reference = sname+"!A1:A1"; // area reference
     namedCell.setReference(reference);
 
     // 2. create named range for a single cell using cellreference
-    HSSFName namedCell = wb.createName();
+    Name namedCell = wb.createName();
     namedCell.setNameName(cname);
     String reference = sname+"!A1"; // cell reference
     namedCell.setReference(reference);
 
     // 3. create named range for an area using AreaReference
-    HSSFName namedCell = wb.createName();
+    Name namedCell = wb.createName();
     namedCell.setNameName(cname);
     String reference = sname+"!A1:C5"; // area reference
     namedCell.setReference(reference);
-
             </source>
             <p>
             Reading from Named Range / Named Cell
@@ -1192,19 +1192,19 @@ Examples:
             <source>
     // setup code
     String cname = "TestName";
-    HSSFWorkbook wb = getMyWorkbook(); // retrieve workbook
+    Workbook wb = getMyWorkbook(); // retrieve workbook
 
     // retrieve the named range
     int namedCellIdx = wb.getNameIndex(cellName);
-    HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
+    Name aNamedCell = wb.getNameAt(namedCellIdx);
 
     // retrieve the cell at the named range and test its contents
     AreaReference aref = new AreaReference(aNamedCell.getReference());
     CellReference[] crefs = aref.getAllReferencedCells();
     for (int i=0; i&lt;crefs.length; i++) {
-        HSSFSheet s = wb.getSheet(crefs[i].getSheetName());
-        HSSFRow r = sheet.getRow(crefs[i].getRow());
-        HSSFCell c = r.getCell(crefs[i].getCol());
+        Sheet s = wb.getSheet(crefs[i].getSheetName());
+        Row r = sheet.getRow(crefs[i].getRow());
+        Cell c = r.getCell(crefs[i].getCol());
         // extract the cell contents based on cell type etc.
     }
             </source>
@@ -1214,12 +1214,12 @@ Examples:
             <source>
     // Setup code
     String cname = "TestName";
-    HSSFWorkbook wb = getMyWorkbook(); // retrieve workbook
+    Workbook wb = getMyWorkbook(); // retrieve workbook
 
     // Retrieve the named range
     // Will be something like "$C$10,$D$12:$D$14";
     int namedCellIdx = wb.getNameIndex(cellName);
-    HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
+    Name aNamedCell = wb.getNameAt(namedCellIdx);
 
     // Retrieve the cell at the named range and test its contents
     // Will get back one AreaReference for C10, and
@@ -1231,18 +1231,18 @@ Examples:
         CellReference[] crefs = arefs[i].getCells();
         for (int j=0; j&lt;crefs.length; j++) {
             // Check it turns into real stuff
-            HSSFSheet s = wb.getSheet(crefs[j].getSheetName());
-            HSSFRow r = s.getRow(crefs[j].getRow());
-            HSSFCell c = r.getCell(crefs[j].getCol());
+            Sheet s = wb.getSheet(crefs[j].getSheetName());
+            Row r = s.getRow(crefs[j].getRow());
+            Cell c = r.getCell(crefs[j].getCol());
             // Do something with this corner cell
         }
     }
             </source>
         </section>
         <anchor id="CellComments"/>
-        <section><title>Cell Comments</title>
+        <section><title>Cell Comments - HSSF</title>
         <p>
-  In Excel a comment is a kind of a text shape,
+  In HSSF Excel, a comment is a kind of a text shape,
   so inserting a comment is very similar to placing a text box in a worksheet:
         </p>
             <source>
@@ -1320,6 +1320,90 @@ Examples:
     comment = sheet.getCellComment(3, 1);
   </source>
      </section>
+
+        <section><title>Cell Comments - XSSF</title>
+        <p>
+  In XSSF Excel, a comment is still a kind of a text shape, but
+  things are generally much simpler.
+        </p>
+            <source>
+    Workbook wb = new XSSFWorkbook();
+    CreationHelper createHelper = wb.getCreationHelper();
+
+    Sheet sheet = wb.createSheet("Cell comments in POI XSSF");
+
+    //create a cell in row 3
+    Cell cell1 = sheet.createRow(3).createCell((short)1);
+    cell1.setCellValue(createHelper.createRichTextString("Hello, World"));
+
+    //anchor defines size and position of the comment in worksheet
+    Comment comment1 = createHelper.createComment();
+
+     // set text in the comment
+    comment1.setString(createHelper.createRichTextString(
+               "We can set comments in POI"));
+
+    //set comment author.
+    //you can see it in the status bar when moving mouse over the commented cell
+    comment1.setAuthor("Apache Software Foundation");
+
+    // The first way to assign comment to a cell is via HSSFCell.setCellComment method
+    cell1.setCellComment(comment1);
+
+
+    //create another cell in row 6
+    Cell cell2 = sheet.createRow(6).createCell((short)1);
+    cell2.setCellValue(36.6);
+
+
+    Comment comment2 = createHelper.createComment();
+    //modify background color of the comment
+    comment2.setFillColor(204, 236, 255);
+
+    RichTextString string = createHelper.createRichTextString(
+               "Normal body temperature");
+
+    //apply custom font to the text in the comment
+    Font font = wb.createFont();
+    font.setFontName("Arial");
+    font.setFontHeightInPoints((short)10);
+    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
+    font.setColor(Color.RED.index);
+    string.applyFont(font);
+
+    comment2.setString(string);
+    //by default comments are hidden. This one is always visible.
+    comment2.setVisible(true);
+
+    comment2.setAuthor("Bill Gates");
+
+    /**
+     * The second way to assign comment to a cell is to implicitly specify its row and column.
+     * Note, it is possible to set row and column of a non-existing cell.
+     * It works, the commnet is visible.
+     */
+    comment2.setRow(6);
+    comment2.setColumn((short)1);
+
+    FileOutputStream out = new FileOutputStream("poi_comment.xls");
+    wb.write(out);
+    out.close();
+        </source>
+         <p>
+  Reading cell comments
+        </p>
+  <source>
+    Cell cell = sheet.get(3).getColumn((short)1);
+    Comment comment = cell.getCellComment();
+    if (comment != null) {
+      RichTextString str = comment.getString();
+      String author = comment.getAuthor();
+    }
+    //  alternatively you can retrieve cell comments by (row, column)
+    comment = sheet.getCellComment(3, 1);
+  </source>
+     </section>
+
      <anchor id="Autofit"/>
      <section><title>Adjust column width to fit the contents</title>
         <source>
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java
new file mode 100644 (file)
index 0000000..190b740
--- /dev/null
@@ -0,0 +1,38 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Allows the getting and saving of cell comments, 
+ *  associated with a given sheet.
+ */
+public interface CommentsSource {
+       public String getAuthor(long authorId);
+       
+       public int findAuthor(String author);
+       
+       public Comment findCellComment(int row, int column);
+       
+       public Comment findCellComment(String cellRef);
+       
+       public void setCellComment (int row, int column, Comment comment);
+       
+       public void setCellComment (String cellRef, Comment comment);
+
+       public Comment addComment();
+}
index 3a2794caf28f55f5932b63fc2fa48acae06933fc..2f01b227b8bc53a4eb703d213dad22abf72b4c4a 100644 (file)
@@ -17,8 +17,6 @@
 
 package org.apache.poi.ss.usermodel;
 
-import java.io.IOException;
-
 /**
  * Allows the getting and saving of shared strings
  */
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
new file mode 100644 (file)
index 0000000..4372e0e
--- /dev/null
@@ -0,0 +1,136 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CommentsSource;
+import org.apache.poi.xssf.usermodel.XSSFComment;
+import org.apache.poi.xssf.util.CellReference;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
+
+public class CommentsTable implements CommentsSource, XSSFModel {
+       private CTComments comments;
+
+       public CommentsTable(InputStream is) throws IOException {
+               readFrom(is);
+       }
+       public CommentsTable() {
+               comments = CTComments.Factory.newInstance();
+       }
+       /**
+        * For unit testing only!
+        */
+       public CommentsTable(CTComments comments) {
+               this.comments = comments;
+       }
+       
+       public void readFrom(InputStream is) throws IOException {
+               try {
+                       CommentsDocument doc = CommentsDocument.Factory.parse(is);
+                       comments = doc.getComments();
+        } catch (XmlException e) {
+            throw new IOException(e.getLocalizedMessage());
+        }
+       }
+       public void writeTo(OutputStream out) throws IOException {
+        XmlOptions options = new XmlOptions();
+        options.setSaveOuter();
+        options.setUseDefaultNamespace();
+        
+        // Requests use of whitespace for easier reading
+        options.setSavePrettyPrint();
+        
+        CommentsDocument doc = CommentsDocument.Factory.newInstance(options);
+        doc.setComments(comments);
+        doc.save(out, options);
+       }
+       
+       public String getAuthor(long authorId) {
+               return getCommentsAuthors().getAuthorArray((int)authorId);
+       }
+       
+       public int findAuthor(String author) {
+               for (int i = 0 ; i < getCommentsAuthors().sizeOfAuthorArray() ; i++) {
+                       if (getCommentsAuthors().getAuthorArray(i).equals(author)) {
+                               return i;
+                       }
+               }
+               return addNewAuthor(author);
+       }
+       
+       public XSSFComment findCellComment(int row, int column) {
+               return findCellComment(new CellReference().convertRowColToString((short)row, (short)column));
+       }
+       
+       public XSSFComment findCellComment(String cellRef) {
+               for (CTComment comment : getCommentsList().getCommentArray()) {
+                       if (cellRef.equals(comment.getRef())) {
+                               return new XSSFComment(this, comment);
+                       }
+               }
+               return null;
+       }
+       
+       public void setCellComment (int row, int column, Comment comment) {
+               XSSFComment current = findCellComment(row, column);
+               if (current == null) {
+                       current = addComment();
+               }
+               current = (XSSFComment)comment;
+               current.setRow(row);
+               current.setColumn((short) column);
+       }
+       
+       public void setCellComment (String cellRef, Comment comment) {
+               CellReference cellReference = new CellReference(cellRef);
+               setCellComment(cellReference.getRow(), cellReference.getCol(), comment);
+       }
+
+       public XSSFComment addComment() {
+               return new XSSFComment(this, getCommentsList().addNewComment());
+       }
+
+       private CTCommentList getCommentsList() {
+               if (comments.getCommentList() == null) {
+                       comments.addNewCommentList();
+               }
+               return comments.getCommentList();
+       }
+
+       private CTAuthors getCommentsAuthors() {
+               if (comments.getAuthors() == null) {
+                       comments.addNewAuthors();
+               }
+               return comments.getAuthors();
+       }
+       
+       private int addNewAuthor(String author) {
+               int index = getCommentsAuthors().sizeOfAuthorArray();
+               getCommentsAuthors().insertAuthor(index, author);
+               return index;
+       }
+}
\ No newline at end of file
index c1ec4db3e0ee4c491505152a475f23e046aa1769..f726a22b41c4b4b1a852aacede8c38dbadf0fa9a 100644 (file)
@@ -17,8 +17,8 @@
 package org.apache.poi.xssf.usermodel;
 
 import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CommentsSource;
 import org.apache.poi.ss.usermodel.RichTextString;
-import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
 import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
 import org.apache.poi.xssf.util.CellReference;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
@@ -27,14 +27,14 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
 public class XSSFComment implements Comment {
        
        private CTComment comment;
-       private XSSFComments comments;
+       private CommentsSource comments;
 
-       public XSSFComment(XSSFComments comments, CTComment comment) {
+       public XSSFComment(CommentsSource comments, CTComment comment) {
                this.comment = comment;
                this.comments = comments;
        }
 
-       public XSSFComment(XSSFComments sheetComments) {
+       public XSSFComment(CommentsSource sheetComments) {
                this(sheetComments, CTComment.Factory.newInstance());
        }
 
index fd4918cb26fd6b8905a8b8e66d51cedb1763c9ba..a9476d453e6a9dc49612c4f09e1e3aa6d9764cff 100644 (file)
@@ -27,20 +27,19 @@ import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.hssf.util.Region;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CommentsSource;
 import org.apache.poi.ss.usermodel.Footer;
 import org.apache.poi.ss.usermodel.Header;
 import org.apache.poi.ss.usermodel.Patriarch;
 import org.apache.poi.ss.usermodel.PrintSetup;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.apache.poi.xssf.util.CellReference;
 import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
@@ -59,15 +58,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
 
 
 public class XSSFSheet implements Sheet {
-
     protected CTSheet sheet;
     protected CTWorksheet worksheet;
     protected CTDialogsheet dialogsheet;
-    protected CTComments comments;
     protected List<Row> rows;
     protected ColumnHelper columnHelper;
     protected XSSFWorkbook workbook;
-    protected XSSFComments sheetComments;
+    protected CommentsSource sheetComments;
 
     public static final short LeftMargin = 0;
     public static final short RightMargin = 1;
@@ -76,7 +73,7 @@ public class XSSFSheet implements Sheet {
     public static final short HeaderMargin = 4;
     public static final short FooterMargin = 5;
 
-       public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook, XSSFComments sheetComments) {
+       public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook, CommentsSource sheetComments) {
                this(sheet, worksheet, workbook);
                this.sheetComments = sheetComments;
        }
@@ -908,18 +905,10 @@ public class XSSFSheet implements Sheet {
                this.sheet = sheet;
        }
        
-       private XSSFComments getComments() {
+       private CommentsSource getComments() {
                if (sheetComments == null) {
-                       sheetComments = new XSSFComments(getCTComments());
+                       sheetComments = new CommentsTable();
                }
                return sheetComments;
        }
-
-       private CTComments getCTComments() {
-               if (comments == null) {
-                       comments = CTComments.Factory.newInstance();
-               }
-               return comments;
-       }
-
 }
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFComments.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFComments.java
deleted file mode 100644 (file)
index 666bd16..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.xssf.usermodel.extensions;
-
-import org.apache.poi.xssf.usermodel.XSSFComment;
-import org.apache.poi.xssf.util.CellReference;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
-
-public class XSSFComments {
-       
-       private CTComments comments;
-
-       public XSSFComments() {
-               this(CTComments.Factory.newInstance());
-       }
-
-       public XSSFComments(CTComments comments) {
-               this.comments = comments;
-       }
-
-       public String getAuthor(long authorId) {
-               return getCommentsAuthors().getAuthorArray((int)authorId);
-       }
-       
-       public int findAuthor(String author) {
-               for (int i = 0 ; i < getCommentsAuthors().sizeOfAuthorArray() ; i++) {
-                       if (getCommentsAuthors().getAuthorArray(i).equals(author)) {
-                               return i;
-                       }
-               }
-               return addNewAuthor(author);
-       }
-       
-       public XSSFComment findCellComment(int row, int column) {
-               return findCellComment(new CellReference().convertRowColToString((short)row, (short)column));
-       }
-       
-       public XSSFComment findCellComment(String cellRef) {
-               for (CTComment comment : getCommentsList().getCommentArray()) {
-                       if (cellRef.equals(comment.getRef())) {
-                               return new XSSFComment(this, comment);
-                       }
-               }
-               return null;
-       }
-       
-       public void setCellComment (int row, int column, XSSFComment comment) {
-               XSSFComment current = findCellComment(row, column);
-               if (current == null) {
-                       current = addComment();
-               }
-               current = comment;
-               current.setRow(row);
-               current.setColumn((short) column);
-       }
-       
-       public void setCellComment (String cellRef, XSSFComment comment) {
-               CellReference cellReference = new CellReference(cellRef);
-               setCellComment(cellReference.getRow(), cellReference.getCol(), comment);
-       }
-
-       public XSSFComment addComment() {
-               return new XSSFComment(this, getCommentsList().addNewComment());
-       }
-
-       private CTCommentList getCommentsList() {
-               if (comments.getCommentList() == null) {
-                       comments.addNewCommentList();
-               }
-               return comments.getCommentList();
-       }
-
-       private CTAuthors getCommentsAuthors() {
-               if (comments.getAuthors() == null) {
-                       comments.addNewAuthors();
-               }
-               return comments.getAuthors();
-       }
-       
-       private int addNewAuthor(String author) {
-               int index = getCommentsAuthors().sizeOfAuthorArray();
-               getCommentsAuthors().insertAuthor(index, author);
-               return index;
-       }
-
-}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFSheetComments.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFSheetComments.java
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
new file mode 100644 (file)
index 0000000..c231ba6
--- /dev/null
@@ -0,0 +1,84 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.model;
+
+import org.apache.poi.xssf.usermodel.XSSFComment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+
+import junit.framework.TestCase;
+
+
+public class TestCommentsTable extends TestCase {
+       
+       private static final String TEST_A2_TEXT = "test A2 text";
+       private static final String TEST_A1_TEXT = "test A1 text";
+       private static final String TEST_AUTHOR = "test author";
+
+       public void testfindAuthor() {
+               CTComments comments = CTComments.Factory.newInstance();
+               CommentsTable sheetComments = new CommentsTable(comments);
+
+               assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
+               assertEquals(1, sheetComments.findAuthor("another author"));
+               assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
+       }
+       
+       public void testGetCellComment() {
+               CTComments comments = CTComments.Factory.newInstance();
+               CommentsTable sheetComments = new CommentsTable(comments);
+               CTCommentList commentList = comments.addNewCommentList();
+               
+               // Create 2 comments for A1 and A" cells
+               CTComment comment0 = commentList.insertNewComment(0);
+               comment0.setRef("A1");
+               CTRst ctrst0 = CTRst.Factory.newInstance();
+               ctrst0.setT(TEST_A1_TEXT);
+               comment0.setText(ctrst0);
+               CTComment comment1 = commentList.insertNewComment(0);
+               comment1.setRef("A2");
+               CTRst ctrst1 = CTRst.Factory.newInstance();
+               ctrst1.setT(TEST_A2_TEXT);
+               comment1.setText(ctrst1);
+               
+               // test finding the right comment for a cell
+               assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").getString());
+               assertEquals(TEST_A1_TEXT, sheetComments.findCellComment(0, 0).getString());
+               assertEquals(TEST_A2_TEXT, sheetComments.findCellComment("A2").getString());
+               assertEquals(TEST_A2_TEXT, sheetComments.findCellComment(1, 0).getString());
+               assertNull(sheetComments.findCellComment("A3"));
+               assertNull(sheetComments.findCellComment(2, 0));
+       }
+       
+       public void testSetCellComment() {
+               CTComments comments = CTComments.Factory.newInstance();
+               CommentsTable sheetComments = new CommentsTable(comments);
+               CTCommentList commentList = comments.addNewCommentList();
+               assertEquals(0, commentList.sizeOfCommentArray());
+               XSSFComment comment = new XSSFComment(sheetComments);
+               comment.setAuthor("test A1 author");
+               
+               sheetComments.setCellComment("A1", comment);
+               assertEquals(1, commentList.sizeOfCommentArray());
+               assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId()));
+               
+       }
+    
+}
index f3e78e38aa11adb803a03627d23737ba8a26ea29..bf32d3d0bcd3bfd86a92a6151adc94448daf8144 100644 (file)
@@ -33,7 +33,7 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.SharedStringSource;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
@@ -235,7 +235,7 @@ public class TestXSSFCell extends TestCase {
         CTSheet ctSheet = CTSheet.Factory.newInstance();
         CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
         CTComments ctComments = CTComments.Factory.newInstance();
-        XSSFComments sheetComments = new XSSFComments(ctComments);
+        CommentsTable sheetComments = new CommentsTable(ctComments);
         XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
         assertNotNull(sheet);
         
@@ -261,7 +261,7 @@ public class TestXSSFCell extends TestCase {
         CTSheet ctSheet = CTSheet.Factory.newInstance();
         CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
         CTComments ctComments = CTComments.Factory.newInstance();
-        XSSFComments comments = new XSSFComments(ctComments);
+        CommentsTable comments = new CommentsTable(ctComments);
         XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, comments);
         assertNotNull(sheet);
         
index de00b1a6a50a3a3d19257f57bce05f13c7d8f0ea..8cc0ed0f38878d721da1ffea0321066b11bc254e 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.xssf.usermodel;
 
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.ss.usermodel.RichTextString;
-import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.util.CellReference;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
@@ -34,7 +34,7 @@ public class TestXSSFComment extends TestCase {
        private static final String TEST_AUTHOR = "test_author";
 
        public void testConstructors() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                XSSFComment comment = new XSSFComment(sheetComments);
                assertNotNull(comment);
                
@@ -44,7 +44,7 @@ public class TestXSSFComment extends TestCase {
        }
        
        public void testGetColumn() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                ctComment.setRef("A1");
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
@@ -55,7 +55,7 @@ public class TestXSSFComment extends TestCase {
        }
        
        public void testGetRow() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                ctComment.setRef("A1");
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
@@ -72,14 +72,14 @@ public class TestXSSFComment extends TestCase {
                ctAuthors.insertAuthor(0, TEST_AUTHOR);
                ctComment.setAuthorId(0);
 
-               XSSFComments sheetComments = new XSSFComments(ctComments);
+               CommentsTable sheetComments = new CommentsTable(ctComments);
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
                assertNotNull(comment);
                assertEquals(TEST_AUTHOR, comment.getAuthor());
        }
        
        public void testSetColumn() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
                comment.setColumn((short)3);
@@ -92,7 +92,7 @@ public class TestXSSFComment extends TestCase {
        }
        
        public void testSetRow() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
                comment.setRow(20);
@@ -105,7 +105,7 @@ public class TestXSSFComment extends TestCase {
        }
        
        public void testSetAuthor() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
                comment.setAuthor(TEST_AUTHOR);
@@ -113,7 +113,7 @@ public class TestXSSFComment extends TestCase {
        }
        
        public void testSetString() {
-               XSSFComments sheetComments = new XSSFComments();
+               CommentsTable sheetComments = new CommentsTable();
                CTComment ctComment = CTComment.Factory.newInstance();
                XSSFComment comment = new XSSFComment(sheetComments, ctComment);
                RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
index 4c1abab826297cfe901b22ea9bac67f5c2473987..4b9abe2514ff62a7f8785437f127440d38aea666 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
@@ -490,7 +490,7 @@ public class TestXSSFSheet extends TestCase {
         CTSheet ctSheet = CTSheet.Factory.newInstance();
         CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
         CTComments ctComments = CTComments.Factory.newInstance();
-        XSSFComments sheetComments = new XSSFComments(ctComments);
+        CommentsTable sheetComments = new CommentsTable(ctComments);
         XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
         assertNotNull(sheet);
         
@@ -509,7 +509,7 @@ public class TestXSSFSheet extends TestCase {
         XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
         Cell cell = sheet.createRow(0).createCell((short)0);
         CTComments ctComments = CTComments.Factory.newInstance();
-        XSSFComments comments = new XSSFComments(ctComments);
+        CommentsTable comments = new CommentsTable(ctComments);
         XSSFComment comment = comments.addComment();
         
         sheet.setCellComment("A1", comment);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFComments.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFComments.java
deleted file mode 100644 (file)
index 90fa1b2..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.xssf.usermodel.extensions;
-
-import org.apache.poi.xssf.usermodel.XSSFComment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-
-import junit.framework.TestCase;
-
-
-public class TestXSSFComments extends TestCase {
-       
-       private static final String TEST_A2_TEXT = "test A2 text";
-       private static final String TEST_A1_TEXT = "test A1 text";
-       private static final String TEST_AUTHOR = "test author";
-
-       public void testfindAuthor() {
-               CTComments comments = CTComments.Factory.newInstance();
-               XSSFComments sheetComments = new XSSFComments(comments);
-
-               assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
-               assertEquals(1, sheetComments.findAuthor("another author"));
-               assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
-       }
-       
-       public void testGetCellComment() {
-               CTComments comments = CTComments.Factory.newInstance();
-               XSSFComments sheetComments = new XSSFComments(comments);
-               CTCommentList commentList = comments.addNewCommentList();
-               
-               // Create 2 comments for A1 and A" cells
-               CTComment comment0 = commentList.insertNewComment(0);
-               comment0.setRef("A1");
-               CTRst ctrst0 = CTRst.Factory.newInstance();
-               ctrst0.setT(TEST_A1_TEXT);
-               comment0.setText(ctrst0);
-               CTComment comment1 = commentList.insertNewComment(0);
-               comment1.setRef("A2");
-               CTRst ctrst1 = CTRst.Factory.newInstance();
-               ctrst1.setT(TEST_A2_TEXT);
-               comment1.setText(ctrst1);
-               
-               // test finding the right comment for a cell
-               assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").getString());
-               assertEquals(TEST_A1_TEXT, sheetComments.findCellComment(0, 0).getString());
-               assertEquals(TEST_A2_TEXT, sheetComments.findCellComment("A2").getString());
-               assertEquals(TEST_A2_TEXT, sheetComments.findCellComment(1, 0).getString());
-               assertNull(sheetComments.findCellComment("A3"));
-               assertNull(sheetComments.findCellComment(2, 0));
-       }
-       
-       public void testSetCellComment() {
-               CTComments comments = CTComments.Factory.newInstance();
-               XSSFComments sheetComments = new XSSFComments(comments);
-               CTCommentList commentList = comments.addNewCommentList();
-               assertEquals(0, commentList.sizeOfCommentArray());
-               XSSFComment comment = new XSSFComment(sheetComments);
-               comment.setAuthor("test A1 author");
-               
-               sheetComments.setCellComment("A1", comment);
-               assertEquals(1, commentList.sizeOfCommentArray());
-               assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId()));
-               
-       }
-    
-}