Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.TextDocument$ListContainerImpl


*/
public class TableBuilderTest {
   
    @Test
    public void testCreateTable() throws Exception {
        TextDocument textDoc = TextDocument.newTextDocument();
        TableBuilder tableBuilder = textDoc.getTableBuilder();
        Table table = tableBuilder.newTable(4, 3, 2, 1);
        assertEquals(4, table.getRowCount());
        assertEquals(3, table.getColumnCount());
        assertEquals(2, table.getHeaderRowCount());
        assertEquals(1, table.getHeaderColumnCount());
View Full Code Here


        assertNotNull(table.getCellByPosition(1, 1));
    }
   
    @Test
    public void testAppendRow() throws Exception {
        TextDocument textDoc = TextDocument.newTextDocument();
        TableBuilder tableBuilder = textDoc.getTableBuilder();
        Table table = tableBuilder.newTable(4, 3, 2, 1);
        assertEquals(4, table.getRowCount());
        Row row = table.appendRow();
        assertNotNull(row);
        assertEquals(5, table.getRowCount());
View Full Code Here

        assertNotNull(table.getCellByPosition(1, 1));
    }
   
    @Test
    public void test363() throws Exception {
        TextDocument document = TextDocument.newTextDocument();
        TableBuilder tableBuilder = document.getTableBuilder();
        Table docBuiltTable1 = tableBuilder.newTable(2, 5, 1, 5);
        assertNotNull(docBuiltTable1.getCellByPosition(1,1));
        Table docBuiltTable2 = tableBuilder.newTable(1, 5, 1, 5);
        docBuiltTable2.appendRow();
        assertNotNull(docBuiltTable2.getCellByPosition(1,1));
View Full Code Here

  }

  @Test
  public void testAddRemoveIterateList() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Table table = Table.newTable(doc, 3, 3);
      ListDecorator bulletDecorator = new BulletDecorator(doc);
      ListDecorator numberDecorator = new NumberDecorator(doc);
      ListDecorator imageDecorator = new ImageDecorator(doc, ResourceUtilities.getURI("image_list_item.png"));
      String[] numberItemContents = { "number item 1", "number item 2", "number item 3" };
View Full Code Here

  }

  @Test
  public void testGetSetImage() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Table table = Table.newTable(doc, 2, 2);
      table.setTableName("ImageTable");
      Cell cell = table.getCellByPosition(0, 0);
      cell.setImage(ResourceUtilities.getURI("image_list_item.png"));
      doc.save(ResourceUtilities.newTestOutputFile("ImageCellTable.odt"));

      // load the document again.
      doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("ImageCellTable.odt"));
      table = doc.getTableByName("ImageTable");
      cell = table.getCellByPosition(0, 0);
      // image height = 34 pixels.
      Assert.assertEquals(34, cell.getBufferedImage().getHeight(null));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

        { "three trailing spaces ", "*s2" }, { "one", "*t", "tab" }, { "two", "*t", "*t", "tabs" },
        { "*t", "leading tab" }, { "trailing tab", "*t" },
        { "mixed ", "*s2", "*t", " ", "*s2", "spaces and tabs" }, { "line", "*n", "break" } };
    try {
      // test append paragraph
      TextDocument doc = TextDocument.newTextDocument();
      Table table = Table.newTable(doc, 2, 2);
      Cell cell = table.getCellByPosition(0, 0);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
      }

      // test set paragraph content
      cell = table.getCellByPosition(0, 1);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
        String content = para.getTextContent();
        Assert.assertEquals(plainText[i], content);
      }

      // test remove paragraph content
      cell = table.getCellByPosition(1, 0);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        String content = para.getTextContent();
        Assert.assertEquals(plainText[i], content);
        para.removeTextContent();
        content = para.getTextContent();
        Assert.assertEquals("", content);
      }

      // test get paragraph by index
      cell = table.getCellByPosition(1, 1);
      Paragraph paragraph1 = cell.addParagraph("paragraph1");
      Paragraph paragraphE = cell.addParagraph(null);
      Paragraph paragraph2 = cell.addParagraph("p2");

      Paragraph t1 = cell.getParagraphByIndex(0, false);
      Assert.assertEquals(t1, paragraph1);
      t1 = cell.getParagraphByIndex(2, false);
      Assert.assertEquals(t1, paragraph2);
      t1 = cell.getParagraphByIndex(1, true);
      Assert.assertEquals(t1, paragraph2);
      t1 = cell.getParagraphByReverseIndex(0, false);
      Assert.assertEquals(t1, paragraph2);
      t1 = cell.getParagraphByReverseIndex(2, false);
      Assert.assertEquals(t1, paragraph1);
      t1 = cell.getParagraphByReverseIndex(1, true);
      Assert.assertEquals(t1, paragraph1);
      doc.save(ResourceUtilities.newTestOutputFile("testCellParagraph.odt"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

   */
  @Test
  public void testReplaceWith() {

    try {
      TextDocument doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));

      TextNavigation search = new TextNavigation("mnop", doc);

      int i = 0;
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        try {
          item.replaceWith("success");
          i++;
          // item.addHref(new URL("http://www.oracle.com"));
        } catch (InvalidNavigationException e) {
          Assert.fail(e.getMessage());
        }
      }
      Assert.assertTrue(18 == i);
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE));
    } catch (Exception e) {
      Logger.getLogger(MONPTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
  }
View Full Code Here

 
 
  @Test
  public void testGetTableBuilder() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Header header = doc.getHeader();
     
      TableBuilder tabBuilder = header.getTableBuilder();
      Table tab = tabBuilder.newTable();
      Assert.assertNotNull(tab);
      Assert.assertTrue(2 == tab.getRowCount());
      Assert.assertTrue(5 == tab.getColumnCount());
     
      //validate
      List<Table> listTab = header.getTableList();
      Table tab1 = listTab.get(0);
      Assert.assertNotNull(tab1);
      Assert.assertEquals(tab, tab1);

      //save
      doc.save(ResourceUtilities.newTestOutputFile("headerTableOutput.odt"));
    } catch (Exception e) {
      Logger.getLogger(HeaderTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

 
 
  @Test
  public void testGetVariableContainerElement() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Header header = doc.getHeader();
     
      OdfElement odfEle = header.getVariableContainerElement();
     
      TableBuilder tb = header.getTableBuilder();
      Table tab = tb.newTable();
     
      Assert.assertNotNull(tab);
      Assert.assertTrue(2 == tab.getRowCount());
      Assert.assertTrue(5 == tab.getColumnCount());
     
      Node nod = odfEle.getFirstChild();
      Assert.assertEquals("table:table", nod.getNodeName());

      //save
      doc.save(ResourceUtilities.newTestOutputFile("headerTableOutput.odt"));
    } catch (Exception e) {
      Logger.getLogger(HeaderTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

 
 
  @Test
  public void testDeclareVariable() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Header header = doc.getHeader();
     
      header.declareVariable("headername", VariableType.USER);
     
      //validate
      StyleHeaderElement styleHeader = header.getOdfElement();
      Node nod = styleHeader.getFirstChild().getFirstChild();
      NamedNodeMap nameMap = nod.getAttributes();
      Node nodtext = nameMap.getNamedItem("text:name");
      Assert.assertEquals("headername", nodtext.getNodeValue());

      //save
      doc.save(ResourceUtilities.newTestOutputFile("headerTableOutput.odt"));
    } catch (Exception e) {
      Logger.getLogger(HeaderTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.TextDocument$ListContainerImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.