You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2013/01/11 22:51:50 UTC

[Bug 53009] Problem creating header and footer

https://issues.apache.org/bugzilla/show_bug.cgi?id=53009

--- Comment #2 from Mike McCullough <mi...@gmail.com> ---
I have noticed the same problems as well, and can provide some additional
information where the problem likely occurs. Within XWPFHeaderFooterPolicy, the
code for creating of a footer looks like:

public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) throws
IOException {
        XWPFRelation relation = XWPFRelation.FOOTER;
        String pStyle = "Footer";
        int i = getRelationIndex(relation);
        FtrDocument ftrDoc = FtrDocument.Factory.newInstance();
        XWPFFooter wrapper = (XWPFFooter)doc.createRelationship(relation,
XWPFFactory.getInstance(), i);

        CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);
        wrapper.setHeaderFooter(ftr);

        OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
        ftrDoc.setFtr(ftr);

        XmlOptions xmlOptions = commit(wrapper);

        assignFooter(wrapper, type);
        ftrDoc.save(outputStream, xmlOptions);
        outputStream.close();
        return wrapper;
    }

The important line of code is:

ftrDoc.save(outputStream, xmlOptions);

which provides the first line of XML to be saved (e.g., saved in footer1.xml).

The footer will additionally be saved with the final write() function within
the POIXMLDocument. Since a header or footer is considered to be a
org.apache.poi.openxml4j.opc.PackagePart, the write() function will iterate
through all package parts and save them as well.

The onSave(Set<PackagePart> alreadySaved) function in POIXMLDocumentPart calls
commit() in the first line of the function. Within the overriden implementation
of commit() in the XWPFFooter class, the penultimate line has:

super._getHdrFtr().save(out, xmlOptions);

which will cause the second line of the XML footer information to be written as
well.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org