Example usage for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument

List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument.

Prototype

public XWPFDocument(InputStream is) throws IOException 

Source Link

Usage

From source file:org.obeonetwork.m2doc.api.POIServices.java

License:Open Source License

/**
 * Get XWPFDocument from template path./*from ww  w . j a  v  a  2  s .  c  o m*/
 * 
 * @param templatePath
 *            String
 * @return XWPFDocument
 * @throws IOException
 *             IOException
 */
public XWPFDocument getXWPFDocument(String templatePath) throws IOException {
    OPCPackage oPackage = getOPCPackage(templatePath);
    XWPFDocument document = new XWPFDocument(oPackage);
    return document;
}

From source file:org.obeonetwork.m2doc.generator.DocumentGenerator.java

License:Open Source License

/**
 * creates the destination document./*from  w  w  w  . j  a va2 s .  c o  m*/
 * 
 * @param inputDocumentFileName
 *            the name of the destination document's file.
 * @return the created document
 * @throws IOException
 *             if an I/O problem occurs.
 * @throws InvalidFormatException
 *             if the generated file has a format problem.
 */
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);
    }
    return document;
}

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

License:Open Source License

@Test
public void testFormsAndTextArea()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testTextAreaAndForms.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/testTextAreaAndForms.docx",
            "results/testTextAreaAndForms.docx", template, definitions, queryEnvironment);
    generator.generate();/*from   w  w w. j  av  a  2s .  c o  m*/
}

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

License:Open Source License

@Test
public void testStaticFragmentWithFieldProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testStaticFragmentWithfields.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/testStaticFragmentWithfields.docx",
            "results/testStaticFragmentWithfields.docx", template, definitions, queryEnvironment);
    generator.generate();/*from w w w  .ja va 2 s .com*/
}

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

License:Open Source License

@Test
public void testStaticFragmentProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testStaticFragment.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/testStaticFragment.docx",
            "results/testStaticFragment.docx", template, definitions, queryEnvironment);
    generator.generate();//from  w  w  w.j ava  2  s. c om
}

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

License:Open Source License

@Test
public void testVarRefInHeaderProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testVarInHeader.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/testVarInHeader.docx",
            "results/testVarInHeaderResult.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 testVarRefInFooterProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testVarInFooter.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/testVarInFooter.docx",
            "results/testVarInFooterResult.docx", template, definitions, queryEnvironment);
    generator.generate();//from  w  w w .  ja v a  2  s  .c  om
}

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

License:Open Source License

@Test
public void testVarRefProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testVar.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/testVar.docx", "results/testVarResult.docx",
            template, definitions, queryEnvironment);
    generator.generate();/* ww w.  j  a va2s  .  c o  m*/
}

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

License:Open Source License

@Test
public void testVarRefErrorProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testVar.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>();
    DocumentGenerator generator = new DocumentGenerator("templates/testVar.docx", "results/testVarResult.docx",
            template, definitions, queryEnvironment);
    generator.generate();/* w w  w  . java2  s  . co m*/
}

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

License:Open Source License

@Test
public void testVarRefStyledProcessing()
        throws InvalidFormatException, IOException, DocumentParserException, DocumentGenerationException {
    IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
            .newEnvironmentWithDefaultServices(null);
    FileInputStream is = new FileInputStream("templates/testVarStyle.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/testVarStyle.docx",
            "results/testVarStyleResult.docx", template, definitions, queryEnvironment);
    generator.generate();//from  w  w  w. j  av a2  s.  c  om
}