aboutsummaryrefslogtreecommitdiffstats
path: root/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-03-01 17:50:16 +0000
committerDominik Stadler <centic@apache.org>2015-03-01 17:50:16 +0000
commit6eeb0a7c19287ad149d13e3b6741a5233273aac5 (patch)
tree55fb83376c11c114612ec1f834e98100975b85e8 /src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
parentaa08cababdcfc97d210e7599222d27ff8670b45d (diff)
downloadpoi-6eeb0a7c19287ad149d13e3b6741a5233273aac5.tar.gz
poi-6eeb0a7c19287ad149d13e3b6741a5233273aac5.zip
Add missing close and handle theme-pptx in ExtractorFactory. Add creating slide-bitmaps to PPTX integration test.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1663137 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java')
-rw-r--r--src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java66
1 files changed, 62 insertions, 4 deletions
diff --git a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
index e6cbb184b2..b734c4e4bc 100644
--- a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java
@@ -18,35 +18,93 @@ package org.apache.poi.stress;
import static org.junit.Assert.assertNotNull;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFNotes;
+import org.apache.poi.xslf.usermodel.XSLFShape;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
import org.junit.Test;
public class XSLFFileHandler extends AbstractFileHandler {
@Override
public void handleFile(InputStream stream) throws Exception {
- // ignore password protected files
- if (POIXMLDocumentHandler.isEncrypted(stream)) return;
-
XSLFSlideShow slide = new XSLFSlideShow(OPCPackage.open(stream));
assertNotNull(slide.getPresentation());
assertNotNull(slide.getSlideMasterReferences());
assertNotNull(slide.getSlideReferences());
new POIXMLDocumentHandler().handlePOIXMLDocument(slide);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ slide.write(out);
+ } finally {
+ out.close();
+ }
+
+ createBitmaps(out);
}
+ private void createBitmaps(ByteArrayOutputStream out) throws IOException {
+ XMLSlideShow ppt = new XMLSlideShow(new ByteArrayInputStream(out.toByteArray()));
+ Dimension pgsize = ppt.getPageSize();
+ XSLFSlide[] xmlSlide = ppt.getSlides();
+ int slideSize = xmlSlide.length;
+ for (int i = 0; i < slideSize; i++) {
+// System.out.println("slide-" + (i + 1));
+// System.out.println("" + xmlSlide[i].getTitle());
+
+ BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = img.createGraphics();
+
+ // draw stuff
+ xmlSlide[i].draw(graphics);
+
+ // Also try to read notes
+ XSLFNotes notes = xmlSlide[i].getNotes();
+ if(notes != null) {
+ for (XSLFShape note : notes) {
+ note.draw(graphics);
+
+ if (note instanceof XSLFTextShape) {
+ XSLFTextShape txShape = (XSLFTextShape) note;
+ for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
+ xslfParagraph.getText();
+ }
+ }
+ }
+ }
+ }
+ }
+
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
- InputStream stream = new FileInputStream("test-data/slideshow/testPPT.pptx");
+ InputStream stream = new FileInputStream("test-data/slideshow/pptx2svg.pptx");
try {
handleFile(stream);
} finally {
stream.close();
}
}
+
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void testExtractor() throws Exception {
+ handleExtracting(new File("test-data/slideshow/testPPT.thmx"));
+ }
} \ No newline at end of file