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;
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++) {
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);
}
}
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());
+ }
}