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