You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/04/03 02:24:00 UTC

svn commit: r644118 - in /poi/branches/ooxml: ./ src/java/org/apache/poi/hssf/usermodel/ src/ooxml/java/org/apache/poi/xssf/usermodel/ src/ooxml/testcases/org/apache/poi/xssf/model/ src/testcases/org/apache/poi/hssf/usermodel/

Author: nick
Date: Wed Apr  2 17:23:59 2008
New Revision: 644118

URL: http://svn.apache.org/viewvc?rev=644118&view=rev
Log:
New ooxml4j, and finish getting xssf comments to be saved and re-loaded again

Modified:
    poi/branches/ooxml/build.xml
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFComment.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
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java

Modified: poi/branches/ooxml/build.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/build.xml?rev=644118&r1=644117&r2=644118&view=diff
==============================================================================
--- poi/branches/ooxml/build.xml (original)
+++ poi/branches/ooxml/build.xml Wed Apr  2 17:23:59 2008
@@ -151,8 +151,8 @@
   <property name="ooxml.jar5.dir" location="${ooxml.lib}/jsr173_1.0_api.jar"/>
   <property name="ooxml.jar5.url" value="${repository}/xmlbeans/jars/jsr173_1.0_api.jar"/>
   <!-- No official release of openxml4j yet -->
-  <property name="ooxml.jar6.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080322.jar"/>
-  <property name="ooxml.jar6.url" value="http://people.apache.org/~nick/openxml4j-bin-alpha-080322.jar"/>
+  <property name="ooxml.jar6.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080403.jar"/>
+  <property name="ooxml.jar6.url" value="http://people.apache.org/~nick/openxml4j-bin-alpha-080403.jar"/>
 
   <!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
   <!-- "Copy these file(s), free of charge" -->

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java?rev=644118&r1=644117&r2=644118&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java Wed Apr  2 17:23:59 2008
@@ -139,13 +139,6 @@
     }
     
     /**
-     * Fetches the rich text string of the comment
-     */
-    public HSSFRichTextString getString() {
-    	return txo.getStr();
-    }
-
-    /**
      * Sets the rich text string used by this comment.
      *
      * @param string    Sets the rich text string used by this object.

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=644118&r1=644117&r2=644118&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 Wed Apr  2 17:23:59 2008
@@ -919,6 +919,13 @@
 		}
 		return sheetComments;
 	}
+	/**
+	 * Returns the sheet's comments object if there is one,
+	 *  or null if not
+	 */
+	protected CommentsSource getCommentsSourceIfExists() {
+		return sheetComments;
+	}
 	
 	/**
 	 * Does this sheet have any comments on it? We need to know,

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=644118&r1=644117&r2=644118&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 Wed Apr  2 17:23:59 2008
@@ -133,6 +133,18 @@
 		public String getContentType() { return TYPE; }
 		public String getRelation() { return REL; }
 		public String getDefaultFileName() { return DEFAULT_NAME; }
+		
+		/**
+		 * Returns the filename for the nth one of these, 
+		 *  eg /xl/comments4.xml
+		 */
+		public String getFileName(int index) {
+			if(DEFAULT_NAME.indexOf("#") == -1) {
+				// Generic filename in all cases
+				return getDefaultFileName();
+			}
+			return DEFAULT_NAME.replace("#", Integer.toString(index));
+		}
 
 		/**
 		 * Fetches the InputStream to read the contents, based
@@ -667,7 +679,8 @@
             for (int i=0 ; i < this.getNumberOfSheets(); i++) {
             	int sheetNumber = (i+1);
             	XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
-                PackagePartName partName = PackagingURIHelper.createPartName("/xl/worksheets/sheet" + sheetNumber + ".xml");
+                PackagePartName partName = PackagingURIHelper.createPartName(
+                		WORKSHEET.getFileName(sheetNumber));
                 PackageRelationship rel =
                 	 corePart.addRelationship(partName, TargetMode.INTERNAL, WORKSHEET.getRelation(), "rSheet" + sheetNumber);
                 PackagePart part = pkg.createPart(partName, WORKSHEET.getContentType());
@@ -683,7 +696,17 @@
                 workbook.getSheets().getSheetArray(i).setSheetId(sheetNumber);
                 
                 // If our sheet has comments, then write out those
-                // TODO
+                if(sheet.hasComments()) {
+                	CommentsTable ct = (CommentsTable)sheet.getCommentsSourceIfExists();
+                    PackagePartName ctName = PackagingURIHelper.createPartName(
+                    		SHEET_COMMENTS.getFileName(sheetNumber));
+                    part.addRelationship(ctName, TargetMode.INTERNAL, SHEET_COMMENTS.getRelation(), "rComments");
+                    PackagePart ctPart = pkg.createPart(ctName, SHEET_COMMENTS.getContentType());
+                    
+                    out = ctPart.getOutputStream();
+                    ct.writeTo(out);
+                    out.close();
+                }
             }
              
             // 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=644118&r1=644117&r2=644118&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 Wed Apr  2 17:23:59 2008
@@ -20,6 +20,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Comment;
@@ -128,7 +129,7 @@
 		assertEquals(2, cc7.getColumn());
 	}
 	
-	public void DISABLEDtestWriteRead() throws Exception {
+	public void testWriteRead() throws Exception {
 		File xml = new File(
 				System.getProperty("HSSF.testdata.path") +
 				File.separator + "WithVariousData.xlsx"

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java?rev=644118&r1=644117&r2=644118&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java Wed Apr  2 17:23:59 2008
@@ -78,6 +78,26 @@
         assertEquals(commentText, comment.getString().getString());
         assertEquals(cellRow, comment.getRow());
         assertEquals(cellColumn, comment.getColumn());
+        
+        
+        // Change slightly, and re-test
+        comment.setString(new HSSFRichTextString("New Comment Text"));
+        
+        out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        sheet = wb.getSheetAt(0);
+        cell = sheet.getRow(cellRow).getCell(cellColumn);
+        comment = cell.getCellComment();
+
+        assertNotNull(comment);
+        assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
+        assertEquals(commentAuthor, comment.getAuthor());
+        assertEquals("New Comment Text", comment.getString().getString());
+        assertEquals(cellRow, comment.getRow());
+        assertEquals(cellColumn, comment.getColumn());
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org