Index: src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
===================================================================
--- src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (revision 712662)
+++ src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (working copy)
@@ -17,80 +17,182 @@
package org.apache.poi.xwpf.usermodel;
import java.io.File;
+import java.math.BigInteger;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
-
import junit.framework.TestCase;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
+
/**
* Tests for XWPF Paragraphs
*/
public class TestXWPFParagraph extends TestCase {
- /**
- * A simple file
- */
- private XWPFDocument xml;
- private File file;
+ /**
+ * A simple file
+ */
+ private XWPFDocument xml;
+ private File file;
+
+ /*
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ file = new File(
+ System.getProperty("HWPF.testdata.path") +
+ File.separator + "ThreeColHead.docx"
+ );
+ assertTrue(file.exists());
+ xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
+ }
+ */
+
+ /**
+ * Check that we get the right paragraph from the header
+ */
+ public void testHeaderParagraph() throws Exception {
+ XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
+ assertNotNull(hdr);
+
+ XWPFParagraph[] ps = hdr.getParagraphs();
+ assertEquals(1, ps.length);
+ XWPFParagraph p = ps[0];
+
+ assertEquals(5, p.getCTP().getRArray().length);
+ assertEquals("First header column!\tMid header\tRight header!", p
+ .getText());
+ }
+
+ /**
+ * Check that we get the right paragraphs from the document
+ */
+ public void testDocumentParagraph() throws Exception {
+ XWPFParagraph[] ps = xml.getParagraphs();
+ assertEquals(10, ps.length);
+
+ assertFalse(ps[0].isEmpty());
+ assertEquals(
+ "This is a sample word document. It has two pages. It has a three column heading, but no footer.",
+ ps[0].getText());
+
+ assertTrue(ps[1].isEmpty());
+ assertEquals("", ps[1].getText());
+
+ assertFalse(ps[2].isEmpty());
+ assertEquals("HEADING TEXT", ps[2].getText());
+
+ assertTrue(ps[3].isEmpty());
+ assertEquals("", ps[3].getText());
+
+ assertFalse(ps[4].isEmpty());
+ assertEquals("More on page one", ps[4].getText());
+ }
+
+ public void testSetGetBorderTop() {
+ //new clean instance of paragraph
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
+ //bordi
+ CTPBdr bdr = ppr.addNewPBdr();
+ CTBorder borderTop = bdr.addNewTop();
+ borderTop.setVal(STBorder.APPLES);
+ bdr.setTop(borderTop);
+ assertEquals(Borders.APPLES, p.getBorderTop());
+ p.setBorderTop(Borders.SINGLE);
+ assertEquals(STBorder.SINGLE, borderTop.getVal());
+ }
+
+ public void testSetGetAlignment() {
+ //new clean instance of paragraph
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
+
+ CTJc align = ppr.addNewJc();
+ align.setVal(STJc.CENTER);
+ assertEquals(ParagraphAlignment.CENTER,p.getAlignment());
- protected void setUp() throws Exception {
- super.setUp();
-
- file = new File(
- System.getProperty("HWPF.testdata.path") +
- File.separator + "ThreeColHead.docx"
- );
- assertTrue(file.exists());
- xml = new XWPFDocument(POIXMLDocument.openPackage(file.toString()));
- }
+ p.setAlignment(ParagraphAlignment.BOTH);
+ assertEquals(STJc.BOTH,ppr.getJc().getVal());
+ }
+
+ public void testSetGetSpacing() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
- /**
- * Check that we get the right paragraph from the header
- */
- public void testHeaderParagraph() throws Exception {
- XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
- assertNotNull(hdr);
-
- XWPFParagraph[] ps = hdr.getParagraphs();
- assertEquals(1, ps.length);
- XWPFParagraph p = ps[0];
-
- assertEquals(5, p.getCTP().getRArray().length);
- assertEquals(
- "First header column!\tMid header\tRight header!",
- p.getText()
- );
- }
+ //TEST ALL OTHERS POSSIBLE COMBINATIONS
+ CTSpacing spacing = ppr.addNewSpacing();
+ spacing.setAfter(new BigInteger("10"));
+ assertEquals(10, p.getSpacingAfter().longValue());
- /**
- * Check that we get the right paragraphs from the document
- */
- public void testDocumentParagraph() throws Exception {
- XWPFParagraph[] ps = xml.getParagraphs();
- assertEquals(10, ps.length);
-
- assertFalse(ps[0].isEmpty());
- assertEquals(
- "This is a sample word document. It has two pages. It has a three column heading, but no footer.",
- ps[0].getText()
- );
-
- assertTrue(ps[1].isEmpty());
- assertEquals("", ps[1].getText());
-
- assertFalse(ps[2].isEmpty());
- assertEquals(
- "HEADING TEXT",
- ps[2].getText()
- );
-
- assertTrue(ps[3].isEmpty());
- assertEquals("", ps[3].getText());
-
- assertFalse(ps[4].isEmpty());
- assertEquals(
- "More on page one",
- ps[4].getText()
- );
- }
+ p.setSpacingAfter(new BigInteger("100"));
+ assertEquals(100, spacing.getAfter().longValue());
+ }
+
+ public void testSetGetVerticalAlignment() {
+ //new clean instance of paragraph
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
+
+ CTTextAlignment txtAlign = ppr.addNewTextAlignment();
+ txtAlign.setVal(STTextAlignment.CENTER);
+ assertEquals(TextAlignment.CENTER,p.getVerticalAlignment());
+
+ p.setVerticalAlignment(TextAlignment.BOTTOM);
+ assertEquals(STTextAlignment.BOTTOM,ppr.getTextAlignment().getVal());
+ }
+
+ public void testSetGetWordWrap() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
+
+ CTOnOff wordWrap = ppr.addNewWordWrap();
+ wordWrap.setVal(STOnOff.FALSE);
+ assertEquals(false,p.isWordWrap());
+
+ p.setWordWrap(true);
+ assertEquals(STOnOff.TRUE,ppr.getWordWrap().getVal());
+ }
+
+
+ public void testSetGetPageBreak() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTP ctp = p.getCTP();
+ CTPPr ppr = ctp.addNewPPr();
+
+ CTOnOff pageBreak = ppr.addNewPageBreakBefore();
+ pageBreak.setVal(STOnOff.FALSE);
+ assertEquals(false,p.isPageBreak());
+
+ p.setPageBreak(true);
+ assertEquals(STOnOff.TRUE,ppr.getPageBreakBefore().getVal());
+ }
+
+
}
Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
===================================================================
--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (revision 712662)
+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (working copy)
@@ -16,168 +16,908 @@
==================================================================== */
package org.apache.poi.xwpf.usermodel;
+import java.math.BigInteger;
import java.util.ArrayList;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+
/**
* Sketch of XWPF paragraph class
*/
-public class XWPFParagraph
-{
+public class XWPFParagraph {
private CTP paragraph;
- protected XWPFDocument document; // XXX: we'd like to have access to document's hyperlink, comments and other tables
+ protected XWPFDocument document; // XXX: we'd like to have access to
+ // document's hyperlink, comments and
+ // other tables
/**
* TODO - replace with RichText String
*/
private StringBuffer text = new StringBuffer();
private StringBuffer pictureText = new StringBuffer();
-
- protected XWPFParagraph(CTP prgrph, XWPFDocument docRef)
- {
- this.paragraph = prgrph;
- this.document = docRef;
- if(!isEmpty()) {
- // All the runs to loop over
- // TODO - replace this with some sort of XPath expression
- // to directly find all the CTRs, in the right order
- ArrayList
- * If this element is not set on a given paragraph, its value is determined by the setting previously - * set at any level of the style hierarchy (i.e. that previous setting remains unchanged). - * If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph. + * If this element is not set on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no alignment is applied to the + * paragraph. *
- * - * @param align the paragraph alignment to apply to this paragraph. + * + * @param align + * the paragraph alignment to apply to this paragraph. */ - public void setAlignment(ParagraphAlignment align){ - CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph.addNewPPr(); - CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc(); - STJc.Enum en = STJc.Enum.forInt(align.getValue()); - jc.setVal(en); + public void setAlignment(ParagraphAlignment align) { + CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph + .addNewPPr(); + CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc(); + STJc.Enum en = STJc.Enum.forInt(align.getValue()); + jc.setVal(en); } + /** + * Returns the text vertical alignment which shall be applied to text in + * this paragraph. + *+ * If the line height (before any added spacing) is larger than one or more + * characters on the line, all characters will be aligned to each other as + * specified by this element. + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then the vertical alignment of all + * characters on the line shall be automatically determined by the consumer. + *
+ * + * @return the vertical alignment of this paragraph. + */ + public TextAlignment getVerticalAlignment() { + CTPPr pr = paragraph.getPPr(); + return pr == null || !pr.isSetTextAlignment() ? TextAlignment.AUTO + : TextAlignment.valueOf(pr.getTextAlignment().getVal() + .intValue()); + } + + /** + * Specifies the text vertical alignment which shall be applied to text in + * this paragraph. + *+ * If the line height (before any added spacing) is larger than one or more + * characters on the line, all characters will be aligned to each other as + * specified by this element. + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then the vertical alignment of all + * characters on the line shall be automatically determined by the consumer. + *
+ * + * @param valign + * the paragraph vertical alignment to apply to this + * paragraph. + */ + public void setVerticalAlignment(TextAlignment valign) { + CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph + .addNewPPr(); + CTTextAlignment textAlignment = pr.isSetTextAlignment() ? pr + .getTextAlignment() : pr.addNewTextAlignment(); + STTextAlignment.Enum en = STTextAlignment.Enum + .forInt(valign.getValue()); + textAlignment.setVal(en); + } + + /** + * Specifies the border which shall be displayed above a set of paragraphs + * which have the same set of paragraph border settings. + * + *+ * To determine if any two adjoining paragraphs shall have an individual top + * and bottom border or a between border, the set of borders on the two + * adjoining paragraphs are compared. If the border information on those two + * paragraphs is identical for all possible paragraphs borders, then the + * between border is displayed. Otherwise, the final paragraph shall use its + * bottom border and the following paragraph shall use its top border, + * respectively. If this border specifies a space attribute, that value + * determines the space above the text (ignoring any spacing above) which + * should be left before this border is drawn, specified in points. + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no between border shall be applied + * above identical paragraphs. + *
+ * This border can only be a line border. + * @see Borders for a list of all types of borders + * @param border + */ + public void setBorderTop(Borders border) { + CTPBdr ct = getCTPBrd(true); + CTBorder pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop(); + if (border.getValue() == Borders.NONE.getValue()) + ct.unsetTop(); + else + pr.setVal(STBorder.Enum.forInt(border.getValue())); + } + + /** + * Specifies the border which shall be displayed above a set of paragraphs + * which have the same set of paragraph border settings. + * + * @see #setBorderTop() + * @see Borders a list of all types of borders + * @return paragraphBorder - the top border for the paragraph + * + */ + public Borders getBorderTop() { + CTPBdr border = getCTPBrd(false); + CTBorder ct = null; + if (border != null) { + ct = border.getTop(); + STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE; + return Borders.valueOf(ptrn.intValue()); + } + return Borders.NONE; + } + + /** + * Specifies the border which shall be displayed below a set of paragraphs + * which have the same set of paragraph border settings. + *+ * To determine if any two adjoining paragraphs shall have an individual top + * and bottom border or a between border, the set of borders on the two + * adjoining paragraphs are compared. If the border information on those two + * paragraphs is identical for all possible paragraphs borders, then the + * between border is displayed. Otherwise, the final paragraph shall use its + * bottom border and the following paragraph shall use its top border, + * respectively. If this border specifies a space attribute, that value + * determines the space after the bottom of the text (ignoring any space + * below) which should be left before this border is drawn, specified in + * points. + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no between border shall be applied + * below identical paragraphs. + *
+ * This border can only be a line border. + * @see Borders a list of all types of borders + * @param border + */ + public void setBorderBottom(Borders border) { + CTPBdr ct = getCTPBrd(true); + CTBorder pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom(); + if (border.getValue() == Borders.NONE.getValue()) + ct.unsetBottom(); + else + pr.setVal(STBorder.Enum.forInt(border.getValue())); + } + + /** + * Specifies the border which shall be displayed below a set of + * paragraphs which have the same set of paragraph border settings. + * + * @see #setBorderBottom() + * @see Borders a list of all types of borders + * @return paragraphBorder - the bottom border for the paragraph + */ + public Borders getBorderBottom() { + CTPBdr border = getCTPBrd(false); + CTBorder ct = null; + if (border != null) { + ct = border.getBottom(); + } + STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE; + return Borders.valueOf(ptrn.intValue()); + } + + /** + * Specifies the border which shall be displayed on the left side of the + * page around the specified paragraph. + *+ * To determine if any two adjoining paragraphs should have a left border + * which spans the full line height or not, the left border shall be drawn + * between the top border or between border at the top (whichever would be + * rendered for the current paragraph), and the bottom border or between + * border at the bottom (whichever would be rendered for the current + * paragraph). + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no left border shall be applied. + *
+ * This border can only be a line border. + * @see Borders for a list of all possible borders + * @param border + */ + public void setBorderLeft(Borders border) { + CTPBdr ct = getCTPBrd(true); + CTBorder pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft(); + if (border.getValue() == Borders.NONE.getValue()) + ct.unsetLeft(); + else + pr.setVal(STBorder.Enum.forInt(border.getValue())); + } + + /** + * Specifies the border which shall be displayed on the left side of the + * page around the specified paragraph. + * @see #setBorderLeft() + * @see Borders for a list of all possible borders + * @return ParagraphBorder - the left border for the paragraph + */ + public Borders getBorderLeft() { + CTPBdr border = getCTPBrd(false); + CTBorder ct = null; + if (border != null) { + ct = border.getLeft(); + } + STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE; + return Borders.valueOf(ptrn.intValue()); + } + + /** + * Specifies the border which shall be displayed on the right side of the + * page around the specified paragraph. + *+ * To determine if any two adjoining paragraphs should have a right border + * which spans the full line height or not, the right border shall be drawn + * between the top border or between border at the top (whichever would be + * rendered for the current paragraph), and the bottom border or between + * border at the bottom (whichever would be rendered for the current + * paragraph). + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no right border shall be applied. + *
+ * This border can only be a line border. + * @see Borders for a list of all possible borders + * @param border + */ + public void setBorderRight(Borders border) { + CTPBdr ct = getCTPBrd(true); + CTBorder pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight(); + if (border.getValue() == Borders.NONE.getValue()) + ct.unsetRight(); + else + pr.setVal(STBorder.Enum.forInt(border.getValue())); + } + + /** + * Specifies the border which shall be displayed on the right side of the + * page around the specified paragraph. + * @see #setBorderRight() + * @see Borders for a list of all possible borders + * @return ParagraphBorder - the right border for the paragraph + */ + public Borders getBorderRight() { + CTPBdr border = getCTPBrd(false); + CTBorder ct = null; + if (border != null) { + ct = border.getRight(); + } + STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE; + return Borders.valueOf(ptrn.intValue()); + } + + /** + * Specifies the border which shall be displayed between each paragraph in a + * set of paragraphs which have the same set of paragraph border settings. + *+ * To determine if any two adjoining paragraphs should have a between border + * or an individual top and bottom border, the set of borders on the two + * adjoining paragraphs are compared. If the border information on those two + * paragraphs is identical for all possible paragraphs borders, then the + * between border is displayed. Otherwise, each paragraph shall use its + * bottom and top border, respectively. If this border specifies a space + * attribute, that value is ignored - this border is always located at the + * bottom of each paragraph with an identical following paragraph, taking + * into account any space after the line pitch. + *
+ *+ * If this element is omitted on a given paragraph, its value is determined + * by the setting previously set at any level of the style hierarchy (i.e. + * that previous setting remains unchanged). If this setting is never + * specified in the style hierarchy, then no between border shall be applied + * between identical paragraphs. + *
+ * This border can only be a line border. + * @see Borders for a list of all possible borders + * @param border + */ + public void setBorderBetween(Borders border) { + CTPBdr ct = getCTPBrd(true); + CTBorder pr = ct.isSetBetween() ? ct.getBetween() : ct.addNewBetween(); + if (border.getValue() == Borders.NONE.getValue()) + ct.unsetBetween(); + else + pr.setVal(STBorder.Enum.forInt(border.getValue())); + } + + /** + * + * Specifies the border which shall be displayed between each paragraph in a + * set of paragraphs which have the same set of paragraph border settings. + * @see #setBorderBetween() + * @see Borders for a list of all possible borders + * @return ParagraphBorder - the between border for the paragraph + */ + public Borders getBorderBetween() { + CTPBdr border = getCTPBrd(false); + CTBorder ct = null; + if (border != null) { + ct = border.getBetween(); + } + STBorder.Enum ptrn = ct != null ? ct.getVal() : STBorder.NONE; + return Borders.valueOf(ptrn.intValue()); + } + + /** + * Specifies that when rendering this document in a paginated + * view, the contents of this paragraph are rendered on the start of a new + * page in the document. + *+ * If this element is omitted on a given paragraph, + * its value is determined by the setting previously set at any level of the + * style hierarchy (i.e. that previous setting remains unchanged). If this + * setting is never specified in the style hierarchy, then this property + * shall not be applied. Since the paragraph is specified to start on a new + * page, it begins page two even though it could have fit on page one. + *
+ * @param pageBreak - + * boolean value + */ + public void setPageBreak(boolean pageBreak) { + CTPPr ppr = getCTPPr(); + CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr + .getPageBreakBefore() : ppr.addNewPageBreakBefore(); + if (pageBreak) + ct_pageBreak.setVal(STOnOff.TRUE); + else + ct_pageBreak.setVal(STOnOff.FALSE); + } + + /** + * Specifies that when rendering this document in a paginated + * view, the contents of this paragraph are rendered on the start of a new + * page in the document. + *+ * If this element is omitted on a given paragraph, + * its value is determined by the setting previously set at any level of the + * style hierarchy (i.e. that previous setting remains unchanged). If this + * setting is never specified in the style hierarchy, then this property + * shall not be applied. Since the paragraph is specified to start on a new + * page, it begins page two even though it could have fit on page one. + *
+ * @return boolean - if page break is set + */ + public boolean isPageBreak() { + CTPPr ppr = getCTPPr(); + CTOnOff ct_pageBreak = ppr.isSetPageBreakBefore() ? ppr + .getPageBreakBefore() : null; + if (ct_pageBreak != null + && ct_pageBreak.getVal().intValue() == STOnOff.INT_TRUE) + return true; + else + return false; + } + + /** + * Specifies the spacing that should be added after the last line in this + * paragraph in the document in absolute units. + *+ * If the afterLines attribute or the afterAutoSpacing attribute is also + * specified, then this attribute value is ignored. + *
+ * + * @param spaces - + * a positive whole number, whose contents consist of a + * measurement in twentieths of a point. + */ + public void setSpacingAfter(BigInteger spaces) { + CTSpacing spacing = getCTSpacing(true); + if (spacing != null) + spacing.setAfter(spaces); + } + + /** + * Specifies the spacing that should be added after the last line in this + * paragraph in the document in absolute units. + * + * @return bigInteger - value representing the spacing after the paragraph + */ + public BigInteger getSpacingAfter() { + CTSpacing spacing = getCTSpacing(false); + return spacing.isSetAfter() ? spacing.getAfter() : null; + } + + /** + * Specifies the spacing that should be added after the last line in this + * paragraph in the document in line units. + * The value of this attribute is + * specified in one hundredths of a line. + * + *+ * If the afterAutoSpacing attribute + * is also specified, then this attribute value is ignored. If this setting + * is never specified in the style hierarchy, then its value shall be zero + * (if needed) + *
+ * @param spaces - + * a positive whole number, whose contents consist of a + * measurement in twentieths of a + */ + public void setSpacingAfterLines(BigInteger spaces) { + CTSpacing spacing = getCTSpacing(true); + spacing.setAfterLines(spaces); + } + + + /** + * Specifies the spacing that should be added after the last line in this + * paragraph in the document in absolute units. + * @see #setSpacingAfterLines(BigInteger) + * @return bigInteger - value representing the spacing after the paragraph + */ + public BigInteger getSpacingAfterLines() { + CTSpacing spacing = getCTSpacing(false); + return spacing.isSetAfterLines() ? spacing.getAfterLines() : null; + } + + /** + * Specifies the spacing that should be added above the first line in this + * paragraph in the document in absolute units. + *+ * If the beforeLines attribute or the beforeAutoSpacing attribute is also + * specified, then this attribute value is ignored. + *
+ * + * @param spaces + */ + public void setSpacingBefore(BigInteger spaces) { + CTSpacing spacing = getCTSpacing(true); + spacing.setBefore(spaces); + } + + /** + * Specifies the spacing that should be added above the first line in this + * paragraph in the document in absolute units. + * @see #setSpacingBefore(BigInteger) + * @return + */ + public BigInteger getSpacingBefore() { + CTSpacing spacing = getCTSpacing(false); + return spacing.isSetBefore() ? spacing.getBefore() : null; + } + + /** + * Specifies the spacing that should be added before the first line in this + * paragraph in the document in line units. The value of this attribute + * is specified in one hundredths of a line. + *+ * If the beforeAutoSpacing attribute is also specified, then this attribute + * value is ignored. If this setting is never specified in the style + * hierarchy, then its value shall be zero. + *
+ * + * @param spaces + */ + public void setSpacingBeforeLines(BigInteger spaces) { + CTSpacing spacing = getCTSpacing(true); + spacing.setBeforeLines(spaces); + } + + /** + *Specifies the spacing that should be added before the first line in this paragraph in the +document in line units. +The value of this attribute is specified in one hundredths of a line. + * @see #setSpacingBeforeLines(BigInteger) + * @return + */ + public BigInteger getSpacingBeforeLines() { + CTSpacing spacing = getCTSpacing(false); + return spacing.isSetBeforeLines() ? spacing.getBeforeLines() : null; + } + + /** + * Specifies the indentation which shall be placed between the left text + * margin for this paragraph and the left edge of that paragraph's content + * in a left to right paragraph, and the right text margin and the right + * edge of that paragraph's text in a right to left paragraph + *+ * If this attribute is omitted, its value shall be assumed to be zero. + * Negative values are defined such that the text is moved past the text margin, + * positive values move the text inside the text margin. + *
+ * @param indentation + */ + public void setIndentationLeft(BigInteger indentation) { + CTInd indent = getCTInd(true); + indent.setLeft(indentation); + } + + /** + * Specifies the indentation which shall be placed between the left text + * margin for this paragraph and the left edge of that paragraph's content + * in a left to right paragraph, and the right text margin and the right + * edge of that paragraph's text in a right to left paragraph + *+ * If this attribute is omitted, its value shall be assumed to be zero. + * Negative values are defined such that the text is moved past the text margin, + * positive values move the text inside the text margin. + *
+ * + * @return indentation or null if indentation is not set + */ + public BigInteger getIndentationLeft() { + CTInd indentation = getCTInd(false); + return indentation.isSetLeft() ? indentation.getLeft() + : new BigInteger("0"); + } + + /** + * Specifies the indentation which shall be placed between the right text + * margin for this paragraph and the right edge of that paragraph's content + * in a left to right paragraph, and the right text margin and the right + * edge of that paragraph's text in a right to left paragraph + *+ * If this attribute is omitted, its value shall be assumed to be zero. + * Negative values are defined such that the text is moved past the text margin, + * positive values move the text inside the text margin. + *
+ * @param indentation + */ + public void setIndentationRight(BigInteger indentation) { + CTInd indent = getCTInd(true); + indent.setRight(indentation); + } + + /** + * Specifies the indentation which shall be placed between the right text + * margin for this paragraph and the right edge of that paragraph's content + * in a left to right paragraph, and the right text margin and the right + * edge of that paragraph's text in a right to left paragraph + *+ * If this attribute is omitted, its value shall be assumed to be zero. + * Negative values are defined such that the text is moved past the text margin, + * positive values move the text inside the text margin. + *
+ * @return indentation or null if indentation is not set + */ + + public BigInteger getIndentationRight() { + CTInd indentation = getCTInd(false); + return indentation.isSetRight() ? indentation.getRight() + : new BigInteger("0"); + } + + /** + * Specifies the indentation which shall be removed from the first line of + * the parent paragraph, by moving the indentation on the first line back + * towards the beginning of the direction of text flow. + * This indentation is specified relative to the paragraph indentation which is specified for + * all other lines in the parent paragraph. + *+ * The firstLine and hanging attributes are mutually exclusive, if both are specified, then the + * firstLine value is ignored. + *
+ * @param indentation + */ + + public void setIndentationHanging(BigInteger indentation) { + CTInd indent = getCTInd(true); + indent.setHanging(indentation); + } + + /** + * Specifies the indentation which shall be removed from the first line of + * the parent paragraph, by moving the indentation on the first line back + * towards the beginning of the direction of text flow. + * This indentation is + * specified relative to the paragraph indentation which is specified for + * all other lines in the parent paragraph. + * The firstLine and hanging + * attributes are mutually exclusive, if both are specified, then the + * firstLine value is ignored. + * + * @return indentation or null if indentation is not set + */ + public BigInteger getIndentationHanging() { + CTInd indentation = getCTInd(false); + return indentation.isSetHanging() ? indentation.getHanging() : null; + } + + /** + * Specifies the additional indentation which shall be applied to the first + * line of the parent paragraph. This additional indentation is specified + * relative to the paragraph indentation which is specified for all other + * lines in the parent paragraph. + * The firstLine and hanging attributes are + * mutually exclusive, if both are specified, then the firstLine value is + * ignored. + * If the firstLineChars attribute is also specified, then this + * value is ignored. If this attribute is omitted, then its value shall be + * assumed to be zero (if needed). + * + * @param indentation + */ + public void setIndentationFirstLine(BigInteger indentation) { + CTInd indent = getCTInd(true); + indent.setFirstLine(indentation); + } + + /** + * Specifies the additional indentation which shall be applied to the first + * line of the parent paragraph. This additional indentation is specified + * relative to the paragraph indentation which is specified for all other + * lines in the parent paragraph. + * The firstLine and hanging attributes are + * mutually exclusive, if both are specified, then the firstLine value is + * ignored. + * If the firstLineChars attribute is also specified, then this + * value is ignored. + * If this attribute is omitted, then its value shall be + * assumed to be zero (if needed). + * + * @return indentation or null if indentation is not set + */ + public BigInteger getIndentationFirstLine() { + CTInd indentation = getCTInd(false); + return indentation.isSetFirstLine() ? indentation.getFirstLine() + : new BigInteger("0"); + } + + /** + * This element specifies whether a consumer shall break Latin text which + * exceeds the text extents of a line by breaking the word across two lines + * (breaking on the character level) or by moving the word to the following + * line (breaking on the word level). + * + * @param wrap - boolean + */ + public void setWordWrap(boolean wrap) { + CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr() + .getWordWrap() : getCTPPr().addNewWordWrap(); + if (wrap) + wordWrap.setVal(STOnOff.TRUE); + else + wordWrap.unsetVal(); + } + + /** + * This element specifies whether a consumer shall break Latin text which + * exceeds the text extents of a line by breaking the word across two lines + * (breaking on the character level) or by moving the word to the following + * line (breaking on the word level). + * + * @return boolean + */ + public boolean isWordWrap() { + CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr() + .getWordWrap() : null; + if (wordWrap != null) { + return (wordWrap.getVal() == STOnOff.ON + || wordWrap.getVal() == STOnOff.TRUE || wordWrap.getVal() == STOnOff.X_1) ? true + : false; + } else + return false; + } + + /** + * Get a copy of the currently used CTPBrd, if none is used, return + * a new instance. + */ + private CTPBdr getCTPBrd(boolean create) { + CTPPr pr = getCTPPr(); + if (pr != null) { + CTPBdr ct = pr.isSetPBdr() ? ct = pr.getPBdr() : null; + if (create && ct == null) + ct=pr.addNewPBdr(); + return ct; + } + return null; + } + + /** + * Get a copy of the currently used CTSpacing, if none is used, + * return a new instance. + */ + private CTSpacing getCTSpacing(boolean create) { + CTPPr pr = getCTPPr(); + if (pr != null) { + CTSpacing ct = pr.isSetSpacing() ? pr.getSpacing() : null; + if (create && ct == null) + ct = pr.addNewSpacing(); + return ct; + } + return null; + } + + /** + * Get a copy of the currently used CTPInd, if none is used, return + * a new instance. + */ + private CTInd getCTInd(boolean create) { + CTPPr pr = getCTPPr(); + if (pr != null) { + CTInd ct = pr.isSetInd() ? pr.getInd() : null; + if (create && ct == null) + ct = pr.addNewInd(); + return ct; + } + return null; + } + + private CTPPr getCTPPr() { + CTPPr pr = paragraph.getPPr() == null ? paragraph.addNewPPr() + : paragraph.getPPr(); + return pr; + } + } Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/Borders.java =================================================================== --- src/ooxml/java/org/apache/poi/xwpf/usermodel/Borders.java (revision 0) +++ src/ooxml/java/org/apache/poi/xwpf/usermodel/Borders.java (revision 0) @@ -0,0 +1,626 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.util.HashMap; +import java.util.Map; + +/** + * Specifies all types of borders which can be specified for WordprocessingML + * objects which have a border. Borders can be separated into two types: + *+ * If the border is on the left or right, no border is displayed. + *
+ */ + CERTIFICATE_BANNER(51), + + /** + * Specifies an art border consisting of a repeating image of a chain link + * pattern. + */ + CHAIN_LINK(52), + + /** + * Specifies an art border consisting of a repeated image of a champagne + * bottle + */ + CHAMPAGNE_BOTTLE(53), + + /** + * Specifies an art border consisting of repeating images of a compass + */ + CHECKED_BAR_BLACK(54), + + /** + * Specifies an art border consisting of a repeating image of a colored + * pattern. + */ + CHECKED_BAR_COLOR(55), + + /** + * Specifies an art border consisting of a repeated image of a checkerboard + */ + CHECKERED(56), + + /** + * Specifies an art border consisting of a repeated image of a Christmas + * tree + */ + CHRISTMAS_TREE(57), + + /** + * Specifies an art border consisting of repeating images of lines and + * circles + */ + CIRCLES_LINES(58), + + /** + * Specifies an art border consisting of a repeated image of a rectangular + * pattern + */ + CIRCLES_RECTANGLES(59), + + /** + * Specifies an art border consisting of a repeated image of a wave + */ + CLASSICAL_WAVE(60), + + /** + * Specifies an art border consisting of a repeated image of a clock + */ + CLOCKS(61), + + /** + * Specifies an art border consisting of repeating images of a compass + */ + COMPASS(62), + + /** + * Specifies an art border consisting of a repeated image of confetti + */ + CONFETTI(63), + + /** + * Specifies an art border consisting of a repeated image of confetti + */ + CONFETTI_GRAYS(64), + + /** + * Specifies an art border consisting of a repeated image of confetti + */ + CONFETTI_OUTLINE(65), + + /** + * Specifies an art border consisting of a repeated image of confetti + * streamers + */ + CONFETTI_STREAMERS(66), + + /** + * Specifies an art border consisting of a repeated image of confetti + */ + CONFETTI_WHITE(67), + + /** + * Specifies an art border consisting of a repeated image + */ + CORNER_TRIANGLES(68), + + /** + * Specifies an art border consisting of a dashed line + */ + COUPON_CUTOUT_DASHES(69), + + /** + * Specifies an art border consisting of a dotted line + */ + COUPON_CUTOUT_DOTS(70), + + /** + * Specifies an art border consisting of a repeated image of a maze-like + * pattern + */ + CRAZY_MAZE(71), + + /** + * Specifies an art border consisting of a repeated image of a butterfly + */ + CREATURES_BUTTERFLY(72), + + /** + * Specifies an art border consisting of a repeated image of a fish + */ + CREATURES_FISH(73), + + /** + * Specifies an art border consisting of repeating images of insects. + */ + CREATURES_INSECTS(74), + + /** + * Specifies an art border consisting of a repeated image of a ladybug + */ + CREATURES_LADY_BUG(75), + + /** + * Specifies an art border consisting of repeating images of a cross-stitch + * pattern + */ + CROSS_STITCH(76), + + /** + * Specifies an art border consisting of a repeated image of Cupid + */ + CUP(77), + + DECO_ARCH(78), + + DECO_ARCH_COLOR(79), + + DECO_BLOCKS(80), + + DIAMONDS_GRAY(81), + + DOUBLE_D(82), + + DOUBLE_DIAMONDS(83), + + EARTH_1(84), + + EARTH_2(85), + + ECLIPSING_SQUARES_1(86), + + ECLIPSING_SQUARES_2(87), + + EGGS_BLACK(88), + + FANS(89), + + FILM(90), + + FIRECRACKERS(91), + + FLOWERS_BLOCK_PRINT(92), + + FLOWERS_DAISIES(93), + + FLOWERS_MODERN_1(94), + + FLOWERS_MODERN_2(95), + + FLOWERS_PANSY(96), + + FLOWERS_RED_ROSE(97), + + FLOWERS_ROSES(98), + + FLOWERS_TEACUP(99), + + FLOWERS_TINY(100), + + GEMS(101), + + GINGERBREAD_MAN(102), + + GRADIENT(103), + + HANDMADE_1(104), + + HANDMADE_2(105), + + HEART_BALLOON(106), + + HEART_GRAY(107), + + HEARTS(108), + + HEEBIE_JEEBIES(109), + + HOLLY(110), + + HOUSE_FUNKY(111), + + HYPNOTIC(112), + + ICE_CREAM_CONES(113), + + LIGHT_BULB(114), + + LIGHTNING_1(115), + + LIGHTNING_2(116), + + MAP_PINS(117), + + MAPLE_LEAF(118), + + MAPLE_MUFFINS(119), + + MARQUEE(120), + + MARQUEE_TOOTHED(121), + + MOONS(122), + + MOSAIC(123), + + MUSIC_NOTES(124), + + NORTHWEST(125), + + OVALS(126), + + PACKAGES(127), + + PALMS_BLACK(128), + + PALMS_COLOR(129), + + PAPER_CLIPS(130), + + PAPYRUS(131), + + PARTY_FAVOR(132), + + PARTY_GLASS(133), + + PENCILS(134), + + PEOPLE(135), + + PEOPLE_WAVING(136), + + PEOPLE_HATS(137), + + POINSETTIAS(138), + + POSTAGE_STAMP(139), + + PUMPKIN_1(140), + + PUSH_PIN_NOTE_2(141), + + PUSH_PIN_NOTE_1(142), + + PYRAMIDS(143), + + PYRAMIDS_ABOVE(144), + + QUADRANTS(145), + + RINGS(146), + + SAFARI(147), + + SAWTOOTH(148), + + SAWTOOTH_GRAY(149), + + SCARED_CAT(150), + + SEATTLE(151), + + SHADOWED_SQUARES(152), + + SHARKS_TEETH(153), + + SHOREBIRD_TRACKS(154), + + SKYROCKET(155), + + SNOWFLAKE_FANCY(156), + + SNOWFLAKES(157), + + SOMBRERO(158), + + SOUTHWEST(159), + + STARS(160), + + STARS_TOP(161), + + STARS_3_D(162), + + STARS_BLACK(163), + + STARS_SHADOWED(164), + + SUN(165), + + SWIRLIGIG(166), + + TORN_PAPER(167), + + TORN_PAPER_BLACK(168), + + TREES(169), + + TRIANGLE_PARTY(170), + + TRIANGLES(171), + + TRIBAL_1(172), + + TRIBAL_2(173), + + TRIBAL_3(174), + + TRIBAL_4(175), + + TRIBAL_5(176), + + TRIBAL_6(177), + + TWISTED_LINES_1(178), + + TWISTED_LINES_2(179), + + VINE(180), + + WAVELINE(181), + + WEAVING_ANGLES(182), + + WEAVING_BRAID(183), + + WEAVING_RIBBON(184), + + WEAVING_STRIPS(185), + + WHITE_FLOWERS(186), + + WOODWORK(187), + + X_ILLUSIONS(188), + + ZANY_TRIANGLES(189), + + ZIG_ZAG(190), + + ZIG_ZAG_STITCH(191); + + private final int value; + + private Borders(int val) { + value = val; + } + + public int getValue() { + return value; + } + + private static Map