poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1594721 - in /poi/trunk/src/ooxml: java/org/apache/poi/ java/org/apache/poi/openxml4j/opc/ java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/xssf/usermodel/
Date Wed, 14 May 2014 21:14:16 GMT
Author: kiwiwings
Date: Wed May 14 21:14:16 2014
New Revision: 1594721

URL: http://svn.apache.org/r1594721
Log:
Bug 56468 - Writing a workbook more than once corrupts the file

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java?rev=1594721&r1=1594720&r2=1594721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLProperties.java Wed May 14 21:14:16 2014
@@ -148,6 +148,9 @@ public class POIXMLProperties {
 			xmlOptions.setSaveSuggestedPrefixes(map);
 
 			OutputStream out = extPart.getOutputStream();
+			if (extPart.getSize() > 0) {
+			    extPart.clear();
+			}
 			ext.props.save(out, xmlOptions);
 			out.close();
 		}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1594721&r1=1594720&r2=1594721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Wed May 14 21:14:16
2014
@@ -599,7 +599,10 @@ public abstract class OPCPackage impleme
 			throw new IllegalArgumentException("relationshipType");
 		ArrayList<PackagePart> retArr = new ArrayList<PackagePart>();
 		for (PackageRelationship rel : getRelationshipsByType(relationshipType)) {
-			retArr.add(getPart(rel));
+			PackagePart part = getPart(rel);
+			if (part != null) {
+			    retArr.add(part);
+			}
 		}
 		return retArr;
 	}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1594721&r1=1594720&r2=1594721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Wed May 14 21:14:16
2014
@@ -37,7 +37,6 @@ import org.apache.poi.openxml4j.opc.inte
 import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
 import org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.ZipHelper;
-import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller;
 import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
 import org.apache.poi.openxml4j.util.ZipEntrySource;
 import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
@@ -444,9 +443,8 @@ public final class ZipPackage extends Pa
                 this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size()
== 0    ) {
 				logger.log(POILogger.DEBUG,"Save core properties part");
 
-				// We have to save the core properties part ...
-				new ZipPackagePropertiesMarshaller().marshall(
-                        this.packageProperties, zos);
+				// Add core properties to part list ...
+				addPackagePart(this.packageProperties);
 				// ... and to add its relationship ...
 				this.relationships.addRelationship(this.packageProperties
 						.getPartName().getURI(), TargetMode.INTERNAL,

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1594721&r1=1594720&r2=1594721&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Wed May 14 21:14:16
2014
@@ -321,13 +321,7 @@ public class XSSFWorkbook extends POIXML
             }
 
             // Process the named ranges
-            namedRanges = new ArrayList<XSSFName>();
-            if(workbook.isSetDefinedNames()) {
-                for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray())
{
-                    namedRanges.add(new XSSFName(ctName, this));
-                }
-            }
-
+            reprocessNamedRanges();
         } catch (XmlException e) {
             throw new POIXMLException(e);
         }
@@ -1307,13 +1301,28 @@ public class XSSFWorkbook extends POIXML
                 i++;
             }
             names.setDefinedNameArray(nr);
+            if(workbook.isSetDefinedNames()) {
+                workbook.unsetDefinedNames();
+            }
             workbook.setDefinedNames(names);
+                        
+            // Re-process the named ranges
+            reprocessNamedRanges();
         } else {
             if(workbook.isSetDefinedNames()) {
                 workbook.unsetDefinedNames();
             }
         }
     }
+    
+    private void reprocessNamedRanges() {
+        namedRanges = new ArrayList<XSSFName>();
+        if(workbook.isSetDefinedNames()) {
+            for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameList()) {
+                namedRanges.add(new XSSFName(ctName, this));
+            }
+        }
+    }
 
     private void saveCalculationChain(){
         if(calcChain != null){

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=1594721&r1=1594720&r2=1594721&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 Wed May
14 21:14:16 2014
@@ -17,10 +17,12 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -60,6 +62,7 @@ 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.util.AreaReference;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -1464,4 +1467,23 @@ public final class TestXSSFBugs extends 
         double rounded = cv.getNumberValue();
         assertEquals(0.1, rounded, 0.0);
     }
+
+    @Test
+    public void bug56468() throws Exception {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        XSSFRow row = sheet.createRow(0);
+        XSSFCell cell = row.createCell(0);
+        cell.setCellValue("Hi");
+        sheet.setRepeatingRows(new CellRangeAddress(0, 0, 0, 0));
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(8096);
+        wb.write(bos);
+        byte firstSave[] = bos.toByteArray();
+        bos.reset();
+        wb.write(bos);
+        byte secondSave[] = bos.toByteArray();
+        
+        assertThat(firstSave, equalTo(secondSave));
+    }
 }



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


Mime
View raw message