use of org.docx4j.wml.R.Separator in project flexmark-java by vsch.
the class DocxContextImpl method getFootnotesPart.
// @formatter:off
// static String footnotePartXML = "<w:footnotes mc:Ignorable=\"w14 wp14\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\">"
// + "<w:footnote w:id=\"-1\" w:type=\"separator\">" // matching CTFtnDocProps below
// + "<w:p>"
// + "<w:pPr>"
// + "<w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/>"
// +"</w:pPr>"
// + "<w:r>"
// + "<w:separator/>"
// +"</w:r>"
// +"</w:p>"
// +"</w:footnote>"
// + "<w:footnote w:id=\"0\" w:type=\"continuationSeparator\">"
// + "<w:p>"
// + "<w:pPr>"
// + "<w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/>"
// +"</w:pPr>"
// + "<w:r>"
// + "<w:continuationSeparator/>"
// +"</w:r>"
// +"</w:p>"
// +"</w:footnote>"
// +"</w:footnotes>";
// @formatter:on
@Override
public FootnotesPart getFootnotesPart() throws Docx4JException {
// Setup FootnotesPart if necessary,
// along with DocumentSettings
FootnotesPart footnotesPart = myDocumentPart.getFootnotesPart();
if (footnotesPart == null) {
// that'll be the case in this example
// initialise it
footnotesPart = new FootnotesPart();
myDocumentPart.addTargetPart(footnotesPart);
// CTFootnotes footnotes = null;
// footnotes = (CTFootnotes) XmlUtils.unwrap(XmlUtils.unmarshalString(footnotePartXML));
// footnotesPart.setJaxbElement(footnotes);
CTFootnotes footnotes = myFactory.createCTFootnotes();
// JAXBElement<CTFootnotes> footnotesWrapped = myFactory.createFootnotes(footnotes);
// Create object for footnote
CTFtnEdn ftnedn = myFactory.createCTFtnEdn();
footnotes.getFootnote().add(ftnedn);
ftnedn.setId(BigInteger.valueOf(-1));
ftnedn.setType(org.docx4j.wml.STFtnEdn.SEPARATOR);
// Create object for p
P p = myFactory.createP();
ftnedn.getContent().add(p);
// Create object for r
R r = myFactory.createR();
p.getContent().add(r);
// Create object for separator (wrapped in JAXBElement)
Separator rseparator = myFactory.createRSeparator();
JAXBElement<Separator> rseparatorWrapped = myFactory.createRSeparator(rseparator);
r.getContent().add(rseparatorWrapped);
// Create object for footnote
CTFtnEdn ftnedn2 = myFactory.createCTFtnEdn();
footnotes.getFootnote().add(ftnedn2);
ftnedn2.setId(BigInteger.valueOf(0));
ftnedn2.setType(org.docx4j.wml.STFtnEdn.CONTINUATION_SEPARATOR);
// Create object for p
P p2 = myFactory.createP();
ftnedn2.getContent().add(p2);
// Create object for r
R r2 = myFactory.createR();
p2.getContent().add(r2);
// Create object for continuationSeparator (wrapped in JAXBElement)
ContinuationSeparator rcontinuationseparator = myFactory.createRContinuationSeparator();
JAXBElement<ContinuationSeparator> rcontinuationseparatorWrapped = myFactory.createRContinuationSeparator(rcontinuationseparator);
r2.getContent().add(rcontinuationseparatorWrapped);
footnotesPart.setJaxbElement(footnotes);
// Usually the settings part contains footnote properties;
// so add these if not present
DocumentSettingsPart dsp = myDocumentPart.getDocumentSettingsPart();
if (dsp == null) {
// create it
dsp = new DocumentSettingsPart();
myDocumentPart.addTargetPart(dsp);
}
CTSettings settings = dsp.getContents();
if (settings == null) {
settings = myFactory.createCTSettings();
dsp.setJaxbElement(settings);
}
CTFtnDocProps ftndocprops = settings.getFootnotePr();
if (ftndocprops == null) {
// String openXML = "<w:footnotePr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
// + "<w:footnote w:id=\"-1\"/>" // these 2 numbers are special, and correspond with string footnotePartXML above
// + "<w:footnote w:id=\"0\"/>"
// + "</w:footnotePr>";
// settings.setFootnotePr((CTFtnDocProps) XmlUtils.unmarshalString(openXML, Context.jc, CTFtnDocProps.class));
ftndocprops = myFactory.createCTFtnDocProps();
CTFtnEdnSepRef sepRef = myFactory.createCTFtnEdnSepRef();
sepRef.setId(BigInteger.valueOf(-1));
ftndocprops.getFootnote().add(sepRef);
sepRef = myFactory.createCTFtnEdnSepRef();
sepRef.setId(BigInteger.valueOf(0));
ftndocprops.getFootnote().add(sepRef);
settings.setFootnotePr(ftndocprops);
}
}
return footnotesPart;
}
Aggregations