use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestExHyperlink method testRealFile.
@Test
public void testRealFile() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
HSLFSlideShow ss = new HSLFSlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
// Get the ExObjList
ExObjList exObjList = null;
for (final Record rec : doc._children) {
if (rec instanceof ExObjList) {
exObjList = (ExObjList) rec;
}
}
assertNotNull(exObjList);
// Within that, grab out the Hyperlink atoms
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
for (Record ch : exObjList._children) {
if (ch instanceof ExHyperlink) {
linksA.add((ExHyperlink) ch);
}
}
// Should be 4 of them
assertEquals(4, linksA.size());
ExHyperlink[] links = new ExHyperlink[linksA.size()];
linksA.toArray(links);
assertEquals(4, exObjList.getExHyperlinks().length);
// Check the other way
// Check they have what we expect in them
assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/poi/", links[0].getLinkURL());
assertEquals(2, links[1].getExHyperlinkAtom().getNumber());
assertEquals("http://slashdot.org/", links[1].getLinkURL());
assertEquals(3, links[2].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/poi/hssf/", links[2].getLinkURL());
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestRecordContainer method setUp.
@Before
public void setUp() throws IOException {
// Find a real RecordContainer record
InputStream is = slTests.openResourceAsStream("basic_test_ppt_file.ppt");
hss = new HSLFSlideShowImpl(is);
is.close();
Record[] r = hss.getRecords();
for (Record rec : r) {
if (rec instanceof RecordContainer) {
recordContainer = (RecordContainer) rec;
return;
}
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class HSLFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws Exception {
HSLFSlideShowImpl slide = new HSLFSlideShowImpl(stream);
assertNotNull(slide.getCurrentUserAtom());
assertNotNull(slide.getEmbeddedObjects());
assertNotNull(slide.getUnderlyingBytes());
assertNotNull(slide.getPictureData());
Record[] records = slide.getRecords();
assertNotNull(records);
for (Record record : records) {
assertNotNull("Found a record which was null", record);
assertTrue(record.getRecordType() >= 0);
}
handlePOIDocument(slide);
HSLFSlideShow ss = new HSLFSlideShow(slide);
handleSlideShow(ss);
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl 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();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestReWrite method setUp.
@Before
public void setUp() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hssA = new HSLFSlideShowImpl(pfsA);
pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
hssB = new HSLFSlideShowImpl(pfsB);
pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
hssC = new HSLFSlideShowImpl(pfsC);
}
Aggregations