Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.TextDocument


  @Test
  public void testGetIndex() {
    try {
      // load test list container, which contains 2 lists.
      TextDocument odtdoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(SAMPLE_LIST_DOCUMENT));
      Iterator<List> listIterator = odtdoc.getListIterator();
      if (listIterator.hasNext()) {
        List list = listIterator.next();
        java.util.List<ListItem> items = list.getItems();
        int i = 0;
        for (ListItem item : items) {
View Full Code Here


  @Test
  public void testAddRemoveIterateSubList() {
    try {
      // load test list container, which contains 2 lists.
      TextDocument odtdoc = (TextDocument) TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(SAMPLE_LIST_DOCUMENT));
      ListDecorator bulletDecorator = new BulletDecorator(odtdoc);
      ListDecorator numberDecorator = new NumberDecorator(odtdoc);
      ListDecorator imageDecorator = new ImageDecorator(odtdoc, ResourceUtilities.getURI("image_list_item.png"));
      Iterator<List> listIterator = odtdoc.getListIterator();

      if (listIterator.hasNext()) {
        List list = listIterator.next();
        // add list.
        ListContainer container = list.getItem(0);
View Full Code Here

  private static final String TEST_FILE = "CommentBreakHeadingDocument.odt";

  @Test
  public void testAppend() {
    TextDocument doc;
    try {
      doc = TextDocument.newTextDocument();
      int i;
      for (i = 0; i < PLAIN_TEXT.length; i++) {
        Paragraph para = Paragraph.newParagraph(doc);
View Full Code Here

    }
  }

  @Test
  public void testSetTextContent() {
    TextDocument doc;
    try {
      doc = TextDocument.newTextDocument();
      int i;
      for (i = 0; i < PLAIN_TEXT.length; i++) {
        Paragraph para = Paragraph.newParagraph(doc);
View Full Code Here

    }
  }

  @Test
  public void testRemoveContent() {
    TextDocument doc;
    try {
      doc = TextDocument.newTextDocument();
      int i;
      for (i = 0; i < PLAIN_TEXT.length; i++) {
        Paragraph para = Paragraph.newParagraph(doc);
View Full Code Here

  }

  @Test
  public void testGetParagraphByIndex() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");
      Paragraph paragraphE = doc.addParagraph(null);
      Paragraph paragraph2 = doc.addParagraph("p2");

      Paragraph t1 = doc.getParagraphByIndex(1, false);
      Assert.assertEquals(t1, paragraph1);
      t1 = doc.getParagraphByIndex(3, false);
      Assert.assertEquals(t1, paragraph2);
      t1 = doc.getParagraphByIndex(1, true);
      Assert.assertEquals(t1, paragraph2);
      t1 = doc.getParagraphByReverseIndex(0, false);
      Assert.assertEquals(t1, paragraph2);
      t1 = doc.getParagraphByReverseIndex(2, false);
      Assert.assertEquals(t1, paragraph1);
      t1 = doc.getParagraphByReverseIndex(1, true);
      Assert.assertEquals(t1, paragraph1);
      doc.save(ResourceUtilities.newTestOutputFile("testGetParagraphByIndex.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

  }

  @Test
  public void testSetGetFont() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      paragraph1.setFont(font1);
      Font font11 = paragraph1.getFont();
      LOGGER.info(font11.toString());
      if (!font11.equals(font1)) {
        Assert.fail();
      }

      Paragraph paragraph2 = doc.addParagraph("paragraph2");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      paragraph2.setFont(font2);
      Font font22 = paragraph2.getFont();
      LOGGER.info(font22.toString());
      if (!font22.equals(font2)) {
        Assert.fail();
      }

      Paragraph paragraph3 = doc.addParagraph("paragraph3");
      Font font3 = paragraph3.getFont();
      LOGGER.info(font3.toString());
      font3.setColor(Color.GREEN);
      font3.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
      paragraph3.setFont(font3);
      LOGGER.info(font3.toString());
      Font font33 = paragraph3.getFont();
      if (!font33.equals(font3)) {
        Assert.fail();
      }
      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetFont.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
    }
  }
View Full Code Here

  }

  @Test
  public void testGetSetHoriAlignment() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");

      paragraph1.setHorizontalAlignment(HorizontalAlignmentType.DEFAULT);
      HorizontalAlignmentType align = paragraph1.getHorizontalAlignment();
      Assert.assertEquals(HorizontalAlignmentType.DEFAULT, align);

      paragraph1.setHorizontalAlignment(HorizontalAlignmentType.LEFT);
      align = paragraph1.getHorizontalAlignment();
      Assert.assertEquals(HorizontalAlignmentType.LEFT, align);

      paragraph1.setHorizontalAlignment(HorizontalAlignmentType.RIGHT);
      align = paragraph1.getHorizontalAlignment();
      Assert.assertEquals(HorizontalAlignmentType.RIGHT, align);

      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHoriAlignment.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
    }
  }
View Full Code Here

  }

  @Test
  public void testGetSetHeading() {
    try {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));
      // test isHeading() and getHeadingLevel();
      Paragraph headingParagraph = doc.getParagraphByIndex(0, true);
      Assert.assertEquals(true, headingParagraph.isHeading());
      Assert.assertEquals(1, headingParagraph.getHeadingLevel());
      Paragraph textParagraph = doc.getParagraphByIndex(1, true);
      Assert.assertEquals(false, textParagraph.isHeading());
      Assert.assertEquals(0, textParagraph.getHeadingLevel());

      // test applyHeading()
      textParagraph.applyHeading();
      Assert.assertEquals(true, textParagraph.isHeading());
      Assert.assertEquals(1, textParagraph.getHeadingLevel());
      textParagraph.applyHeading(true, 3);
      Assert.assertEquals(true, textParagraph.isHeading());
      Assert.assertEquals(3, textParagraph.getHeadingLevel());

      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHeading.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
    }
  }
View Full Code Here

  }

  @Test
  public void testHyperlink() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph para = doc.addParagraph("abc");
      TextHyperlink link1 = para.applyHyperlink(new URI("http://odftoolkit.org"));
      Assert.assertEquals("http://odftoolkit.org", link1.getURI().toString());
      Assert.assertEquals("abc", link1.getTextContent());

      String text = para.getTextContent();
      Assert.assertEquals("abc", text);

      para.removeTextContent();
      text = para.getTextContent();
      Assert.assertEquals("", text);
      para.setTextContent("no hyperlink there ");
      para.appendHyperlink("link to ibm", new URI("http://www.ibm.com"));

      Paragraph heading = doc.addParagraph("Heading1");
      TextHyperlink link2 = heading.applyHyperlink(new URI("mailto:daisy@odftoolkit.org"));
      heading.applyHeading(true, 1);

      link2.setTextContent("New Heading1");
      link2.setURI(new URI("mailto:devin@odftoolkit.org"));
      Assert.assertEquals("mailto:devin@odftoolkit.org", link2.getURI().toString());

      Paragraph para3 = doc.addParagraph("world");
      TextHyperlink link3 = para3.applyHyperlink(new URI("http://odftoolkit.org"));
      link3.setTextContent("new world");
      para3.appendTextContent("_prefix");
      para3.appendTextContent("_nolink", false);

      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphHyperlink.odt"));

      TextDocument textdoc = TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestParagraphHyperlink.odt"));
      Iterator<TextHyperlink> linkList = textdoc.getParagraphByReverseIndex(1, true).getHyperlinkIterator();
      if (linkList.hasNext()) {
        TextHyperlink aLink = linkList.next();
        Assert.assertEquals("New Heading1", aLink.getTextContent());
        Assert.assertEquals("mailto:devin@odftoolkit.org", aLink.getURI().toString());
      }

      linkList = textdoc.getParagraphByReverseIndex(0, true).getHyperlinkIterator();
      if (linkList.hasNext()) {
        TextHyperlink aLink = linkList.next();
        Assert.assertEquals("new world_prefix", aLink.getTextContent());
        Assert.assertEquals("http://odftoolkit.org", aLink.getURI().toString());
      }
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.