List of usage examples for org.apache.poi.openxml4j.opc OPCPackage open
public static OPCPackage open(InputStream in) throws InvalidFormatException, IOException
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserErrorsTest.java
License:Open Source License
/** * Tests the error reporting on a conditionnal tag with an else without an * gd:endif tag// w w w .j a va2 s .co m * * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testConditionnalError3() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testInvalidConditionnal3.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(1, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof Conditionnal); Default elseBranch = ((Conditionnal) template.getSubConstructs().get(0)).getElse(); assertNotNull(elseBranch); assertEquals(1, elseBranch.getParsingErrors().size()); assertEquals("Unexpected tag EOF at this location", elseBranch.getParsingErrors().get(0).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserErrorsTest.java
License:Open Source License
/** * Tests the error reporting on a conditionnal tag with a syntactically * invalid expression//from w w w. j av a 2 s . c o m * * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testConditionnalError4() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testInvalidConditionnal4.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(1, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof Conditionnal); Conditionnal elseIfBranch = ((Conditionnal) template.getSubConstructs().get(0)).getAlternative(); assertNotNull(elseIfBranch); assertEquals(2, elseIfBranch.getParsingErrors().size()); assertEquals("Unexpected tag EOF at this location", elseIfBranch.getParsingErrors().get(0).getMessage()); assertEquals("gd:elseif, gd:else or gd:endif expected here.", elseIfBranch.getParsingErrors().get(1).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserErrorsTest.java
License:Open Source License
/** * Tests the error reporting on a conditionnal tag with a syntactically * invalid expression//w w w. jav a 2 s .c om * * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testConditionnalError5() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testInvalidConditionnal5.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(1, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof Conditionnal); Conditionnal elseIfBranch = ((Conditionnal) template.getSubConstructs().get(0)).getAlternative(); assertNotNull(elseIfBranch); assertEquals(1, elseIfBranch.getParsingErrors().size()); assertEquals("Expression x= is invalid", elseIfBranch.getParsingErrors().get(0).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserErrorsTest.java
License:Open Source License
/** * Tests the error reporting on a conditionnal tag with a syntactically * invalid expression//from w ww .ja v a 2 s. c o m * * @throws InvalidFormatException * @throws IOException * @throws DocumentParserException */ @Test public void testVarRefError() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testVarInvalid.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(1, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof Query); Query query = ((Query) template.getSubConstructs().get(0)); assertEquals(1, query.getParsingErrors().size()); assertEquals("Expression is invalid", query.getParsingErrors().get(0).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testTemplateParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testTemplate.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(1, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertEquals(2, ((StaticFragment) template.getSubConstructs().get(0)).getRuns().size()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testVarParsing() 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(); assertEquals(document, template.getDocument()); assertEquals(3, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(template.getSubConstructs().get(1) instanceof Query); assertTrue(template.getSubConstructs().get(2) instanceof StaticFragment); Query varRef = (Query) template.getSubConstructs().get(1); assertNotNull(varRef.getQuery());// w ww . j a v a2 s .c o m }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testQueryParsing() 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(); assertEquals(document, template.getDocument()); assertEquals(3, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(template.getSubConstructs().get(1) instanceof Query); assertTrue(template.getSubConstructs().get(2) instanceof StaticFragment); Query query = (Query) template.getSubConstructs().get(1); assertNotNull(query.getQuery());/*from ww w. j av a2s .co m*/ }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testRepetitionParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testGDFOR.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(3, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(template.getSubConstructs().get(1) instanceof Repetition); assertTrue(template.getSubConstructs().get(2) instanceof StaticFragment); Repetition repetition = (Repetition) template.getSubConstructs().get(1); assertNotNull(repetition.getQuery()); assertEquals("v", repetition.getIterationVar()); assertTrue(repetition.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(repetition.getSubConstructs().get(1) instanceof Query); assertTrue(repetition.getSubConstructs().get(0) instanceof StaticFragment); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testSimpleConditionnalParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testConditionnal1.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(3, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(template.getSubConstructs().get(1) instanceof Conditionnal); assertTrue(template.getSubConstructs().get(2) instanceof StaticFragment); Conditionnal conditionnal = (Conditionnal) template.getSubConstructs().get(1); assertNotNull(conditionnal.getQuery()); assertTrue(conditionnal.getSubConstructs().get(0) instanceof StaticFragment); assertNull(conditionnal.getElse());//from w w w . java 2 s .c om assertNull(conditionnal.getAlternative()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testConditionnalWithElseParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testConditionnal2.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(document, template.getDocument()); assertEquals(3, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof StaticFragment); assertTrue(template.getSubConstructs().get(1) instanceof Conditionnal); assertTrue(template.getSubConstructs().get(2) instanceof StaticFragment); Conditionnal conditionnal = (Conditionnal) template.getSubConstructs().get(1); assertNotNull(conditionnal.getQuery()); assertTrue(conditionnal.getSubConstructs().get(0) instanceof StaticFragment); assertNull(conditionnal.getAlternative()); assertEquals(1, conditionnal.getElse().getSubConstructs().size()); assertTrue(conditionnal.getElse().getSubConstructs().get(0) instanceof StaticFragment); }