Search in sources :

Example 1 with HSLFSlideShowImpl

use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.

the class SLWTListing 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);
    }
    HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
    // Find the documents, and then their SLWT
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        if (records[i] instanceof Document) {
            Document doc = (Document) records[i];
            SlideListWithText[] slwts = doc.getSlideListWithTexts();
            System.out.println("Document at " + i + " had " + slwts.length + " SlideListWithTexts");
            if (slwts.length == 0) {
                System.err.println("** Warning: Should have had at least 1! **");
            }
            if (slwts.length > 3) {
                System.err.println("** Warning: Shouldn't have more than 3!");
            }
            // Check the SLWTs contain what we'd expect
            for (int j = 0; j < slwts.length; j++) {
                SlideListWithText slwt = slwts[j];
                Record[] children = slwt.getChildRecords();
                System.out.println(" - SLWT at " + j + " had " + children.length + " children:");
                // Should only have SlideAtomSets if the second one
                int numSAS = slwt.getSlideAtomsSets().length;
                if (j == 1) {
                    if (numSAS == 0) {
                        System.err.println("  ** 2nd SLWT didn't have any SlideAtomSets!");
                    } else {
                        System.out.println("  - Contains " + numSAS + " SlideAtomSets");
                    }
                } else {
                    if (numSAS > 0) {
                        System.err.println("  ** SLWT " + j + " had " + numSAS + " SlideAtomSets! (expected 0)");
                    }
                }
                // Report the first 5 children, to give a flavour
                int upTo = 5;
                if (children.length < 5) {
                    upTo = children.length;
                }
                for (int k = 0; k < upTo; k++) {
                    Record r = children[k];
                    int typeID = (int) r.getRecordType();
                    String typeName = RecordTypes.forTypeID(typeID).name();
                    System.out.println("   - " + typeID + " (" + typeName + ")");
                }
            }
        }
    }
    ss.close();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record) Document(org.apache.poi.hslf.record.Document) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 2 with HSLFSlideShowImpl

use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.

the class SlideAndNotesAtomListing 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);
    }
    HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
    System.out.println("");
    // Find either Slides or Notes
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        Record r = records[i];
        // When we find them, print out their IDs
        if (r instanceof Slide) {
            Slide s = (Slide) r;
            SlideAtom sa = s.getSlideAtom();
            System.out.println("Found Slide at " + i);
            System.out.println("  Slide's master ID is " + sa.getMasterID());
            System.out.println("  Slide's notes ID is  " + sa.getNotesID());
            System.out.println("");
        }
        if (r instanceof Notes) {
            Notes n = (Notes) r;
            NotesAtom na = n.getNotesAtom();
            System.out.println("Found Notes at " + i);
            System.out.println("  Notes ID is " + na.getSlideID());
            System.out.println("");
        }
    }
    ss.close();
}
Also used : SlideAtom(org.apache.poi.hslf.record.SlideAtom) Slide(org.apache.poi.hslf.record.Slide) Record(org.apache.poi.hslf.record.Record) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Notes(org.apache.poi.hslf.record.Notes) NotesAtom(org.apache.poi.hslf.record.NotesAtom)

Example 3 with HSLFSlideShowImpl

use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.

the class TestPOIDocumentScratchpad method setUp.

/**
	 * Set things up, using a PowerPoint document and
	 *  a Word Document for our testing
	 */
@Before
public void setUp() throws IOException {
    doc = new HSLFSlideShowImpl(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
    doc2 = HWPFTestDataSamples.openSampleFile("test2.doc");
}
Also used : HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Before(org.junit.Before)

Example 4 with HSLFSlideShowImpl

use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.

the class TestEncryptedFile method testLoadNonEncrypted.

@Test
public void testLoadNonEncrypted() throws IOException {
    InputStream is = slTests.openResourceAsStream("basic_test_ppt_file.ppt");
    HSLFSlideShowImpl hss = new HSLFSlideShowImpl(is);
    assertNotNull(hss);
    hss.close();
    is.close();
}
Also used : InputStream(java.io.InputStream) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 5 with HSLFSlideShowImpl

use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.

the class TestReWrite method assertWritesOutTheSame.

public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
    // Write out to a byte array, and to a temp file
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    hss.write(baos);
    final File file = TempFile.createTempFile("TestHSLF", ".ppt");
    final File file2 = TempFile.createTempFile("TestHSLF", ".ppt");
    hss.write(file);
    hss.write(file2);
    // Build an input stream of it, and read back as a POIFS from the stream
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    POIFSFileSystem npfS = new POIFSFileSystem(bais);
    // And the same on the temp file
    POIFSFileSystem npfF = new POIFSFileSystem(file);
    // And another where we do an in-place write
    POIFSFileSystem npfRF = new POIFSFileSystem(file2, false);
    HSLFSlideShowImpl hssRF = new HSLFSlideShowImpl(npfRF);
    hssRF.write();
    hssRF.close();
    npfRF = new POIFSFileSystem(file2);
    // Check all of them in turn
    for (POIFSFileSystem npf : new POIFSFileSystem[] { npfS, npfF, npfRF }) {
        // Check that the "PowerPoint Document" sections have the same size
        DocumentEntry oProps = (DocumentEntry) pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
        DocumentEntry nProps = (DocumentEntry) npf.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
        assertEquals(oProps.getSize(), nProps.getSize());
        // Check that they contain the same data
        byte[] _oData = new byte[oProps.getSize()];
        byte[] _nData = new byte[nProps.getSize()];
        pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
        npf.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
        for (int i = 0; i < _oData.length; i++) {
            //System.out.println(i + "\t" + Integer.toHexString(i));
            assertEquals(_oData[i], _nData[i]);
        }
        npf.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) DocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TempFile(org.apache.poi.util.TempFile) File(java.io.File) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Aggregations

HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)27 Test (org.junit.Test)11 Record (org.apache.poi.hslf.record.Record)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)5 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)5 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)4 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 POIDataSamples (org.apache.poi.POIDataSamples)3 Document (org.apache.poi.hslf.record.Document)3 PersistPtrHolder (org.apache.poi.hslf.record.PersistPtrHolder)3 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)3 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)3 File (java.io.File)2 CurrentUserAtom (org.apache.poi.hslf.record.CurrentUserAtom)2 Notes (org.apache.poi.hslf.record.Notes)2