==================================================================== */
package org.apache.poi.stress;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.junit.Test;
slide.close();
}
- // a test-case to test this locally without executing the full TestAllFiles
+ public void handleExtracting(File file) throws Exception {
+ super.handleExtracting(file);
+
+
+ // additionally try the other getText() methods
+
+ XSLFPowerPointExtractor extractor = (XSLFPowerPointExtractor) ExtractorFactory.createExtractor(file);
+ try {
+ assertNotNull(extractor);
+
+ assertNotNull(extractor.getText(true, true, true));
+ assertEquals("With all options disabled we should not get text",
+ "", extractor.getText(false, false, false));
+ } finally {
+ extractor.close();
+ }
+ }
+
+ // 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/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx");
@Test
public void testExtractor() throws Exception {
handleExtracting(new File("test-data/slideshow/ae.ac.uaeu.faculty_nafaachbili_GeomLec1.pptx"));
- }
+ }
}
\ No newline at end of file
==================================================================== */
package org.apache.poi.xslf.extractor;
-import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.POITextExtractor;
+import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow;
+import junit.framework.TestCase;
+
/**
* Tests for HXFPowerPointExtractor
*/
extractor.close();
}
}
+
+ public void test45541() throws Exception {
+ // extract text from a powerpoint that has a header in the notes-element
+ POITextExtractor extr = ExtractorFactory.createExtractor(slTests
+ .openResourceAsStream("45541_Header.pptx"));
+ String text = extr.getText();
+ assertNotNull(text);
+ assertFalse("Had: " + text, text.contains("testdoc"));
+
+ text = ((XSLFPowerPointExtractor)extr).getText(false, true);
+ assertNotNull(text);
+ assertTrue("Had: " + text, text.contains("testdoc"));
+ extr.close();
+ assertNotNull(text);
+
+ // extract text from a powerpoint that has a footer in the master-slide
+ extr = ExtractorFactory.createExtractor(slTests
+ .openResourceAsStream("45541_Footer.pptx"));
+ text = extr.getText();
+ assertNotNull(text);
+ assertFalse("Had " + text, text.contains("testdoc"));
+
+ text = ((XSLFPowerPointExtractor)extr).getText(false, true);
+ assertNotNull(text);
+ assertFalse("Had: " + text, text.contains("testdoc"));
+
+ text = ((XSLFPowerPointExtractor)extr).getText(false, false, true);
+ assertNotNull(text);
+ assertFalse("Had: " + text, text.contains("testdoc"));
+
+ extr.close();
+ }
}