Example usage for org.apache.poi.xwpf.usermodel IBody getBodyElements

List of usage examples for org.apache.poi.xwpf.usermodel IBody getBodyElements

Introduction

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

Prototype

public List<IBodyElement> getBodyElements();

Source Link

Document

Returns an Iterator with paragraphs and tables, in the order that they occur in the text.

Usage

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

License:Open Source License

/**
 * Returns true if the given paragraph which is empty (none <w:r> run) must generate new line and false otherwise.
 * // w w  w .ja  v  a2  s  .c  o  m
 * @param paragraph
 * @param index
 * @return
 */
private boolean isAddNewLine(XWPFParagraph paragraph, int index) {
    // a new line must be generated if :
    // - there is next paragraph/table
    // - if the body is a cell (with none vMerge) and contains just this paragraph
    IBody body = paragraph.getBody();
    List<IBodyElement> bodyElements = body.getBodyElements();
    if (body.getPartType() == BodyType.TABLECELL && bodyElements.size() == 1) {
        XWPFTableCell cell = (XWPFTableCell) body;
        STMerge.Enum vMerge = stylesDocument.getTableCellVMerge(cell);
        if (vMerge != null && vMerge.equals(STMerge.CONTINUE)) {
            // here a new line must not be generated because the body is a cell (with none vMerge) and contains just
            // this paragraph
            return false;
        }
        // Loop for each cell of the row : if all cells are empty, new line must be generated otherwise none empty
        // line must be generated.
        XWPFTableRow row = cell.getTableRow();
        List<XWPFTableCell> cells = row.getTableCells();
        for (XWPFTableCell c : cells) {
            if (c.getBodyElements().size() != 1) {
                return false;
            }
            IBodyElement element = c.getBodyElements().get(0);
            if (element.getElementType() != BodyElementType.PARAGRAPH) {
                return false;
            }
            return ((XWPFParagraph) element).getRuns().size() == 0;
        }
        return true;

    }
    // here a new line must be generated if there is next paragraph/table
    return bodyElements.size() > index + 1;
}

From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XWPFWordExtractorDecorator.java

License:Apache License

private void extractIBodyText(IBody bodyElement, XHTMLContentHandler xhtml)
        throws SAXException, XmlException, IOException {
    for (IBodyElement element : bodyElement.getBodyElements()) {
        if (element instanceof XWPFParagraph) {
            XWPFParagraph paragraph = (XWPFParagraph) element;
            extractParagraph(paragraph, xhtml);
        }//from   w ww. j  a  va2s  .co m
        if (element instanceof XWPFTable) {
            XWPFTable table = (XWPFTable) element;
            extractTable(table, xhtml);
        }
        if (element instanceof XWPFSDT) {
            extractSDT((XWPFSDT) element, xhtml);
        }
    }
}

From source file:org.apache.tika.parser.microsoft.ooxml.XWPFWordExtractorDecorator.java

License:Apache License

private void extractIBodyText(IBody bodyElement, XWPFListManager listManager, XHTMLContentHandler xhtml)
        throws SAXException, XmlException, IOException {
    for (IBodyElement element : bodyElement.getBodyElements()) {
        if (element instanceof XWPFParagraph) {
            XWPFParagraph paragraph = (XWPFParagraph) element;
            extractParagraph(paragraph, listManager, xhtml);
        }/*from  w  w w .  j  a va 2  s . c  om*/
        if (element instanceof XWPFTable) {
            XWPFTable table = (XWPFTable) element;
            extractTable(table, listManager, xhtml);
        }
        if (element instanceof XWPFSDT) {
            extractSDT((XWPFSDT) element, xhtml);
        }

    }
}

From source file:org.obeonetwork.m2doc.parser.TokenIterator.java

License:Open Source License

/**
 * Creates a new {@link TokenIterator} instance.
 * /*from   w  w w.  j av a2 s  .com*/
 * @param inputBody
 *            the body.
 */
public TokenIterator(IBody inputBody) {
    if (inputBody == null) {
        throw new IllegalArgumentException("Input documnet shouldn't be null");
    }
    elementIterator = inputBody.getBodyElements().iterator();
}