List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument
public XWPFDocument(InputStream is) throws IOException
From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java
License:Open Source License
@Test public void testConditionnal5Processing() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testConditionnal5.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "value1"); DocumentGenerator generator = new DocumentGenerator("templates/testConditionnal5.docx", "results/testConditionnal5Result.docx", template, definitions, queryEnvironment); generator.generate();// ww w. j av a 2s. co m }
From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java
License:Open Source License
@Test public void testConditionnal6Processing() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testConditionnal5.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "value2"); DocumentGenerator generator = new DocumentGenerator("templates/testConditionnal5.docx", "results/testConditionnal6Result.docx", template, definitions, queryEnvironment); generator.generate();/*from www .ja va 2 s.com*/ }
From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java
License:Open Source License
@Test public void testConditionnal7Processing() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testConditionnal5.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "value3"); DocumentGenerator generator = new DocumentGenerator("templates/testConditionnal5.docx", "results/testConditionnal7Result.docx", template, definitions, queryEnvironment); generator.generate();//from w w w . j a v a 2 s. c o m }
From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java
License:Open Source License
@Test public void testConditionnal8Processing() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testConditionnal5.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "valueofx"); DocumentGenerator generator = new DocumentGenerator("templates/testConditionnal5.docx", "results/testConditionnal8Result.docx", template, definitions, queryEnvironment); generator.generate();/*from w w w . j a v a2 s .c o m*/ }
From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java
License:Open Source License
@Test public void testImageGeneration() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testImageTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("x", "valueofx"); DocumentGenerator generator = new DocumentGenerator("templates/testImageTag.docx", "results/testImageTag.docx", template, definitions, queryEnvironment); generator.generate();//from w ww .j av a 2s .c om }
From source file:org.obeonetwork.m2doc.generator.test.EcoreDocumentationGeneration.java
License:Open Source License
@Test public void testStaticFragmentWithFieldProcessing() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException, InvalidAcceleoPackageException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); queryEnvironment.registerEPackage(EcorePackage.eINSTANCE); queryEnvironment.registerServicePackage(EcoreDocumentationServices.class); FileInputStream is = new FileInputStream("templates/ecoreDocumentationTemplate.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); Map<String, Object> definitions = new HashMap<String, Object>(); definitions.put("self", TemplatePackage.eINSTANCE); DocumentGenerator generator = new DocumentGenerator("templates/ecoreDocumentationTemplate.docx", "results/ecoreDocumentationTemplateResults.docx", template, definitions, queryEnvironment); generator.generate();// w ww . jav a 2s.c o m }
From source file:org.obeonetwork.m2doc.generator.test.TemplateGeneratorTest.java
License:Open Source License
/** * Ensure that the validation generation produces a document with an info. * // w w w . jav a2s . co m * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException * @throws DocumentGenerationException */ @Test public void testInfoGeneration() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); final XWPFRun location = ((XWPFParagraph) template.getDocument().getBodyElements().get(0)).getRuns().get(0); template.getBody().getValidationMessages().add( new TemplateValidationMessage(ValidationMessageLevel.INFO, "XXXXXXXXXXXXXXXXXXXXXXXX", location)); TemplateGenerator generator = new TemplateGenerator("results/testParsingErrorSimpleTag.docx", template); generator.generate(); assertTrue(new File("results/testParsingErrorSimpleTag.docx").exists()); FileInputStream resIs = new FileInputStream("results/testParsingErrorSimpleTag.docx"); OPCPackage resOPackage = OPCPackage.open(resIs); XWPFDocument resDocument = new XWPFDocument(resOPackage); final XWPFRun messageRun = M2DocTestUtils.getRunContaining(resDocument, "XXXXXXXXXXXXXXXXXXXXXXXX"); assertNotNull(messageRun); assertEquals("XXXXXXXXXXXXXXXXXXXXXXXX", messageRun.text()); assertEquals("0000FF", messageRun.getColor()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateGeneratorTest.java
License:Open Source License
/** * Ensure that the validation generation produces a document with an warning. * /* w w w. jav a 2 s. c o m*/ * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException * @throws DocumentGenerationException */ @Test public void testWarningGeneration() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); final XWPFRun location = ((XWPFParagraph) template.getDocument().getBodyElements().get(0)).getRuns().get(0); template.getBody().getValidationMessages().add(new TemplateValidationMessage(ValidationMessageLevel.WARNING, "XXXXXXXXXXXXXXXXXXXXXXXX", location)); TemplateGenerator generator = new TemplateGenerator("results/testParsingErrorSimpleTag.docx", template); generator.generate(); assertTrue(new File("results/testParsingErrorSimpleTag.docx").exists()); FileInputStream resIs = new FileInputStream("results/testParsingErrorSimpleTag.docx"); OPCPackage resOPackage = OPCPackage.open(resIs); XWPFDocument resDocument = new XWPFDocument(resOPackage); final XWPFRun messageRun = M2DocTestUtils.getRunContaining(resDocument, "XXXXXXXXXXXXXXXXXXXXXXXX"); assertNotNull(messageRun); assertEquals("XXXXXXXXXXXXXXXXXXXXXXXX", messageRun.text()); assertEquals("FFFF00", messageRun.getColor()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateGeneratorTest.java
License:Open Source License
/** * Ensure that the validation generation produces a document with an error. * /* ww w . ja v a2 s. c o m*/ * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException * @throws DocumentGenerationException */ @Test public void testErrorGeneration() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); final XWPFRun location = ((XWPFParagraph) template.getDocument().getBodyElements().get(0)).getRuns().get(0); template.getBody().getValidationMessages().add( new TemplateValidationMessage(ValidationMessageLevel.ERROR, "XXXXXXXXXXXXXXXXXXXXXXXX", location)); TemplateGenerator generator = new TemplateGenerator("results/testParsingErrorSimpleTag.docx", template); generator.generate(); assertTrue(new File("results/testParsingErrorSimpleTag.docx").exists()); FileInputStream resIs = new FileInputStream("results/testParsingErrorSimpleTag.docx"); OPCPackage resOPackage = OPCPackage.open(resIs); XWPFDocument resDocument = new XWPFDocument(resOPackage); final XWPFRun messageRun = M2DocTestUtils.getRunContaining(resDocument, "XXXXXXXXXXXXXXXXXXXXXXXX"); assertNotNull(messageRun); assertEquals("XXXXXXXXXXXXXXXXXXXXXXXX", messageRun.text()); assertEquals("FF0000", messageRun.getColor()); }
From source file:org.obeonetwork.m2doc.generator.test.TemplateGeneratorTest.java
License:Open Source License
/** * Ensure that the validation generation produces a document with errors in the good order. * /*from w w w. j ava 2 s.co m*/ * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException * @throws DocumentGenerationException */ @Test public void testErrorGenerationOrder() throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException { IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query .newEnvironmentWithDefaultServices(null); FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); DocumentParser parser = new DocumentParser(document, queryEnvironment); DocumentTemplate template = parser.parseDocument(); final XWPFRun location = ((XWPFParagraph) template.getDocument().getBodyElements().get(0)).getRuns().get(0); template.getBody().getValidationMessages() .add(new TemplateValidationMessage(ValidationMessageLevel.ERROR, "AAAA", location)); template.getBody().getValidationMessages() .add(new TemplateValidationMessage(ValidationMessageLevel.ERROR, "BBBB", location)); template.getBody().getValidationMessages() .add(new TemplateValidationMessage(ValidationMessageLevel.ERROR, "CCCC", location)); template.getBody().getValidationMessages() .add(new TemplateValidationMessage(ValidationMessageLevel.ERROR, "DDDD", location)); TemplateGenerator generator = new TemplateGenerator("results/testParsingErrorSimpleTag.docx", template); generator.generate(); assertTrue(new File("results/testParsingErrorSimpleTag.docx").exists()); FileInputStream resIs = new FileInputStream("results/testParsingErrorSimpleTag.docx"); OPCPackage resOPackage = OPCPackage.open(resIs); XWPFDocument resDocument = new XWPFDocument(resOPackage); final XWPFRun messageARun = M2DocTestUtils.getRunContaining(resDocument, "AAAA"); final XWPFRun messageBRun = M2DocTestUtils.getRunContaining(resDocument, "BBBB"); final XWPFRun messageCRun = M2DocTestUtils.getRunContaining(resDocument, "CCCC"); final XWPFRun messageDRun = M2DocTestUtils.getRunContaining(resDocument, "DDDD"); assertNotNull(messageARun); assertEquals("AAAA", messageARun.text()); assertEquals("FF0000", messageARun.getColor()); assertNotNull(messageBRun); assertEquals("BBBB", messageBRun.text()); assertEquals("FF0000", messageBRun.getColor()); assertNotNull(messageCRun); assertEquals("CCCC", messageCRun.text()); assertEquals("FF0000", messageCRun.getColor()); assertNotNull(messageDRun); assertEquals("DDDD", messageDRun.text()); assertEquals("FF0000", messageDRun.getColor()); final int indexA = ((XWPFParagraph) messageARun.getParent()).getRuns().indexOf(messageARun); final int indexB = ((XWPFParagraph) messageBRun.getParent()).getRuns().indexOf(messageBRun); final int indexC = ((XWPFParagraph) messageCRun.getParent()).getRuns().indexOf(messageCRun); final int indexD = ((XWPFParagraph) messageDRun.getParent()).getRuns().indexOf(messageDRun); assertTrue(indexA < indexB); assertTrue(indexB < indexC); assertTrue(indexC < indexD); }