Author: centic
Date: Sat Oct 26 07:31:47 2013
New Revision: 1535938

URL: http://svn.apache.org/r1535938
Log:
Bug 49940: Apply patch to avoid XmlValueDisconnectedException when
saving a file twice and enable reproducing unit test

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=1535938&r1=1535937&r2=1535938&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Sat Oct 
26 07:31:47 2013
@@ -39,22 +39,7 @@ import org.apache.poi.xssf.usermodel.ext
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxfs;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFills;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
-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.STPatternType;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 
 /**
@@ -367,7 +352,7 @@ public class StylesTable extends POIXMLD
                // Work on the current one
                // Need to do this, as we don't handle
                //  all the possible entries yet
-        CTStylesheet styleSheet = doc.getStyleSheet();
+               CTStylesheet styleSheet = doc.getStyleSheet();
 
                // Formats
                CTNumFmts formats = CTNumFmts.Factory.newInstance();
@@ -381,7 +366,10 @@ public class StylesTable extends POIXMLD
 
                int idx;
                // Fonts
-               CTFonts ctFonts = CTFonts.Factory.newInstance();
+               CTFonts ctFonts = styleSheet.getFonts();
+               if (ctFonts == null) {
+                       ctFonts = CTFonts.Factory.newInstance();
+               }
                ctFonts.setCount(fonts.size());
                CTFont[] ctfnt = new CTFont[fonts.size()];
                idx = 0;
@@ -390,7 +378,10 @@ public class StylesTable extends POIXMLD
                styleSheet.setFonts(ctFonts);
 
                // Fills
-               CTFills ctFills = CTFills.Factory.newInstance();
+               CTFills ctFills = styleSheet.getFills();
+               if (ctFills == null) {
+                       ctFills = CTFills.Factory.newInstance();
+               }
                ctFills.setCount(fills.size());
                CTFill[] ctf = new CTFill[fills.size()];
                idx = 0;
@@ -399,7 +390,10 @@ public class StylesTable extends POIXMLD
                styleSheet.setFills(ctFills);
 
                // Borders
-               CTBorders ctBorders = CTBorders.Factory.newInstance();
+               CTBorders ctBorders = styleSheet.getBorders();
+               if (ctBorders == null) {
+                       ctBorders = CTBorders.Factory.newInstance();
+               }
                ctBorders.setCount(borders.size());
                CTBorder[] ctb = new CTBorder[borders.size()];
                idx = 0;
@@ -409,7 +403,10 @@ public class StylesTable extends POIXMLD
 
                // Xfs
                if(xfs.size() > 0) {
-                       CTCellXfs ctXfs = CTCellXfs.Factory.newInstance();
+                       CTCellXfs ctXfs = styleSheet.getCellXfs();
+                       if (ctXfs == null) {
+                               ctXfs = CTCellXfs.Factory.newInstance();
+                       }
                        ctXfs.setCount(xfs.size());
                        ctXfs.setXfArray(
                                        xfs.toArray(new CTXf[xfs.size()])
@@ -419,7 +416,10 @@ public class StylesTable extends POIXMLD
 
                // Style xfs
                if(styleXfs.size() > 0) {
-                       CTCellStyleXfs ctSXfs = 
CTCellStyleXfs.Factory.newInstance();
+                       CTCellStyleXfs ctSXfs = styleSheet.getCellStyleXfs();
+                       if (ctSXfs == null) {
+                               ctSXfs = CTCellStyleXfs.Factory.newInstance();
+                       }
                        ctSXfs.setCount(styleXfs.size());
                        ctSXfs.setXfArray(
                                        styleXfs.toArray(new 
CTXf[styleXfs.size()])
@@ -429,7 +429,10 @@ public class StylesTable extends POIXMLD
 
                // Style dxfs
                if(dxfs.size() > 0) {
-                       CTDxfs ctDxfs = CTDxfs.Factory.newInstance();
+                       CTDxfs ctDxfs = styleSheet.getDxfs();
+                       if (ctDxfs == null) {
+                               ctDxfs = CTDxfs.Factory.newInstance();
+                       }
                        ctDxfs.setCount(dxfs.size());
                        ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
                        );

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1535938&r1=1535937&r2=1535938&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java 
(original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java 
Sat Oct 26 07:31:47 2013
@@ -35,24 +35,7 @@ import org.apache.poi.ss.formula.Workboo
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.functions.Function;
-import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CellValue;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Comment;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaError;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Name;
-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.ss.usermodel.WorkbookFactory;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
@@ -181,7 +164,7 @@ public final class TestXSSFBugs extends 
      *  read the file despite the naughtyness
      */
     public void test49020() throws Exception {
-       XSSFWorkbook wb = 
XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx");
+       /*XSSFWorkbook wb =*/ 
XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx");
     }
 
     /**
@@ -326,9 +309,9 @@ public final class TestXSSFBugs extends 
           assertEquals(startingFonts+1, wb.getNumberOfFonts());
           
           // Get two more, unchanged
-          Font b = wb.createFont();
+          /*Font b =*/ wb.createFont();
           assertEquals(startingFonts+2, wb.getNumberOfFonts());
-          Font c = wb.createFont();
+          /*Font c =*/ wb.createFont();
           assertEquals(startingFonts+3, wb.getNumberOfFonts());
        }
     }
@@ -550,9 +533,8 @@ public final class TestXSSFBugs extends 
     
     /**
      * Repeatedly writing the same file which has styles
-     * TODO Currently failing
      */
-    public void DISABLEDtest49940() throws Exception {
+    public void test49940() throws Exception {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx");
        assertEquals(3, wb.getNumberOfSheets());
        assertEquals(10, wb.getStylesSource().getNumCellStyles());
@@ -1004,7 +986,8 @@ public final class TestXSSFBugs extends 
      * Setting repeating rows and columns shouldn't break
      *  any print settings that were there before
      */
-    public void test49253() throws Exception {
+    @SuppressWarnings("deprecation")
+       public void test49253() throws Exception {
        XSSFWorkbook wb1 = new XSSFWorkbook();
        XSSFWorkbook wb2 = new XSSFWorkbook();
        
@@ -1342,7 +1325,7 @@ public final class TestXSSFBugs extends 
         assertEquals(259.0, a1Value, 0.0);
 
         // KY: SUM(B1: IZ1)
-        double ky1Value =
+        /*double ky1Value =*/
                 
evaluator.evaluate(workbook.getSheetAt(0).getRow(0).getCell(310)).getNumberValue();
 
         // Assert



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

Reply via email to