Browse Source

Fix bug #49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@998967 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_7_BETA3
Nick Burch 13 years ago
parent
commit
2fbe2f48a1

+ 1
- 0
src/documentation/content/xdocs/status.xml View File



<changes> <changes>
<release version="3.7-beta3" date="2010-??-??"> <release version="3.7-beta3" date="2010-??-??">
<action dev="poi-developers" type="fix">49931 - Avoid concurrency problems when re-ordering multiple HSSF header records for a PageSettingsBlock</action>
<action dev="poi-developers" type="fix">49765 - Fix XWPFDocument.addPicture so that it correctly sets up relationships</action> <action dev="poi-developers" type="fix">49765 - Fix XWPFDocument.addPicture so that it correctly sets up relationships</action>
<action dev="poi-developers" type="fix">48018 - Improve HWPF handling of lists in documents read and then saved, by preserving order better</action> <action dev="poi-developers" type="fix">48018 - Improve HWPF handling of lists in documents read and then saved, by preserving order better</action>
<action dev="poi-developers" type="fix">49820 - Fix HWPF paragraph levels, so that outline levels can be properly fetched</action> <action dev="poi-developers" type="fix">49820 - Fix HWPF paragraph levels, so that outline levels can be properly fetched</action>

+ 8
- 4
src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java View File

package org.apache.poi.hssf.record.aggregates; package org.apache.poi.hssf.record.aggregates;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Arrays; import java.util.Arrays;


/** /**
* Some apps can define multiple HeaderFooterRecord records for a sheet. * Some apps can define multiple HeaderFooterRecord records for a sheet.
* When saving such a file Excel 2007 re-positiones them according to the followig rules:
* When saving such a file Excel 2007 re-positions them according to the following rules:
* - take a HeaderFooterRecord and read 16-byte GUID at offset 12. If it is zero, * - take a HeaderFooterRecord and read 16-byte GUID at offset 12. If it is zero,
* it means the current sheet and the given HeaderFooterRecord belongs to this PageSettingsBlock * it means the current sheet and the given HeaderFooterRecord belongs to this PageSettingsBlock
* - If GUID is not zero then search in preceding CustomViewSettingsRecordAggregates. * - If GUID is not zero then search in preceding CustomViewSettingsRecordAggregates.
* @param sheetRecords the list of sheet records read so far * @param sheetRecords the list of sheet records read so far
*/ */
public void positionRecords(List<RecordBase> sheetRecords) { public void positionRecords(List<RecordBase> sheetRecords) {
// Take a copy to loop over, so we can update the real one
// without concurrency issues
List<HeaderFooterRecord> hfRecordsToIterate = new ArrayList<HeaderFooterRecord>(_sviewHeaderFooters);
// loop through HeaderFooterRecord records having not-empty GUID and match them with // loop through HeaderFooterRecord records having not-empty GUID and match them with
// CustomViewSettingsRecordAggregate blocks having UserSViewBegin with the same GUID // CustomViewSettingsRecordAggregate blocks having UserSViewBegin with the same GUID
for (final Iterator<HeaderFooterRecord> it = _sviewHeaderFooters.iterator(); it.hasNext(); ) {
final HeaderFooterRecord hf = it.next();
for(final HeaderFooterRecord hf : hfRecordsToIterate) {
for (RecordBase rb : sheetRecords) { for (RecordBase rb : sheetRecords) {
if (rb instanceof CustomViewSettingsRecordAggregate) { if (rb instanceof CustomViewSettingsRecordAggregate) {
final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb; final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb;
byte[] guid2 = hf.getGuid(); byte[] guid2 = hf.getGuid();
if (Arrays.equals(guid1, guid2)) { if (Arrays.equals(guid1, guid2)) {
cv.append(hf); cv.append(hf);
it.remove();
_sviewHeaderFooters.remove(hf);
} }
} }
} }

+ 10
- 1
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java View File

} }
} }
assertTrue(namedStyles.containsAll(collecteddStyles)); assertTrue(namedStyles.containsAll(collecteddStyles));

} }
/**
* Regression with the PageSettingsBlock
*/
public void test49931() throws Exception {
HSSFWorkbook wb = openSample("49931.xls");
assertEquals(1, wb.getNumberOfSheets());
assertEquals("Foo", wb.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().toString());
}
} }

BIN
test-data/spreadsheet/49931.xls View File


Loading…
Cancel
Save