List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument XWPFDocument
public XWPFDocument(InputStream is) throws IOException
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testConditionnalWith2ElseIfParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testConditionnal4.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); assertTrue(conditionnal.getAlternative() instanceof Conditionnal); assertNull(conditionnal.getElse());// ww w .j av a 2 s .com assertTrue(conditionnal.getAlternative().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(conditionnal.getAlternative().getQuery()); assertNotNull(conditionnal.getAlternative().getAlternative()); assertNull(conditionnal.getAlternative().getElse()); assertTrue( conditionnal.getAlternative().getAlternative().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(conditionnal.getAlternative().getAlternative().getQuery()); assertNull(conditionnal.getAlternative().getAlternative().getAlternative()); assertNull(conditionnal.getAlternative().getAlternative().getElse()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void testConditionnalWith2ElseIfAndElseParsing() throws InvalidFormatException, IOException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testConditionnal5.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); assertTrue(conditionnal.getAlternative() instanceof Conditionnal); assertNull(conditionnal.getElse());/*from w ww . j av a 2 s.c o m*/ assertTrue(conditionnal.getAlternative().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(conditionnal.getAlternative().getQuery()); assertNotNull(conditionnal.getAlternative().getAlternative()); assertNull(conditionnal.getAlternative().getElse()); assertTrue( conditionnal.getAlternative().getAlternative().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(conditionnal.getAlternative().getAlternative().getQuery()); assertNull(conditionnal.getAlternative().getAlternative().getAlternative()); assertNotNull(conditionnal.getAlternative().getAlternative().getElse()); assertTrue(conditionnal.getAlternative().getAlternative().getElse() instanceof Default); assertTrue(conditionnal.getAlternative().getAlternative().getElse().getSubConstructs() .get(0) instanceof StaticFragment); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void tableParsingTest() throws IOException, InvalidFormatException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testTable.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(2, template.getSubConstructs().size()); assertTrue(template.getSubConstructs().get(0) instanceof Table); Table table = (Table) template.getSubConstructs().get(0); assertEquals(2, table.getRows().size()); // First row testing. Row row = table.getRows().get(0);//from ww w. ja v a 2 s . c o m assertEquals(2, row.getCells().size()); assertTrue(row.getCells().get(0).getTemplate().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(row.getCells().get(0).getTableCell()); assertTrue(row.getCells().get(1).getTemplate().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(row.getCells().get(1).getTableCell()); // Second row testing. row = table.getRows().get(1); assertEquals(2, row.getCells().size()); assertTrue(row.getCells().get(0).getTemplate().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(row.getCells().get(0).getTableCell()); assertTrue(row.getCells().get(1).getTemplate().getSubConstructs().get(0) instanceof Query); assertNotNull(row.getCells().get(1).getTableCell()); assertNotNull(((Query) row.getCells().get(1).getTemplate().getSubConstructs().get(0)).getQuery()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void forWithtableParsingTest() throws IOException, InvalidFormatException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testGDFORWithTable.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(6, template.getSubConstructs().size()); Repetition rep = (Repetition) template.getSubConstructs().get(4); Table table = (Table) rep.getSubConstructs().get(0); assertEquals(1, table.getRows().size()); // First row testing. Row row = table.getRows().get(0);// www .jav a 2 s . co m assertEquals(2, row.getCells().size()); assertTrue(row.getCells().get(0).getTemplate().getSubConstructs().get(0) instanceof StaticFragment); assertNotNull(row.getCells().get(0).getTableCell()); assertTrue(row.getCells().get(1).getTemplate().getSubConstructs().get(0) instanceof Query); assertNotNull(((Query) row.getCells().get(1).getTemplate().getSubConstructs().get(0)).getQuery()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void imageParsingTest() throws IOException, InvalidFormatException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testImageTag.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(1, template.getSubConstructs().size()); Image im = (Image) template.getSubConstructs().get(0); assertEquals("images/dh1.gif", im.getFileName()); assertEquals(100, im.getHeight());/* w ww .j a v a 2s.com*/ assertEquals(100, im.getWidth()); assertEquals("plan de forme du dingy herbulot", im.getLegend()); assertEquals(POSITION.BELOW, im.getLegendPOS()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void imageParsingTestWithoutFiledirective() throws IOException, InvalidFormatException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testImageTag2.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(1, template.getSubConstructs().size()); Image im = (Image) template.getSubConstructs().get(0); assertEquals("Invalid image directive : no file name provided.", im.getParsingErrors().get(0).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.DocumentParserTest.java
License:Open Source License
@Test public void imageParsingTestWithBadOptionName() throws IOException, InvalidFormatException, DocumentParserException { FileInputStream is = new FileInputStream("templates/testImageTag3.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); BodyParser parser = new BodyParser(document, env); Template template = parser.parseTemplate(); assertEquals(1, template.getSubConstructs().size()); Image im = (Image) template.getSubConstructs().get(0); assertEquals("Invalid image option (leg): unknown option name.", im.getParsingErrors().get(0).getMessage()); }
From source file:org.obeonetwork.m2doc.parser.test.OptionParserTest.java
License:Open Source License
/** * Initialize needed elements for testing. * /*ww w . j a v a2 s.co m*/ * @throws IOException * @throws InvalidFormatException */ @Before public void setUp() throws InvalidFormatException, IOException { optionParser = new OptionParser(); try (FileInputStream is = new FileInputStream("templates/allDiagram.docx")) { OPCPackage oPackage = OPCPackage.open(is); document = new XWPFDocument(oPackage); XWPFParagraph paragraph = document.getParagraphs().get(0); construct = TemplateFactory.eINSTANCE.createRepresentation(); construct.getRuns().add(paragraph.getRuns().get(0)); construct.setStyleRun(paragraph.getRuns().get(0)); } }
From source file:org.obeonetwork.m2doc.parser.test.RunIteratorTests.java
License:Open Source License
@Test public void testNonEmptyDoc() throws InvalidFormatException, IOException { FileInputStream is = new FileInputStream("templates/RunIteratorTest.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); TokenIterator iterator = new TokenIterator(document); XWPFRun run = iterator.next().getRun(); assertEquals("P1Run1 ", run.getText(run.getTextPosition())); run = iterator.next().getRun();//from w w w .j av a 2 s .c o m assertEquals("P1Run2", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals(" P1Run3", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals("P2Run1 ", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals("P2Run2", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals(" ", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals("P2Run3", run.getText(run.getTextPosition())); run = iterator.next().getRun(); assertEquals("", run.getText(run.getTextPosition())); assertTrue(!iterator.hasNext()); }
From source file:org.obeonetwork.m2doc.parser.test.RunIteratorTests.java
License:Open Source License
@Test(expected = NoSuchElementException.class) public void testAccessEmptyIterator() throws InvalidFormatException, IOException { FileInputStream is = new FileInputStream("templates/RunIteratorTest.docx"); OPCPackage oPackage = OPCPackage.open(is); XWPFDocument document = new XWPFDocument(oPackage); TokenIterator iterator = new TokenIterator(document); iterator.next();/*from ww w . j a va2s . c o m*/ iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); }