Search in sources :

Example 31 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class AbstractEscherHolderRecord method getRecordSize.

@Override
public int getRecordSize() {
    byte[] rawData = getRawData();
    if (escherRecords.size() == 0 && rawData != null) {
        // XXX: It should be possible to derive this without concatenating the array, too.
        return rawData.length;
    }
    int size = 0;
    for (EscherRecord r : escherRecords) {
        size += r.getRecordSize();
    }
    return size;
}
Also used : EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 32 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class EscherRecordHolder method fillEscherRecords.

private void fillEscherRecords(byte[] data, int offset, int size) {
    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
    int pos = offset;
    while (pos < offset + size) {
        EscherRecord r = recordFactory.createRecord(data, pos);
        escherRecords.add(r);
        int bytesRead = r.fillFields(data, pos, recordFactory);
        // There is an empty byte between each top-level record in a Word doc
        pos += bytesRead + 1;
    }
}
Also used : EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory) EscherRecordFactory(org.apache.poi.ddf.EscherRecordFactory) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 33 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class EscherRecordHolder method toString.

public String toString() {
    StringBuffer buffer = new StringBuffer();
    if (escherRecords.size() == 0) {
        buffer.append("No Escher Records Decoded").append("\n");
    }
    Iterator<EscherRecord> iterator = escherRecords.iterator();
    while (iterator.hasNext()) {
        EscherRecord r = iterator.next();
        buffer.append(r);
    }
    return buffer.toString();
}
Also used : EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 34 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class PicturesTable method searchForPictures.

/**
     * Performs a recursive search for pictures in the given list of escher records.
     *
     * @param escherRecords the escher records.
     * @param pictures the list to populate with the pictures.
     */
private void searchForPictures(List<EscherRecord> escherRecords, List<Picture> pictures) {
    for (EscherRecord escherRecord : escherRecords) {
        if (escherRecord instanceof EscherBSERecord) {
            EscherBSERecord bse = (EscherBSERecord) escherRecord;
            EscherBlipRecord blip = bse.getBlipRecord();
            if (blip != null) {
                pictures.add(new Picture(blip));
            } else if (bse.getOffset() > 0) {
                try {
                    // Blip stored in delay stream, which in a word doc, is
                    // the main stream
                    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                    EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset());
                    if (record instanceof EscherBlipRecord) {
                        record.fillFields(_mainStream, bse.getOffset(), recordFactory);
                        blip = (EscherBlipRecord) record;
                        pictures.add(new Picture(blip));
                    }
                } catch (Exception exc) {
                    logger.log(POILogger.WARN, "Unable to load picture from BLIB record at offset #", Integer.valueOf(bse.getOffset()), exc);
                }
            }
        }
        // Recursive call.
        searchForPictures(escherRecord.getChildRecords(), pictures);
    }
}
Also used : Picture(org.apache.poi.hwpf.usermodel.Picture) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord) EscherRecordFactory(org.apache.poi.ddf.EscherRecordFactory) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 35 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class TestDrawingAggregate method testIncompleteData.

/**
     * when reading incomplete data ensure that the serialized bytes match the source
     */
@Test
public void testIncompleteData() throws IOException {
    //EscherDgContainer and EscherSpgrContainer length exceeds the actual length of the data
    String data = "H4sIAAAAAAAAAGWOOw7CQAxE32YTsSRIWSgQJSUloqSm5g4ICURBg+iBK3APGi6wBWeh9xGYbEps2WON" + "P+OWwpYeIsECMFC8S2jxNvMdlrYQ5xha5N8K6ryHdir6+avwOer5l3hq2NPYWuWN0n1dIsgfbgshuSj1" + "+2eqbvLdxQ0ndhy5KJ/lc1ZZK9okY5X/gSbrHZTH1vE/ozagTcwAAAA=";
    byte[] dgBytes = decompress(data);
    List<EscherRecord> records = new ArrayList<EscherRecord>();
    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
    int pos = 0;
    while (pos < dgBytes.length) {
        EscherRecord r = recordFactory.createRecord(dgBytes, pos);
        int bytesRead = r.fillFields(dgBytes, pos, recordFactory);
        records.add(r);
        pos += bytesRead;
    }
    assertEquals("data was not fully read", dgBytes.length, pos);
    // serialize to byte array
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (EscherRecord r : records) {
        out.write(r.serialize());
    }
    assertEquals(HexDump.toHex(dgBytes, 10), HexDump.toHex(out.toByteArray(), 10));
}
Also used : ArrayList(java.util.ArrayList) EscherRecord(org.apache.poi.ddf.EscherRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory) EscherRecordFactory(org.apache.poi.ddf.EscherRecordFactory) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory) Test(org.junit.Test)

Aggregations

EscherRecord (org.apache.poi.ddf.EscherRecord)42 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)20 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)10 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)9 ArrayList (java.util.ArrayList)7 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)6 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)6 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)6 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)5 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)4 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)4 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)4 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)4 Document (org.apache.poi.hslf.record.Document)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)3 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 EscherProperty (org.apache.poi.ddf.EscherProperty)2