Search in sources :

Example 11 with HSLFSlideShowImpl

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();
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) ArrayList(java.util.ArrayList) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Test(org.junit.Test)

Example 12 with HSLFSlideShowImpl

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;
        }
    }
}
Also used : InputStream(java.io.InputStream) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) Before(org.junit.Before)

Example 13 with HSLFSlideShowImpl

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);
}
Also used : Record(org.apache.poi.hslf.record.Record) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 14 with HSLFSlideShowImpl

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();
}
Also used : HashMap(java.util.HashMap) PersistPtrHolder(org.apache.poi.hslf.record.PersistPtrHolder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CurrentUserAtom(org.apache.poi.hslf.record.CurrentUserAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Record(org.apache.poi.hslf.record.Record) UserEditAtom(org.apache.poi.hslf.record.UserEditAtom) Test(org.junit.Test)

Example 15 with HSLFSlideShowImpl

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

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