]> source.dussan.org Git - poi.git/commitdiff
Bug 49940: Apply patch to avoid XmlValueDisconnectedException when
authorDominik Stadler <centic@apache.org>
Sat, 26 Oct 2013 07:31:47 +0000 (07:31 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 26 Oct 2013 07:31:47 +0000 (07:31 +0000)
saving a file twice and enable reproducing unit test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1535938 13f79535-47bb-0310-9956-ffa450edef68

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

index 0f60994dde0ba24b2880aee0021f0c435f7eb948..02a7079ffd6e716f2d075ab08aedfc790b920c48 100644 (file)
@@ -39,22 +39,7 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 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 POIXMLDocumentPart {
                // 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 POIXMLDocumentPart {
 
                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 POIXMLDocumentPart {
                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 POIXMLDocumentPart {
                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 POIXMLDocumentPart {
 
                // 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 POIXMLDocumentPart {
 
                // 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 POIXMLDocumentPart {
 
                // 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()])
                        );
index 7a7cbe01e357192dc1ff1521badb369bbfcf9ee7..4fce9b34924e71cad7ee6c30c94e0b50ff51a898 100644 (file)
@@ -35,24 +35,7 @@ import org.apache.poi.ss.formula.WorkbookEvaluator;
 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 BaseTestBugzillaIssues {
      *  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 BaseTestBugzillaIssues {
           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 BaseTestBugzillaIssues {
     
     /**
      * 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 BaseTestBugzillaIssues {
      * 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 BaseTestBugzillaIssues {
         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