use of org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument in project poi by apache.
the class XWPFHeaderFooterPolicy method createFooter.
/**
* Creates a new footer of the specified type, to which the
* supplied (and previously unattached!) paragraphs are
* added to.
*/
public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) {
XWPFFooter footer = getFooter(type);
if (footer == null) {
FtrDocument ftrDoc = FtrDocument.Factory.newInstance();
XWPFRelation relation = XWPFRelation.FOOTER;
int i = getRelationIndex(relation);
XWPFFooter wrapper = (XWPFFooter) doc.createRelationship(relation, XWPFFactory.getInstance(), i);
wrapper.setXWPFDocument(doc);
String pStyle = "Footer";
CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);
wrapper.setHeaderFooter(ftr);
ftrDoc.setFtr(ftr);
assignFooter(wrapper, type);
footer = wrapper;
}
return footer;
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument in project poi by apache.
the class XWPFFooter method onDocumentRead.
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
FtrDocument ftrDocument = null;
InputStream is = null;
try {
is = getPackagePart().getInputStream();
ftrDocument = FtrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = ftrDocument.getFtr();
// parse the document with cursor and add
// the XmlObject to its lists
XmlCursor cursor = headerFooter.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
paragraphs.add(p);
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
tables.add(t);
bodyElements.add(t);
}
if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
} catch (Exception e) {
throw new POIXMLException(e);
} finally {
if (is != null) {
is.close();
}
}
}
Aggregations