Search in sources :

Example 1 with FtrDocument

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;
}
Also used : XWPFRelation(org.apache.poi.xwpf.usermodel.XWPFRelation) CTHdrFtr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr) XWPFFooter(org.apache.poi.xwpf.usermodel.XWPFFooter) FtrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument)

Example 2 with FtrDocument

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) POIXMLException(org.apache.poi.POIXMLException) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) IOException(java.io.IOException) POIXMLException(org.apache.poi.POIXMLException) FtrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Aggregations

FtrDocument (org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 POIXMLException (org.apache.poi.POIXMLException)1 XWPFFooter (org.apache.poi.xwpf.usermodel.XWPFFooter)1 XWPFRelation (org.apache.poi.xwpf.usermodel.XWPFRelation)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTHdrFtr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr)1 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)1 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)1 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)1