use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestMovieShape method testCreate.
@Test
public void testCreate() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
String path = "/test-movie.mpg";
int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);
HSLFPictureData thumbnailData = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
MovieShape shape = new MovieShape(movieIdx, thumbnailData);
shape.setAnchor(new Rectangle2D.Double(300, 225, 120, 90));
slide.addShape(shape);
assertEquals(path, shape.getPath());
assertTrue(shape.isAutoPlay());
shape.setAutoPlay(false);
assertFalse(shape.isAutoPlay());
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides().get(0);
shape = (MovieShape) slide.getShapes().get(0);
assertEquals(path, shape.getPath());
assertFalse(shape.isAutoPlay());
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class EmbeddedObjects method main.
@SuppressWarnings("unused")
public static void main(String[] args) throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
HSSFWorkbook workbook = new HSSFWorkbook(fs);
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
//the OLE2 Class Name of the object
String oleName = obj.getOLE2ClassName();
DirectoryNode dn = (obj.hasDirectoryEntry()) ? (DirectoryNode) obj.getDirectory() : null;
Closeable document = null;
if (oleName.equals("Worksheet")) {
document = new HSSFWorkbook(dn, fs, false);
} else if (oleName.equals("Document")) {
document = new HWPFDocument(dn);
} else if (oleName.equals("Presentation")) {
document = new HSLFSlideShow(dn);
} else {
if (dn != null) {
// The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
for (Entry entry : dn) {
String name = entry.getName();
}
} else {
// There is no DirectoryEntry
// Recover the object's data from the HSSFObjectData instance.
byte[] objectData = obj.getObjectData();
}
}
if (document != null) {
document.close();
}
}
workbook.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class LoadEmbedded method loadEmbedded.
public static void loadEmbedded(HSSFWorkbook workbook) throws IOException {
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
//the OLE2 Class Name of the object
String oleName = obj.getOLE2ClassName();
if (oleName.equals("Worksheet")) {
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false);
embeddedWorkbook.close();
} else if (oleName.equals("Document")) {
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
embeddedWordDocument.close();
} else if (oleName.equals("Presentation")) {
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
SlideShow<?, ?> embeddedSlieShow = new HSLFSlideShow(dn);
embeddedSlieShow.close();
} else {
if (obj.hasDirectoryEntry()) {
// The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
for (Entry entry : dn) {
//System.out.println(oleName + "." + entry.getName());
}
} else {
// There is no DirectoryEntry
// Recover the object's data from the HSSFObjectData instance.
byte[] objectData = obj.getObjectData();
}
}
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSound method testRealFile.
@Test
public void testRealFile() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt"));
// Get the document
Document doc = ppt.getDocumentRecord();
SoundCollection soundCollection = null;
Record[] doc_ch = doc.getChildRecords();
for (Record rec : doc_ch) {
if (rec instanceof SoundCollection) {
soundCollection = (SoundCollection) rec;
break;
}
}
assertNotNull(soundCollection);
Sound sound = null;
Record[] sound_ch = soundCollection.getChildRecords();
int k = 0;
for (Record rec : sound_ch) {
if (rec instanceof Sound) {
sound = (Sound) rec;
k++;
}
}
assertNotNull(sound);
assertEquals(1, k);
assertEquals("ringin.wav", sound.getSoundName());
assertEquals(".WAV", sound.getSoundType());
assertNotNull(sound.getSoundData());
byte[] ref_data = slTests.readFile("ringin.wav");
assertArrayEquals(ref_data, sound.getSoundData());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow 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();
}
Aggregations