Search in sources :

Example 1 with CurrentUserAtom

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

the class UserEditAndPersistListing method main.

public static void main(String[] args) throws IOException {
    if (args.length < 1) {
        System.err.println("Need to give a filename");
        System.exit(1);
    }
    // Create the slideshow object, for normal working with
    HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
    fileContents = ss.getUnderlyingBytes();
    System.out.println("");
    // Find any persist ones first
    int pos = 0;
    for (Record r : ss.getRecords()) {
        if (r.getRecordType() == 6001l) {
            // PersistPtrFullBlock
            System.out.println("Found PersistPtrFullBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
        }
        if (r.getRecordType() == 6002l) {
            // PersistPtrIncrementalBlock
            System.out.println("Found PersistPtrIncrementalBlock at " + pos + " (" + Integer.toHexString(pos) + ")");
            PersistPtrHolder pph = (PersistPtrHolder) r;
            // Check the sheet offsets
            Map<Integer, Integer> sheetOffsets = pph.getSlideLocationsLookup();
            for (int id : pph.getKnownSlideIDs()) {
                Integer offset = sheetOffsets.get(id);
                System.out.println("  Knows about sheet " + id);
                System.out.println("    That sheet lives at " + offset);
                Record atPos = findRecordAtPos(offset.intValue());
                System.out.println("    The record at that pos is of type " + atPos.getRecordType());
                System.out.println("    The record at that pos has class " + atPos.getClass().getName());
                if (!(atPos instanceof PositionDependentRecord)) {
                    System.out.println("    ** The record class isn't position aware! **");
                }
            }
        }
        // Increase the position by the on disk size
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        r.writeOut(baos);
        pos += baos.size();
    }
    System.out.println("");
    pos = 0;
    // Now look for UserEditAtoms
    for (Record r : ss.getRecords()) {
        if (r instanceof UserEditAtom) {
            UserEditAtom uea = (UserEditAtom) r;
            System.out.println("Found UserEditAtom at " + pos + " (" + Integer.toHexString(pos) + ")");
            System.out.println("  lastUserEditAtomOffset = " + uea.getLastUserEditAtomOffset());
            System.out.println("  persistPointersOffset  = " + uea.getPersistPointersOffset());
            System.out.println("  docPersistRef          = " + uea.getDocPersistRef());
            System.out.println("  maxPersistWritten      = " + uea.getMaxPersistWritten());
        }
        // Increase the position by the on disk size
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        r.writeOut(baos);
        pos += baos.size();
    }
    System.out.println("");
    // Query the CurrentUserAtom
    CurrentUserAtom cua = ss.getCurrentUserAtom();
    System.out.println("Checking Current User Atom");
    System.out.println("  Thinks the CurrentEditOffset is " + cua.getCurrentEditOffset());
    System.out.println("");
    ss.close();
}
Also used : PositionDependentRecord(org.apache.poi.hslf.record.PositionDependentRecord) PersistPtrHolder(org.apache.poi.hslf.record.PersistPtrHolder) Record(org.apache.poi.hslf.record.Record) PositionDependentRecord(org.apache.poi.hslf.record.PositionDependentRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserEditAtom(org.apache.poi.hslf.record.UserEditAtom) CurrentUserAtom(org.apache.poi.hslf.record.CurrentUserAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 2 with CurrentUserAtom

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

the class TestReWriteSanity method testUserEditAtomsRight.

@Test
public void testUserEditAtomsRight() throws Exception {
    // Write out to a byte array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ss.write(baos);
    // Build an input stream of it
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    // Create a new one from that
    HSLFSlideShowImpl wss = new HSLFSlideShowImpl(bais);
    // Find the location of the PersistPtrIncrementalBlocks and
    // UserEditAtoms
    Record[] r = wss.getRecords();
    Map<Integer, Record> pp = new HashMap<Integer, Record>();
    Map<Integer, Object> ue = new HashMap<Integer, Object>();
    // Will show 0 if first
    ue.put(Integer.valueOf(0), Integer.valueOf(0));
    int pos = 0;
    int lastUEPos = -1;
    for (final Record rec : r) {
        if (rec instanceof PersistPtrHolder) {
            pp.put(Integer.valueOf(pos), rec);
        }
        if (rec instanceof UserEditAtom) {
            ue.put(Integer.valueOf(pos), rec);
            lastUEPos = pos;
        }
        ByteArrayOutputStream bc = new ByteArrayOutputStream();
        rec.writeOut(bc);
        pos += bc.size();
    }
    // Check that the UserEditAtom's point to right stuff
    for (final Record rec : r) {
        if (rec instanceof UserEditAtom) {
            UserEditAtom uea = (UserEditAtom) rec;
            int luPos = uea.getLastUserEditAtomOffset();
            int ppPos = uea.getPersistPointersOffset();
            assertContains(ue, Integer.valueOf(luPos));
            assertContains(pp, Integer.valueOf(ppPos));
        }
    }
    // Check that the CurrentUserAtom points to the right UserEditAtom
    CurrentUserAtom cua = wss.getCurrentUserAtom();
    int listedUEPos = (int) cua.getCurrentEditOffset();
    assertEquals(lastUEPos, listedUEPos);
    wss.close();
}
Also used : HashMap(java.util.HashMap) PersistPtrHolder(org.apache.poi.hslf.record.PersistPtrHolder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CurrentUserAtom(org.apache.poi.hslf.record.CurrentUserAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Record(org.apache.poi.hslf.record.Record) UserEditAtom(org.apache.poi.hslf.record.UserEditAtom) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 CurrentUserAtom (org.apache.poi.hslf.record.CurrentUserAtom)2 PersistPtrHolder (org.apache.poi.hslf.record.PersistPtrHolder)2 Record (org.apache.poi.hslf.record.Record)2 UserEditAtom (org.apache.poi.hslf.record.UserEditAtom)2 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 PositionDependentRecord (org.apache.poi.hslf.record.PositionDependentRecord)1 Test (org.junit.Test)1