use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock 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();
}
}
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock in project poi by apache.
the class XWPFFootnote method init.
private void init() {
XmlCursor cursor = ctFtnEdn.newCursor();
//copied from XWPFDocument...should centralize this code
//to avoid duplication
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock in project poi by apache.
the class XWPFHeader method onDocumentRead.
/**
* reads the document
*
* @throws IOException
*/
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
HdrDocument hdrDocument = null;
InputStream is = null;
try {
is = getPackagePart().getInputStream();
hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = hdrDocument.getHdr();
// 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 (XmlException e) {
throw new POIXMLException(e);
} finally {
if (is != null) {
is.close();
}
}
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock in project poi by apache.
the class TestXWPFHeadings method testSetParagraphStyle.
public void testSetParagraphStyle() throws IOException, XmlException {
//new clean instance of paragraph
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("heading123.docx");
XWPFParagraph p = doc.createParagraph();
XWPFRun run = p.createRun();
run.setText("Heading 1");
CTSdtBlock block = doc.getDocument().getBody().addNewSdt();
assertNull(p.getStyle());
p.setStyle(HEADING1);
assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal());
doc.createTOC();
/*
// TODO - finish this test
if (false) {
CTStyles styles = doc.getStyle();
CTStyle style = styles.addNewStyle();
style.setType(STStyleType.PARAGRAPH);
style.setStyleId("Heading1");
}
if (false) {
File file = TempFile.createTempFile("testHeaders", ".docx");
OutputStream out = new FileOutputStream(file);
doc.write(out);
out.close();
}
*/
}
Aggregations