Example usage for org.apache.poi.openxml4j.opc OPCPackage open

List of usage examples for org.apache.poi.openxml4j.opc OPCPackage open

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.opc OPCPackage open.

Prototype

public static OPCPackage open(InputStream in) throws InvalidFormatException, IOException 

Source Link

Document

Open a package.

Usage

From source file:org.obeonetwork.m2doc.generator.test.DocumentGeneratorTest.java

License:Open Source License

@Test
public void testImagesAndFootersAndHeadersAndBullets()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    queryEnvironment.registerEPackage(EcorePackage.eINSTANCE);
    FileInputStream is = new FileInputStream("templates/test.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", EcorePackage.eINSTANCE);
    DocumentGenerator generator = new DocumentGenerator("templates/test.docx", "results/testResult.docx",
            template, definitions, queryEnvironment);
    generator.generate();//from  www.  j  a va2s.  c  om
}

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();// w ww  .j  ava  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 w  ww  . j a va2 s. c  om*/
}

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();/*  www.  java  2  s  .c  om*/
}

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();/* www.j  av a 2 s. co 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();//w  w w .  j  a va  2s.com
}

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();/*from  w ww . j  a v  a 2s. co 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.j av  a 2 s  .  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.
 * //from  www  . j a v  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.
 * //from w w  w.  ja  v a 2  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());
}