use of org.docx4j.openpackaging.parts.Part in project flexmark-java by vsch.
the class DocxRenderer method setDefaultStyleAndNumbering.
static void setDefaultStyleAndNumbering(WordprocessingMLPackage out, final DataHolder options) {
try {
// (main doc part it if necessary)
MainDocumentPart documentPart = out.getMainDocumentPart();
if (documentPart == null) {
try {
documentPart = new MainDocumentPart();
out.addTargetPart(documentPart);
} catch (InvalidFormatException e) {
e.printStackTrace();
}
}
if (documentPart.getStyleDefinitionsPart() == null) {
Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
final Styles styles = (Styles) XmlUtils.unmarshalString(STYLES_XML.getFrom(options));
((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart).setJaxbElement(styles);
// NB - add it to main doc part, not package!
documentPart.addTargetPart(stylesPart);
assert documentPart.getStyleDefinitionsPart() != null : "Styles failed to set";
}
if (documentPart.getNumberingDefinitionsPart() == null) {
// add it
Part numberingPart = new org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart();
final Numbering numbering = (Numbering) XmlUtils.unmarshalString(NUMBERING_XML.getFrom(options));
((org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) numberingPart).setJaxbElement(numbering);
// NB - add it to main doc part, not package!
documentPart.addTargetPart(numberingPart);
assert documentPart.getNumberingDefinitionsPart() != null : "Numbering failed to set";
}
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Aggregations