Search in sources :

Example 6 with Record

use of org.apache.poi.hslf.record.Record 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 7 with Record

use of org.apache.poi.hslf.record.Record in project poi by apache.

the class UserEditAndPersistListing method findRecordAtPos.

// Finds the record at a given position
public static Record findRecordAtPos(int pos) {
    long type = LittleEndian.getUShort(fileContents, pos + 2);
    long rlen = LittleEndian.getUInt(fileContents, pos + 4);
    Record r = Record.createRecordForType(type, fileContents, pos, (int) rlen + 8);
    return r;
}
Also used : Record(org.apache.poi.hslf.record.Record) PositionDependentRecord(org.apache.poi.hslf.record.PositionDependentRecord)

Example 8 with Record

use of org.apache.poi.hslf.record.Record in project poi by apache.

the class HSLFSlideShowImpl method getEmbeddedObjects.

/**
     * Gets embedded object data from the slide show.
     *
     * @return the embedded objects.
     */
public HSLFObjectData[] getEmbeddedObjects() {
    if (_objects == null) {
        List<HSLFObjectData> objects = new ArrayList<HSLFObjectData>();
        for (Record r : _records) {
            if (r instanceof ExOleObjStg) {
                objects.add(new HSLFObjectData((ExOleObjStg) r));
            }
        }
        _objects = objects.toArray(new HSLFObjectData[objects.size()]);
    }
    return _objects;
}
Also used : ArrayList(java.util.ArrayList) Record(org.apache.poi.hslf.record.Record) PositionDependentRecord(org.apache.poi.hslf.record.PositionDependentRecord) PersistRecord(org.apache.poi.hslf.record.PersistRecord) ExOleObjStg(org.apache.poi.hslf.record.ExOleObjStg)

Example 9 with Record

use of org.apache.poi.hslf.record.Record in project poi by apache.

the class HSLFSlideShowImpl method read.

private Record[] read(byte[] docstream, int usrOffset) throws IOException {
    //sort found records by offset.
    //(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)
    // offset -> record
    NavigableMap<Integer, Record> records = new TreeMap<Integer, Record>();
    // offset -> persistId
    Map<Integer, Integer> persistIds = new HashMap<Integer, Integer>();
    initRecordOffsets(docstream, usrOffset, records, persistIds);
    HSLFSlideShowEncrypted decryptData = new HSLFSlideShowEncrypted(docstream, records);
    for (Map.Entry<Integer, Record> entry : records.entrySet()) {
        Integer offset = entry.getKey();
        Record record = entry.getValue();
        Integer persistId = persistIds.get(offset);
        if (record == null) {
            // all plain records have been already added,
            // only new records need to be decrypted (tbd #35897)
            decryptData.decryptRecord(docstream, persistId, offset);
            record = Record.buildRecordAtOffset(docstream, offset);
            entry.setValue(record);
        }
        if (record instanceof PersistRecord) {
            ((PersistRecord) record).setPersistId(persistId);
        }
    }
    decryptData.close();
    return records.values().toArray(new Record[records.size()]);
}
Also used : PersistRecord(org.apache.poi.hslf.record.PersistRecord) HashMap(java.util.HashMap) Record(org.apache.poi.hslf.record.Record) PositionDependentRecord(org.apache.poi.hslf.record.PositionDependentRecord) PersistRecord(org.apache.poi.hslf.record.PersistRecord) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap)

Example 10 with Record

use of org.apache.poi.hslf.record.Record in project poi by apache.

the class HSLFTextParagraph method findStyleAtomPresent.

/**
     * Search for a StyleTextPropAtom is for this text header (list of paragraphs)
     *
     * @param header the header
     * @param textLen the length of the rawtext, or -1 if the length is not known
     */
private static StyleTextPropAtom findStyleAtomPresent(TextHeaderAtom header, int textLen) {
    boolean afterHeader = false;
    StyleTextPropAtom style = null;
    for (Record record : header.getParentRecord().getChildRecords()) {
        long rt = record.getRecordType();
        if (afterHeader && rt == RecordTypes.TextHeaderAtom.typeID) {
            // already on the next header, quit searching
            break;
        }
        afterHeader |= (header == record);
        if (afterHeader && rt == RecordTypes.StyleTextPropAtom.typeID) {
            // found it
            style = (StyleTextPropAtom) record;
        }
    }
    if (style == null) {
        logger.log(POILogger.INFO, "styles atom doesn't exist. Creating dummy record for later saving.");
        style = new StyleTextPropAtom((textLen < 0) ? 1 : textLen);
    } else {
        if (textLen >= 0) {
            style.setParentTextSize(textLen);
        }
    }
    return style;
}
Also used : Record(org.apache.poi.hslf.record.Record) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom)

Aggregations

Record (org.apache.poi.hslf.record.Record)39 PositionDependentRecord (org.apache.poi.hslf.record.PositionDependentRecord)10 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)8 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)8 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)7 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)7 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)7 UserEditAtom (org.apache.poi.hslf.record.UserEditAtom)7 DrawPaint (org.apache.poi.sl.draw.DrawPaint)7 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)7 PersistPtrHolder (org.apache.poi.hslf.record.PersistPtrHolder)6 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)6 ArrayList (java.util.ArrayList)5 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)5 Document (org.apache.poi.hslf.record.Document)5 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)5 Test (org.junit.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Map (java.util.Map)4