Search in sources :

Example 1 with EscherRecord

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

the class HSSFWorkbook method getAllPictures.

/**
     * Gets all pictures from the Workbook.
     *
     * @return the list of pictures (a list of {@link HSSFPictureData} objects.)
     */
@Override
public List<HSSFPictureData> getAllPictures() {
    // The drawing group record always exists at the top level, so we won't need to do this recursively.
    List<HSSFPictureData> pictures = new ArrayList<HSSFPictureData>();
    for (Record r : workbook.getRecords()) {
        if (r instanceof AbstractEscherHolderRecord) {
            ((AbstractEscherHolderRecord) r).decode();
            List<EscherRecord> escherRecords = ((AbstractEscherHolderRecord) r).getEscherRecords();
            searchForPictures(escherRecords, pictures);
        }
    }
    return Collections.unmodifiableList(pictures);
}
Also used : AbstractEscherHolderRecord(org.apache.poi.hssf.record.AbstractEscherHolderRecord) ArrayList(java.util.ArrayList) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) Record(org.apache.poi.hssf.record.Record) AbstractEscherHolderRecord(org.apache.poi.hssf.record.AbstractEscherHolderRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 2 with EscherRecord

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

the class HSSFSheet method dumpDrawingRecords.

/**
     * Aggregates the drawing records and dumps the escher record hierarchy
     * to the standard output.
     */
public void dumpDrawingRecords(boolean fat, PrintWriter pw) {
    _sheet.aggregateDrawingRecords(_book.getDrawingManager(), false);
    EscherAggregate r = (EscherAggregate) getSheet().findFirstRecordBySid(EscherAggregate.sid);
    List<EscherRecord> escherRecords = r.getEscherRecords();
    for (EscherRecord escherRecord : escherRecords) {
        if (fat) {
            pw.println(escherRecord);
        } else {
            escherRecord.display(pw, 0);
        }
    }
    pw.flush();
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 3 with EscherRecord

use of org.apache.poi.ddf.EscherRecord 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 4 with EscherRecord

use of org.apache.poi.ddf.EscherRecord 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 5 with EscherRecord

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

the class PPDrawing method findEscherTextboxRecord.

/**
	 * Look for EscherTextboxRecords
	 */
private void findEscherTextboxRecord(List<EscherRecord> toSearch, List<EscherTextboxWrapper> found) {
    EscherSpRecord sp = null;
    for (EscherRecord r : toSearch) {
        if (r instanceof EscherSpRecord) {
            sp = (EscherSpRecord) r;
        } else if (r instanceof EscherTextboxRecord) {
            EscherTextboxRecord tbr = (EscherTextboxRecord) r;
            EscherTextboxWrapper w = new EscherTextboxWrapper(tbr);
            if (sp != null) {
                w.setShapeId(sp.getShapeId());
            }
            found.add(w);
        } else if (r.isContainerRecord()) {
            // If it has children, walk them
            List<EscherRecord> children = r.getChildRecords();
            findEscherTextboxRecord(children, found);
        }
    }
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherRecord(org.apache.poi.ddf.EscherRecord)

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