Search in sources :

Example 1 with DefaultEscherRecordFactory

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

the class SlideShowDumper method walkEscherDDF.

/**
   * Use the DDF code to walk the Escher records
   */
public void walkEscherDDF(int indent, int pos, int len) {
    if (len < 8) {
        return;
    }
    final String ind = (indent == 0) ? "%1$s" : "%1$" + indent + "s";
    byte[] contents = new byte[len];
    System.arraycopy(docstream, pos, contents, 0, len);
    DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
    EscherRecord record = erf.createRecord(contents, 0);
    // For now, try filling in the fields
    record.fillFields(contents, 0, erf);
    long atomType = LittleEndian.getUShort(contents, 2);
    // This lacks the 8 byte header size
    long atomLen = LittleEndian.getUShort(contents, 4);
    // This (should) include the 8 byte header size
    int recordLen = record.getRecordSize();
    String fmt = ind + "At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x) (%5$d) - record claims %6$d";
    out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, atomLen + 8, recordLen));
    // Check for corrupt / lying ones
    if (recordLen != 8 && (recordLen != (atomLen + 8))) {
        out.println(String.format(Locale.ROOT, ind + "** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen + 8, recordLen));
    }
    // Print the record's details
    String recordStr = record.toString().replace("\n", String.format(Locale.ROOT, "\n" + ind, ""));
    out.println(String.format(Locale.ROOT, ind + "%2$s", "", recordStr));
    if (record instanceof EscherContainerRecord) {
        walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
    }
    // Handle records that seem to lie
    if (atomType == 61451L) {
        // Normally claims a size of 8
        recordLen = (int) atomLen + 8;
    }
    if (atomType == 61453L) {
        // Returns EscherContainerRecord, but really msofbtClientTextbox
        recordLen = (int) atomLen + 8;
        record.fillFields(contents, 0, erf);
        if (!(record instanceof EscherTextboxRecord)) {
            out.println(String.format(Locale.ROOT, ind + "%2$s", "", "** Really a msofbtClientTextbox !"));
        }
    }
    // Decide on what to do, based on how the lengths match up
    if (recordLen == 8 && atomLen > 8) {
        // Assume it has children, rather than being corrupted
        walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
        // Wind on our length + our header
        pos += atomLen;
        pos += 8;
        len -= atomLen;
        len -= 8;
    } else {
        // No children, wind on our real length
        pos += atomLen;
        pos += 8;
        len -= atomLen;
        len -= 8;
    }
    // Move on to the next one, if we're not at the end yet
    if (len >= 8) {
        walkEscherDDF(indent, pos, len);
    }
}
Also used : EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) HSLFEscherRecordFactory(org.apache.poi.hslf.record.HSLFEscherRecordFactory) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 2 with DefaultEscherRecordFactory

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

the class SlideShowRecordDumper method walkTree.

public void walkTree(int depth, int pos, Record[] records, int indent) throws IOException {
    String ind = tabs.substring(0, indent);
    for (int i = 0; i < records.length; i++) {
        Record r = records[i];
        if (r == null) {
            ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
            ps.println(ind + "Warning! Null record found.");
            continue;
        }
        // Figure out how big it is
        int len = getDiskLen(r);
        // Grab the type as hex
        String hexType = makeHex((int) r.getRecordType(), 4);
        String rHexType = reverseHex(hexType);
        // Grab the hslf.record type
        Class<? extends Record> c = r.getClass();
        String cname = c.toString();
        if (cname.startsWith("class ")) {
            cname = cname.substring(6);
        }
        if (cname.startsWith("org.apache.poi.hslf.record.")) {
            cname = cname.substring(27);
        }
        // Display the record
        ps.println(ind + "At position " + pos + " (" + makeHex(pos, 6) + "):");
        ps.println(ind + " Record is of type " + cname);
        ps.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
        ps.println(ind + " Len is " + (len - 8) + " (" + makeHex((len - 8), 8) + "), on disk len is " + len);
        // print additional information for drawings and atoms
        if (optEscher && cname.equals("PPDrawing")) {
            DefaultEscherRecordFactory factory = new HSLFEscherRecordFactory();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            r.writeOut(baos);
            byte[] b = baos.toByteArray();
            EscherRecord er = factory.createRecord(b, 0);
            er.fillFields(b, 0, factory);
            printEscherRecord(er, indent + 1);
        } else if (optVerbose && r.getChildRecords() == null) {
            String recData = getPrintableRecordContents(r);
            ps.println(ind + recData);
        }
        ps.println();
        // If it has children, show them
        if (r.getChildRecords() != null) {
            walkTree((depth + 3), pos + 8, r.getChildRecords(), indent + 1);
        }
        // Wind on the position marker
        pos += len;
    }
}
Also used : Record(org.apache.poi.hslf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) HSLFEscherRecordFactory(org.apache.poi.hslf.record.HSLFEscherRecordFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 3 with DefaultEscherRecordFactory

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

the class AbstractEscherHolderRecord method convertToEscherRecords.

private void convertToEscherRecords(int offset, int size, byte[] data) {
    escherRecords.clear();
    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
    int pos = offset;
    while (pos < offset + size) {
        EscherRecord r = recordFactory.createRecord(data, pos);
        int bytesRead = r.fillFields(data, pos, recordFactory);
        escherRecords.add(r);
        pos += bytesRead;
    }
}
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 4 with DefaultEscherRecordFactory

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

the class HSSFComment method cloneShape.

@Override
protected HSSFShape cloneShape() {
    TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
    EscherContainerRecord spContainer = new EscherContainerRecord();
    byte[] inSp = getEscherContainer().serialize();
    spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
    ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
    NoteRecord note = (NoteRecord) getNoteRecord().cloneViaReserialise();
    return new HSSFComment(spContainer, obj, txo, note);
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 5 with DefaultEscherRecordFactory

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

the class HSSFPicture method cloneShape.

@Override
protected HSSFShape cloneShape() {
    EscherContainerRecord spContainer = new EscherContainerRecord();
    byte[] inSp = getEscherContainer().serialize();
    spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
    ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
    return new HSSFPicture(spContainer, obj);
}
Also used : ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Aggregations

DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)12 EscherRecord (org.apache.poi.ddf.EscherRecord)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)7 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)3 ObjRecord (org.apache.poi.hssf.record.ObjRecord)3 ArrayList (java.util.ArrayList)2 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)2 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)2 HSLFEscherRecordFactory (org.apache.poi.hslf.record.HSLFEscherRecordFactory)2 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)2 IOException (java.io.IOException)1 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)1 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)1 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)1 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)1 Record (org.apache.poi.hslf.record.Record)1 NoteRecord (org.apache.poi.hssf.record.NoteRecord)1 Picture (org.apache.poi.hwpf.usermodel.Picture)1