Search in sources :

Example 6 with RecordCollector

use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.

the class TestPageSettingsBlock method testDuplicateHeaderFooter_bug48026.

public void testDuplicateHeaderFooter_bug48026() {
    Record[] recs = { BOFRecord.createSheetBOF(), new IndexRecord(), //PageSettingsBlock
    new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate
    new UserSViewBegin(HexRead.readFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), new UserSViewEnd(HexRead.readFromString("01 00")), // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
    new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet;
    try {
        sheet = InternalSheet.createSheet(rs);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) {
            throw new AssertionFailedError("Identified bug 48026");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    assertEquals(recs.length, outRecs.length);
    //expected order of records:
    Record[] expectedRecs = { //BOFRecord
    recs[0], //IndexRecord
    recs[1], //HeaderRecord
    recs[2], //FooterRecord
    recs[3], //HeaderFooterRecord
    recs[9], // DimensionsRecord
    recs[4], // WindowTwoRecord
    recs[5], // UserSViewBegin
    recs[6], // SelectionRecord
    recs[7], // HeaderFooterRecord
    recs[10], // UserSViewEnd
    recs[8], //EOFRecord
    recs[11] };
    for (int i = 0; i < expectedRecs.length; i++) {
        assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass());
    }
    HeaderFooterRecord hd1 = (HeaderFooterRecord) expectedRecs[4];
    //GUID is zero
    assertArrayEquals(new byte[16], hd1.getGuid());
    assertTrue(hd1.isCurrentSheet());
    UserSViewBegin svb = (UserSViewBegin) expectedRecs[7];
    HeaderFooterRecord hd2 = (HeaderFooterRecord) expectedRecs[9];
    assertFalse(hd2.isCurrentSheet());
    //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
    assertArrayEquals(svb.getGuid(), hd2.getGuid());
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) AssertionFailedError(junit.framework.AssertionFailedError)

Example 7 with RecordCollector

use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.

the class TestPageSettingsBlock method testLateMargins_bug47199.

/**
	 * Bug 47199 was due to the margin records being located well after the initial PSB records.
	 * The example file supplied (attachment 23710) had three non-PSB record types
	 * between the PRINTSETUP record and first MARGIN record:
	 * <ul>
	 * <li>PRINTSETUP(0x00A1)</li>
	 * <li>DEFAULTCOLWIDTH(0x0055)</li>
	 * <li>COLINFO(0x007D)</li>
	 * <li>DIMENSIONS(0x0200)</li>
	 * <li>BottomMargin(0x0029)</li>
	 * </ul>
	 */
public void testLateMargins_bug47199() {
    Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), createBottomMargin(0.787F), new WindowTwoRecord(), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet;
    try {
        sheet = InternalSheet.createSheet(rs);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("two Page Settings Blocks found in the same sheet")) {
            throw new AssertionFailedError("Identified bug 47199a - failed to process late margings records");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    // +1 for index record
    assertEquals(recs.length + 1, outRecs.length);
    assertEquals(BOFRecord.class, outRecs[0].getClass());
    assertEquals(IndexRecord.class, outRecs[1].getClass());
    assertEquals(HeaderRecord.class, outRecs[2].getClass());
    assertEquals(FooterRecord.class, outRecs[3].getClass());
    assertEquals(DimensionsRecord.class, outRecs[5].getClass());
    assertEquals(WindowTwoRecord.class, outRecs[6].getClass());
    assertEquals(EOFRecord.instance, outRecs[7]);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) AssertionFailedError(junit.framework.AssertionFailedError)

Example 8 with RecordCollector

use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.

the class TestHSSFSheet method protectSheetRecordOrder_bug47363a.

/**
     * {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block
     * (which should be before {@link DimensionsRecord}).
     */
@Test
public void protectSheetRecordOrder_bug47363a() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet s = wb.createSheet();
    s.protectSheet("secret");
    RecordCollector rc = new RecordCollector();
    s.getSheet().visitContainedRecords(rc, 0);
    Record[] recs = rc.getRecords();
    int nRecs = recs.length;
    if (recs[nRecs - 2] instanceof PasswordRecord && recs[nRecs - 5] instanceof DimensionsRecord) {
        fail("Identified bug 47363a - PASSWORD after DIMENSION");
    }
    // Check that protection block is together, and before DIMENSION
    confirmRecordClass(recs, nRecs - 4, DimensionsRecord.class);
    confirmRecordClass(recs, nRecs - 9, ProtectRecord.class);
    confirmRecordClass(recs, nRecs - 8, ObjectProtectRecord.class);
    confirmRecordClass(recs, nRecs - 7, ScenarioProtectRecord.class);
    confirmRecordClass(recs, nRecs - 6, PasswordRecord.class);
    wb.close();
}
Also used : PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) VCenterRecord(org.apache.poi.hssf.record.VCenterRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) GridsetRecord(org.apache.poi.hssf.record.GridsetRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) FtCblsSubRecord(org.apache.poi.hssf.record.FtCblsSubRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) LbsDataSubRecord(org.apache.poi.hssf.record.LbsDataSubRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) SubRecord(org.apache.poi.hssf.record.SubRecord) HCenterRecord(org.apache.poi.hssf.record.HCenterRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) Test(org.junit.Test)

Example 9 with RecordCollector

use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.

the class TestHSSFSheet method dvProtectionOrder_bug47363b.

/**
     * There should be no problem with adding data validations after sheet protection
     */
@Test
public void dvProtectionOrder_bug47363b() throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Sheet1");
    sheet.protectSheet("secret");
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    DataValidationConstraint dvc = dataValidationHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.BETWEEN, "10", "100");
    CellRangeAddressList numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1);
    DataValidation dv = dataValidationHelper.createValidation(dvc, numericCellAddressList);
    try {
        sheet.addValidationData(dv);
    } catch (IllegalStateException e) {
        String expMsg = "Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos";
        if (expMsg.equals(e.getMessage())) {
            fail("Identified bug 47363b");
        }
        workbook.close();
        throw e;
    }
    RecordCollector rc;
    rc = new RecordCollector();
    sheet.getSheet().visitContainedRecords(rc, 0);
    int nRecsWithProtection = rc.getRecords().length;
    sheet.protectSheet(null);
    rc = new RecordCollector();
    sheet.getSheet().visitContainedRecords(rc, 0);
    int nRecsWithoutProtection = rc.getRecords().length;
    assertEquals(4, nRecsWithProtection - nRecsWithoutProtection);
    workbook.close();
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) Test(org.junit.Test)

Example 10 with RecordCollector

use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.

the class TestRowRecordsAggregate method testUnknownContinue_bug46280.

/**
	 * This problem was noted as the overt symptom of bug 46280.  The logic for skipping {@link
	 * UnknownRecord}s in the constructor {@link RowRecordsAggregate} did not allow for the
	 * possibility of tailing {@link ContinueRecord}s.<br/>
	 * The functionality change being tested here is actually not critical to the overall fix
	 * for bug 46280, since the fix involved making sure the that offending <i>PivotTable</i>
	 * records do not get into {@link RowRecordsAggregate}.<br/>
	 * This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
	 * UnknownRecord} has the potential of being 'continued'.
	 */
@Test
public void testUnknownContinue_bug46280() {
    Record[] inRecs = { new RowRecord(0), new NumberRecord(), new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)), new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)) };
    RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
    RowRecordsAggregate rra;
    try {
        rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
    } catch (RuntimeException e) {
        if (e.getMessage().startsWith("Unexpected record type")) {
            fail("Identified bug 46280a");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    rra.visitContainedRecords(rv);
    Record[] outRecs = rv.getRecords();
    assertEquals(5, outRecs.length);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Aggregations

RecordCollector (org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector)14 AssertionFailedError (junit.framework.AssertionFailedError)10 RecordStream (org.apache.poi.hssf.model.RecordStream)8 InternalSheet (org.apache.poi.hssf.model.InternalSheet)5 Record (org.apache.poi.hssf.record.Record)5 Test (org.junit.Test)5 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)4 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)3 NumberRecord (org.apache.poi.hssf.record.NumberRecord)3 ObjRecord (org.apache.poi.hssf.record.ObjRecord)3 RowRecord (org.apache.poi.hssf.record.RowRecord)3 StringRecord (org.apache.poi.hssf.record.StringRecord)3 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)3 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 BOFRecord (org.apache.poi.hssf.record.BOFRecord)2 BlankRecord (org.apache.poi.hssf.record.BlankRecord)2 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)2 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)2 EOFRecord (org.apache.poi.hssf.record.EOFRecord)2 GutsRecord (org.apache.poi.hssf.record.GutsRecord)2