poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r696584 [1/2] - in /poi/branches/ooxml: ./ src/examples/src/org/apache/poi/xssf/usermodel/examples/ src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/ src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ src/ooxml/java/org/apache/po...
Date Thu, 18 Sep 2008 07:42:41 GMT
Author: yegor
Date: Thu Sep 18 00:42:40 2008
New Revision: 696584

URL: http://svn.apache.org/viewvc?rev=696584&view=rev
Log:
1. initial support for rich text in xssf"
2. cleaned common ooxml-ole2 interfaces, removed ole2-specific stuff
3. added new examples from the quick guide
4. misc xssf refactoring, tending to use enums intstead of final static constants
5. refactored XSSFFont
6. included test-ooxml and jar-ooxml in the dist target, they are part of release and should be there

Added:
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java   (with props)
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java   (with props)
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java   (with props)
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java   (with props)
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java
      - copied, changed from r695757, poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/IndexedColors.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java   (with props)
Removed:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/IndexedColors.java
Modified:
    poi/branches/ooxml/build.xml
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Color.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/RichTextString.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.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/XSSFFont.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.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/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/CTFontWrapper.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.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/TestXSSFFont.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Modified: poi/branches/ooxml/build.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/build.xml?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/build.xml (original)
+++ poi/branches/ooxml/build.xml Thu Sep 18 00:42:40 2008
@@ -555,8 +555,8 @@
 	<delete file="${version.java}" />
   </target>
 
-  <target name="test" depends="test-main,test-scratchpad,test-contrib"
-    description="Tests main, contrib and scratchpad"/>
+  <target name="test" depends="test-main,test-scratchpad,test-contrib,test-ooxml"
+    description="Tests main, contrib, scratchpad and ooxml"/>
 
     <target name="-test-main-check">
         <uptodate property="main.test.notRequired" targetfile="${main.testokfile}">
@@ -1206,7 +1206,7 @@
             </manifest>        
         </jar>
 	</target>
-    <target name="jar" depends="compile, compile-version, jar-14" description="Creates jar files for distribution">
+    <target name="jar" depends="compile, compile-version, jar-14, jar-ooxml" description="Creates jar files for distribution">
         <jar destfile="${dist.dir}/${jar.name}-${version.id}-${DSTAMP}.jar">
 			<fileset dir="${main.output.dir}" />
 			<fileset dir="legal/" />

Added: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java?rev=696584&view=auto
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java (added)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java Thu Sep 18 00:42:40 2008
@@ -0,0 +1,76 @@
+/* ====================================================================
+   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.examples;
+
+import java.io.FileOutputStream;
+import java.util.Date;
+
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+/**
+ *
+ */
+public class CreateCell {
+
+
+	public static void main(String[]args) throws Exception {
+        Workbook wb = new XSSFWorkbook();
+        CreationHelper creationHelper = wb.getCreationHelper();
+        Sheet sheet = wb.createSheet("new sheet");
+
+        // Create a row and put some cells in it. Rows are 0 based.
+        Row row = sheet.createRow((short)0);
+        // Create a cell and put a value in it.
+        Cell cell = row.createCell((short)0);
+        cell.setCellValue(1);
+
+        //numeric value
+        row.createCell(1).setCellValue(1.2);
+
+        //plain string value
+        row.createCell(2).setCellValue("This is a string cell");
+
+        //rich text string
+        RichTextString str = creationHelper.createRichTextString("Apache");
+        Font font = wb.createFont();
+        font.setItalic(true);
+        font.setUnderline(Font.U_SINGLE);
+        str.applyFont(font);
+        row.createCell(3).setCellValue(str);
+
+        //boolean value
+        row.createCell(4).setCellValue(true);
+
+        //formula
+        row.createCell(5).setCellFormula("SUM(A1:B1)");
+
+        //date
+        CellStyle style = wb.createCellStyle();
+        style.setDataFormat(creationHelper.createDataFormat().getFormat("m/d/yy h:mm"));
+        cell = row.createCell(6);
+        cell.setCellValue(new Date());
+        cell.setCellStyle(style);
+
+        // Write the output to a file
+        FileOutputStream fileOut = new FileOutputStream("ooxml-cell.xlsx");
+        wb.write(fileOut);
+        fileOut.close();
+	}
+}

Propchange: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateNewSpreadsheet.java Thu Sep 18 00:42:40 2008
@@ -46,7 +46,7 @@
 		
 		s2.getRow(2).createCell(1).setCellValue(createHelper.createRichTextString("Sheet 2"));
 
-		
+/*
 		// Comment
 		Comment comment = ((XSSFSheet)s1).createComment();
 //		HSSFPatriarch patriach = (HSSFPatriarch)s1.createDrawingPatriarch();
@@ -62,7 +62,7 @@
 		hyperlink.setLabel("Link to POI");
 		s1.getRow(1).createCell(1).setHyperlink(hyperlink);
 		s1.getRow(1).getCell(1).setCellValue(createHelper.createRichTextString("Link to POI"));
-		
+*/
 		// Save
 		FileOutputStream fout = new FileOutputStream("NewFile.xlsx");
 		wb.write(fout);

Added: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java?rev=696584&view=auto
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java (added)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java Thu Sep 18 00:42:40 2008
@@ -0,0 +1,65 @@
+/* ====================================================================
+   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.examples;
+
+import java.io.FileOutputStream;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.DataFormat;
+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.XSSFWorkbook;
+
+/**
+ * How to set user-defined date formats
+ */
+public class CreateUserDefinedDataFormats {
+
+
+    public static void main(String[]args) throws Exception {
+        Workbook wb = new XSSFWorkbook();
+        Sheet sheet = wb.createSheet("format sheet");
+        CellStyle style;
+        DataFormat format = wb.createDataFormat();
+        Row row;
+        Cell cell;
+        short rowNum = 0;
+        short colNum = 0;
+
+        row = sheet.createRow(rowNum++);
+        cell = row.createCell(colNum);
+        cell.setCellValue(11111.25);
+        style = wb.createCellStyle();
+        style.setDataFormat(format.getFormat("0.0"));
+        cell.setCellStyle(style);
+
+        row = sheet.createRow(rowNum++);
+        cell = row.createCell(colNum);
+        cell.setCellValue(11111.25);
+        style = wb.createCellStyle();
+        style.setDataFormat(format.getFormat("#,##0.0000"));
+        cell.setCellStyle(style);
+
+        FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
+        wb.write(fileOut);
+        fileOut.close();
+    }
+
+}

Propchange: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java Thu Sep 18 00:42:40 2008
@@ -17,7 +17,7 @@
 package org.apache.poi.xssf.usermodel.examples;
 
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xssf.util.IndexedColors;
+import org.apache.poi.xssf.usermodel.IndexedColors;
 import org.apache.poi.ss.usermodel.*;
 
 import java.io.FileOutputStream;
@@ -40,13 +40,13 @@
         // Style the cell with borders all around.
         CellStyle style = wb.createCellStyle();
         style.setBorderBottom(CellStyle.BORDER_THIN);
-        style.setBottomBorderColor((short)IndexedColors.BLACK);
+        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
         style.setBorderLeft(CellStyle.BORDER_THIN);
-        style.setLeftBorderColor((short)IndexedColors.GREEN);
+        style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
         style.setBorderRight(CellStyle.BORDER_THIN);
-        style.setRightBorderColor((short)IndexedColors.BLUE);
+        style.setRightBorderColor(IndexedColors.BLUE.getIndex());
         style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
-        style.setTopBorderColor((short)IndexedColors.BLACK);
+        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
         cell.setCellStyle(style);
 
         // Write the output to a file

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java Thu Sep 18 00:42:40 2008
@@ -21,8 +21,8 @@
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.IndexedColors;
 import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
-import org.apache.poi.xssf.util.IndexedColors;
 
 import java.io.FileOutputStream;
 
@@ -42,7 +42,7 @@
         font.setFontHeightInPoints((short)24);
         font.setFontName("Courier New");
 
-        font.setColor((short)IndexedColors.RED);
+        font.setColor(IndexedColors.RED.getIndex());
 
         font.setItalic(true);
         font.setStrikeout(true);

Added: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java?rev=696584&view=auto
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java (added)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java Thu Sep 18 00:42:40 2008
@@ -0,0 +1,62 @@
+/* ====================================================================
+   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.examples;
+
+import org.apache.poi.xssf.usermodel.*;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+
+import java.io.FileOutputStream;
+import java.io.Writer;
+import java.io.StringWriter;
+
+/**
+ *  Demonstrates how to work with rich text
+ */
+public class WorkingWithRichText {
+
+    public static void main(String[] args)
+                throws Exception
+        {
+            XSSFWorkbook wb = new XSSFWorkbook();
+
+            XSSFSheet sheet = wb.createSheet();
+            XSSFRow row = sheet.createRow((short) 2);
+
+            XSSFCell cell = row.createCell(1);
+            XSSFRichTextString rt = new XSSFRichTextString("The quick");
+
+            XSSFFont font1 = wb.createFont();
+            font1.setBold(true);
+            rt.append(" brown fox", font1);
+
+            XSSFFont font2 = wb.createFont();
+            font2.setItalic(true);
+            font2.setColor(IndexedColors.RED.getIndex());
+            rt.applyFont((short)0);
+            cell.setCellValue(rt);
+
+            // Write the output to a file
+            FileOutputStream fileOut = new FileOutputStream("rich_text.xlsx");
+            wb.write(fileOut);
+            fileOut.close();
+
+        }
+
+ }

Propchange: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Comment.java Thu Sep 18 00:42:40 2008
@@ -18,6 +18,6 @@
 package org.apache.poi.ss.usermodel;
 
 public interface Comment {
-	public void setRow(short row);
+	public void setRow(int row);
 	public void setColumn(short row);
 }

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java Thu Sep 18 00:42:40 2008
@@ -173,6 +173,8 @@
 
     void setCellValue(RichTextString value);
 
+    void setCellValue(String value);
+
     void setCellFormula(String formula);
 
     String getCellFormula();

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Color.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Color.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Color.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Color.java Thu Sep 18 00:42:40 2008
@@ -19,22 +19,5 @@
 
 public interface Color {
 
-    /**
-     * @return index to the standard palette
-     */
-
-    short getIndex();
-
-    /**
-     * @return  triplet representation like that in Excel
-     */
-
-    short[] getTriplet();
-
-    /**
-     * @return a hex string exactly like a gnumeric triplet
-     */
-
-    String getHexString();
 
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java Thu Sep 18 00:42:40 2008
@@ -130,14 +130,6 @@
     String getFontName();
 
     /**
-     * get the index within the HSSFWorkbook (sequence within the collection of Font objects)
-     * @return unique index number of the underlying record this Font represents (probably you don't care
-     *  unless you're comparing which one is which)
-     */
-
-    short getIndex();
-
-    /**
      * set the font height in unit's of 1/20th of a point.  Maybe you might want to
      * use the setFontHeightInPoints which matches to the familiar 10, 12, 14 etc..
      * @param height height in 1/20ths of a point
@@ -218,24 +210,6 @@
     short getColor();
 
     /**
-     * set the boldness to use
-     * @param boldweight
-     * @see #BOLDWEIGHT_NORMAL
-     * @see #BOLDWEIGHT_BOLD
-     */
-
-    void setBoldweight(short boldweight);
-
-    /**
-     * get the boldness to use
-     * @return boldweight
-     * @see #BOLDWEIGHT_NORMAL
-     * @see #BOLDWEIGHT_BOLD
-     */
-
-    short getBoldweight();
-
-    /**
      * set normal,super or subscript.
      * @param offset type to use (none,super,sub)
      * @see #SS_NONE

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/RichTextString.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/RichTextString.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/RichTextString.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/RichTextString.java Thu Sep 18 00:42:40 2008
@@ -25,8 +25,6 @@
  * @author Jason Height (jheight at apache.org)
  */
 public interface RichTextString {
-    /** Place holder for indicating that NO_FONT has been applied here */
-    public static final short NO_FONT = 0;
     
     /**
      * Applies a font to the specified characters of a string.
@@ -68,20 +66,8 @@
     int length();
 
     /**
-     * Returns the font in use at a particular index.
+     * @return  The number of formatting runs used.
      *
-     * @param index         The index.
-     * @return              The font that's currently being applied at that
-     *                      index or null if no font is being applied or the
-     *                      index is out of range.
-     */
-    short getFontAtIndex(int index);
-
-    /**
-     * @return  The number of formatting runs used. There will always be at
-     *          least one of font NO_FONT.
-     *
-     * @see #NO_FONT
      */
     int numFormattingRuns();
 
@@ -93,14 +79,6 @@
     int getIndexOfFormattingRun(int index);
 
     /**
-     * Gets the font used in a particular formatting run.
-     *
-     * @param index     the index of the formatting run
-     * @return  the font number used.
-     */
-    short getFontOfFormattingRun(int index);
-
-    /**
      * Applies the specified font to the entire string.
      *
      * @param fontIndex  the font to apply.

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java Thu Sep 18 00:42:40 2008
@@ -100,7 +100,14 @@
             throw new IOException(e.toString());
         }
     }
-    
+    public static Package openPackage(InputStream is) throws IOException {
+        try {
+            return Package.open(is);
+        } catch (InvalidFormatException e) {
+            throw new IOException(e.toString());
+        }
+    }
+
     protected Package getPackage() {
         return this.pkg;
     }

Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java?rev=696584&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java Thu Sep 18 00:42:40 2008
@@ -0,0 +1,42 @@
+/* ====================================================================
+   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.dev;
+
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.FileOutputStream;
+
+/**
+ * Utility which loads a SpreadsheetML file and saves it back.
+ * This is a handy tool to investigate read-write round trip safety.
+ *
+ * @author Yegor Kozlov
+ */
+public class XSSFSave {
+    public static void main(String[] args) throws Exception {
+        for (int i = 0; i < args.length; i++) {
+            XSSFWorkbook wb = new XSSFWorkbook(args[i]);
+
+            int sep = args[i].lastIndexOf('.');
+            String outfile = args[i].substring(0, sep) + "-save.xlsx";
+            FileOutputStream out = new FileOutputStream(outfile);
+            wb.write(out);
+            out.close();
+        }
+    }
+
+}

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Thu Sep 18 00:42:40 2008
@@ -195,7 +195,7 @@
         options.setUseDefaultNamespace();
 
         //re-create the sst table every time saving a workbook
-        SstDocument doc = SstDocument.Factory.newInstance(options);
+        SstDocument doc = SstDocument.Factory.newInstance();
         CTSst sst = doc.addNewSst();
         sst.setCount(count);
         sst.setUniqueCount(uniqueCount);

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.LinkedList;
@@ -59,7 +60,7 @@
  */
 public class StylesTable implements StylesSource, XSSFModel {
     private final Hashtable<Long,String> numberFormats = new Hashtable<Long,String>();
-    private final LinkedList<CTFont> fonts = new LinkedList<CTFont>();
+    private final ArrayList<CTFont> fonts = new ArrayList<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>();
@@ -230,7 +231,12 @@
     public int getNumCellStyles(){
         return styleXfs.size();
     }
-      
+    /**
+     * get the size of fonts
+     */
+    public int getNumberOfFonts(){
+        return this.fonts.size();
+    } 
     /**
      * For unit testing only
      */
@@ -367,7 +373,7 @@
 		return fill.putFill(fills);
 	}
 
-    private long putFont(XSSFFont font, LinkedList<CTFont> fonts) {
+    private long putFont(XSSFFont font, ArrayList<CTFont> fonts) {
     	return font.putFont(fonts);
 	}
 	private void initialize() {
@@ -423,8 +429,8 @@
     	XSSFFont font=new XSSFFont(ctFont);
 		return font;
 		*/
-		
-		XSSFFont xssfFont=new XSSFFont();
+		CTFont ctFont = CTFont.Factory.newInstance();		
+		XSSFFont xssfFont=new XSSFFont(ctFont);
 		xssfFont.setFontHeightInPoints(XSSFFont.DEFAULT_FONT_SIZE);
 		xssfFont.setColor(XSSFFont.DEFAULT_FONT_COLOR);//setTheme 
 		xssfFont.setFontName(XSSFFont.DEFAULT_FONT_NAME);

Copied: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java (from r695757, poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/IndexedColors.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java?p2=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java&p1=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/IndexedColors.java&r1=695757&r2=696584&rev=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/util/IndexedColors.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java Thu Sep 18 00:42:40 2008
@@ -1,16 +1,79 @@
-package org.apache.poi.xssf.util;
+package org.apache.poi.xssf.usermodel;
 
-public class IndexedColors {
-    	
-	public static int BLACK=0;
-	public static int WHITE=1;
-	public static int RED=2;
-	public static int GREEN=3;
-	public static int BLUE=4;
-	public static int YELLOW=5;
-	public static int PINK=6;
-	
-	public static int LIGHT_GREY=22;
-	public static int DARK_GREY=23;
-	
+/**
+ * A deprecated indexing scheme for colours that is still required for some records, and for backwards
+ *  compatibility with OLE2 formats.
+ *
+ * <p>
+ * Each element corresponds to a color index (zero-based). When using the default indexed color palette,
+ * the values are not written out, but instead are implied. When the color palette has been modified from default,
+ * then the entire color palette is used.
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public enum IndexedColors {
+
+    BLACK(8),
+    WHITE(9),
+    RED(10),
+    BRIGHT_GREEN(11),
+    BLUE(12),
+    YELLOW(13),
+    PINK(14),
+    TURQUOISE(15),
+    DARK_RED(16),
+    GREEN(17),
+    DARK_BLUE(18),
+    DARK_YELLOW(19),
+    VIOLET(20),
+    TEAL(21),
+    GREY_25_PERCENT(22),
+    GREY_50_PERCENT(23),
+    CORNFLOWER_BLUE(24),
+    MAROON(25),
+    LEMON_CHIFFON(26),
+    ORCHID(28),
+    CORAL(29),
+    ROYAL_BLUE(30),
+    LIGHT_CORNFLOWER_BLUE(31),
+    SKY_BLUE(40),
+    LIGHT_TURQUOISE(41),
+    LIGHT_GREEN(42),
+    LIGHT_YELLOW(43),
+    PALE_BLUE(44),
+    ROSE(45),
+    LAVENDER(46),
+    TAN(47),
+    LIGHT_BLUE(48),
+    AQUA(49),
+    LIME(50),
+    GOLD(51),
+    LIGHT_ORANGE(52),
+    ORANGE(53),
+    BLUE_GREY(54),
+    GREY_40_PERCENT(55),
+    DARK_TEAL(56),
+    SEA_GREEN(57),
+    DARK_GREEN(58),
+    OLIVE_GREEN(59),
+    BROWN(60),
+    PLUM(61),
+    INDIGO(62),
+    GREY_80_PERCENT(63);
+
+    private short index;
+
+    IndexedColors(int idx){
+        index = (short)idx;
+    }
+
+    /**
+     * Returns index of this color
+     *
+     * @return index of this color
+     */
+    public short getIndex(){
+        return index;
+    }
 }

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -392,6 +392,10 @@
 
     }
 
+    public void setCellValue(String str) {
+        this.setCellValue(new XSSFRichTextString(str));
+    }
+    
     public void setCellValue(RichTextString value) {
         if(this.cell.getT() == STCellType.INLINE_STR) {
             this.cell.setV(value.getString());
@@ -401,6 +405,7 @@
             this.cell.setT(STCellType.S);
         }
         XSSFRichTextString rt = (XSSFRichTextString)value;
+        rt.setStylesTableReference(stylesSource);
         int sRef = sharedStringSource.addEntry(rt.getCTRst());
         this.cell.setV(Integer.toString(sRef));
     }
@@ -437,13 +442,6 @@
       }
     }
 
-    /**
-     * Creates an XSSFRichTextString for you.
-     */
-	public RichTextString createRichTextString(String text) {
-		return new XSSFRichTextString(text);
-	}
-	
 	public Hyperlink getHyperlink() {
 		return row.getSheet().getHyperlink(row.getRowNum(), cellNum);
 	}

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -417,7 +417,7 @@
         return (short) getBorderColor(side).getIndexed();
     }
 
-    private void setBorderColorIndexed(BorderSide side, long color) {
+    private void setBorderColorIndexed(BorderSide side, int color) {
         getBorderColor(side).setIndexed(color);
     }
 

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Thu Sep 18 00:42:40 2008
@@ -1,491 +1,406 @@
-/* ====================================================================
-   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;
-
-import java.util.LinkedList;
-
-import org.apache.poi.ss.usermodel.Font;
-
-import org.apache.poi.xssf.util.CTFontWrapper;
-import org.apache.poi.xssf.util.Charset;
-import org.apache.poi.xssf.util.IndexedColors;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
-
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
-
-public class XSSFFont implements Font {
-
-
-	public static final int SCHEME_MAJOR=2;
-	public static final int SCHEME_MINOR=3;
-	public static final int SCHEME_NONE=0;
-
-	public static final int FONT_FAMILY_NOT_APPLICABLE=0;
-	public static final int FONT_FAMILY_ROMAN=1;
-	public static final int FONT_FAMILY_SWISS=2;
-	public static final int FONT_FAMILY_MODERN=3;
-	public static final int FONT_FAMILY_SCRIPT=4;
-	public static final int FONT_FAMILY_DECORATIVE=5;
-
-
-	public static final String DEFAULT_FONT_NAME="Calibri";
-	public static final short DEFAULT_FONT_SIZE=11;
-	public static final short DEFAULT_FONT_COLOR=(short)IndexedColors.BLACK;
-
-	private int index=0;
-
-
-	private CTFontWrapper fontWrapper;
-
-
-
-	public XSSFFont(CTFont font) {
-		this.fontWrapper=new CTFontWrapper(font);
-	}
-
-	/*	
-	public XSSFFont(int index) {
-		this.fontWrapper=new CTFontWrapper(font);
-		this.index=index;
-	}
-	 */
-
-	public XSSFFont() {
-		this.fontWrapper = new CTFontWrapper(CTFont.Factory.newInstance());
-	}
-
-
-	public CTFont getCTFont(){
-		return fontWrapper.getCTFont();
-	}
-
-
-	public short getBoldweight() {
-		CTBooleanProperty bold=fontWrapper.getB();
-		if(bold!=null && bold.getVal())
-			return Font.BOLDWEIGHT_BOLD;
-		else
-			return Font.BOLDWEIGHT_NORMAL;
-	} 
-
-
-
-	public byte getCharSet() {
-		CTIntProperty charset= fontWrapper.getCharset();
-		if(charset!=null){
-			//this value must be set -- can't be null
-			switch (charset.getVal()) {
-			case Charset.ANSI_CHARSET:
-				return Font.ANSI_CHARSET;
-
-			case Charset.DEFAULT_CHARSET:
-				return Font.DEFAULT_CHARSET;
-
-			case Charset.SYMBOL_CHARSET:
-				return Font.SYMBOL_CHARSET;
-
-			default://maight be correct to return this byte value???
-				return Byte.parseByte(Integer.toString(charset.getVal()));
-			}
-		}
-		else
-			return Font.ANSI_CHARSET;
-	}
-
-	public short getColor() {
-		CTColor color=fontWrapper.getColor();
-		long index=color.getIndexed();
-		if (index==XSSFFont.DEFAULT_FONT_COLOR){
-			return Font.COLOR_NORMAL;
-		}
-		else if(index==IndexedColors.RED){
-			return Font.COLOR_RED;
-		}
-		else{
-			return Short.parseShort(new Long(index).toString());
-		}
-	}
-
-	public short getFontHeight() {
-		if(fontWrapper.getSz()!=null){
-			double fontHeight= fontWrapper.getSz().getVal()/20;
-			return (short)fontHeight;
-		}
-		else
-			return DEFAULT_FONT_SIZE/20;
-	}
-
-	public short getFontHeightInPoints() {
-		if(fontWrapper.getSz()!=null){
-			double fontHeight= fontWrapper.getSz().getVal();// /72;
-			return (short)fontHeight;//new Double(fontHeight).shortValue();
-		}
-		else
-			return DEFAULT_FONT_SIZE;
-	}
-
-	//AGGIUNGERE CONTROLLO NULL
-	public String getFontName() {	
-		if(fontWrapper.getName()!=null)
-			return fontWrapper.getName().getVal();
-		else
-			return DEFAULT_FONT_NAME;
-	}
-
-
-	public short getIndex() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	public boolean getItalic() {
-		if(fontWrapper.getI()!=null)
-			return fontWrapper.getI().getVal();
-		else
-			return false;
-	}
-
-	public boolean getStrikeout() {
-		if(fontWrapper.getStrike()!=null)
-			return fontWrapper.getStrike().getVal();
-		else
-			return false;
-	}
-
-	public short getTypeOffset() {
-		if(fontWrapper.getVertAlign()!=null){
-			int val=fontWrapper.getVertAlign().getVal().intValue();
-			switch (val) {
-			case STVerticalAlignRun.INT_BASELINE:
-				return Font.SS_NONE;
-			case STVerticalAlignRun.INT_SUBSCRIPT:
-				return Font.SS_SUB;
-			case STVerticalAlignRun.INT_SUPERSCRIPT:
-				return Font.SS_SUPER;
-			default: throw new RuntimeException("Wrong offset value "+val);
-			}
-		}
-		else
-			return Font.SS_NONE;
-	}
-
-	public byte getUnderline() {		
-		if(fontWrapper.getU()!=null){
-			//attenzione : -- get val pu˜ tornare null----
-			switch (fontWrapper.getU().getVal().intValue()) {
-			case STUnderlineValues.INT_DOUBLE:
-				return Font.U_DOUBLE;	
-			case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
-				return Font.U_DOUBLE_ACCOUNTING;	
-
-			case STUnderlineValues.INT_SINGLE_ACCOUNTING:
-				return Font.U_SINGLE_ACCOUNTING;	
-
-			case STUnderlineValues.INT_NONE:
-				return Font.U_NONE;
-
-			case STUnderlineValues.INT_SINGLE:	
-			default:
-				return Font.U_SINGLE;
-			}
-		}
-		return Font.U_NONE;
-	}
-
-	public void setBoldweight(short boldweight) {		
-		if(boldweight==Font.BOLDWEIGHT_BOLD){
-
-			CTBooleanProperty bold;
-			if(fontWrapper.getCTFont().getBArray().length==0){
-				bold=fontWrapper.getCTFont().addNewB();
-			}
-			else{
-				bold=CTBooleanProperty.Factory.newInstance();
-			}
-			bold.setVal(true);
-			fontWrapper.setB(bold);
-		}
-	}
-
-	public void setCharSet(byte charset) {
-		CTIntProperty charsetProperty;
-		if(fontWrapper.getCTFont().getCharsetArray().length==0){
-			charsetProperty=fontWrapper.getCTFont().addNewCharset();
-		}
-		else{
-			charsetProperty=CTIntProperty.Factory.newInstance();
-		}
-		switch (charset) {
-		case Font.ANSI_CHARSET:
-			charsetProperty.setVal(Charset.ANSI_CHARSET);	
-			break;
-		case Font.SYMBOL_CHARSET:
-			charsetProperty.setVal(Charset.SYMBOL_CHARSET);	
-			break;
-		case Font.DEFAULT_CHARSET:
-			charsetProperty.setVal(Charset.DEFAULT_CHARSET);	
-			break;
-		default:
-			throw new RuntimeException("Attention: an attempt to set a type of unknow charset and charset");
-		}
-
-		fontWrapper.setCharset(charsetProperty);
-	}
-
-
-	public void setColor(short color) {
-		CTColor ctColor;
-		if(fontWrapper.getCTFont().getColorArray().length==0){
-			ctColor=fontWrapper.getCTFont().addNewColor();
-		}
-		else{
-			ctColor=CTColor.Factory.newInstance();
-		}
-		
-		switch (color) {
-		case Font.COLOR_NORMAL:{
-			ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
-			break;
-		}
-		case Font.COLOR_RED:{
-			ctColor.setIndexed(IndexedColors.RED);
-			break;
-		}
-		default:
-			ctColor.setIndexed(color);
-		}
-
-		fontWrapper.setColor(ctColor);
-	}
-
-
-
-	public void setFontHeight(short height) {
-		CTFontSize fontSize;
-		if(fontWrapper.getCTFont().getSzArray().length==0){
-			fontSize=fontWrapper.getCTFont().addNewSz();
-		}
-		else{
-			fontSize=CTFontSize.Factory.newInstance();
-		}
-		fontSize.setVal(height*20);
-		fontWrapper.setSz(fontSize);
-	}
-
-
-	public void setFontHeightInPoints(short height) {
-		CTFontSize fontSize;
-		if(fontWrapper.getCTFont().getSzArray().length==0){
-			fontSize=fontWrapper.getCTFont().addNewSz();
-		}
-		else{
-			fontSize=CTFontSize.Factory.newInstance();
-		}
-
-		fontSize.setVal(height);
-		fontWrapper.setSz(fontSize);
-	}
-
-
-
-	public void setFontName(String name) {
-		CTFontName fontName;
-		if(fontWrapper.getCTFont().getNameArray().length==0){
-			fontName=fontWrapper.getCTFont().addNewName();
-		}
-		else{
-			fontName=CTFontName.Factory.newInstance();
-		}
-
-		fontName.setVal(name);
-		fontWrapper.setName(fontName);	
-	}
-	
-
-	public void setItalic(boolean italic) {
-		CTBooleanProperty bool;
-		if(fontWrapper.getCTFont().getIArray().length==0){
-			bool=fontWrapper.getCTFont().addNewI();			
-		}
-		else{
-			bool=CTBooleanProperty.Factory.newInstance();
-		}
-
-		bool.setVal(italic);
-		fontWrapper.setI(bool);
-	}
-
-	public void setStrikeout(boolean strikeout) {
-		CTBooleanProperty strike;
-		if(fontWrapper.getCTFont().getStrikeArray().length==0){
-			strike=fontWrapper.getCTFont().addNewStrike();
-		}
-		else{
-			strike=CTBooleanProperty.Factory.newInstance();
-		}
-		strike.setVal(strikeout);
-		fontWrapper.setStrike(strike);
-	}
-
-	public void setTypeOffset(short offset) {
-		CTVerticalAlignFontProperty offsetProperty;
-		if(fontWrapper.getCTFont().getVertAlignArray().length==0){
-			offsetProperty=fontWrapper.getCTFont().addNewVertAlign();			
-		}
-		else{
-			offsetProperty=CTVerticalAlignFontProperty.Factory.newInstance();
-		}
-		switch (offset) {
-		case Font.SS_NONE:
-			offsetProperty.setVal(STVerticalAlignRun.BASELINE);
-			break;
-		case Font.SS_SUB:
-			offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
-			break;
-		case Font.SS_SUPER:
-			offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
-			break;
-		}
-		fontWrapper.setVertAlign(offsetProperty);
-	}
-
-	public void setUnderline(byte underline) {
-		CTUnderlineProperty ctUnderline;
-		if(fontWrapper.getCTFont().getUArray().length==0){
-			ctUnderline=fontWrapper.getCTFont().addNewU();
-		}
-		else{
-			ctUnderline=CTUnderlineProperty.Factory.newInstance();
-		}
-		switch (underline) {
-		case Font.U_DOUBLE:
-			ctUnderline.setVal(STUnderlineValues.DOUBLE);	
-			break;
-		case Font.U_DOUBLE_ACCOUNTING:
-			ctUnderline.setVal(STUnderlineValues.DOUBLE_ACCOUNTING);	
-			break;
-		case Font.U_SINGLE_ACCOUNTING:
-			ctUnderline.setVal(STUnderlineValues.SINGLE_ACCOUNTING);	
-			break;
-		case Font.U_NONE:
-			ctUnderline.setVal(STUnderlineValues.NONE);	
-			break;
-
-		case Font.U_SINGLE:
-		default:
-			ctUnderline.setVal(STUnderlineValues.SINGLE);
-		break;
-		}
-
-		fontWrapper.setU(ctUnderline);
-	}
-
-
-	public long putFont(LinkedList<CTFont> fonts) {
-		//TODO
-		/*
-		 * we need to implement a method equals to check that 2 instances of CTFont
-		 * are different by comparison of all font attributes.
-		 * NB: take a look to findFont method in XSSFWorkbook
-		 */
-		CTFont font=fontWrapper.getCTFont();
-		if(fonts.contains(font)) {
-			return fonts.indexOf(font);
-		}
-		fonts.add(font);
-		return fonts.size() - 1;
-	}
-
-	// solo di xssfFont - non di Font-
-	//sono utilizzati nel metodo createDefaultFont in StylesTable insta.
-
-	public int getScheme(){
-		int fontScheme = fontWrapper.getFontScheme().getVal().intValue();
-		switch (fontScheme) {
-		case STFontScheme.INT_MAJOR:
-			return XSSFFont.SCHEME_MAJOR; 
-		case STFontScheme.INT_MINOR:
-			return XSSFFont.SCHEME_MINOR;
-		case STFontScheme.INT_NONE:
-			return XSSFFont.SCHEME_NONE;
-
-		default:
-			return fontScheme;
-		} 
-	}
-
-
-	public void setScheme(int scheme){
-		CTFontScheme ctFontScheme;
-		if(fontWrapper.getCTFont().getSchemeArray().length==0){
-			ctFontScheme=fontWrapper.getCTFont().addNewScheme();
-		}
-		else{
-			ctFontScheme=CTFontScheme.Factory.newInstance();
-		}
-		switch (scheme) {
-		case XSSFFont.SCHEME_MAJOR:
-			ctFontScheme.setVal(STFontScheme.MAJOR);
-			break;
-		case XSSFFont.SCHEME_MINOR:
-			ctFontScheme.setVal(STFontScheme.MINOR);
-			break;
-		case XSSFFont.SCHEME_NONE:
-			ctFontScheme.setVal(STFontScheme.NONE);
-			break;
-		default:
-			throw new RuntimeException("Schema value ["+ scheme +"] not supported in XSSFFont");
-		}
-
-		fontWrapper.setFontScheme(ctFontScheme);
-	}	
-
-
-
-	public int getFamily(){
-		if(fontWrapper.getFamily()!=null)
-			return fontWrapper.getFamily().getVal();
-		else
-			return XSSFFont.FONT_FAMILY_SWISS;
-	}
-
-	public void setFamily(int value){
-		//TODO
-		CTIntProperty family;
-		if(fontWrapper.getCTFont().getSchemeArray().length==0){
-			family=fontWrapper.getCTFont().addNewFamily();
-		}
-		else{
-			family=CTIntProperty.Factory.newInstance();
-		}
-		family.setVal(value);
-		//fontWrapper.setFamily
-	}	
-
-
-
-}
+/* ====================================================================
+   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;
+
+import org.apache.poi.ss.usermodel.Font;
+
+import org.apache.poi.xssf.util.Charset;
+import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
+
+import java.util.ArrayList;
+
+public class XSSFFont implements Font {
+
+
+    public static final int SCHEME_MAJOR=2;
+    public static final int SCHEME_MINOR=3;
+    public static final int SCHEME_NONE=0;
+
+    public static final int FONT_FAMILY_NOT_APPLICABLE=0;
+    public static final int FONT_FAMILY_ROMAN=1;
+    public static final int FONT_FAMILY_SWISS=2;
+    public static final int FONT_FAMILY_MODERN=3;
+    public static final int FONT_FAMILY_SCRIPT=4;
+    public static final int FONT_FAMILY_DECORATIVE=5;
+
+
+    public static final String DEFAULT_FONT_NAME="Calibri";
+    public static final short DEFAULT_FONT_SIZE=11;
+    public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex();
+
+     private CTFont ctFont;
+
+    public XSSFFont(CTFont font) {
+         this.ctFont=font;
+    }
+
+     protected XSSFFont() {
+         this.ctFont = CTFont.Factory.newInstance();
+    }
+
+
+    public CTFont getCTFont(){
+         return ctFont;
+    }
+
+     /**
+      *
+      */
+     public boolean getBold() {
+         CTBooleanProperty bold=ctFont.sizeOfBArray() == 0 ? null : ctFont.getBArray(0);
+         return (bold!=null && bold.getVal());
+    }
+
+
+
+    public byte getCharSet() {
+         CTIntProperty charset= ctFont.sizeOfCharsetArray() == 0?null:ctFont.getCharsetArray(0);
+        if(charset!=null){
+            //this value must be set -- can't be null
+            switch (charset.getVal()) {
+            case Charset.ANSI_CHARSET:
+                return Font.ANSI_CHARSET;
+
+            case Charset.DEFAULT_CHARSET:
+                return Font.DEFAULT_CHARSET;
+
+            case Charset.SYMBOL_CHARSET:
+                return Font.SYMBOL_CHARSET;
+
+            default://maight be correct to return this byte value???
+                return Byte.parseByte(Integer.toString(charset.getVal()));
+            }
+        }
+        else
+            return Font.ANSI_CHARSET;
+    }
+
+    public short getColor() {
+        CTColor color=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
+        if(color == null) return Font.COLOR_NORMAL;
+        
+        long index=color.getIndexed();
+        if (index==XSSFFont.DEFAULT_FONT_COLOR){
+            return Font.COLOR_NORMAL;
+        }
+        else if(index == IndexedColors.RED.getIndex()){
+            return Font.COLOR_RED;
+        }
+        else{
+            return Short.parseShort(new Long(index).toString());
+        }
+    }
+
+
+     public byte[] getRgbColor() {
+         CTColor color=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
+         return color.getRgb();
+     }
+
+     public short getThemeColor() {
+         CTColor color=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
+         long index=color.getTheme();
+         return (short)index;
+     }
+
+
+    public short getFontHeight() {
+         CTFontSize size=ctFont.sizeOfSzArray()==0?null: ctFont.getSzArray(0);
+         if(size!=null){
+             double fontHeight= size.getVal()/20;
+            return (short)fontHeight;
+        }
+        else
+            return DEFAULT_FONT_SIZE/20;
+    }
+
+    public short getFontHeightInPoints() {
+         CTFontSize size=ctFont.sizeOfSzArray()==0?null: ctFont.getSzArray(0);
+         if(size!=null){
+             double fontHeight= size.getVal();
+             return (short)fontHeight;
+          }
+        else
+            return DEFAULT_FONT_SIZE;
+    }
+
+
+     public String getFontName() {
+         CTFontName name=ctFont.sizeOfNameArray()==0?null:ctFont.getNameArray(0);
+         return name==null? null:name.getVal();
+    }
+
+
+      public boolean getItalic() {
+         CTBooleanProperty italic=ctFont.sizeOfIArray()==0?null:ctFont.getIArray(0);
+         return italic!=null && italic.getVal();
+      }
+
+      public boolean getStrikeout() {
+         CTBooleanProperty strike=ctFont.sizeOfStrikeArray()==0?null:ctFont.getStrikeArray(0);
+         return strike!=null && strike.getVal();
+      }
+
+    public short getTypeOffset() {
+        CTVerticalAlignFontProperty vAlign=ctFont.sizeOfVertAlignArray()==0?null:ctFont.getVertAlignArray(0);
+        if(vAlign!=null){
+            int val=vAlign.getVal().intValue();
+            switch (val) {
+            case STVerticalAlignRun.INT_BASELINE:
+                return Font.SS_NONE;
+            case STVerticalAlignRun.INT_SUBSCRIPT:
+                return Font.SS_SUB;
+            case STVerticalAlignRun.INT_SUPERSCRIPT:
+                return Font.SS_SUPER;
+            default: throw new RuntimeException("Wrong offset value "+val);
+            }
+        }
+        else
+            return Font.SS_NONE;
+    }
+
+     public byte getUnderline() {
+         CTUnderlineProperty underline=ctFont.sizeOfUArray()==0?null:ctFont.getUArray(0);
+        if(underline!=null){
+             switch (underline.getVal().intValue()) {
+            case STUnderlineValues.INT_DOUBLE:
+                return Font.U_DOUBLE;
+            case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
+                return Font.U_DOUBLE_ACCOUNTING;
+
+            case STUnderlineValues.INT_SINGLE_ACCOUNTING:
+                return Font.U_SINGLE_ACCOUNTING;
+
+            case STUnderlineValues.INT_NONE:
+                return Font.U_NONE;
+
+            case STUnderlineValues.INT_SINGLE:
+            default:
+                return Font.U_SINGLE;
+            }
+        }
+        return Font.U_NONE;
+    }
+
+     /**
+      * Set characters in bold face font style.
+      * If omitted, the default value is true.
+      */
+     public void setBold(boolean bold) {
+         CTBooleanProperty ctBold=ctFont.sizeOfBArray()==0?ctFont.addNewB():ctFont.getBArray(0);
+         ctBold.setVal(true);
+      }
+
+     /**
+      *
+      */
+    public void setCharSet(byte charset) {
+         CTIntProperty charsetProperty=ctFont.sizeOfCharsetArray()==0?ctFont.addNewCharset():ctFont.getCharsetArray(0);
+        switch (charset) {
+        case Font.ANSI_CHARSET:
+            charsetProperty.setVal(Charset.ANSI_CHARSET);
+            break;
+        case Font.SYMBOL_CHARSET:
+            charsetProperty.setVal(Charset.SYMBOL_CHARSET);
+            break;
+        case Font.DEFAULT_CHARSET:
+            charsetProperty.setVal(Charset.DEFAULT_CHARSET);
+            break;
+        default:
+            throw new RuntimeException("Attention: an attempt to set a type of unknow charset and charset");
+        }
+    }
+
+
+    public void setColor(short color) {
+         CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
+
+        switch (color) {
+        case Font.COLOR_NORMAL:{
+            ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
+            break;
+        }
+        case Font.COLOR_RED:{
+            ctColor.setIndexed(IndexedColors.RED.getIndex());
+            break;
+        }
+        default:
+            ctColor.setIndexed(color);
+        }
+    }
+
+
+
+    public void setFontHeight(short height) {
+        CTFontSize fontSize=ctFont.sizeOfSzArray()==0?ctFont.addNewSz():ctFont.getSzArray(0);
+          fontSize.setVal(height*20);
+    }
+
+
+    public void setFontHeightInPoints(short height) {
+          CTFontSize fontSize=ctFont.sizeOfSzArray()==0?ctFont.addNewSz():ctFont.getSzArray(0);
+          fontSize.setVal(height);
+    }
+
+
+
+     public void setRgbColor(XSSFColor color) {
+         CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
+         ctColor.setRgb(color.getRgb());
+        }
+
+     public void setThemeColor(short theme) {
+         CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
+         ctColor.setTheme(theme);
+     }
+
+    public void setFontName(String name) {
+ 		CTFontName fontName=ctFont.sizeOfNameArray()==0?ctFont.addNewName():ctFont.getNameArray(0);
+ 		fontName.setVal(name);
+    }
+
+    public void setItalic(boolean italic) {
+         CTBooleanProperty bool=ctFont.sizeOfIArray()==0?ctFont.addNewI():ctFont.getIArray(0);
+          bool.setVal(italic);
+    }
+
+    public void setStrikeout(boolean strikeout) {
+         CTBooleanProperty strike=ctFont.sizeOfStrikeArray()==0?ctFont.addNewStrike():ctFont.getStrikeArray(0);
+          strike.setVal(strikeout);
+    }
+
+    public void setTypeOffset(short offset) {
+         CTVerticalAlignFontProperty offsetProperty=ctFont.sizeOfVertAlignArray()==0?ctFont.addNewVertAlign(): ctFont.getVertAlignArray(0);
+        switch (offset) {
+        case Font.SS_NONE:
+            offsetProperty.setVal(STVerticalAlignRun.BASELINE);
+            break;
+        case Font.SS_SUB:
+            offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
+            break;
+        case Font.SS_SUPER:
+            offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
+            break;
+        }
+    }
+
+    public void setUnderline(byte underline) {
+         CTUnderlineProperty ctUnderline=ctFont.sizeOfUArray()==0?ctFont.addNewU():ctFont.getUArray(0);
+        switch (underline) {
+        case Font.U_DOUBLE:
+            ctUnderline.setVal(STUnderlineValues.DOUBLE);
+            break;
+        case Font.U_DOUBLE_ACCOUNTING:
+            ctUnderline.setVal(STUnderlineValues.DOUBLE_ACCOUNTING);
+            break;
+        case Font.U_SINGLE_ACCOUNTING:
+            ctUnderline.setVal(STUnderlineValues.SINGLE_ACCOUNTING);
+            break;
+        case Font.U_NONE:
+            ctUnderline.setVal(STUnderlineValues.NONE);
+            break;
+
+        case Font.U_SINGLE:
+        default:
+            ctUnderline.setVal(STUnderlineValues.SINGLE);
+        break;
+        }
+    }
+
+
+     public long putFont(ArrayList<CTFont> fonts) {
+        //TODO
+        /*
+           * we need to implement a method equals to check that 2 instances of CTFont
+           * are different by comparison of all font attributes.
+           * NB: take a look to findFont method in XSSFWorkbook
+           */
+         if(fonts.contains(ctFont)) {
+             return fonts.indexOf(ctFont);
+        }
+         fonts.add(ctFont);
+        return fonts.size() - 1;
+    }
+
+    // solo di xssfFont - non di Font-
+    //sono utilizzati nel metodo createDefaultFont in StylesTable insta.
+
+    public int getScheme(){
+        CTFontScheme scheme=ctFont.sizeOfSchemeArray()==0?null:ctFont.getSchemeArray(0);
+        if(scheme!=null){
+            int fontScheme = scheme.getVal().intValue();
+            switch (fontScheme) {
+            case STFontScheme.INT_MAJOR:
+                return XSSFFont.SCHEME_MAJOR;
+            case STFontScheme.INT_MINOR:
+                return XSSFFont.SCHEME_MINOR;
+            case STFontScheme.INT_NONE:
+                return XSSFFont.SCHEME_NONE;
+
+            default:
+                return fontScheme;
+            }
+        }
+        return 0;
+    }
+
+
+      public void setScheme(int scheme){
+         CTFontScheme ctFontScheme=ctFont.sizeOfSchemeArray()==0?ctFont.addNewScheme():ctFont.getSchemeArray(0);
+        switch (scheme) {
+        case XSSFFont.SCHEME_MAJOR:
+            ctFontScheme.setVal(STFontScheme.MAJOR);
+            break;
+        case XSSFFont.SCHEME_MINOR:
+            ctFontScheme.setVal(STFontScheme.MINOR);
+            break;
+        case XSSFFont.SCHEME_NONE:
+            ctFontScheme.setVal(STFontScheme.NONE);
+            break;
+        default:
+            throw new RuntimeException("Schema value ["+ scheme +"] not supported in XSSFFont");
+        }
+    }
+
+
+      public int getFamily(){
+         CTIntProperty family=ctFont.sizeOfFamilyArray()==0?ctFont.addNewFamily():ctFont.getFamilyArray(0);
+         if(family!=null)
+             return family.getVal();
+          else
+              return XSSFFont.FONT_FAMILY_SWISS;
+      }
+
+      public void setFamily(int value){
+         CTIntProperty family=ctFont.sizeOfFamilyArray()==0?ctFont.addNewFamily():ctFont.getFamilyArray(0);
+          family.setVal(value);
+     }
+
+}

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=696584&r1=696583&r2=696584&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Thu Sep 18 00:42:40 2008
@@ -20,8 +20,9 @@
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.xssf.model.StylesTable;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+
+import java.util.ArrayList;
 
 
 /**
@@ -30,23 +31,11 @@
  * <p>
  * Most strings in a workbook have formatting applied at the cell level, that is, the entire string in the cell has the
  * same formatting applied. In these cases, the formatting for the cell is stored in the styles part,
- * and the string for the cell can be shared across the workbook. The following xml and code snippet illustrate the example.
+ * and the string for the cell can be shared across the workbook. The following code illustrates the example.
  * </p>
  *
  * <blockquote>
  * <pre>
- * &lt;sst xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/5/main
- * count="1" uniqueCount="1">
- * &lt;si&gt;
- * &lt;t&gt;Apache POI&lt;/t&gt;
- * &lt;/si&gt;
- * &lt;/sst&gt;
- * </pre>
- * </blockquote>
- *
- * The code to produce xml above:
- * <blockquote>
- * <pre>
  *     cell1.setCellValue(new XSSFRichTextString("Apache POI"));
  *     cell2.setCellValue(new XSSFRichTextString("Apache POI"));
  *     cell3.setCellValue(new XSSFRichTextString("Apache POI"));
@@ -73,56 +62,32 @@
  * </pre>
  * </blockquote>
  *
- * The code above will produce the following xml:
- * <blockquote>
- * <pre>
- * &lt;sst xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/5/main count="2" uniqueCount="2"&gt;
- *  &lt;si&gt;
- *    &lt;r&gt;
- *      &lt;rPr&gt;
- *        &lt;b/&gt;
- *        &lt;sz val="11"/&gt;
- *        &lt;color theme="1"/&gt;
- *        &lt;rFont val="Arial"/&gt;
- *        &lt;family val="2"/&gt;
- *        &lt;scheme val="minor"/&gt;
- *      &lt;/rPr&gt;
- *      &lt;t&gt;Apache POI&lt;/t&gt;
- *    &lt;/r&gt;
- *  &lt;/si&gt;
- *  &lt;si&gt;
- *    &lt;r&gt;
- *      &lt;rPr&gt;
- *       &lt;i/&gt;
- *       &lt;sz val="11"/&gt;
- *        &lt;color theme="1"/&gt;
- *        &lt;rFont val="Courier"/&gt;
- *        &lt;family val="1"/&gt;
- *        &lt;scheme val="minor"/&gt;
- *      &lt;/rPr&gt;
- *      &lt;t&gt;Apache POI&lt;/t&gt;
- *    &lt;/r&gt;
- *  &lt;/si&gt;
- *&lt;/sst&gt;
- *
- * </pre>
- * </blockquote>
  *
  * @author Yegor Kozlov
  */
 public class XSSFRichTextString implements RichTextString {
     private CTRst st;
     private StylesTable styles;
+    private ArrayList<CTRPrElt> fontIdRuns;
 
+    /**
+     * Create a rich text string and initialize it with empty string
+     */
     public XSSFRichTextString(String str) {
         st = CTRst.Factory.newInstance();
         st.setT(str);
     }
 
+    /**
+     * Create empty rich text string
+     */
     public XSSFRichTextString() {
         st = CTRst.Factory.newInstance();
     }
 
+    /**
+     * Create a rich text string from the supplied XML bean
+     */
     public XSSFRichTextString(CTRst st) {
         this.st = st;
     }
@@ -135,8 +100,17 @@
      * @param fontIndex     The font to use.
      */
     public void applyFont(int startIndex, int endIndex, short fontIndex) {
-        // TODO Auto-generated method stub
-
+        XSSFFont font;
+        if(styles == null) {
+            //style table is not set, remember fontIndex and set the run properties later,
+            //when setStylesTableReference is called
+            font = new XSSFFont();
+            font.setFontName("#" + fontIndex);
+            fontIdRuns = new ArrayList<CTRPrElt>();
+        } else {
+            font = (XSSFFont)styles.getFontAt(fontIndex);
+        }
+        applyFont(startIndex, endIndex, font);
     }
 
     /**
@@ -147,7 +121,69 @@
      * @param font          The index of the font to use.
      */
     public void applyFont(int startIndex, int endIndex, Font font) {
-        applyFont(0, length(), font.getIndex());
+        if (startIndex > endIndex)
+            throw new IllegalArgumentException("Start index must be less than end index.");
+        if (startIndex < 0 || endIndex > length())
+            throw new IllegalArgumentException("Start and end index not in range.");
+        if (startIndex == endIndex)
+            return;
+
+        if(st.sizeOfRArray() == 0 && st.isSetT()) {
+            //convert <t>string</t> into a text run: <r><t>string</t></r>
+            st.addNewR().setT(st.getT());
+            st.unsetT();
+        }
+
+        String text = getString();
+
+        XSSFFont xssfFont = (XSSFFont)font;
+        ArrayList<CTRElt> runs = new ArrayList<CTRElt>();
+
+        int pos = 0;
+        int i;
+        for (i = 0; i < st.sizeOfRArray(); i++) {
+            CTRElt r = st.getRArray(i);
+
+            int len = r.getT().length();
+            int p1 = pos;
+            int p2 = pos + len;
+            if(startIndex > p2) {
+                runs.add(r);
+            } else if (startIndex >= p1 && startIndex < p2){
+                String t = r.getT();
+                r.setT(t.substring(0, startIndex-p1));
+                runs.add(r);
+            } else {
+                break;
+            }
+            pos = p2;
+        }
+        CTRElt r = CTRElt.Factory.newInstance();
+        r.setT(text.substring(startIndex, endIndex));
+        CTRPrElt pr = r.addNewRPr();
+        setRunAttributes(xssfFont.getCTFont(), pr);
+        if(fontIdRuns != null) fontIdRuns.add(pr);
+        runs.add(r);
+
+        for (; i < st.sizeOfRArray(); i++) {
+            r = st.getRArray(i);
+
+            int len = r.getT().length();
+            int p1 = pos;
+            int p2 = pos + len;
+            if(endIndex > p2) {
+                ;
+            } else if (endIndex >= p1 && endIndex < p2){
+                String t = r.getT();
+                r.setT(t.substring(endIndex-p1, len));
+                runs.add(r);
+            } else {
+                runs.add(r);
+            }
+            pos = p2;
+        }
+
+        st.setRArray(runs.toArray(new CTRElt[runs.size()]));
     }
 
     /**
@@ -155,7 +191,20 @@
      * @param font          The font to use.
      */
     public void applyFont(Font font) {
-        applyFont(0, length(), font);
+        if(st.sizeOfRArray() == 0 && st.isSetT()) {
+            CTRElt r = st.addNewR();
+            r.setT(st.getT());
+            setRunAttributes(((XSSFFont)font).getCTFont(), r.addNewRPr());
+            st.unsetT();
+        } else {
+            CTRElt r = CTRElt.Factory.newInstance();
+            r.setT(getString());
+            setRunAttributes(((XSSFFont)font).getCTFont(), r.addNewRPr());
+            st.setRArray(new CTRElt[]{r});
+        }
+
+        if(fontIdRuns != null) fontIdRuns.add(st.getRArray(0).getRPr());
+
     }
 
     /**
@@ -164,50 +213,118 @@
      * @param fontIndex  the font to apply.
      */
     public void applyFont(short fontIndex) {
-        applyFont(0, length(), fontIndex);
+        XSSFFont font;
+        if(styles == null) {
+            font = new XSSFFont();
+            font.setFontName("#" + fontIndex);
+            fontIdRuns = new ArrayList<CTRPrElt>();
+        } else {
+            font = (XSSFFont)styles.getFontAt(fontIndex);
+        }
+        applyFont(font);
     }
 
     /**
-     * Removes any formatting that may have been applied to the string.
+     * Append new text to this text run and apply the specify font to it
+     *
+     * @param text  the text to append
+     * @param font  the font to apply to the appended text or <code>null</code> if no formatting is required
      */
-    public void clearFormatting() {
-        for (int i = 0; i < st.sizeOfRArray(); i++) {
-            st.removeR(i);
+    public void append(String text, XSSFFont font){
+        if(st.sizeOfRArray() == 0 && st.isSetT()) {
+            //convert <t>string</t> into a text run: <r><t>string</t></r>
+            st.addNewR().setT(st.getT());
+            st.unsetT();
         }
+        CTRElt lt = st.addNewR();
+        lt.setT(text);
+        CTRPrElt pr = lt.addNewRPr();
+        if(font != null) setRunAttributes(font.getCTFont(), pr);
+
+        if(fontIdRuns != null) fontIdRuns.add(pr);
     }
 
     /**
-     * Returns the font in use at a particular index.
+     * Append new text to this text run
      *
-     * @param index         The index.
-     * @return              The font that's currently being applied at that
-     *                      index or null if no font is being applied or the
-     *                      index is out of range.
+     * @param text  the text to append
      */
-    public short getFontAtIndex(int index) {
-        // TODO Auto-generated method stub
-        return 0;
+    public void append(String text){
+        append(text, null);
     }
 
     /**
-     * Gets the font used in a particular formatting run.
-     *
-     * @param index     the index of the formatting run
-     * @return  the font number used.
+     * Copy font attributes from CTFont bean into CTRPrElt bean
      */
-    public short getFontOfFormattingRun(int index) {
-        // TODO Auto-generated method stub
-        return 0;
+    private void setRunAttributes(CTFont ctFont, CTRPrElt pr){
+        if(ctFont.sizeOfBArray() > 0) pr.addNewB().setVal(ctFont.getBArray(0).getVal());
+        if(ctFont.sizeOfUArray() > 0) pr.addNewU().setVal(ctFont.getUArray(0).getVal());
+        if(ctFont.sizeOfIArray() > 0) pr.addNewI().setVal(ctFont.getIArray(0).getVal());
+        if(ctFont.sizeOfColorArray() > 0) {
+            CTColor c1 = ctFont.getColorArray(0);
+            CTColor c2 = pr.addNewColor();
+            if(c1.isSetAuto()) c2.setAuto(c1.getAuto());
+            if(c1.isSetIndexed()) c2.setIndexed(c1.getIndexed());
+            if(c1.isSetRgb()) c2.setRgb(c1.getRgb());
+            if(c1.isSetTheme()) c2.setTheme(c1.getTheme());
+            if(c1.isSetTint()) c2.setTint(c1.getTint());
+        }
+        if(ctFont.sizeOfNameArray() > 0) pr.addNewRFont().setVal(ctFont.getNameArray(0).getVal());
+        if(ctFont.sizeOfFamilyArray() > 0) pr.addNewFamily().setVal(ctFont.getFamilyArray(0).getVal());
+        if(ctFont.sizeOfSchemeArray() > 0) pr.addNewScheme().setVal(ctFont.getSchemeArray(0).getVal());
+        if(ctFont.sizeOfCharsetArray() > 0) pr.addNewCharset().setVal(ctFont.getCharsetArray(0).getVal());
+        if(ctFont.sizeOfCondenseArray() > 0) pr.addNewCondense().setVal(ctFont.getCondenseArray(0).getVal());
+        if(ctFont.sizeOfExtendArray() > 0) pr.addNewExtend().setVal(ctFont.getExtendArray(0).getVal());
+        if(ctFont.sizeOfVertAlignArray() > 0) pr.addNewVertAlign().setVal(ctFont.getVertAlignArray(0).getVal());
+        if(ctFont.sizeOfOutlineArray() > 0) pr.addNewOutline().setVal(ctFont.getOutlineArray(0).getVal());
+        if(ctFont.sizeOfShadowArray() > 0) pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
+        if(ctFont.sizeOfStrikeArray() > 0) pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
+    }
+
+    /**
+     * Removes any formatting that may have been applied to the string.
+     */
+    public void clearFormatting() {
+        String text = getString();
+        while (st.sizeOfRArray() > 0) {
+            st.removeR(st.sizeOfRArray()-1);
+        }
+        st.setT(text);
     }
 
     /**
      * The index within the string to which the specified formatting run applies.
+     *
      * @param index     the index of the formatting run
      * @return  the index within the string.
      */
     public int getIndexOfFormattingRun(int index) {
-        // TODO Auto-generated method stub
-        return 0;
+        if(st.sizeOfRArray() == 0) return 0;
+
+        int pos = 0;
+        for(int i = 0; i < st.sizeOfRArray(); i++){
+            CTRElt r = st.getRArray(i);
+            if(i == index) return pos;
+
+            pos += r.getT().length();
+        }
+        return -1;
+    }
+
+    /**
+     * Returns the number of characters this format run covers.
+     *
+     * @param index     the index of the formatting run
+     * @return  the number of characters this format run covers
+     */
+    public int getLengthOfFormattingRun(int index) {
+        if(st.sizeOfRArray() == 0) return length();
+
+        for(int i = 0; i < st.sizeOfRArray(); i++){
+            CTRElt r = st.getRArray(i);
+            if(i == index) return r.getT().length();
+        }
+        return -1;
     }
 
     /**
@@ -256,6 +373,44 @@
     }
 
     /**
+     * Gets a copy of the font used in a particular formatting run.
+     *
+     * @param index     the index of the formatting run
+     * @return  A copy of the  font used or null if no formatting is applied to the specified text run.
+     */
+    public XSSFFont getFontOfFormattingRun(int index) {
+        if(st.sizeOfRArray() == 0) return null;
+
+        for(int i = 0; i < st.sizeOfRArray(); i++){
+            CTRElt r = st.getRArray(i);
+            if(i == index) return new XSSFFont(toCTFont(r.getRPr()));
+        }
+        return null;
+    }
+
+    /**
+     * Return a copy of the font in use at a particular index.
+     *
+     * @param index         The index.
+     * @return              A copy of the  font that's currently being applied at that
+     *                      index or null if no font is being applied or the
+     *                      index is out of range.
+     */
+    public XSSFFont getFontAtIndex( int index ) {
+        if(st.sizeOfRArray() == 0) return null;
+
+        int pos = 0;
+        for(int i = 0; i < st.sizeOfRArray(); i++){
+            CTRElt r = st.getRArray(i);
+            if(index >= pos && index < pos + r.getT().length()) return new XSSFFont(toCTFont(r.getRPr()));
+
+            pos += r.getT().length();
+        }
+        return null;
+
+    }
+
+    /**
      * Return the underlying xml bean
      */
     public CTRst getCTRst() {
@@ -264,5 +419,51 @@
 
     protected void setStylesTableReference(StylesTable tbl){
         styles = tbl;
+        if(fontIdRuns != null){
+            for (CTRPrElt pr : fontIdRuns) {
+                if(pr.sizeOfRFontArray() > 0 ) {
+                    String fontName = pr.getRFontArray(0).getVal();
+                    if(fontName.startsWith("#")){
+                        int idx = Integer.parseInt(fontName.substring(1));
+                        XSSFFont font = (XSSFFont)styles.getFontAt(idx);
+                        pr.removeRFont(0);
+                        setRunAttributes(font.getCTFont(), pr);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     *
+     * CTRPrElt --> CTFont adapter
+     */
+    protected static CTFont toCTFont(CTRPrElt pr){
+        CTFont ctFont =  CTFont.Factory.newInstance();
+
+        if(pr.sizeOfBArray() > 0) ctFont.addNewB().setVal(pr.getBArray(0).getVal());
+        if(pr.sizeOfUArray() > 0) ctFont.addNewU().setVal(pr.getUArray(0).getVal());
+        if(pr.sizeOfIArray() > 0) ctFont.addNewI().setVal(pr.getIArray(0).getVal());
+        if(pr.sizeOfColorArray() > 0) {
+            CTColor c1 = pr.getColorArray(0);
+            CTColor c2 = ctFont.addNewColor();
+            if(c1.isSetAuto()) c2.setAuto(c1.getAuto());
+            if(c1.isSetIndexed()) c2.setIndexed(c1.getIndexed());
+            if(c1.isSetRgb()) c2.setRgb(c1.getRgb());
+            if(c1.isSetTheme()) c2.setTheme(c1.getTheme());
+            if(c1.isSetTint()) c2.setTint(c1.getTint());
+        }
+        if(pr.sizeOfRFontArray() > 0) ctFont.addNewName().setVal(pr.getRFontArray(0).getVal());
+        if(pr.sizeOfFamilyArray() > 0) ctFont.addNewFamily().setVal(pr.getFamilyArray(0).getVal());
+        if(pr.sizeOfSchemeArray() > 0) ctFont.addNewScheme().setVal(pr.getSchemeArray(0).getVal());
+        if(pr.sizeOfCharsetArray() > 0) ctFont.addNewCharset().setVal(pr.getCharsetArray(0).getVal());
+        if(pr.sizeOfCondenseArray() > 0) ctFont.addNewCondense().setVal(pr.getCondenseArray(0).getVal());
+        if(pr.sizeOfExtendArray() > 0) ctFont.addNewExtend().setVal(pr.getExtendArray(0).getVal());
+        if(pr.sizeOfVertAlignArray() > 0) ctFont.addNewVertAlign().setVal(pr.getVertAlignArray(0).getVal());
+        if(pr.sizeOfOutlineArray() > 0) ctFont.addNewOutline().setVal(pr.getOutlineArray(0).getVal());
+        if(pr.sizeOfShadowArray() > 0) ctFont.addNewShadow().setVal(pr.getShadowArray(0).getVal());
+        if(pr.sizeOfStrikeArray() > 0) ctFont.addNewStrike().setVal(pr.getStrikeArray(0).getVal());
+
+        return ctFont;
     }
 }

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -134,6 +134,8 @@
         if (this.worksheet.getSheetData() == null) {
         	this.worksheet.addNewSheetData();
         }
+        //CTSheetView sheetView = getSheetTypeSheetView();
+        //sheetView.setWorkbookViewId(0);
         initRows(this.worksheet);
         initColumns(this.worksheet);
         
@@ -984,8 +986,17 @@
     }
 
     // HSSFSheet compatibility methods. See also the following zoom related methods
+    /**
+     * Sets the zoom magnication for the sheet.  The zoom is expressed as a
+     * fraction.  For example to express a zoom of 75% use 3 for the numerator
+     * and 4 for the denominator.
+     *
+     * @param numerator     The numerator for the zoom magnification.
+     * @param denominator   The denominator for the zoom magnification.
+     */    
     public void setZoom(int numerator, int denominator) {
-    	setZoom((numerator/denominator) * 100);
+        Float result = new Float(numerator)/new Float(denominator)*100;
+    	setZoom(result.intValue());
     }
 
     public void setZoom(long scale) {

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
@@ -102,6 +103,10 @@
     public XSSFWorkbook(String path) throws IOException {
     	this(openPackage(path));
     }
+    public XSSFWorkbook(InputStream  is) throws IOException {
+    	this(openPackage(is));
+    }
+
     public XSSFWorkbook(Package pkg) throws IOException {
         super(pkg);
         try {
@@ -299,11 +304,11 @@
 
     }
 
-    public Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
+    public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
     	short fontNum=getNumberOfFonts();
-        for (short i = 0; i <= fontNum; i++) {
-            XSSFFont xssfFont = (XSSFFont)getFontAt(i);
-            if (xssfFont.getBoldweight() == boldWeight
+        for (short i = 0; i < fontNum; i++) {
+            XSSFFont xssfFont = getFontAt(i);
+            if (    xssfFont.getBold() == (boldWeight == XSSFFont.BOLDWEIGHT_BOLD)
                     && xssfFont.getColor() == color
                     && xssfFont.getFontHeightInPoints() == fontHeight
                     && xssfFont.getFontName().equals(name)
@@ -384,8 +389,8 @@
         return (short) getFirstVisibleTab();
     }
 
-    public Font getFontAt(short idx) {
-        return stylesSource.getFontAt(idx);
+    public XSSFFont getFontAt(short idx) {
+        return (XSSFFont)stylesSource.getFontAt(idx);
     }
 
     public XSSFName getNameAt(int index) {
@@ -418,7 +423,7 @@
 
     public short getNumberOfFonts() {
         // TODO Auto-generated method stub
-        return 0;
+        return (short)((StylesTable)stylesSource).getNumberOfFonts();
     }
 
     public int getNumberOfNames() {

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=696584&r1=696583&r2=696584&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 Thu Sep 18 00:42:40 2008
@@ -70,7 +70,7 @@
 	}
 
 	public void setBorderColor(BorderSide side, XSSFColor color) {
-		color.setToBorder(getBorder(side));
+		getBorder(side).setColor(color.getCTColor());
 	}
 	
 	private CTBorderPr getBorder(BorderSide side) {



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


Mime
View raw message