<changes>
<release version="3.7-beta3" date="2010-??-??">
+ <action dev="poi-developers" type="fix">49936 - Handle HWPF documents with problematic HeaderStories better</action>
<action dev="poi-developers" type="fix">49933 - Support sections in Word 6 and Word 95 files (HWPFOldDocument)</action>
<action dev="poi-developers" type="fix">49941 - Correctly handle space preservation of XSSFRichTextRuns when applying fonts to parts of the string</action>
<action dev="poi-developers" type="fix">Correct XWPFRun detection of bold/italic in a paragraph with multiple runs of different styles</action>
// Empty story
return "";
}
+ if(prop.getEnd() < prop.getStart()) {
+ // Broken properties?
+ return "";
+ }
+
+ // Ensure we're getting a sensible length
+ String rawText = headerStories.text();
+ int start = Math.min(prop.getStart(), rawText.length());
+ int end = Math.min(prop.getEnd(), rawText.length());
// Grab the contents
- String text =
- headerStories.text().substring(prop.getStart(), prop.getEnd());
+ String text = rawText.substring(start, end);
// Strip off fields and macros if requested
if(stripFields) {
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestCase;
import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.hwpf.model.StyleSheet;
/**
}
}
}
+
+ /**
+ * Bug #49936 - Problems with reading the header out of
+ * the Header Stories
+ */
+ public void testProblemHeaderStories49936() throws Exception {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("HeaderFooterProblematic.doc");
+ HeaderStories hs = new HeaderStories(doc);
+
+ assertEquals("", hs.getFirstHeader());
+ assertEquals("\r", hs.getEvenHeader());
+ assertEquals("", hs.getOddHeader());
+
+ assertEquals("", hs.getFirstFooter());
+ assertEquals("", hs.getEvenFooter());
+ assertEquals("", hs.getOddFooter());
+
+ WordExtractor ext = new WordExtractor(doc);
+ assertEquals("\n", ext.getHeaderText());
+ assertEquals("", ext.getFooterText());
+ }
/**
* Bug #48245 - don't include the text from the