60293 -- Handle illegal "Odd" header/footer in XWPF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1767353 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14babbb970
commit
2633894b39
@ -29,6 +29,7 @@ import org.apache.poi.xwpf.usermodel.XWPFHeader;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
||||
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
|
||||
@ -115,8 +116,14 @@ public class XWPFHeaderFooterPolicy {
|
||||
if (relatedPart != null && relatedPart instanceof XWPFHeader) {
|
||||
hdr = (XWPFHeader) relatedPart;
|
||||
}
|
||||
// Assign it
|
||||
Enum type = ref.getType();
|
||||
// Assign it; treat invalid options as "default" POI-60293
|
||||
Enum type;
|
||||
try {
|
||||
type = ref.getType();
|
||||
} catch (XmlValueOutOfRangeException e) {
|
||||
type = STHdrFtr.DEFAULT;
|
||||
}
|
||||
|
||||
assignHeader(hdr, type);
|
||||
}
|
||||
for (int i = 0; i < sectPr.sizeOfFooterReferenceArray(); i++) {
|
||||
@ -127,8 +134,13 @@ public class XWPFHeaderFooterPolicy {
|
||||
if (relatedPart != null && relatedPart instanceof XWPFFooter) {
|
||||
ftr = (XWPFFooter) relatedPart;
|
||||
}
|
||||
// Assign it
|
||||
Enum type = ref.getType();
|
||||
// Assign it; treat invalid options as "default" POI-60293
|
||||
Enum type;
|
||||
try {
|
||||
type = ref.getType();
|
||||
} catch (XmlValueOutOfRangeException e) {
|
||||
type = STHdrFtr.DEFAULT;
|
||||
}
|
||||
assignFooter(ftr, type);
|
||||
}
|
||||
}
|
||||
|
@ -220,4 +220,11 @@ public final class TestXWPFHeader {
|
||||
public void testGetPictureDataById() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug60293() throws Exception {
|
||||
//test handling of non-standard header/footer options
|
||||
XWPFDocument xwpf = XWPFTestDataSamples.openSampleDocument("60293.docx");
|
||||
assertEquals(3, xwpf.getHeaderList().size());
|
||||
}
|
||||
}
|
||||
|
BIN
test-data/document/60293.docx
Normal file
BIN
test-data/document/60293.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user