Search in sources :

Example 6 with HSLFSlideShowImpl

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

the class TestReWriteSanity method setUp.

@Before
public void setUp() throws Exception {
    POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
    pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
    ss = new HSLFSlideShowImpl(pfs);
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) POIDataSamples(org.apache.poi.POIDataSamples) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Before(org.junit.Before)

Example 7 with HSLFSlideShowImpl

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

the class TestOleEmbedding method testOleEmbedding2003.

/**
     * Tests support for OLE objects.
     *
     * @throws Exception if an error occurs.
     */
@Test
public void testOleEmbedding2003() throws IOException {
    HSLFSlideShowImpl slideShow = new HSLFSlideShowImpl(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
    // Placeholder EMFs for clients that don't support the OLE components.
    List<HSLFPictureData> pictures = slideShow.getPictureData();
    assertEquals("Should be two pictures", 2, pictures.size());
    long[] checkSums = { 0xD37A4204l, 0x26A62F68l, 0x82853169l, 0xE0E45D2Bl };
    int checkId = 0;
    // check for checksum to be uptodate
    for (HSLFPictureData pd : pictures) {
        long checkEMF = IOUtils.calculateChecksum(pd.getData());
        assertEquals(checkSums[checkId++], checkEMF);
    }
    // Actual embedded objects.
    HSLFObjectData[] objects = slideShow.getEmbeddedObjects();
    assertEquals("Should be two objects", 2, objects.length);
    for (HSLFObjectData od : objects) {
        long checkEMF = IOUtils.calculateChecksum(od.getData());
        assertEquals(checkSums[checkId++], checkEMF);
    }
    slideShow.close();
}
Also used : HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFObjectData(org.apache.poi.hslf.usermodel.HSLFObjectData) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 8 with HSLFSlideShowImpl

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

the class PPDrawingTextListing 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 PPDrawings at any second level position
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        Record[] children = records[i].getChildRecords();
        if (children != null && children.length != 0) {
            for (int j = 0; j < children.length; j++) {
                if (children[j] instanceof PPDrawing) {
                    System.out.println("Found PPDrawing at " + j + " in top level record " + i + " (" + records[i].getRecordType() + ")");
                    // Look for EscherTextboxWrapper's
                    PPDrawing ppd = (PPDrawing) children[j];
                    EscherTextboxWrapper[] wrappers = ppd.getTextboxWrappers();
                    System.out.println("  Has " + wrappers.length + " textbox wrappers within");
                    // Loop over the wrappers, showing what they contain
                    for (int k = 0; k < wrappers.length; k++) {
                        EscherTextboxWrapper tbw = wrappers[k];
                        System.out.println("    " + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
                        // Loop over the records, printing the text
                        Record[] pptatoms = tbw.getChildRecords();
                        for (int l = 0; l < pptatoms.length; l++) {
                            String text = null;
                            if (pptatoms[l] instanceof TextBytesAtom) {
                                TextBytesAtom tba = (TextBytesAtom) pptatoms[l];
                                text = tba.getText();
                            }
                            if (pptatoms[l] instanceof TextCharsAtom) {
                                TextCharsAtom tca = (TextCharsAtom) pptatoms[l];
                                text = tca.getText();
                            }
                            if (text != null) {
                                text = text.replace('\r', '\n');
                                System.out.println("        ''" + text + "''");
                            }
                        }
                    }
                }
            }
        }
    }
    ss.close();
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 9 with HSLFSlideShowImpl

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

the class TestCurrentUserAtom method readEnc.

@Test(expected = EncryptedPowerPointFileException.class)
public void readEnc() throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(encFile));
    try {
        new CurrentUserAtom(fs.getRoot());
        // not yet failed
        assertTrue(true);
        new HSLFSlideShowImpl(fs).close();
    } finally {
        fs.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 10 with HSLFSlideShowImpl

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

the class TestDocumentEncryption method cryptoAPIChangeKeySize.

@Test
public void cryptoAPIChangeKeySize() throws Exception {
    String pptFile = "cryptoapi-proc2356.ppt";
    Biff8EncryptionKey.setCurrentUserPassword("crypto");
    NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
    HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
    // need to cache data (i.e. read all data) before changing the key size
    List<HSLFPictureData> picsExpected = hss.getPictureData();
    hss.getDocumentSummaryInformation();
    EncryptionInfo ei = hss.getDocumentEncryptionAtom().getEncryptionInfo();
    ((CryptoAPIEncryptionHeader) ei.getHeader()).setKeySize(0x78);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    hss.write(bos);
    hss.close();
    fs.close();
    fs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
    hss = new HSLFSlideShowImpl(fs);
    List<HSLFPictureData> picsActual = hss.getPictureData();
    assertEquals(picsExpected.size(), picsActual.size());
    for (int i = 0; i < picsExpected.size(); i++) {
        assertArrayEquals(picsExpected.get(i).getRawData(), picsActual.get(i).getRawData());
    }
    hss.close();
    fs.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) CryptoAPIEncryptionHeader(org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

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