Search in sources :

Example 1 with CTBr

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr in project poi by apache.

the class XWPFRun method addBreak.

/**
     * Specifies that a break shall be placed at the current location in the run
     * content.
     * A break is a special character which is used to override the
     * normal line breaking that would be performed based on the normal layout
     * of the document's contents.
     * <p>
     * The behavior of this break character (the
     * location where text shall be restarted after this break) shall be
     * determined by its type values.
     * </p>
     *
     * @see BreakType
     */
public void addBreak(BreakType type) {
    CTBr br = run.addNewBr();
    br.setType(STBrType.Enum.forInt(type.getValue()));
}
Also used : CTBr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr)

Example 2 with CTBr

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr in project poi by apache.

the class XWPFRun method text.

/**
     * Returns the string version of the text, with tabs and
     * carriage returns in place of their xml equivalents.
     */
public String text() {
    StringBuffer text = new StringBuffer();
    // Grab the text and tabs of the text run
    // Do so in a way that preserves the ordering
    XmlCursor c = run.newCursor();
    c.selectPath("./*");
    while (c.toNextSelection()) {
        XmlObject o = c.getObject();
        if (o instanceof CTText) {
            String tagName = o.getDomNode().getNodeName();
            //  in the normal text output
            if (!"w:instrText".equals(tagName)) {
                text.append(((CTText) o).getStringValue());
            }
        }
        // Complex type evaluation (currently only for extraction of check boxes)
        if (o instanceof CTFldChar) {
            CTFldChar ctfldChar = ((CTFldChar) o);
            if (ctfldChar.getFldCharType() == STFldCharType.BEGIN) {
                if (ctfldChar.getFfData() != null) {
                    for (CTFFCheckBox checkBox : ctfldChar.getFfData().getCheckBoxList()) {
                        if (checkBox.getDefault() != null && checkBox.getDefault().getVal() == STOnOff.X_1) {
                            text.append("|X|");
                        } else {
                            text.append("|_|");
                        }
                    }
                }
            }
        }
        if (o instanceof CTPTab) {
            text.append("\t");
        }
        if (o instanceof CTBr) {
            text.append("\n");
        }
        if (o instanceof CTEmpty) {
            // Some inline text elements get returned not as
            //  themselves, but as CTEmpty, owing to some odd
            //  definitions around line 5642 of the XSDs
            // This bit works around it, and replicates the above
            //  rules for that case
            String tagName = o.getDomNode().getNodeName();
            if ("w:tab".equals(tagName) || "tab".equals(tagName)) {
                text.append("\t");
            }
            if ("w:br".equals(tagName) || "br".equals(tagName)) {
                text.append("\n");
            }
            if ("w:cr".equals(tagName) || "cr".equals(tagName)) {
                text.append("\n");
            }
        }
        if (o instanceof CTFtnEdnRef) {
            CTFtnEdnRef ftn = (CTFtnEdnRef) o;
            String footnoteRef = ftn.getDomNode().getLocalName().equals("footnoteReference") ? "[footnoteRef:" + ftn.getId().intValue() + "]" : "[endnoteRef:" + ftn.getId().intValue() + "]";
            text.append(footnoteRef);
        }
    }
    c.dispose();
    // Any picture text?
    if (pictureText != null && pictureText.length() > 0) {
        text.append("\n").append(pictureText);
    }
    return text.toString();
}
Also used : CTFtnEdnRef(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef) CTText(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText) CTEmpty(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty) XmlObject(org.apache.xmlbeans.XmlObject) XmlString(org.apache.xmlbeans.XmlString) CTPTab(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab) CTFFCheckBox(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFFCheckBox) CTBr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr) XmlCursor(org.apache.xmlbeans.XmlCursor) CTFldChar(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar)

Example 3 with CTBr

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr in project poi by apache.

the class XWPFRun method addBreak.

/**
     * Specifies that a break shall be placed at the current location in the run
     * content. A break is a special character which is used to override the
     * normal line breaking that would be performed based on the normal layout
     * of the document's contents.
     * <p>
     * The behavior of this break character (the
     * location where text shall be restarted after this break) shall be
     * determined by its type (in this case is BreakType.TEXT_WRAPPING as default) and clear attribute values.
     * </p>
     *
     * @see BreakClear
     */
public void addBreak(BreakClear clear) {
    CTBr br = run.addNewBr();
    br.setType(STBrType.Enum.forInt(BreakType.TEXT_WRAPPING.getValue()));
    br.setClear(STBrClear.Enum.forInt(clear.getValue()));
}
Also used : CTBr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr)

Example 4 with CTBr

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr in project poi by apache.

the class TestXWPFRun method testAddPageBreak.

@Test
public void testAddPageBreak() {
    ctRun.addNewT().setStringValue("TEST STRING");
    ctRun.addNewBr();
    ctRun.addNewT().setStringValue("TEST2 STRING");
    CTBr breac = ctRun.addNewBr();
    breac.setClear(STBrClear.LEFT);
    ctRun.addNewT().setStringValue("TEST3 STRING");
    assertEquals(2, ctRun.sizeOfBrArray());
    XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), irb);
    run.setText("TEXT1");
    run.addBreak();
    run.setText("TEXT2");
    run.addBreak(BreakType.TEXT_WRAPPING);
    assertEquals(2, run.getCTR().sizeOfBrArray());
}
Also used : CTBr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr) Test(org.junit.Test)

Aggregations

CTBr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr)4 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 XmlString (org.apache.xmlbeans.XmlString)1 Test (org.junit.Test)1 CTEmpty (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty)1 CTFFCheckBox (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFFCheckBox)1 CTFldChar (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar)1 CTFtnEdnRef (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef)1 CTPTab (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab)1 CTText (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText)1