poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r637692 - in /poi/branches/ooxml/src/ooxml: interfaces-jdk15/org/apache/poi/ss/usermodel/ java/org/apache/poi/xssf/model/ java/org/apache/poi/xssf/usermodel/ java/org/apache/poi/xssf/usermodel/extensions/ testcases/org/apache/poi/xssf/userm...
Date Mon, 17 Mar 2008 00:10:18 GMT
Author: nick
Date: Sun Mar 16 17:10:17 2008
New Revision: 637692

URL: http://svn.apache.org/viewvc?rev=637692&view=rev
Log:
Start to tie up the XSSF cell styles stuff with the StylesTable code

Modified:
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/StylesSource.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/StylesSource.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/StylesSource.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/StylesSource.java
(original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/StylesSource.java
Sun Mar 16 17:10:17 2008
@@ -22,4 +22,7 @@
     
     public Font getFontAt(long idx);
     public long putFont(Font font);
+    
+    public CellStyle getStyleAt(long idx);
+    public long putStyle(CellStyle style);
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Sun Mar 16
17:10:17 2008
@@ -25,8 +25,11 @@
 import java.util.LinkedList;
 import java.util.Map.Entry;
 
+import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.StylesSource;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
@@ -35,6 +38,8 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;;
 
 
@@ -48,6 +53,8 @@
     private final LinkedList<CTFont> fonts = new LinkedList<CTFont>();
     private final LinkedList<CTFill> fills = new LinkedList<CTFill>();
     private final LinkedList<CTBorder> borders = new LinkedList<CTBorder>();
+    private final LinkedList<CTXf> styleXfs = new LinkedList<CTXf>();
+    private final LinkedList<CTXf> xfs = new LinkedList<CTXf>();
     
     /**
      * The first style id available for use as a custom style
@@ -71,6 +78,7 @@
      */
     public StylesTable() {
     	doc = StyleSheetDocument.Factory.newInstance();
+    	doc.addNewStyleSheet();
     }
 
     /**
@@ -96,6 +104,12 @@
         	for (CTBorder border : doc.getStyleSheet().getBorders().getBorderArray()) {
         		borders.add(border);
         	}
+        	for (CTXf xf : doc.getStyleSheet().getCellXfs().getXfArray()) {
+        		xfs.add(xf);
+        	}
+        	for (CTXf xf : doc.getStyleSheet().getCellStyleXfs().getXfArray()) {
+        		styleXfs.add(xf);
+        	}
         } catch (XmlException e) {
             throw new IOException(e.getLocalizedMessage());
         }
@@ -138,7 +152,35 @@
     	return -1;
     }
     
-    /**
+    public CellStyle getStyleAt(long idx) {
+    	CTXf mainXf = styleXfs.get((int)idx);
+    	CTXf styleXf = null;
+    	if(mainXf.getXfId() > -1) {
+    		styleXf = styleXfs.get((int)mainXf.getXfId());
+    	}
+    	
+		return new XSSFCellStyle(mainXf, styleXf, this);
+	}
+	public long putStyle(CellStyle style) {
+		// TODO
+		return -1;
+	}
+	
+	public XSSFCellBorder getBorderAt(long idx) {
+		return new XSSFCellBorder(borders.get((int)idx));
+	}
+	public long putBorder(XSSFCellBorder border) {
+		return putBorder(border.getCTBorder());
+	}
+	public synchronized long putBorder(CTBorder border) {
+		if(borders.contains(border)) {
+			return borders.indexOf(border);
+		}
+		borders.add(border);
+		return borders.size() - 1;
+	}
+	
+	/**
      * For unit testing only
      */
     public int _getNumberFormatSize() {
@@ -162,6 +204,12 @@
     public int _getBordersSize() {
     	return borders.size();
     }
+    /**
+     * For unit testing only!
+     */
+    public CTStylesheet _getRawStylesheet() {
+    	return doc.getStyleSheet();
+    }
     
 
     /**
@@ -200,6 +248,9 @@
     	// TODO
     	
     	// Borders
+    	// TODO
+    	
+    	// Xfs
     	// TODO
     	
         // Save

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sun Mar
16 17:10:17 2008
@@ -26,6 +26,7 @@
 import org.apache.poi.ss.usermodel.Comment;
 import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.ss.usermodel.SharedStringSource;
+import org.apache.poi.ss.usermodel.StylesSource;
 import org.apache.poi.xssf.util.CellReference;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
@@ -40,6 +41,7 @@
     private final XSSFRow row;
     private short cellNum;
     private SharedStringSource sharedStringSource;
+    private StylesSource stylesSource;
     
     /**
      * Create a new XSSFCell. This method is protected to be used only by
@@ -56,11 +58,15 @@
             this.cellNum = parseCellNum(cell.getR());
         }
         this.sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource();
+        this.stylesSource = row.getSheet().getWorkbook().getStylesSource();
     }
     
     protected SharedStringSource getSharedStringSource() {
         return this.sharedStringSource;
     }
+    protected StylesSource getStylesSource() {
+    	return this.stylesSource;
+    }
 
     public boolean getBooleanCellValue() {
         if (STCellType.B != cell.getT()) { 
@@ -89,8 +95,10 @@
     }
 
     public CellStyle getCellStyle() {
-        // TODO Auto-generated method stub
-        return null;
+    	if(this.cell.getS() > 0) {
+    		return stylesSource.getStyleAt(this.cell.getS());
+    	}
+    	return null;
     }
 
     public int getCellType() {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sun
Mar 16 17:10:17 2008
@@ -20,27 +20,28 @@
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
 
 
 public class XSSFCellStyle implements CellStyle {
-	
-	private CTStylesheet stylesheet;
+	private StylesTable stylesTable;
 	private CTXf cellXf;
 	private CTXf cellStyleXf;
 	private XSSFCellBorder cellBorder;
 	
-	public XSSFCellStyle(CTStylesheet stylesheet, int cellXfsId) {
-		this.stylesheet = stylesheet;
-		this.cellXf = stylesheet.getCellStyleXfs().getXfArray(cellXfsId);
-		if (cellXf.isSetXfId()) {
-			this.cellStyleXf = stylesheet.getCellStyleXfs().getXfArray((int) cellXf.getXfId());
-		}
+	/**
+	 * @param cellXf The main XF for the cell
+	 * @param cellStyleXf Optional, style xf
+	 * @param stylesTable Styles Table to work off
+	 */
+	public XSSFCellStyle(CTXf cellXf, CTXf cellStyleXf, StylesTable stylesTable) {
+		this.stylesTable = stylesTable;
+		this.cellXf = cellXf;
+		this.cellStyleXf = cellStyleXf;
 	}
 
 	public short getAlignment() {
@@ -85,8 +86,10 @@
 	}
 
 	public short getDataFormat() {
-		// TODO Auto-generated method stub
-		return 0;
+		return (short)cellXf.getNumFmtId();
+	}
+	public String getDataFormatString() {
+		return stylesTable.getNumberFormatAt(getDataFormat());
 	}
 
 	public short getFillBackgroundColor() {
@@ -263,8 +266,7 @@
 
 	private XSSFCellBorder getCellBorder() {
 		if (cellBorder == null) {
-			CTBorder border = stylesheet.getBorders().getBorderArray(getBorderId());
-			cellBorder = new XSSFCellBorder(border);
+			cellBorder = stylesTable.getBorderAt(getBorderId());
 		}
 		return cellBorder;
 	}

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
(original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
Sun Mar 16 17:10:17 2008
@@ -23,17 +23,34 @@
 
 
 public class XSSFCellBorder {
-	
 	private CTBorder border;
 	
+	/**
+	 * Creates a Cell Border from the supplied XML definition
+	 */
 	public XSSFCellBorder(CTBorder border) {
 		this.border = border;
 	}
+	/**
+	 * Creates a new, empty Cell Border, on the
+	 *  given Styles Table
+	 */
+	public XSSFCellBorder() {
+		border = CTBorder.Factory.newInstance();
+	}
 	
 	public static enum BorderSides {
 		TOP, RIGHT, BOTTOM, LEFT
 	}
 	
+	/**
+	 * TODO - is this the best way to allow StylesTable
+	 *  to record us?
+	 */
+	public CTBorder getCTBorder() {
+		return border;
+	}
+	
 	public Enum getBorderStyle(BorderSides side) {
 		return getBorder(side).getStyle();
 	}
@@ -55,5 +72,4 @@
 		default: throw new IllegalArgumentException("No suitable side specified for the border");
 		}
 	}
-
-}
+}
\ No newline at end of file

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
Sun Mar 16 17:10:17 2008
@@ -283,7 +283,13 @@
     }
     
     public void testCellFormatting() {
-    	
+    	Workbook workbook = new XSSFWorkbook();
+    	CTSheet ctSheet = CTSheet.Factory.newInstance();
+    	CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
+    	XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
+    	Cell cell = sheet.createRow(0).createCell((short)0);
+
+    	// TODO
     }
 
     private XSSFRow createParentObjects() {

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=637692&r1=637691&r2=637692&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
Sun Mar 16 17:10:17 2008
@@ -19,6 +19,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
@@ -27,59 +29,71 @@
 
 public class TestXSSFCellStyle extends TestCase {
 	
-	private CTStylesheet ctStylesheet;
-	private CTBorder ctBorder;
+	private StylesTable stylesTable;
+	private CTBorder ctBorderA;
+	private CTBorder ctBorderB;
 	private CTXf cellStyleXf;
 	private CTXf cellXf;
 	private XSSFCellStyle cellStyle;
 
 	public void setUp() {
-		ctStylesheet = CTStylesheet.Factory.newInstance();
-		ctBorder = ctStylesheet.addNewBorders().insertNewBorder(0);
+		stylesTable = new StylesTable();
+		
+		CTStylesheet ctStylesheet = stylesTable._getRawStylesheet();
+		
+		// Until we do XSSFBorder properly, cheat
+		ctBorderA = CTBorder.Factory.newInstance();
+		long borderId = stylesTable.putBorder(ctBorderA);
+		assertEquals(0, borderId);
+		
+		XSSFCellBorder borderB = new XSSFCellBorder();
+		ctBorderB = borderB.getCTBorder();
+		assertEquals(1, stylesTable.putBorder(borderB));
+		
 		cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
 		cellStyleXf.setBorderId(0);
 		cellXf = ctStylesheet.addNewCellXfs().addNewXf();
 		cellXf.setXfId(0);
-		cellStyle = new XSSFCellStyle(ctStylesheet, 0);
+		cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
 	}
 	
 	public void testGetBorderBottom() {		
-		ctBorder.addNewBottom().setStyle(STBorderStyle.THIN);
+		ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
 		assertEquals((short)1, cellStyle.getBorderBottom());
 	}
 
 	public void testGetBorderBottomAsString() {
-		ctBorder.addNewBottom().setStyle(STBorderStyle.THIN);
+		ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
 		assertEquals("thin", cellStyle.getBorderBottomAsString());
 	}
 	
 	public void testGetBorderRight() {
-		ctBorder.addNewRight().setStyle(STBorderStyle.MEDIUM);
+		ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
 		assertEquals((short)2, cellStyle.getBorderRight());
 	}
 
 	public void testGetBorderRightAsString() {
-		ctBorder.addNewRight().setStyle(STBorderStyle.MEDIUM);
+		ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
 		assertEquals("medium", cellStyle.getBorderRightAsString());
 	}
 	
 	public void testGetBorderLeft() {
-		ctBorder.addNewLeft().setStyle(STBorderStyle.DASHED);
+		ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
 		assertEquals((short)3, cellStyle.getBorderLeft());
 	}
 
 	public void testGetBorderLeftAsString() {
-		ctBorder.addNewLeft().setStyle(STBorderStyle.DASHED);
+		ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
 		assertEquals("dashed", cellStyle.getBorderLeftAsString());
 	}
 	
 	public void testGetBorderTop() {
-		ctBorder.addNewTop().setStyle(STBorderStyle.HAIR);
+		ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
 		assertEquals((short)7, cellStyle.getBorderTop());
 	}
 
 	public void testGetTopBottomAsString() {
-		ctBorder.addNewTop().setStyle(STBorderStyle.HAIR);
+		ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
 		assertEquals("hair", cellStyle.getBorderTopAsString());
 	}
 }



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


Mime
View raw message