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.api.POIServices.java

License:Open Source License

/**
 * Get OPCPackage from template path./*from   w ww.  j  av a 2s  .co  m*/
 * 
 * @param templatePath
 *            String
 * @return OPCPackage
 * @throws IOException
 *             IOException
 */
public OPCPackage getOPCPackage(String templatePath) throws IOException {
    FileInputStream is = new FileInputStream(templatePath);
    OPCPackage oPackage;
    try {
        oPackage = OPCPackage.open(is);
    } catch (InvalidFormatException e) {
        throw new IllegalArgumentException("Couldn't open template file", e);
    }
    return oPackage;
}

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

License:Open Source License

/**
 * Get OPCPackage from template file.//from  w  ww  .j a  v  a2  s . c  o m
 * 
 * @param templateFile
 *            IFile
 * @return OPCPackage
 * @throws IOException
 *             IOException
 */
public OPCPackage getOPCPackage(IFile templateFile) throws IOException {
    FileInputStream is = new FileInputStream(templateFile.getLocation().toFile());
    OPCPackage oPackage;
    try {
        oPackage = OPCPackage.open(is);
    } catch (InvalidFormatException e) {
        throw new IllegalArgumentException("Couldn't open template file", e);
    }
    return oPackage;
}

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

License:Open Source License

/**
 * creates the destination document.//from   ww  w.j  a va2  s . c om
 * 
 * @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 a va  2 s.c om*/
}

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   ww w  . ja  v  a 2s  . c o  m
}

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  av a2 s  .  co  m*/
}

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();/*ww 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  ww .  j av  a 2 s  . c o m*/
}

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();//  w  ww  .  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 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();/* ww w .ja v  a2  s . co m*/
}