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.TemplateGeneratorTest.java

License:Open Source License

/**
 * Ensure that the validation generation produces a document with errors in the good order.
 * /*from   ww w  .  j a  v a2 s  .  c  o 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);
}

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

License:Open Source License

/**
 * Tests that parsing errors from AQL template tag (conditional here) are placed next to the start tag.
 * The tested tag is <{m:wrong->.}ajout de value1{m:endif}>
 * The expected tag is : <{m:wrong->.} Expression wrong->. is invalid ajout de value1{m:endif}>
 * After the run with the end '}' char, the following runs must be present :
 * A run must contains blanks char./* w ww.j a va 2  s . c  o  m*/
 * The next one must contains the error message.
 * The next one must contains blank char and the next one the static content of the conditional.
 * 
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 * @throws DocumentGenerationException
 */
@Test
public void testErrorInStartTag()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    FileInputStream is = new FileInputStream("templates/testParsingErrorStartTag.docx");
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    BodyParser parser = new BodyParser(document, env);
    Template template = parser.parseTemplate();
    TemplateValidationGenerator validator = new TemplateValidationGenerator();
    validator.doSwitch(template);
    createDestinationDocument(document, "results/testParsingErrorStartTag.docx");

    // scan the destination document
    assertEquals(2, document.getParagraphs().size());
    assertEquals(16, document.getParagraphs().get(0).getRuns().size());
    assertEquals(1, document.getParagraphs().get(1).getRuns().size());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(5).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(6).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(6).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(6).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(7).getCTR().getRPr().getHighlight().getVal());
    assertEquals("Expression \"wrong->.\" is invalid: missing collection service call",
            document.getParagraphs().get(0).getRuns().get(7).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(7).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(7).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(7).getCTR().getRPr().getHighlight().getVal());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(8).getText(0));
    assertEquals("ajout de value1", document.getParagraphs().get(0).getRuns().get(9).getText(0));
    assertEquals("Unexpected tag m:endif at this location",
            document.getParagraphs().get(0).getRuns().get(13).getText(0));
}

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

License:Open Source License

/**
 * Tests that parsing errors from AQL template tag (conditional here) are placed next to the start tag.
 * The tested tag is <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}Some text>
 * The expected tag is : <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}<---The image
 * tag is referencing an unknown diagram provider : 'noExistingProvider' Some text>
 * After the run with the end '}' char, the following runs must be present :
 * A run must contains blanks char.//from  w  w  w.j  a  v a 2 s.  c o m
 * The next one must contains the error message.
 * The next one is a blank separator.
 * The next one must contains the other error message.
 * The next one must contains blank char and the next one the static content after the tag in the original template.
 * 
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 * @throws DocumentGenerationException
 */
@Test
public void testErrorInSimpleTag()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTag.docx");
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    BodyParser parser = new BodyParser(document, env);
    Template template = parser.parseTemplate();
    TemplateValidationGenerator validator = new TemplateValidationGenerator();
    validator.doSwitch(template);
    createDestinationDocument(document, "results/testParsingErrorSimpleTag.docx");
    // scan the destination document
    assertEquals(2, document.getParagraphs().size());
    assertEquals(11, document.getParagraphs().get(0).getRuns().size());
    assertEquals(1, document.getParagraphs().get(1).getRuns().size());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(2).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(3).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(3).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(3).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(5).getCTR().getRPr().getHighlight().getVal());
    assertEquals("The image tag is referencing an unknown diagram provider : 'noExistingProvider'",
            document.getParagraphs().get(0).getRuns().get(5).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(5).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(5).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(5).getCTR().getRPr().getHighlight().getVal());
    assertEquals("Some text", document.getParagraphs().get(0).getRuns().get(10).getText(0));
}

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

License:Open Source License

/**
 * Tests that parsing errors from AQL template tag (conditional here) are placed next to the start tag.
 * The tested tag is <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}Some text>
 * The expected tag is : <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}<---The image
 * tag is referencing an unknown diagram provider : 'noExistingProvider' <---The start of an option's key has been read but the end of
 * it and the value were missing : ' title="representationTitle"'. Some text>
 * After the run with the end '}' char, the following runs must be present :
 * A run must contains blanks char.//from ww w  .j  a  v a2s .  c o m
 * The next one must contains the error message.
 * The next one is a blank separator.
 * The next one must contains the other error message.
 * The next one must contains blank char and the next one the static content after the tag in the original template.
 * 
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 * @throws DocumentGenerationException
 */
@Test
public void testMultiErrorInSimpleTag()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    FileInputStream is = new FileInputStream("templates/testMultiParsingErrorSimpleTag.docx");
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    BodyParser parser = new BodyParser(document, env);
    Template template = parser.parseTemplate();
    TemplateValidationGenerator validator = new TemplateValidationGenerator();
    validator.doSwitch(template);
    createDestinationDocument(document, "results/testMultiParsingErrorSimpleTag.docx");
    // scan the destination document
    assertEquals(1, document.getParagraphs().size());
    assertEquals(14, document.getParagraphs().get(0).getRuns().size());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(2).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(3).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(3).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(3).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(3).getCTR().getRPr().getHighlight().getVal());
    assertEquals("The image tag is referencing an unknown diagram provider : 'noExistingProvider'",
            document.getParagraphs().get(0).getRuns().get(6).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(6).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(6).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(6).getCTR().getRPr().getHighlight().getVal());

    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(10).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(11).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(11).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(11).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(11).getCTR().getRPr().getHighlight().getVal());
    assertEquals(
            "The start of an option's key has been read but the end of it and the value were missing : ' title=\"representationTitle\"'.",
            document.getParagraphs().get(0).getRuns().get(12).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(12).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(12).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(11).getCTR().getRPr().getHighlight().getVal());

    assertEquals("Some text", document.getParagraphs().get(0).getRuns().get(13).getText(0));
}

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

License:Open Source License

/**
 * Tests that parsing errors from AQL template tag (conditional here) are placed next to the start tag.
 * The tested tag is <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}Some text>
 * The expected tag is : <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}<---The image
 * tag is referencing an unknown diagram provider : 'noExistingProvider' Some text>
 * After the run with the end '}' char, the following runs must be present :
 * A run must contains blanks char.// w w  w  .j a  va  2  s  . c o m
 * The next one must contains the error message.
 * The next one is a blank separator.
 * The next one must contains the other error message.
 * The next one must contains blank char and the next one the static content after the tag in the original template.
 * 
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 * @throws DocumentGenerationException
 */
@Test
public void testErrorInEndTag()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    FileInputStream is = new FileInputStream("templates/testParsingErrorEndTag.docx");
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    BodyParser parser = new BodyParser(document, env);
    Template template = parser.parseTemplate();
    TemplateValidationGenerator validator = new TemplateValidationGenerator();
    validator.doSwitch(template);
    createDestinationDocument(document, "results/testParsingErrorEndTag.docx");
    // scan the destination document
    assertEquals(1, document.getParagraphs().size());
    assertEquals(24, document.getParagraphs().get(0).getRuns().size());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(9).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(10).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(10).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(10).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(10).getCTR().getRPr().getHighlight().getVal());
    assertEquals("Unexpected tag m:endlet at this location",
            document.getParagraphs().get(0).getRuns().get(11).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(11).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(11).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(11).getCTR().getRPr().getHighlight().getVal());

    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(10).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(10).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(10).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(10).getCTR().getRPr().getHighlight().getVal());
    assertEquals("Unexpected tag m:endlet at this location",
            document.getParagraphs().get(0).getRuns().get(11).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(11).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(11).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(11).getCTR().getRPr().getHighlight().getVal());

    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(15).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(16).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(16).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(16).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(16).getCTR().getRPr().getHighlight().getVal());
    assertEquals("gd:elseif, gd:else or gd:endif expected here.",
            document.getParagraphs().get(0).getRuns().get(17).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(17).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(17).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(17).getCTR().getRPr().getHighlight().getVal());

    assertEquals("Some", document.getParagraphs().get(0).getRuns().get(18).getText(0));
    assertEquals(" t", document.getParagraphs().get(0).getRuns().get(19).getText(0));
    assertEquals("ext", document.getParagraphs().get(0).getRuns().get(20).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(22).getText(0));
    assertEquals("Unexpected tag EOF at this location",
            document.getParagraphs().get(0).getRuns().get(23).getText(0));
}

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

License:Open Source License

/**
 * Tests that parsing errors from AQL template tag (conditional here) are placed next to the start tag when no following text exists.
 * The tested tag is <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}>
 * The expected tag is : <{m:diagram provider:"noExistingProvider" width:"500" height:"500" title="representationTitle"}<---The image
 * tag is referencing an unknown diagram provider : 'noExistingProvider' >
 * After the run with the end '}' char, the following runs must be present :
 * A run must contains blanks char.//w  ww  .ja  va  2  s . c  om
 * The next one must contains the error message.
 * The next one is a blank separator.
 * The next one must contains the other error message.
 * The next one must contains blank char and the next one the static content after the tag in the original template.
 * 
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 * @throws DocumentGenerationException
 */
@Test
public void testErrorInSimpleTagWithoutFollowing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    FileInputStream is = new FileInputStream("templates/testParsingErrorSimpleTagWithoutFollowingText.docx");
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    BodyParser parser = new BodyParser(document, env);
    Template template = parser.parseTemplate();
    TemplateValidationGenerator validator = new TemplateValidationGenerator();
    validator.doSwitch(template);
    createDestinationDocument(document, "results/testParsingErrorSimpleTagWithoutFollowingText.docx");
    // scan the destination document
    assertEquals(1, document.getParagraphs().size());
    assertEquals(11, document.getParagraphs().get(0).getRuns().size());
    assertEquals("    ", document.getParagraphs().get(0).getRuns().get(2).getText(0));
    assertEquals("<---", document.getParagraphs().get(0).getRuns().get(3).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(3).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(3).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(5).getCTR().getRPr().getHighlight().getVal());
    assertEquals("The image tag is referencing an unknown diagram provider : 'noExistingProvider'",
            document.getParagraphs().get(0).getRuns().get(5).getText(0));
    assertEquals("FF0000", document.getParagraphs().get(0).getRuns().get(5).getColor());
    assertEquals(16, document.getParagraphs().get(0).getRuns().get(5).getFontSize());
    assertEquals(STHighlightColor.LIGHT_GRAY,
            document.getParagraphs().get(0).getRuns().get(5).getCTR().getRPr().getHighlight().getVal());
}

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

License:Open Source License

private XWPFDocument createDestinationDocument(String inputDocumentFileName)
        throws IOException, InvalidFormatException {
    FileInputStream is = new FileInputStream(inputDocumentFileName);
    OPCPackage oPackage = OPCPackage.open(is);
    XWPFDocument document = new XWPFDocument(oPackage);
    int size = document.getBodyElements().size();
    for (int i = 0; i < size; i++) {
        document.removeBodyElement(0);/*  ww w .  j  a va2  s.  c  o m*/
    }
    return document;
}

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

License:Open Source License

/**
 * Test the replacement of a variable in a doc.
 * /*from w w  w  .  ja  v  a  2  s.  c o m*/
 * @throws InvalidFormatException
 * @throws IOException
 * @throws DocumentParserException
 */
@Test
public void testVarRefProcessing() 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>();
    definitions.put("x", "valueofx");
    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: valueofx",
            destinationDoc.getParagraphs().get(0).getText());
    assertEquals("Fin du gabarit", destinationDoc.getParagraphs().get(1).getText());
}

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);// ww w  .  j  a  va 2s  .c o  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 testQueryProcessing() 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>();
    definitions.put("self", EcorePackage.eINSTANCE);
    XWPFDocument destinationDoc = createDestinationDocument("templates/testAQL.docx");
    TemplateProcessor processor = new TemplateProcessor(definitions, "", env, destinationDoc);
    processor.doSwitch(template);//  w w  w.j  a  v a2s  . co m
    // scan the destination document
    assertEquals(3, destinationDoc.getParagraphs().size());
    System.out.println(destinationDoc.getParagraphs().get(0).getText());
    assertEquals("Template de test pour les balises de query aql\u00a0: ecore",
            destinationDoc.getParagraphs().get(0).getText());
    assertEquals("Fin du gabarit", destinationDoc.getParagraphs().get(1).getText());
    assertEquals("", destinationDoc.getParagraphs().get(2).getText());
}