Author: nick
Date: Mon Mar 31 16:30:56 2008
New Revision: 643208

URL: http://svn.apache.org/viewvc?rev=643208&view=rev
Log:
Start to wire up the commentstable stuff, now partly in place, and partly tested

Modified:
    
poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java
    
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
    
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java

Modified: 
poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java
URL: 
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java?rev=643208&r1=643207&r2=643208&view=diff
==============================================================================
--- 
poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java
 (original)
+++ 
poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CommentsSource.java
 Mon Mar 31 16:30:56 2008
@@ -24,6 +24,8 @@
 public interface CommentsSource {
        public String getAuthor(long authorId);
        
+       public int getNumberOfComments();
+       
        public int findAuthor(String author);
        
        public Comment findCellComment(int row, int column);

Modified: 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
URL: 
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java?rev=643208&r1=643207&r2=643208&view=diff
==============================================================================
--- 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java 
(original)
+++ 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java 
Mon Mar 31 16:30:56 2008
@@ -69,6 +69,10 @@
         doc.save(out, options);
        }
        
+       public int getNumberOfComments() {
+               return comments.getCommentList().sizeOfCommentArray();
+       }
+       
        public String getAuthor(long authorId) {
                return getCommentsAuthors().getAuthorArray((int)authorId);
        }

Modified: 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: 
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=643208&r1=643207&r2=643208&view=diff
==============================================================================
--- 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java 
(original)
+++ 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java 
Mon Mar 31 16:30:56 2008
@@ -911,4 +911,13 @@
                }
                return sheetComments;
        }
+       
+       /**
+        * Does this sheet have any comments on it? We need to know,
+        *  so we can decide about writing it to disk or not
+        */
+       public boolean hasComments() {
+               if(sheetComments == null) { return false; }
+               return (sheetComments.getNumberOfComments() > 0);
+       }
 }

Modified: 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: 
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=643208&r1=643207&r2=643208&view=diff
==============================================================================
--- 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
 (original)
+++ 
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
 Mon Mar 31 16:30:56 2008
@@ -29,10 +29,10 @@
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CommentsSource;
 import org.apache.poi.ss.usermodel.CreationHelper;
 import org.apache.poi.ss.usermodel.DataFormat;
 import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Palette;
 import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.SharedStringSource;
@@ -41,6 +41,7 @@
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.model.XSSFModel;
@@ -105,6 +106,18 @@
                "/xl/image#.xml",
                null
     );
+       public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
+                   
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
+                   
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";,
+                   "/xl/comments#.xml",
+                   CommentsTable.class
+       );
+       public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
+                   null,
+                   
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";,
+                   null,
+                   null
+       );
     
        public static class XSSFRelation {
                private String TYPE;
@@ -241,8 +254,20 @@
                        log.log(POILogger.WARN, "Sheet with name " + 
ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't 
exist in package, skipping");
                     continue;
                 }
+                
+                // Get the comments for the sheet, if there are any
+                CommentsSource comments = null;
+                PackageRelationshipCollection commentsRel =
+                       part.getRelationshipsByType(SHEET_COMMENTS.REL);
+                if(commentsRel != null && commentsRel.size() > 0) {
+                       PackagePart commentsPart = 
+                               getTargetPart(commentsRel.getRelationship(0));
+                       comments = new 
CommentsTable(commentsPart.getInputStream());
+                }
+                
+                // Now create the sheet
                 WorksheetDocument worksheetDoc = 
WorksheetDocument.Factory.parse(part.getInputStream());
-                XSSFSheet sheet = new XSSFSheet(ctSheet, 
worksheetDoc.getWorksheet(), this);
+                XSSFSheet sheet = new XSSFSheet(ctSheet, 
worksheetDoc.getWorksheet(), this, comments);
                 this.sheets.add(sheet);
             }
         } catch (XmlException e) {
@@ -656,6 +681,9 @@
                 // Update our internal reference for the package part
                 workbook.getSheets().getSheetArray(i).setId(rel.getId());
                 workbook.getSheets().getSheetArray(i).setSheetId(sheetNumber);
+                
+                // If our sheet has comments, then write out those
+                // TODO
             }
              
             // Write shared strings and styles

Modified: 
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
URL: 
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java?rev=643208&r1=643207&r2=643208&view=diff
==============================================================================
--- 
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
 (original)
+++ 
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
 Mon Mar 31 16:30:56 2008
@@ -17,7 +17,12 @@
 
 package org.apache.poi.xssf.model;
 
+import java.io.File;
+
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFComment;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
@@ -78,7 +83,26 @@
                sheetComments.setCellComment("A1", comment);
                assertEquals(1, commentList.sizeOfCommentArray());
                assertEquals("test A1 author", 
sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId()));
+       }
+
+       public void testExisting() throws Exception {
+               File xml = new File(
+                               System.getProperty("HSSF.testdata.path") +
+                               File.separator + "WithVariousData.xlsx"
+               );
+               assertTrue(xml.exists());
+       
+               XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
+               Sheet sheet1 = workbook.getSheetAt(0);
+               Sheet sheet2 = workbook.getSheetAt(1);
                
+               assertTrue( ((XSSFSheet)sheet1).hasComments() );
+               assertFalse( ((XSSFSheet)sheet2).hasComments() );
+               
+               // TODO - check rest of comments
+       }
+       
+       public void testWriteRead() throws Exception {
+               // TODO
        }
-    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to