Start on bug #45537 - headers and footers from ppt

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@682778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-08-05 16:33:07 +00:00
parent 36dd48e1f1
commit d09ecf579c
4 changed files with 45 additions and 0 deletions

View File

@ -175,6 +175,12 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
if(getSlideText) { if(getSlideText) {
for(int i=0; i<_slides.length; i++) { for(int i=0; i<_slides.length; i++) {
Slide slide = _slides[i]; Slide slide = _slides[i];
HeadersFooters hf = slide.getHeadersFooters();
if(hf != null && hf.getHeaderText() != null) {
ret.append(hf.getHeaderText() + "\n");
}
TextRun[] runs = slide.getTextRuns(); TextRun[] runs = slide.getTextRuns();
for(int j=0; j<runs.length; j++) { for(int j=0; j<runs.length; j++) {
TextRun run = runs[j]; TextRun run = runs[j];
@ -187,6 +193,10 @@ public class PowerPointExtractor extends POIOLE2TextExtractor
} }
} }
if(hf != null && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
}
if(getCommentText) { if(getCommentText) {
Comment[] comments = slide.getComments(); Comment[] comments = slide.getComments();
for(int j=0; j<comments.length; j++) { for(int j=0; j<comments.length; j++) {

View File

@ -24,6 +24,7 @@ package org.apache.poi.hslf.extractor;
import java.io.FileInputStream; import java.io.FileInputStream;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@ -248,4 +249,38 @@ public class TextExtractor extends TestCase {
text = ppe.getText(); text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc")); assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
} }
/**
* From bug #45537
*/
public void DISABLEDtestHeaderFooter() throws Exception {
String filename, text;
// With a header
filename = dirname + "/45537_Header.ppt";
HSLFSlideShow hslf = new HSLFSlideShow(new FileInputStream(filename));
SlideShow ss = new SlideShow(hslf);
assertNotNull(ss.getSlides()[0].getHeadersFooters());
assertEquals("testdoc test phrase", ss.getSlides()[0].getHeadersFooters().getHeaderText());
ppe = new PowerPointExtractor(hslf);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
// And with a footer
filename = dirname + "/45537_Footer.ppt";
hslf = new HSLFSlideShow(new FileInputStream(filename));
ss = new SlideShow(hslf);
assertNotNull(ss.getSlides()[0].getHeadersFooters());
assertEquals("testdoc test phrase", ss.getSlides()[0].getHeadersFooters().getFooterText());
ppe = new PowerPointExtractor(filename);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
}
} }