diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2017-12-31 01:14:08 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2017-12-31 01:14:08 +0000 |
commit | 704b41ab9a11574bcce25a63c4bf43670389f841 (patch) | |
tree | f66d8dd2fd373c1506cf644d9fd648d2225c298f /src/scratchpad/testcases/org/apache/poi | |
parent | cdab1a45110536d6e4abed82152d288b70568d82 (diff) | |
download | poi-704b41ab9a11574bcce25a63c4bf43670389f841.tar.gz poi-704b41ab9a11574bcce25a63c4bf43670389f841.zip |
#61797 - Embed Excel / Ole objects into powerpoint
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819710 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache/poi')
3 files changed, 17 insertions, 16 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java index 281173e23f..f2700d4fac 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java @@ -33,9 +33,9 @@ import java.io.InputStream; import java.util.List; import org.apache.poi.POIDataSamples; -import org.apache.poi.hslf.model.OLEShape; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; +import org.apache.poi.hslf.usermodel.HSLFObjectShape; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.poifs.filesystem.DirectoryNode; @@ -206,12 +206,12 @@ public final class TestExtractor { @Test public void testExtractFromOwnEmbeded() throws IOException { PowerPointExtractor ppe = openExtractor("ppt_with_embeded.ppt"); - List<OLEShape> shapes = ppe.getOLEShapes(); + List<HSLFObjectShape> shapes = ppe.getOLEShapes(); assertEquals("Expected 6 ole shapes", 6, shapes.size()); int num_ppt = 0, num_doc = 0, num_xls = 0; - for (OLEShape ole : shapes) { + for (HSLFObjectShape ole : shapes) { String name = ole.getInstanceName(); - InputStream data = ole.getObjectData().getData(); + InputStream data = ole.getObjectData().getInputStream(); if ("Worksheet".equals(name)) { HSSFWorkbook wb = new HSSFWorkbook(data); num_xls++; @@ -239,8 +239,8 @@ public final class TestExtractor { @Test public void test52991() throws IOException { PowerPointExtractor ppe = openExtractor("badzip.ppt"); - for (OLEShape shape : ppe.getOLEShapes()) { - IOUtils.copy(shape.getObjectData().getData(), new ByteArrayOutputStream()); + for (HSLFObjectShape shape : ppe.getOLEShapes()) { + IOUtils.copy(shape.getObjectData().getInputStream(), new ByteArrayOutputStream()); } ppe.close(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java index d8c331b7fd..16f40a72f7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java @@ -35,6 +35,7 @@ import org.apache.poi.hslf.usermodel.HSLFShape; import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl; +import org.apache.poi.hslf.usermodel.HSLFObjectShape; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; @@ -70,7 +71,7 @@ public final class TestOleEmbedding { HSLFObjectData[] objects = slideShow.getEmbeddedObjects(); assertEquals("Should be two objects", 2, objects.length); for (HSLFObjectData od : objects) { - long checkEMF = IOUtils.calculateChecksum(od.getData()); + long checkEMF = IOUtils.calculateChecksum(od.getInputStream()); assertEquals(checkSums[checkId++], checkEMF); } @@ -86,13 +87,13 @@ public final class TestOleEmbedding { HSLFSlide slide = ppt.getSlides().get(0); int cnt = 0; for (HSLFShape sh : slide.getShapes()) { - if(sh instanceof OLEShape){ + if(sh instanceof HSLFObjectShape){ cnt++; - OLEShape ole = (OLEShape)sh; + HSLFObjectShape ole = (HSLFObjectShape)sh; HSLFObjectData data = ole.getObjectData(); if("Worksheet".equals(ole.getInstanceName())){ //Voila! we created a workbook from the embedded OLE data - HSSFWorkbook wb = new HSSFWorkbook(data.getData()); + HSSFWorkbook wb = new HSSFWorkbook(data.getInputStream()); HSSFSheet sheet = wb.getSheetAt(0); //verify we can access the xls data assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0); @@ -103,7 +104,7 @@ public final class TestOleEmbedding { wb.close(); } else if ("Document".equals(ole.getInstanceName())){ //creating a HWPF document - HWPFDocument doc = new HWPFDocument(data.getData()); + HWPFDocument doc = new HWPFDocument(data.getInputStream()); String txt = doc.getRange().getParagraph(0).text(); assertEquals("OLE embedding is thoroughly unremarkable.\r", txt); doc.close(); @@ -129,14 +130,14 @@ public final class TestOleEmbedding { int oleObjectId1 = ppt.addEmbed(poiData1); HSLFSlide slide1 = ppt.createSlide(); - OLEShape oleShape1 = new OLEShape(pictData); + HSLFObjectShape oleShape1 = new HSLFObjectShape(pictData); oleShape1.setObjectID(oleObjectId1); slide1.addShape(oleShape1); oleShape1.setAnchor(new Rectangle2D.Double(100,100,100,100)); // add second slide with different order in object creation HSLFSlide slide2 = ppt.createSlide(); - OLEShape oleShape2 = new OLEShape(pictData); + HSLFObjectShape oleShape2 = new HSLFObjectShape(pictData); is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleWithImages.xls"); POIFSFileSystem poiData2 = new POIFSFileSystem(is); @@ -152,8 +153,8 @@ public final class TestOleEmbedding { ppt.write(bos); ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray())); - OLEShape comp = (OLEShape)ppt.getSlides().get(0).getShapes().get(0); - byte compData[] = IOUtils.toByteArray(comp.getObjectData().getData()); + HSLFObjectShape comp = (HSLFObjectShape)ppt.getSlides().get(0).getShapes().get(0); + byte compData[] = IOUtils.toByteArray(comp.getObjectData().getInputStream()); bos.reset(); poiData1.writeFilesystem(bos); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 8bb83852e1..df44216093 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -1010,7 +1010,7 @@ public final class TestBugs { long persistId = vbaAtom.getPersistIdRef(); for (HSLFObjectData objData : ppt.getEmbeddedObjects()) { if (objData.getExOleObjStg().getPersistId() == persistId) { - VBAMacroReader mr = new VBAMacroReader(objData.getData()); + VBAMacroReader mr = new VBAMacroReader(objData.getInputStream()); try { return mr.readMacros(); } finally { |