InsertHelper { public void insertImage(final OdsDocument document, final Table table, final String frameName, final File source, final String destName, final SVGRectangle rectangle) throws IOException { final String sourceName = source.getName(); final String mediaType = this.getMediaType(sourceName); document.addExtraFile("Pictures/" + destName, mediaType, this.fileUtil.readFile(source)); table.addShape( DrawFrame.builder(frameName, new DrawImage("Pictures/" + destName), rectangle) .build()); } InsertHelper(final FileUtil fileUtil); static InsertHelper create(); void insertImage(final OdsDocument document, final Table table, final String frameName,
                            final File source, final String destName, final SVGRectangle rectangle); void insertImage(final OdsDocument document, final Table table, final String frameName,
                            final InputStream sourceStream, final String destName,
                            final SVGRectangle rectangle); DrawFillBitmap createDrawFillImage(final OdsDocument document,
                                              final InputStream sourceStream, final String name,
                                              final String href); void insertObject(final OdsDocument document, final Table table, final String frameName,
                             final String objectName, final String objectMediaType,
                             final String objectVersion, final InputStream sourceStream,
                             final SVGRectangle rectangle, final GraphicStyle gs);  }
@Test public void testInsertImageFile() throws IOException { final File source = File.createTempFile("image1", ".jpg"); final SVGRectangle rectangle = SVGRectangle.cm(0, 1, 2, 3); final Capture<DrawFrame> df = EasyMock.newCapture(); PowerMock.resetAll(); this.document.addExtraFile("Pictures/dest1.foo", "image/jpeg", new byte[0]); this.table.addShape(EasyMock.capture(df)); PowerMock.replayAll(); this.ih.insertImage(this.document, this.table, "frame", source, "dest1.foo", rectangle); PowerMock.verifyAll(); TestHelper.assertXMLEquals( "<draw:frame draw:name=\"frame\" draw:z-index=\"0\" svg:x=\"0cm\" svg:y=\"1cm\" svg:width=\"2cm\" svg:height=\"3cm\">" + "<draw:image xlink:href=\"Pictures/dest1.foo\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" + "</draw:frame>", df.getValue()); }
@Test public void testInsertImageStream() throws IOException { final SVGRectangle rectangle = SVGRectangle.cm(0, 1, 2, 3); final Capture<DrawFrame> df = EasyMock.newCapture(); PowerMock.resetAll(); this.document.addExtraFile("Pictures/dest1.foo", "image/foo", new byte[0]); this.table.addShape(EasyMock.capture(df)); PowerMock.replayAll(); this.ih.insertImage(this.document, this.table, "frame", new ByteArrayInputStream(new byte[0]), "dest1.foo", rectangle); PowerMock.verifyAll(); TestHelper.assertXMLEquals( "<draw:frame draw:name=\"frame\" draw:z-index=\"0\" svg:x=\"0cm\" svg:y=\"1cm\" svg:width=\"2cm\" svg:height=\"3cm\">" + "<draw:image xlink:href=\"Pictures/dest1.foo\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" + "</draw:frame>", df.getValue()); }