Package org.odftoolkit.simple.text

Examples of org.odftoolkit.simple.text.Paragraph


  @Test
  public void testAddPageBreak() {
    try {
      // test new creation document.
      TextDocument newDoc = TextDocument.newTextDocument();
      Paragraph paragraph = newDoc.addParagraph("before page break");
      newDoc.addPageBreak();
      validPageBreakExist(newDoc, paragraph);
      Paragraph refParagraph = newDoc.addParagraph("after page break");
      newDoc.addParagraph("end page");
      newDoc.addPageBreak(refParagraph);
      validPageBreakExist(newDoc, refParagraph);
      newDoc.save(ResourceUtilities.newTestOutputFile("AddPageBreakOutput.odt"));
View Full Code Here


  public void testAddComment() {
    try {
      // test new creation document.
      TextDocument newDoc = TextDocument.newTextDocument();
     
      Paragraph paragraph = newDoc.addParagraph("Paragraph1");
      paragraph.addComment("This is a comment for Paragraph1", "Simple ODF");
      Node firstChildNode = paragraph.getOdfElement().getFirstChild();
      Assert.assertTrue(firstChildNode instanceof OfficeAnnotationElement);
      OfficeAnnotationElement comment = (OfficeAnnotationElement) firstChildNode;
      Assert.assertEquals("Simple ODF", comment.getFirstChild().getTextContent());
      Assert.assertEquals("This is a comment for Paragraph1", comment.getLastChild().getTextContent());
      Assert.assertTrue(firstChildNode instanceof OfficeAnnotationElement);
     
      paragraph = newDoc.addParagraph("Paragraph2");
      paragraph.addComment("This is a comment for Paragraph2", null);
      firstChildNode = paragraph.getOdfElement().getFirstChild();
      Assert.assertTrue(firstChildNode instanceof OfficeAnnotationElement);
      comment = (OfficeAnnotationElement) firstChildNode;
      Assert.assertEquals(System.getProperty("user.name"), comment.getFirstChild().getTextContent());
      Assert.assertEquals("This is a comment for Paragraph2", comment.getLastChild().getTextContent());
     
View Full Code Here

      String filePath = ResourceUtilities.getAbsolutePath("headerFooterHidden.odt");
      File file = new File(filePath);
      TextDocument tdoc = TextDocument.loadDocument(file);
      Assert.assertNotNull(tdoc);
     
      Paragraph para = tdoc.addParagraph("paragraph1");
      Assert.assertEquals("paragraph1", para.getTextContent());
      boolean flag = tdoc.removeParagraph(para);
      Document doc = para.getOwnerDocument();
      Assert.assertNotSame(doc, tdoc);
    } catch (Exception e) {
      LOG.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
View Full Code Here

      // 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);
View Full Code Here

   * @param text
   *            the text content of this paragraph
   * @return the new paragraph
   */
  public Paragraph addParagraph(String text) {
    Paragraph para = getParagraphContainerImpl().addParagraph(text);
    return para;
  }
View Full Code Here

   * @throws Exception
   *             if the file DOM could not be created.
   * @since 0.5.5
   */
  public Paragraph addParagraph(String text) {
    Paragraph para = getParagraphContainerImpl().addParagraph(text);
    return para;
  }
View Full Code Here

   * @throws Exception
   *             if the file DOM could not be created.
   * @since 0.5.5
   */
  public Paragraph addParagraph(String text) {
    Paragraph para = getParagraphContainerImpl().addParagraph(text);
    return para;
  }
View Full Code Here

  public void testCellReplacementWithParagraph() throws Exception {
    replace(new ReplacementAction() {

      public void replace(TextSelection selection, String value) throws Exception {
        TextParagraphElementBase paragraphElement = new TextPElement(doc.getContentDom());
        Paragraph para = Paragraph.getInstanceof(paragraphElement);
        para.setTextContent(value);
        selection.replaceWith(para);
      }
    });
   
  }
View Full Code Here

          paraStyle = oddCellParagraphStyle;
        }
        cell.setCellStyleName(tableStyle);
        Iterator<Paragraph> paraIterator = cell.getParagraphIterator();
        while (paraIterator.hasNext()) {
          Paragraph t = paraIterator.next();
          t.getOdfElement().setStyleName(paraStyle);
        }
        cellIndex++;
      }
    }
  }
View Full Code Here

      // 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);
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.text.Paragraph

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.