Search in sources :

Example 1 with CTSdtBlock

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();
        }
    }
}
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)

Example 2 with CTSdtBlock

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

Example 3 with CTSdtBlock

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();
        }
    }
}
Also used : HdrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) 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) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 4 with CTSdtBlock

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();
		}
        */
}
Also used : CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Aggregations

CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)4 XmlCursor (org.apache.xmlbeans.XmlCursor)3 XmlObject (org.apache.xmlbeans.XmlObject)3 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)3 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)3 InputStream (java.io.InputStream)2 POIXMLException (org.apache.poi.POIXMLException)2 IOException (java.io.IOException)1 XmlException (org.apache.xmlbeans.XmlException)1 FtrDocument (org.openxmlformats.schemas.wordprocessingml.x2006.main.FtrDocument)1 HdrDocument (org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument)1