Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.TextDocument$FormContainerImpl


  }

  @Test
  public void testRemoveSection() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("Section11");
      Assert.assertNull(theSec);
      Iterator<Section> sections = doc.getSectionIterator();
      int count = 0;
      while (sections.hasNext()) {
        sections.next();
        count++;
      }

      theSec = doc.getSectionByName("Section1");
      theSec.remove();
      sections = doc.getSectionIterator();
      int i = 0;
      while (sections.hasNext()) {
        sections.next();
        i++;
      }
      Assert.assertEquals(count - 1, i);

      theSec = doc.getSectionByName("ImageSection");
      theSec.remove();
      OdfPackage packageDocument = doc.getPackage();
      String imagePathPrefix = "Pictures/";
      count = 0;
      Iterator<String> filePaths = packageDocument.getFilePaths().iterator();
      while (filePaths.hasNext()) {
        String path = filePaths.next();
View Full Code Here


  }

  @Test
  public void testSetGetName() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("ImageSection");
      theSec.setName("ImageSection_NewName");
      doc.save(ResourceUtilities.newTestOutputFile("NewSection.odt"));

      TextDocument newDoc = TextDocument
          .loadDocument(ResourceUtilities.getTestResourceAsStream("NewSection.odt"));
      theSec = newDoc.getSectionByName("ImageSection");
      Assert.assertNull(theSec);
      theSec = newDoc.getSectionByName("ImageSection_NewName");
      Assert.assertNotNull(theSec);
      Assert.assertEquals("ImageSection_NewName", theSec.getName());
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
View Full Code Here

  }
 
  @Test
  public void testAddParagraph() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("ImageSection");
     
      Paragraph para = theSec.addParagraph("paragraph");
      String paracontent = para.getTextContent();
      Assert.assertEquals("paragraph", paracontent);
     
View Full Code Here

 
 
  @Test
  public void testGetParagraphIterator() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("ImageSection");
     
      Paragraph para = theSec.addParagraph("paragraph");
      String paracontent = para.getTextContent();
      Assert.assertEquals("paragraph", paracontent);
     
View Full Code Here

 
 
  @Test
  public void testGetParagraphByIndex() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("ImageSection");
     
      Paragraph para = theSec.addParagraph("paragraph");
      String paracontent = para.getTextContent();
      Assert.assertEquals("paragraph", paracontent);
     
View Full Code Here

 
 
  @Test
  public void testGetParagraphByReverseIndex() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section theSec = doc.getSectionByName("ImageSection");
      Section theSec2 = doc.getSectionByName("ImageSection");
     
      Paragraph para = theSec.addParagraph("paragraph");
      String paracontent = para.getTextContent();
      Assert.assertEquals("paragraph", paracontent);
     
View Full Code Here

    cellRange.merge();
    Cell cell = cellRange.getCellByPosition(0, 0);
    saveodt("MergeTwoCell");
    Assert.assertEquals(cell.getDisplayText(), "cell1\rcell2");
    try {
      TextDocument saveddoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(odtfilename + "MergeTwoCell.odt"));
      Table savedTable1 = saveddoc.getTableByName("Table1");
      // get the cell range which the first cell is the covered cell.
      // so the cell range will be enlarged
      CellRange savedCellRange = savedTable1.getCellRangeByPosition(1, 0, 2, 0);
      savedCellRange.merge();
      Assert.assertTrue(savedCellRange.getColumnNumber() == 3);
      Cell savedCell = savedCellRange.getCellByPosition(0, 0);
      NodeList paraList = savedCell.getOdfElement().getChildNodes();
      Assert.assertTrue(paraList.item(2) instanceof OdfTextParagraph);
      Assert.assertEquals(TextExtractor.getText((OdfTextParagraph) paraList.item(2)), "0.00");
      saveddoc.save(ResourceUtilities.newTestOutputFile(odtfilename + "MergeCoveredCell.odt"));
    } catch (Exception e) {
      Logger.getLogger(TableCellRangeTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }

    try {
      TextDocument saveddoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(odtfilename + "MergeTwoCell.odt"));
      Table savedTable1 = saveddoc.getTableByName("Table1");
      // get the cell range which the first cell is the covered cell.
      // so the cell range will be enlarged
      CellRange savedCellRange = savedTable1.getCellRangeByPosition(0, 0, 0, 1);
      savedCellRange.merge();
      Assert.assertTrue(savedCellRange.getColumnNumber() == 2);
      Assert.assertTrue(savedCellRange.getRowNumber() == 2);
      Cell savedCell = savedCellRange.getCellByPosition(0, 1);
      Assert.assertTrue(savedCell.getOdfElement() instanceof TableCoveredTableCellElement);
      saveddoc.save(ResourceUtilities.newTestOutputFile(odtfilename + "MergeCoveredCell2.odt"));
    } catch (Exception e) {
      Logger.getLogger(TableCellRangeTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
  }
View Full Code Here

    Cell cell = firstColumn.getCellByPosition(0, 2);
    Cell firstCell = firstColumn.getCellByPosition(0, 0);
    Assert.assertTrue(cell.getOwnerTableCell().equals(firstCell));
    saveodt("MergeFirstColumn");
    try {
      TextDocument saveddoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(odtfilename + "MergeFirstColumn.odt"));
      Table savedTable = saveddoc.getTableByName("Table1");
      CellRange firstTwoColumn = savedTable.getCellRangeByPosition(0, 0, 1, savedTable.getRowCount() - 1);
      firstTwoColumn.merge();
      Cell cell1 = firstTwoColumn.getCellByPosition(0, 2);
      Cell firstCell1 = firstTwoColumn.getCellByPosition(0, 0);
      Assert.assertTrue(cell1.getOwnerTableCell().equals(firstCell1));
      saveddoc.save(ResourceUtilities.newTestOutputFile(odtfilename + "MergeFirstTwoColumn.odt"));
    } catch (Exception e) {
      Logger.getLogger(TableCellRangeTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
  }
View Full Code Here

      Assert.assertTrue(table.getColumnCount() == 5);
      Assert.assertTrue(table.getRowCount() == 1);
      table = ods.getTableByName("Sheet2");
      Assert.assertTrue(table.getColumnCount() == 6);
      Assert.assertTrue(table.getRowCount() == 3);
      TextDocument odt = TextDocument.newTextDocument();
      Table swTable = Table.newTable(odt, 1, 5);
      CellRange swCellRange = swTable.getCellRangeByPosition("A1", "E2");
      Cell swCell = swTable.getCellByPosition("E2");
      swCell.setStringValue("Merge A1:E2");
      swCellRange.merge();
      odt.save(ResourceUtilities.newTestOutputFile(odtfilename + "MergeTextExpandCell.odt"));
      swTable = odt.getTableList().get(0);
      Assert.assertTrue(swTable.getColumnCount() == 1);
      Assert.assertTrue(swTable.getRowCount() == 1);
    } catch (Exception ex) {
      Logger.getLogger(TableCellRangeTest.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
View Full Code Here

  String headerDocumentPath = "HeaderTableDocument.odt";

  @Test
  public void testAddTable() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Header header = doc.getHeader();
      Assert.assertNotNull(header);

      Table table = header.addTable();
      table.setTableName("headerTable");
      int rowCount = table.getRowCount();
      int columnCount = table.getColumnCount();
      String expectedCellValue = "header table cell";
      table.getCellByPosition(1, 1).setStringValue(expectedCellValue);
      Cell cell = table.getCellByPosition(4, 0);
      cell.setImage(ResourceUtilities.getURI("image_list_item.png"));
      // first page
      header = doc.getHeader(true);
      Assert.assertNotNull(header);

      table = header.addTable();
      table.setTableName("headerHTable");
      doc.save(ResourceUtilities.newTestOutputFile(headerDocumentPath));
     
      // load the document again.
      doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream(headerDocumentPath));
      header = doc.getHeader();
      table = header.getTableByName("headerTable");
      Assert.assertEquals(rowCount, table.getRowCount());
      Assert.assertEquals(columnCount, table.getColumnCount());
      Assert.assertEquals(expectedCellValue, table.getCellByPosition(1, 1).getStringValue());
      cell = table.getCellByPosition(4, 0);
      Assert.assertEquals(34, cell.getBufferedImage().getHeight(null));
      table.getColumnByIndex(4).setWidth(15);
     
      header = doc.getHeader(true);
      table = header.getTableByName("headerHTable");
      Assert.assertNotNull(table);
    } 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$FormContainerImpl

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.