Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.TextDocument


    }
  }
       
  @Test
  public void testGetTextContentWithLibreOfficeFile() throws FileNotFoundException, Exception {
    TextDocument document = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("Bell.odt"));
    Paragraph paragraph = document.getParagraphByIndex(0, true);

    Assert.assertEquals(
      "Bell, based in Los Angeles, makes and distributes electronic articles, "
      + "computer and building products.",
      paragraph.getTextContent());
View Full Code Here


  }
       
  @Test
  public void shouldReturnMultipleLines() throws Exception {
    final String expected = "Hello\tWorld!\twho \t ever read this, is stupid.\n\n\nReally!";
    TextDocument document = TextDocument.newTextDocument();
    Paragraph p = document.addParagraph(expected);
    String textContent = p.getTextContent();
    Assert.assertEquals(expected, textContent.replace("\r", ""));
  }
View Full Code Here

   
  }
 

  private void replace(ReplacementAction replacementAction) throws Exception {
    TextDocument docToReplaceIn = TextDocument.newTextDocument();
    Table newTable = docToReplaceIn.getTableBuilder().newTable(2, 2);
    Cell cell = newTable.getCellByPosition(0, 0);
    cell.addParagraph("<<ONE>>");
    cell.addParagraph("<<TWO>>");

    Map<String, String> replacements = new TreeMap<String, String>();
View Full Code Here

    }
  }

  private TextDocument loadODTDocument(String name) {
    try {
      TextDocument odtdoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(name));
      return odtdoc;
    } catch (Exception e) {
      Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
View Full Code Here

  }

  @Test
  public void testNewTable() {
    try {
      TextDocument document = TextDocument.newTextDocument();
      document.newParagraph("Empty table:");
      createEmptyTable(document);

      document.newParagraph();
      document.newParagraph("Table with float values:");
      createTableWithData(document);
      document.newParagraph();
      document.newParagraph("Table with string values:");
      createTableWithString(document);

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

  @Test
  public void testSetGetWidth() {
    long width = 500;
    try {
      TextDocument document = TextDocument.newTextDocument();
      document.newParagraph("Empty table:");
      Table table = createEmptyTable(document);
      table.setWidth(width);
      Assert.assertTrue(Math.abs(width - table.getWidth()) < 3);

      document.save(ResourceUtilities.newTestOutputFile("TestSetGetWidth.odt"));

    } catch (Exception e) {
      Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
View Full Code Here

  }

  @Test
  public void testGetSetTablename() {
    String tablename = "My Table";
    TextDocument document = null;
    try {
      document = TextDocument.newTextDocument();
      document.newParagraph("Empty table:");
      Table table = createEmptyTable(document);
      table.setTableName(tablename);
      Assert.assertEquals(tablename, table.getTableName());

      document.save(ResourceUtilities.newTestOutputFile("TestGetSetName.odt"));
      document.close();
      document = loadODTDocument("TestGetSetName.odt");
      table = document.getTableByName(tablename);
      Assert.assertNotNull(table);
      String tablename2 = table.getTableName();
      Assert.assertEquals(tablename, tablename2);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }

    try {
      // new another table with the same name
      // an exception will be thrown
      Table table2 = Table.newTable(document);
      table2.setTableName(tablename);
      document.save(ResourceUtilities.newTestOutputFile("TestGetSetName.odt"));
      Assert.fail("should not save the tables with the same table name.");
    } catch (Exception e) {
      if (!e.getMessage().startsWith("The table name is duplicate")) {
        Assert.fail(e.getMessage());
      }
View Full Code Here

  @Test
  public void testGetColumnList() {
    String tablename = "MyTable";
    String testFileName = "TestGetColumnList.odt";
    try {
      TextDocument document = TextDocument.newTextDocument();

      int rowcount = 3, columncount = 3;
      String[][] data = new String[rowcount][columncount];
      for (int i = 0; i < rowcount; i++) {
        for (int j = 0; j < columncount; j++) {
          data[i][j] = "string" + (i * columncount + j);
        }
      }

      String[] rowlabels = new String[rowcount];
      for (int i = 0; i < rowcount; i++) {
        rowlabels[i] = "RowHeader" + i;
      }

      String[] columnlabels = new String[columncount];
      for (int i = 0; i < columncount; i++) {
        columnlabels[i] = "ColumnHeader" + i;
      }

      Table table3 = Table.newTable(document, rowlabels, columnlabels, data);
      table3.setTableName(tablename);

      document.save(ResourceUtilities.newTestOutputFile(testFileName));
      document = loadODTDocument(testFileName);
      Table table = document.getTableByName(tablename);
      Column tmpColumn;
      List<Column> columns = table.getColumnList();

      // the code below prints the column value,it shows that the first
      // columns value is the same with the last column
View Full Code Here

  @Test
  public void testGetRowList() {
    String tablename = "MyTable";
    String testFileName = "TestGetRowList.odt";
    try {
      TextDocument document = TextDocument.newTextDocument();

      int rowcount = 3, columncount = 3;
      String[][] data = new String[rowcount][columncount];
      for (int i = 0; i < rowcount; i++) {
        for (int j = 0; j < columncount; j++) {
          data[i][j] = "string" + (i * columncount + j);
        }
      }

      String[] rowlabels = new String[rowcount];
      for (int i = 0; i < rowcount; i++) {
        rowlabels[i] = "RowHeader" + i;
      }

      String[] columnlabels = new String[columncount];
      for (int i = 0; i < columncount; i++) {
        columnlabels[i] = "ColumnHeader" + i;
      }

      Table table3 = Table.newTable(document, rowlabels, columnlabels, data);
      table3.setTableName(tablename);

      document.save(ResourceUtilities.newTestOutputFile(testFileName));
      document = loadODTDocument(testFileName);
      Table table = document.getTableByName(tablename);
      Row tmpRow;
      List<Row> rows = table.getRowList();
      for (int i = 1; i < rows.size(); i++) {
        tmpRow = rows.get(i);
        // each row's first cell is the row header
View Full Code Here

        mOdsTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdsTable);
      }
      odsDoc.save(ResourceUtilities.newTestOutputFile("TestODSAppendRowOutput.ods"));

      TextDocument odtDoc = TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODTAppendRow.odt"));
      dom = odtDoc.getContentDom();
      tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdtTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdtTable);
      }
      odtDoc.save(ResourceUtilities.newTestOutputFile("TestODTAppendRowOutput.odt"));

    } catch (Exception e) {
      Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.TextDocument

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.