Example usage for org.apache.poi.xwpf.usermodel XWPFHeaderFooter _getHdrFtr

List of usage examples for org.apache.poi.xwpf.usermodel XWPFHeaderFooter _getHdrFtr

Introduction

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

Prototype

@Internal
    public CTHdrFtr _getHdrFtr() 

Source Link

Usage

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

License:Open Source License

/**
 * Returns the list of {@link IBodyElement} of the given header/footer. We do that because
 * {@link XWPFHeaderFooter#getBodyElements()} doesn't contains the // <w:sdt><w:sdtContent>
 * <p//w w w.  j  a v a2 s.c  o  m
 * (see JUnit Docx4j_GettingStarted, DocXperT_Output_4_3, Issue222 which defines page number in the <w:sdt. ...
 * 
 * @param part
 * @return
 */
protected List<IBodyElement> getBodyElements(XWPFHeaderFooter part) {
    List<IBodyElement> bodyElements = new ArrayList<IBodyElement>();
    XmlTokenSource headerFooter = part._getHdrFtr();
    addBodyElements(headerFooter, part, bodyElements);
    return bodyElements;
}

From source file:org.obeonetwork.m2doc.generator.DocumentGenerator.java

License:Open Source License

/**
 * Clear up the header or footer from the existing paragraphs and tables.
 * //from w ww .  java  2 s .co  m
 * @param headerFooter
 *            the header or footer to clean up.
 */
void cleanHeaderFooter(XWPFHeaderFooter headerFooter) {
    CTHdrFtr ctHdrFtr = (CTHdrFtr) headerFooter._getHdrFtr().copy();
    ctHdrFtr.getPList().clear();
    ctHdrFtr.getTblList().clear();
    // XXX : there are many other lists in the header and footer that should
    // probably be cleaned.
    headerFooter.setHeaderFooter(ctHdrFtr);
}

From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java

License:Open Source License

/**
 * Inserts the given {@link MTable}.// w  w w.j  a v a 2s  . c  o  m
 * 
 * @param run
 *            the {@link XWPFRun} to insert to
 * @param table
 *            the {@link MTable} to insert
 */
private void insertMTable(XWPFRun run, MTable table) {
    final XWPFTable docTable;
    if (generatedDocument instanceof XWPFDocument) {
        if (table.getLabel() != null) {
            XWPFRun captionRun;
            captionRun = run;
            IRunBody runBody = captionRun.getParent();
            if (runBody instanceof XWPFParagraph) {
                ((XWPFParagraph) runBody).setSpacingAfter(0);
            }
            captionRun.setText(table.getLabel());
            captionRun.setBold(true);
        }
        docTable = ((XWPFDocument) generatedDocument).createTable();
    } else if (generatedDocument instanceof XWPFHeaderFooter) {
        final XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) generatedDocument;
        final int index = headerFooter._getHdrFtr().getTblArray().length;
        final CTTbl cttbl = headerFooter._getHdrFtr().insertNewTbl(index);
        docTable = new XWPFTable(cttbl, headerFooter);
        headerFooter.insertTable(index, docTable);
    } else if (generatedDocument instanceof XWPFTableCell) {
        XWPFTableCell tcell = (XWPFTableCell) generatedDocument;
        if (table.getLabel() != null) {
            final XWPFRun captionRun = run;
            IRunBody runBody = captionRun.getParent();
            if (runBody instanceof XWPFParagraph) {
                ((XWPFParagraph) runBody).setSpacingAfter(0);
            }
            captionRun.setText(table.getLabel());
            captionRun.setBold(true);
        }
        CTTbl ctTbl = tcell.getCTTc().addNewTbl();
        docTable = new XWPFTable(ctTbl, tcell);
        int tableRank = tcell.getTables().size();
        tcell.insertTable(tableRank, docTable);
        // A paragraph is mandatory at the end of a cell, so let's always add one.
        tcell.addParagraph();
    } else {
        docTable = null;
        M2DocUtils.appendMessageRun((XWPFParagraph) run.getParent(), ValidationMessageLevel.ERROR,
                "m:table can't be inserted here.");
    }

    if (docTable != null) {
        fillTable(docTable, table);
    }
}

From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java

License:Open Source License

@Override
public IConstruct caseTable(Table table) {
    // Create the table structure in the destination document.

    CTTbl copy = (CTTbl) table.getTable().getCTTbl().copy();
    copy.getTrList().clear();/* w w  w  .  ja  v  a  2  s  .c  om*/
    if (generatedDocument instanceof XWPFDocument) {
        currentGeneratedTable = ((XWPFDocument) generatedDocument).createTable();
        if (currentGeneratedTable.getRows().size() > 0) {
            currentGeneratedTable.removeRow(0);
        }
        currentGeneratedTable.getCTTbl().set(copy);
    } else if (generatedDocument instanceof XWPFHeaderFooter) {
        final XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) generatedDocument;
        final int index = headerFooter._getHdrFtr().getTblArray().length;
        final CTTbl cttbl = headerFooter._getHdrFtr().insertNewTbl(index);
        XWPFTable newTable = new XWPFTable(cttbl, headerFooter);
        if (newTable.getRows().size() > 0) {
            newTable.removeRow(0);
        }
        headerFooter.insertTable(index, newTable);
        currentGeneratedTable = headerFooter.getTables().get(index);
        currentGeneratedTable.getCTTbl().set(copy);
    } else if (generatedDocument instanceof XWPFTableCell) {
        XWPFTableCell tCell = (XWPFTableCell) generatedDocument;
        int tableRank = tCell.getTables().size();
        XWPFTable newTable = new XWPFTable(copy, tCell, 0, 0);
        if (newTable.getRows().size() > 0) {
            newTable.removeRow(0);
        }
        tCell.insertTable(tableRank, newTable);
        currentGeneratedTable = tCell.getTables().get(tableRank);
    } else {
        throw new UnsupportedOperationException("unknown type of IBody : " + generatedDocument.getClass());
    }
    // iterate on the row
    for (Row row : table.getRows()) {
        doSwitch(row);
    }

    return table;
}