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);
}
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();
}
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();
}
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();
}
}
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();
}
Aggregations