List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun getCTR
@Internal
public CTR getCTR()
From source file:org.obeonetwork.m2doc.generator.test.TemplateProcessorTest.java
License:Open Source License
@Test public void testVarRefStyledProcessing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testVarStyle.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "valueofx"); XWPFDocument destinationDoc = createDestinationDocument("templates/testVarStyle.docx"); TemplateProcessor processor = new TemplateProcessor(definitions, "", env, destinationDoc); processor.doSwitch(template);// w w w . j a v a 2s .co m assertEquals("Template de test pour les balises de rfrence une variable\u00a0: valueofx", destinationDoc.getParagraphs().get(0).getText()); XWPFParagraph paragraph = destinationDoc.getParagraphs().get(0); XWPFRun run = paragraph.getRuns().get(paragraph.getRuns().size() - 1); assertEquals("E36C0A", run.getColor()); assertNotNull(run.getCTR().getRPr().getI()); assertNotNull(run.getCTR().getRPr().getB()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateProcessorTest.java
License:Open Source License
@Test public void testVarQueryStyledProcessing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testVarStyle.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "valueofx"); XWPFDocument destinationDoc = createDestinationDocument("templates/testVarStyle.docx"); TemplateProcessor processor = new TemplateProcessor(definitions, "", env, destinationDoc); processor.doSwitch(template);/*from w w w . j av a2 s . co m*/ assertEquals("Template de test pour les balises de rfrence une variable\u00a0: valueofx", destinationDoc.getParagraphs().get(0).getText()); XWPFParagraph paragraph = destinationDoc.getParagraphs().get(0); XWPFRun run = paragraph.getRuns().get(paragraph.getRuns().size() - 1); assertEquals("E36C0A", run.getColor()); assertNotNull(run.getCTR().getRPr().getI()); assertNotNull(run.getCTR().getRPr().getB()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateRuntimeErrorTests.java
License:Open Source License
/** * Tests processing of a variable reference where the variable is unknown. * // w w w . j a va 2s .co m * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testUnknownVarRefProcessing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testVar.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); Map<String, Object> definitions = new HashMap<String, Object>(); XWPFDocument destinationDoc = createDestinationDocument("templates/testVar.docx"); TemplateProcessor processor = new TemplateProcessor(definitions, "", env, destinationDoc); processor.doSwitch(template); // scan the destination document assertEquals(2, destinationDoc.getParagraphs().size()); System.out.println(destinationDoc.getParagraphs().get(0).getText()); assertEquals( "Template de test pour les balises de rfrence une variable\u00a0: Couldn't find the x variable", destinationDoc.getParagraphs().get(0).getText()); XWPFRun run = destinationDoc.getParagraphs().get(0).getRuns() .get(destinationDoc.getParagraphs().get(0).getRuns().size() - 1); assertEquals("FF0000", run.getColor()); assertNotNull(run.getCTR().getRPr().getB()); assertEquals("Fin du gabarit", destinationDoc.getParagraphs().get(1).getText()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateRuntimeErrorTests.java
License:Open Source License
/** * Tests processing of a query where the evaluation results in an error. * /*from w w w . j av a 2 s.com*/ * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testQueryEvaluationErrorProcessing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testAQL.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); Map<String, Object> definitions = new HashMap<String, Object>(); XWPFDocument destinationDoc = createDestinationDocument("templates/testAQL.docx"); TemplateProcessor processor = new TemplateProcessor(definitions, "", env, destinationDoc); processor.doSwitch(template); // scan the destination document assertEquals(4, destinationDoc.getParagraphs().size()); System.out.println(destinationDoc.getParagraphs().get(0).getText()); assertEquals("Template de test pour les balises de query aql\u00a0: Couldn't find the self variable", destinationDoc.getParagraphs().get(0).getText()); assertEquals( "Attempt to access feature (name) on a non ModelObject value (org.eclipse.acceleo.query.runtime.impl.Nothing).", destinationDoc.getParagraphs().get(1).getText()); XWPFRun run = destinationDoc.getParagraphs().get(0).getRuns() .get(destinationDoc.getParagraphs().get(0).getRuns().size() - 1); assertEquals("FF0000", run.getColor()); assertNotNull(run.getCTR().getRPr().getB()); assertEquals("Fin du gabarit", destinationDoc.getParagraphs().get(2).getText()); assertEquals("", destinationDoc.getParagraphs().get(3).getText()); }
From source file:org.obeonetwork.m2doc.generator.UserContentRawCopy.java
License:Open Source License
/** * Copy./*ww w .j a va2 s . c o m*/ * * @param userContent * UserContent EObject * @param outputParagraphBeforeUserDocContent * Output Paragraph Before User Doc Dest content (User Code dest is writen by {@link M2DocEvaluator} ) * @param outputBody * output body * @return last paragraph created by copy * @throws InvalidFormatException * InvalidFormatException * @throws XmlException * XmlException * @throws IOException * if the copy fails */ @SuppressWarnings("resource") public XWPFParagraph copy(UserContent userContent, XWPFParagraph outputParagraphBeforeUserDocContent, IBody outputBody) throws InvalidFormatException, XmlException, IOException { XWPFDocument containerOutputDocument = outputParagraphBeforeUserDocContent.getDocument(); // Test if run before userContent is in same XWPFParagraph than first run of userContent if (!userDocContentIsFirstRunOfParagraph(userContent)) { previousInputParagraph = (XWPFParagraph) userContent.getRuns().get(userContent.getRuns().size() - 1) .getParent(); currentInputParagraph = previousInputParagraph; currentOutputParagraph = outputParagraphBeforeUserDocContent; } XWPFParagraph currentRunParagraph = null; for (IConstruct abstractConstruct : userContent.getBody().getStatements()) { for (XWPFRun inputRun : abstractConstruct.getRuns()) { currentRunParagraph = (XWPFParagraph) inputRun.getParent(); if (currentRunParagraph != currentInputParagraph) { currentInputParagraph = currentRunParagraph; // currentOutputParagraph = outputDocument.createParagraph(); currentOutputParagraph = createNewParagraph(outputBody); // Copy new paragraph currentOutputParagraph.getCTP().set(currentInputParagraph.getCTP()); listOutputParagraphs.add(currentOutputParagraph); } // Test if some run exist between userContent tag and first paragraph in this tag if (currentRunParagraph == previousInputParagraph) { // Clone run directly, paragraph is already generate by normal processing XWPFRun outputRun = currentOutputParagraph.createRun(); outputRun.getCTR().set(inputRun.getCTR()); // Keep run to change relation id later listOutputRuns.add(outputRun); } // Create picture embedded in run and keep relation id in map (input to output) createPictures(inputRun, containerOutputDocument); } // In case of table (no run in abstractConstruct) if (abstractConstruct instanceof Table) { Table table = (Table) abstractConstruct; XWPFTable inputTable = table.getTable(); // XWPFTable outputTable = contenerOutputDocument.createTable(); XWPFTable outputTable = createNewTable(outputBody, inputTable); outputTable.getCTTbl().set(inputTable.getCTTbl()); copyTableStyle(inputTable, containerOutputDocument); listOutputTables.add(outputTable); // Inspect table to extract all picture ID in run collectRelationId(inputTable, containerOutputDocument); } } // Change Picture Id by xml replacement changePictureId(); if (userContent.getClosingRuns().size() != 0 && currentInputParagraph == userContent.getClosingRuns().get(0).getParent()) { needNewParagraph = false; } return currentOutputParagraph; }
From source file:org.obeonetwork.m2doc.generator.UserContentRawCopy.java
License:Open Source License
/** * Change Picture Id./*from ww w .java 2 s .c om*/ * * @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.parser.BodyParser.java
License:Open Source License
/** * Returns <code>true</code> when the specified run is a field begin run and <code>false</code> otherwise. * //from w w w . j a va 2 s.co m * @param run * the concerned run * @return <code>true</code> for field begin. */ private boolean isFieldBegin(XWPFRun run) { if (run.getCTR().getFldCharList().size() > 0) { CTFldChar fldChar = run.getCTR().getFldCharList().get(0); return STFldCharType.BEGIN.equals(fldChar.getFldCharType()); } else { return false; } }
From source file:org.obeonetwork.m2doc.parser.BodyParser.java
License:Open Source License
/** * Returns <code>true</code> when the specified run is a field end run and <code>false</code> otherwise. * //from w w w.j a v a2s . c o m * @param run * the concerned run * @return <code>true</code> for field end. */ private boolean isFieldEnd(XWPFRun run) { if (run.getCTR().getFldCharList().size() > 0) { CTFldChar fldChar = run.getCTR().getFldCharList().get(0); return STFldCharType.END.equals(fldChar.getFldCharType()); } else { return false; } }
From source file:org.obeonetwork.m2doc.parser.BodyParser.java
License:Open Source License
/** * reads up the instruction of a field's run. * /*from ww w .j a v a2s . c om*/ * @param run * the run to read. * @return the aggregated instruction text of the run */ private StringBuilder readUpInstrText(XWPFRun run) { List<CTText> texts = run.getCTR().getInstrTextList(); StringBuilder runBuilder = new StringBuilder(); for (CTText text : texts) { runBuilder.append(text.getStringValue()); } return runBuilder; }
From source file:org.obeonetwork.m2doc.util.FieldUtils.java
License:Open Source License
/** * Returns <code>true</code> when the specified run is a field begin run and <code>false</code> otherwise. * /*w w w.j a va2s.c o m*/ * @param run * the concerned run * @return <code>true</code> for field begin. */ public boolean isFieldBegin(XWPFRun run) { if (run.getCTR().getFldCharList().size() > 0) { CTFldChar fldChar = run.getCTR().getFldCharList().get(0); return STFldCharType.BEGIN.equals(fldChar.getFldCharType()); } else { return false; } }