Example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getBody

List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getBody

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFParagraph getBody.

Prototype

@Override
    public IBody getBody() 

Source Link

Usage

From source file:apachepoitest.DocumentPropertyChecker.java

public static Boolean checkIfParagraphHasProperty(XWPFParagraph p, String property, String value) {
    try {//from   ww  w  .  jav a 2s . c o m
        switch (property) {
        case "LINE SPACING":
            XWPFParagraphClone pc;
            pc = new XWPFParagraphClone(p.getCTP(), p.getBody());
            return pc.getCTSpacing(false).getLine().floatValue() / 240 == Float.parseFloat(value);
        case "NUMBERING FORMAT":
            return p.getNumFmt().equalsIgnoreCase(value);
        case "ALIGN":
            return p.getAlignment().toString().equalsIgnoreCase(value);
        default:
            System.out.println("Property " + property + " does not exist!");
            return false;
        }
    } catch (NullPointerException e) {
        return false;
    }
}

From source file:apachepoitest.DocumentPropertyEnumerator.java

public static void showParagraphPropertiesOnly(List<XWPFParagraph> lp) {
    int i1 = 1;/*from   w  w w. jav a2s.  c  o m*/
    for (XWPFParagraph p : lp) {
        //System.out.println(p.getStyleID() + " " + sl1.getStyle(p.getStyleID()).getCTStyle().xmlText());
        System.out.println("____________________________________");
        if (p.getParagraphText().trim().length() > 0) {
            System.out.println("\n#" + i1++ + " LINE: " + p.getParagraphText());
            System.out.println("ALIGNMENT: " + p.getAlignment().toString());
            //Uncomment to display other properties

            System.out.println("BORDER BETWEEN: " + p.getBorderBetween().toString());
            System.out.println("BORDER BOTTOM: " + p.getBorderBottom().toString());
            System.out.println("BORDER LEFT: " + p.getBorderLeft().toString());
            System.out.println("BORDER RIGHT: " + p.getBorderRight().toString());
            System.out.println("BORDER TOP: " + p.getBorderTop().toString());
            System.out.println("BODY ELEMENT TYPE: " + p.getElementType().toString());
            System.out.println("FOOTNOTE: " + p.getFootnoteText());
            System.out.println("INDENTATION 1ST LINE: " + p.getIndentationFirstLine());
            System.out.println("INDENTATION HANGING: " + p.getIndentationHanging());
            System.out.println("INDENTATION LEFT: " + p.getIndentationLeft());
            System.out.println("INDENTATION RIGHT: " + p.getIndentationRight());
            System.out.println("NUMBERING FORMAT: " + p.getNumFmt());
            System.out.println("NUMERIC STYLE ILVL: " + p.getNumIlvl());
            System.out.println("STYLE: " + p.getBody().getXWPFDocument().getStyles().getStyle(p.getStyleID()));

            XWPFParagraphClone pc;
            pc = new XWPFParagraphClone(p.getCTP(), p.getBody());

            System.out.println("SPACING VALUE: " + pc.getCTSpacing(false).getLine().floatValue() / 240);
            System.out.println("SPACING AFTER: " + p.getSpacingAfter());
            System.out.println("SPACING AFTER LINES: " + p.getSpacingAfterLines());
            System.out.println("SPACING BEFORE: " + p.getSpacingBefore());
            System.out.println("SPACING BEFORE LINES: " + p.getSpacingBeforeLines());
            System.out.println("SPACING LINE RULE: " + p.getSpacingLineRule());
            System.out.println("VERTICAL ALIGNMENT: " + p.getVerticalAlignment());

        } // can also use .searchText to look for a string
        else {
            // Uncomment to display lines
            //System.out.println("\n#" + i1++ + " LINE: <SPACE>");
        }
    }
}

From source file:com.project3.utils.poiold.DocumentPropertyEnumerator.java

public static void showAllParagraphProperties(List<XWPFParagraph> lp) {
    int i1 = 1;//  w w w.ja  v  a2s  .  com
    for (XWPFParagraph p : lp) {
        //System.out.println(p.getStyleID() + " " + sl1.getStyle(p.getStyleID()).getCTStyle().xmlText());
        System.out.println("____________________________________");
        if (p.getParagraphText().trim().length() > 0) {
            System.out.println("\n#" + i1++ + " LINE: " + p.getParagraphText());
            System.out.println("ALIGNMENT: " + p.getAlignment().toString());

            System.out.println("BORDER BETWEEN: " + p.getBorderBetween().toString());
            System.out.println("BORDER BOTTOM: " + p.getBorderBottom().toString());
            System.out.println("BORDER LEFT: " + p.getBorderLeft().toString());
            System.out.println("BORDER RIGHT: " + p.getBorderRight().toString());
            System.out.println("BORDER TOP: " + p.getBorderTop().toString());
            System.out.println("BODY ELEMENT TYPE: " + p.getElementType().toString());
            System.out.println("FOOTNOTE: " + p.getFootnoteText());
            System.out.println("INDENTATION 1ST LINE: " + p.getIndentationFirstLine());
            System.out.println("INDENTATION HANGING: " + p.getIndentationHanging());
            System.out.println("INDENTATION LEFT: " + p.getIndentationLeft());
            System.out.println("INDENTATION RIGHT: " + p.getIndentationRight());
            System.out.println("NUMBERING FORMAT: " + p.getNumFmt());
            System.out.println("NUMERIC STYLE ILVL: " + p.getNumIlvl());
            System.out.println("STYLE: " + p.getBody().getXWPFDocument().getStyles().getStyle(p.getStyleID()));

            XWPFParagraphClone pc;
            pc = new XWPFParagraphClone(p.getCTP(), p.getBody());

            System.out.println("SPACING VALUE: " + pc.getCTSpacing(false).getLine().floatValue() / 240);
            System.out.println("SPACING AFTER: " + p.getSpacingAfter());
            System.out.println("SPACING AFTER LINES: " + p.getSpacingAfterLines());
            System.out.println("SPACING BEFORE: " + p.getSpacingBefore());
            System.out.println("SPACING BEFORE LINES: " + p.getSpacingBeforeLines());
            System.out.println("SPACING LINE RULE: " + p.getSpacingLineRule());
            System.out.println("VERTICAL ALIGNMENT: " + p.getVerticalAlignment());

        } // can also use .searchText to look for a string
        else {
            // Uncomment to display lines
            //System.out.println("\n#" + i1++ + " LINE: <SPACE>");
        }
    }
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsA(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNull(jc);/*from  www  .  j  ava  2s. c  o m*/

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    if (alignment == null) {
        Assert.assertNull(alignment);
    } else {
        Assert.assertEquals(ParagraphAlignment.LEFT, alignment);
    }
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsB(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {

    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNull(jc);//w ww .  ja v a 2s .  co m

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertNotNull(alignment);
    Assert.assertEquals(ParagraphAlignment.CENTER, alignment);

}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsC(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNull(jc);/*from  w  w  w.  ja v  a2 s .c om*/

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.RIGHT, alignment);
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsD(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);/*from www  .  ja  v a  2s  .c  om*/
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_CENTER);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    if (alignment == null) {
        Assert.assertNull(alignment);
    } else {
        Assert.assertEquals(ParagraphAlignment.LEFT, alignment);
    }
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsE(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);/*  w w  w.j av  a2 s . co  m*/
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_CENTER);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.CENTER, alignment);
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsF(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);/*  ww  w  . j  a  v  a 2  s .c  o  m*/
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_CENTER);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    Assert.assertEquals(ParagraphAlignment.RIGHT, alignment);
}

From source file:fr.opensagres.poi.xwpf.converter.core.styles.TableCellVerticalAlignmentTestCase.java

License:Open Source License

private void testsG(XWPFParagraph paragraph, XWPFStylesDocument stylesDocument) {
    // vertical aligment
    XWPFTableCell cell = (XWPFTableCell) paragraph.getBody();
    Enum jc = stylesDocument.getTableCellVerticalAlignment(cell);
    Assert.assertNotNull(jc);//from w  w  w .j ava  2  s  . c  o  m
    Assert.assertEquals(jc.intValue(), STVerticalJc.INT_BOTTOM);

    // text aligment
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph);
    if (alignment == null) {
        Assert.assertNull(alignment);
    } else {
        Assert.assertEquals(ParagraphAlignment.LEFT, alignment);
    }
}