Search in sources :

Example 21 with XWPFRun

use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.

the class DocxGenerator method fillLicenseList.

private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
    List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
    XWPFRun licenseHeaderRun = document.createParagraph().createRun();
    addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
    addNewLines(document, 0);
    for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
        XWPFParagraph licenseParagraph = document.createParagraph();
        licenseParagraph.setStyle(STYLE_HEADING);
        String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
        addBookmark(licenseParagraph, licenseName, licenseName);
        addNewLines(document, 0);
        setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
        addNewLines(document, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 22 with XWPFRun

use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.

the class DocxGenerator method fillReleaseDetailList.

private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
    addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
    setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
    addNewLines(document, 0);
    for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
        addReleaseTitle(document, parsingResult);
        if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
            addCopyrights(document, parsingResult);
            addLicenses(document, parsingResult, includeObligations);
        } else {
            XWPFRun errorRun = document.createParagraph().createRun();
            String errorText = nullToEmptyString(parsingResult.getMessage());
            String filename = getFilename(parsingResult);
            addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
            addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
        }
        addNewLines(document, 1);
    }
    addPageBreak(document);
}
Also used : XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 23 with XWPFRun

use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.

the class DocxGenerator method addLicenseObligations.

private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
    List<License> sw360Licenses = getLicenses();
    XWPFRun todoTitleRun = document.createParagraph().createRun();
    addNewLines(todoTitleRun, 0);
    Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
    addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
    for (String todo : todos) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);
        XWPFRun todoRun = copyPara.createRun();
        setText(todoRun, todo);
        addNewLines(todoRun, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) License(org.eclipse.sw360.datahandler.thrift.licenses.License) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 24 with XWPFRun

use of org.apache.poi.xwpf.usermodel.XWPFRun in project tutorials by eugenp.

the class WordIntegrationTest method whenParsingOutputDocument_thenCorrect.

@Test
public void whenParsingOutputDocument_thenCorrect() throws Exception {
    Path msWordPath = Paths.get(WordDocument.output);
    XWPFDocument document = new XWPFDocument(Files.newInputStream(msWordPath));
    List<XWPFParagraph> paragraphs = document.getParagraphs();
    document.close();
    XWPFParagraph title = paragraphs.get(0);
    XWPFRun titleRun = title.getRuns().get(0);
    assertEquals("Build Your REST API with Spring", title.getText());
    assertEquals("009933", titleRun.getColor());
    assertTrue(titleRun.isBold());
    assertEquals("Courier", titleRun.getFontFamily());
    assertEquals(20, titleRun.getFontSize());
    assertEquals("from HTTP fundamentals to API Mastery", paragraphs.get(1).getText());
    assertEquals("What makes a good API?", paragraphs.get(3).getText());
    assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph1), paragraphs.get(4).getText());
    assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph2), paragraphs.get(5).getText());
    assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph3), paragraphs.get(6).getText());
}
Also used : Path(java.nio.file.Path) XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) Test(org.junit.Test)

Aggregations

XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)24 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)22 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)13 FileOutputStream (java.io.FileOutputStream)10 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)6 File (java.io.File)5 OutputStream (java.io.OutputStream)5 XWPFTableCell (org.apache.poi.xwpf.usermodel.XWPFTableCell)5 XWPFTableRow (org.apache.poi.xwpf.usermodel.XWPFTableRow)5 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)5 CTTcPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr)4 FileInputStream (java.io.FileInputStream)3 XWPFHeaderFooterPolicy (org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 XWPFFooter (org.apache.poi.xwpf.usermodel.XWPFFooter)2 XWPFHeader (org.apache.poi.xwpf.usermodel.XWPFHeader)2 Test (org.junit.Test)2 CTTblWidth (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth)2