List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph getCTP
@Internal
public CTP getCTP()
From source file:org.cgiar.ccafs.marlo.action.summaries.POWBPOISummaryAction.java
License:Open Source License
@Override public String execute() throws Exception { try {/*from w w w . ja va2 s . com*/ /* Create a portrait text Section */ CTDocument1 doc = document.getDocument(); CTBody body = doc.getBody(); poiSummary.pageHeader(document, this.getText("summaries.powb.header")); // Get datetime ZonedDateTime timezone = ZonedDateTime.now(); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm "); String zone = timezone.getOffset() + ""; if (zone.equals("Z")) { zone = "+0"; } String currentDate = timezone.format(format) + "(GMT" + zone + ")"; poiSummary.pageFooter(document, "This report was generated on " + currentDate); poiSummary.textLineBreak(document, 13); poiSummary.textHeadCoverTitle(document.createParagraph(), this.getText("summaries.powb.mainTitle")); poiSummary.textLineBreak(document, 12); poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.powb.mainTitle2")); poiSummary.textLineBreak(document, 1); poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.powb.cover")); poiSummary.textLineBreak(document, 1); String unitName = this.getLoggedCrp().getAcronym() != null && !this.getLoggedCrp().getAcronym().isEmpty() ? this.getLoggedCrp().getAcronym() : this.getLoggedCrp().getName(); poiSummary.textParagraph(document.createParagraph(), this.getText("summaries.powb.unitName") + ": " + unitName); this.addParticipatingCenters(); poiSummary.textLineBreak(document, 1); poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.powb.expectedKeyResults")); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.expectedKeyResults.toc")); this.addAdjustmentDescription(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.expectedKeyResults.expectedCrp")); this.addExpectedCrp(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.expectedKeyResults.evidence")); this.addEvidence(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.expectedKeyResults.flagshipPlans")); this.addFlagshipPlans(); this.addCrossCutting(); poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.powb.effectiveness")); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.effectiveness.staffing")); this.addCrpStaffing(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.effectiveness.financial")); this.addFinancialPlan(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.effectiveness.collaboration")); this.addCollaboration(); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.effectiveness.mel")); poiSummary.textLineBreak(document, 1); poiSummary.textHead1Title(document.createParagraph(), this.getText("summaries.powb.management")); this.addManagement(); /* Create a landscape text Section */ XWPFParagraph para = document.createParagraph(); CTSectPr sectionTable = body.getSectPr(); CTPageSz pageSizeTable = sectionTable.addNewPgSz(); CTP ctpTable = para.getCTP(); CTPPr brTable = ctpTable.addNewPPr(); brTable.setSectPr(sectionTable); /* standard Letter page size */ pageSizeTable.setOrient(STPageOrientation.LANDSCAPE); pageSizeTable.setW(BigInteger.valueOf(842 * 20)); pageSizeTable.setH(BigInteger.valueOf(595 * 20)); XWPFParagraph paragraph = document.createParagraph(); this.loadTablePMU(); poiSummary.textHead1Title(paragraph, "TABLES"); poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.tableA.title")); poiSummary.textHead3Title(document.createParagraph(), this.getText("summaries.powb.tableA1.title")); this.createTableA1(); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead3Title(document.createParagraph(), this.getText("summaries.powb.tableA2.title")); this.createTableA2(); poiSummary.textNotes(document.createParagraph(), "*" + this.getText("expectedProgress.tableA.milestone.help")); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.tableB.title")); this.createTableB(); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("crossCuttingDimensions.tableC.title")); this.createTableC(); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("crpStaffing.tableD.title")); this.createTableD(); poiSummary.textNotes(document.createParagraph(), this.getText("crpStaffing.tableD.help")); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("financialPlan.tableE.title", new String[] { String.valueOf(this.getSelectedYear()) })); this.createTableE(); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("financialPlan.tableF.title")); this.createTableF(); poiSummary.textNotes(document.createParagraph(), this.getText("financialPlan.tableF.expenditureArea.help")); poiSummary.textNotes(document.createParagraph(), this.getText("financialPlan.tableF.estimatedPercentage.help")); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("collaborationIntegration.listCollaborations.title")); this.createTableG(); poiSummary.textNotes(document.createParagraph(), this.getText("summaries.powb.tableG.description.help")); document.createParagraph().setPageBreak(true); // Fast Page Break poiSummary.textHead2Title(document.createParagraph(), this.getText("summaries.powb.tableF.title")); this.createTableH(); ByteArrayOutputStream os = new ByteArrayOutputStream(); document.write(os); bytesDOC = os.toByteArray(); os.close(); document.close(); } catch (Exception e) { LOG.error("Error generating POWB Summary " + e.getMessage()); throw e; } // Calculate time of generation long stopTime = System.currentTimeMillis(); stopTime = stopTime - startTime; LOG.info("Downloaded successfully: " + this.getFileName() + ". User: " + this.getCurrentUser().getComposedCompleteName() + ". CRP: " + this.getLoggedCrp().getAcronym() + ". Cycle: " + this.getSelectedCycle() + ". Time to generate: " + stopTime + "ms."); return SUCCESS; }
From source file:org.cgiar.ccafs.marlo.utils.POISummary.java
License:Open Source License
public void textHyperlink(String url, String text, XWPFParagraph paragraph) { // Add the link as External relationship String id = paragraph.getDocument().getPackagePart() .addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId(); // Append the link and bind it to the relationship CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); cLink.setId(id);/*from w w w. j a va 2s . c o m*/ // // Create the linked text CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue(text); CTR ctr = CTR.Factory.newInstance(); ctr.setTArray(new CTText[] { ctText }); ctr.addNewRPr().addNewColor().setVal("0000FF"); ctr.addNewRPr().addNewU().setVal(STUnderline.SINGLE); ctr.addNewRPr().addNewRFonts().setAscii(FONT_TYPE); // Insert the linked text into the link cLink.setRArray(new CTR[] { ctr }); }
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java
License:Open Source License
public static void addHyperLink(XWPFParagraph paragraph, String hyperlinkAnchor, String hyperlinkText) { CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); cLink.setAnchor(hyperlinkAnchor);// w ww. j av a 2s. c om CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue(hyperlinkText); CTR ctr = CTR.Factory.newInstance(); ctr.setTArray(new CTText[] { ctText }); // format the hyperlink (underline + color) CTRPr rpr = ctr.addNewRPr(); CTColor colour = CTColor.Factory.newInstance(); colour.setVal("0000FF"); rpr.setColor(colour); CTRPr rpr1 = ctr.addNewRPr(); rpr1.addNewU().setVal(STUnderline.SINGLE); cLink.setRArray(new CTR[] { ctr }); }
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java
License:Open Source License
public static void addBookmark(XWPFParagraph paragraph, String bookmarkAnchor, String bookmarkText) { CTBookmark bookmark = paragraph.getCTP().addNewBookmarkStart(); String bookmarkName = generateValidBookmarkName(bookmarkAnchor); bookmark.setName(bookmarkName);/*from w w w . ja va 2s .c om*/ final BigInteger bookmarkId = generateRandomId(); bookmark.setId(bookmarkId); addFormattedText(paragraph.createRun(), bookmarkText, FONT_SIZE + 2, true); paragraph.getCTP().addNewBookmarkEnd().setId(bookmarkId); }
From source file:org.nuclos.server.common.ooxml.WordXMLReader.java
License:Open Source License
private List<StructuredDocumentTag> structuredDocumentTags() { if (structuredDocumentTags == null) { structuredDocumentTags = new ArrayList<StructuredDocumentTag>(); // TODO: tables, am besten getBodyElements(), siehe JavaDoc... for (XWPFParagraph p : document.getParagraphs()) { extractStructuredDocumentTags(p.getCTP().getSdtArray()); }/*from w w w .j ava 2 s.c om*/ Iterator<XWPFTable> tableIter = document.getTablesIterator(); while (tableIter.hasNext()) { extractStructuredDocumentTags(tableIter.next()); } } return structuredDocumentTags; }
From source file:org.obeonetwork.m2doc.generator.BookmarkManager.java
License:Open Source License
/** * Starts a bookmark in the given {@link CTBody} with the given name. * //from w w w . j av a2s .c o m * @param paragraph * the current {@link XWPFParagraph} * @param name * the bookmark name */ public void startBookmark(XWPFParagraph paragraph, String name) { if (bookmarks.containsKey(name)) { M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR, "Can't start duplicated bookmark " + name); } else { final CTBookmark bookmark = paragraph.getCTP().addNewBookmarkStart(); // we create a new run for future error messages. messagePositions.put(bookmark, paragraph.createRun()); bookmark.setName(name); final BigInteger id = getRandomID(); bookmark.setId(id); bookmarks.put(name, bookmark); startedBookmarks.put(name, bookmark); Set<CTText> pendingRefs = pendingReferences.remove(name); if (pendingRefs != null) { for (CTText pendingRef : pendingRefs) { // we remove the created for error messages. final XWPFRun run = messagePositions.get(pendingRef); final IRunBody parent = run.getParent(); if (parent instanceof XWPFParagraph) { ((XWPFParagraph) parent).removeRun(((XWPFParagraph) parent).getRuns().indexOf(run)); } else { throw new IllegalStateException("this should not happend"); } pendingRef.setStringValue(String.format(REF_TAG, bookmark.getName())); } } } }
From source file:org.obeonetwork.m2doc.generator.BookmarkManager.java
License:Open Source License
/** * Ends the bookmark with the given name. * /*from ww w . j av a 2 s .c o m*/ * @param paragraph * the current {@link XWPFParagraph} * @param name * the bookmark name */ public void endBookmark(XWPFParagraph paragraph, String name) { final CTBookmark bookmark = startedBookmarks.remove(name); if (bookmark != null) { final CTMarkupRange range = paragraph.getCTP().addNewBookmarkEnd(); range.setId(bookmarks.get(name).getId()); // we remove the created for error messages. final XWPFRun run = messagePositions.get(bookmark); final IRunBody parent = run.getParent(); if (parent instanceof XWPFParagraph) { ((XWPFParagraph) parent).removeRun(((XWPFParagraph) parent).getRuns().indexOf(run)); } else { throw new IllegalStateException("this should not happend"); } } else if (bookmarks.containsKey(name)) { M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR, "Can't can't end already closed bookmark " + name); } else { M2DocUtils.appendMessageRun(paragraph, ValidationMessageLevel.ERROR, "Can't can't end not existing bookmark " + name); } }
From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java
License:Open Source License
/** * Creates a new paragraph and replaces the currentParagrap variable. * // ww w . j a va 2 s . c o m * @param srcParagraph * the origin paragraph to copy the style from. */ private void createNewParagraph(XWPFParagraph srcParagraph) { // create a new paragraph. XWPFParagraph newParagraph; if (generatedDocument instanceof XWPFTableCell) { XWPFTableCell cell = (XWPFTableCell) generatedDocument; newParagraph = cell.addParagraph(); } else if (generatedDocument instanceof XWPFDocument) { newParagraph = ((XWPFDocument) generatedDocument).createParagraph(); } else if (generatedDocument instanceof XWPFHeaderFooter) { newParagraph = ((XWPFHeaderFooter) generatedDocument).createParagraph(); } else { throw new UnsupportedOperationException("unkown IBody type :" + generatedDocument.getClass()); } CTP ctp = (CTP) srcParagraph.getCTP().copy(); ctp.getRList().clear(); ctp.getFldSimpleList().clear(); ctp.getHyperlinkList().clear(); newParagraph.getCTP().set(ctp); int runNb = newParagraph.getRuns().size(); for (int i = 0; i < runNb; i++) { newParagraph.removeRun(i); } currentTemplateParagraph = srcParagraph; currentGeneratedParagraph = newParagraph; }
From source file:org.obeonetwork.m2doc.generator.UserContentRawCopy.java
License:Open Source License
/** * Change Picture Id.// w w w .j a va 2s . com * * @throws XmlException * XmlException */ private void changePictureId() throws XmlException { for (XWPFRun run : listOutputRuns) { XmlToken outputXmlObject = getXmlWithOuputId(run.getCTR().xmlText()); if (outputXmlObject != null) { run.getCTR().set(outputXmlObject); } } for (XWPFParagraph paragraph : listOutputParagraphs) { XmlToken outputXmlObject = getXmlWithOuputId(paragraph.getCTP().xmlText()); if (outputXmlObject != null) { paragraph.getCTP().set(outputXmlObject); } } for (XWPFTable table : listOutputTables) { XmlToken outputXmlObject = getXmlWithOuputId(table.getCTTbl().xmlText()); if (outputXmlObject != null) { table.getCTTbl().set(outputXmlObject); } } }
From source file:org.obeonetwork.m2doc.tests.generator.DocumentGeneratorTests.java
License:Open Source License
@Test public void testBookmarkNominal() throws Exception { try (FileInputStream resIs = new FileInputStream( "resources/bookmark/nominal/nominal-expected-generation.docx"); OPCPackage resOPackage = OPCPackage.open(resIs); XWPFDocument resDocument = new XWPFDocument(resOPackage);) { assertEquals(5, resDocument.getBodyElements().size()); assertTrue(resDocument.getBodyElements().get(1) instanceof XWPFParagraph); XWPFParagraph paragraph = (XWPFParagraph) resDocument.getBodyElements().get(1); assertEquals(6, paragraph.getRuns().size()); assertEquals("Test link before bookmark: ", paragraph.getRuns().get(0).text()); final BigInteger id = new BigInteger(paragraph.getRuns().get(1).getCTR().getRsidR()); assertTrue(id != BigInteger.ZERO); assertEquals(1, paragraph.getRuns().get(1).getCTR().getFldCharList().size()); assertEquals(STFldCharType.BEGIN, paragraph.getRuns().get(1).getCTR().getFldCharList().get(0).getFldCharType()); assertEquals(id, new BigInteger(paragraph.getRuns().get(2).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(2).getCTR().getInstrTextList().size()); assertEquals(Space.PRESERVE, paragraph.getRuns().get(2).getCTR().getInstrTextList().get(0).getSpace()); assertEquals(" REF bookmark1 \\h ", paragraph.getRuns().get(2).getCTR().getInstrTextList().get(0).getStringValue()); assertEquals(id, new BigInteger(paragraph.getRuns().get(3).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(3).getCTR().getFldCharList().size()); assertEquals(STFldCharType.SEPARATE, paragraph.getRuns().get(3).getCTR().getFldCharList().get(0).getFldCharType()); assertEquals(id, new BigInteger(paragraph.getRuns().get(4).getCTR().getRsidR())); assertEquals("a reference to bookmark1", paragraph.getRuns().get(4).text()); assertEquals(id, new BigInteger(paragraph.getRuns().get(5).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(5).getCTR().getFldCharList().size()); assertEquals(STFldCharType.END,//from ww w . j a v a 2 s .co m paragraph.getRuns().get(5).getCTR().getFldCharList().get(0).getFldCharType()); assertTrue(resDocument.getBodyElements().get(1) instanceof XWPFParagraph); paragraph = (XWPFParagraph) resDocument.getBodyElements().get(2); assertEquals(1, paragraph.getCTP().getBookmarkStartList().size()); assertEquals("bookmark1", paragraph.getCTP().getBookmarkStartList().get(0).getName()); assertEquals(1, paragraph.getCTP().getBookmarkEndList().size()); assertTrue(resDocument.getBodyElements().get(2) instanceof XWPFParagraph); paragraph = (XWPFParagraph) resDocument.getBodyElements().get(3); assertEquals(7, paragraph.getRuns().size()); assertEquals("Test link after bookmark: ", paragraph.getRuns().get(0).text()); assertEquals(id, new BigInteger(paragraph.getRuns().get(1).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(1).getCTR().getFldCharList().size()); assertEquals(STFldCharType.BEGIN, paragraph.getRuns().get(1).getCTR().getFldCharList().get(0).getFldCharType()); assertEquals(id, new BigInteger(paragraph.getRuns().get(2).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(2).getCTR().getInstrTextList().size()); assertEquals(Space.PRESERVE, paragraph.getRuns().get(2).getCTR().getInstrTextList().get(0).getSpace()); assertEquals(" REF bookmark1 \\h ", paragraph.getRuns().get(2).getCTR().getInstrTextList().get(0).getStringValue()); assertEquals(id, new BigInteger(paragraph.getRuns().get(3).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(3).getCTR().getFldCharList().size()); assertEquals(STFldCharType.SEPARATE, paragraph.getRuns().get(3).getCTR().getFldCharList().get(0).getFldCharType()); assertEquals(id, new BigInteger(paragraph.getRuns().get(4).getCTR().getRsidR())); assertEquals("a reference to bookmark1", paragraph.getRuns().get(4).text()); assertEquals(id, new BigInteger(paragraph.getRuns().get(5).getCTR().getRsidR())); assertEquals(1, paragraph.getRuns().get(5).getCTR().getFldCharList().size()); assertEquals(STFldCharType.END, paragraph.getRuns().get(5).getCTR().getFldCharList().get(0).getFldCharType()); } }