Package org.odftoolkit.simple.common.navigation

Examples of org.odftoolkit.simple.common.navigation.TextNavigation


  @Test
  public void testSpan() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      doc.addParagraph("This is a test paragraph!");
      TextNavigation navigation = new TextNavigation("test", doc);
      TextSelection sel = (TextSelection) navigation.nextSelection();
      Span span = Span.newSpan(sel);
      TextHyperlink link = span.applyHyperlink(new URI("http://www.ibm.com"));
      DefaultStyleHandler handler = span.getStyleHandler();
      Font font1Base = new Font("Arial", FontStyle.ITALIC, 10, Color.BLACK, TextLinePosition.THROUGH);
      handler.getTextPropertiesForWrite().setFont(font1Base);
View Full Code Here


        doc.removeParagraph(pp);
      }
     
      doc.addParagraph("This is a test paragraph!");
     
      TextNavigation navigation = new TextNavigation("test", doc);
      TextSelection sel = (TextSelection) navigation.nextSelection();
      Span span = Span.newSpan(sel);
     
      span.removeTextContent();
      boolean flag = false;
      Iterator<Paragraph> parai = doc.getParagraphIterator();
View Full Code Here

  public void testAppendTextContent() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      doc.addParagraph("This is a test paragraph!");
     
      TextNavigation navigation = new TextNavigation("test", doc);
      TextSelection sel = (TextSelection) navigation.nextSelection();
      Span span = Span.newSpan(sel);
     
      span.appendTextContent("hello world.");
      Assert.assertEquals("testhello world.", span.getTextContent());
View Full Code Here

  public void testAppendTextContentPara() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      doc.addParagraph("This is a test paragraph!");
     
      TextNavigation navigation = new TextNavigation("test", doc);
      TextSelection sel = (TextSelection) navigation.nextSelection();
      Span span = Span.newSpan(sel);
     
      span.appendTextContent("hello world.", true);
      Assert.assertEquals("testhello world.", span.getTextContent());
     
View Full Code Here

  }

  @Test
  public void testGetInstance() {
    //get the text content contains "cell"
    TextNavigation search = new TextNavigation("cell", odtdoc);
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      OdfElement containerEle = item.getContainerElement();
      if (containerEle instanceof OdfTextParagraph) {
        Node ele = containerEle.getParentNode();
        if (ele instanceof TableTableCellElement) {
          Cell cell = Cell.getInstance((TableTableCellElementBase) ele);
View Full Code Here

  }

  @Test
  public void testHasNext() {
    search = null;
    search = new TextNavigation("range", doc);

    Assert.assertTrue(search.hasNext());
    Assert.assertTrue(search.hasNext());
    Assert.assertTrue(search.hasNext());
    Assert.assertTrue(search.hasNext());
View Full Code Here

   * 'change' word in the front of all the 'delete' word
   */
  @Test
  public void testPasteAtFrontOf() {
    search = null;
    search = new TextNavigation("delete", doc);
    TextSelection sel = null;

    TextNavigation search1 = new TextNavigation("change", doc);
    sel = (TextSelection) search1.nextSelection();

    int i = 0;
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      i++;
      try {
        sel.pasteAtFrontOf(item);
      } catch (InvalidNavigationException e) {
        Assert.fail(e.getMessage());
      }
    }

    int j = 0;
    search = new TextNavigation("changedelete", doc);
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
    Assert.assertTrue(i == j);
View Full Code Here

   * 'change' word at the end of all the 'delete' word
   */
  @Test
  public void testPasteAtEndOf() {
    search = null;
    search = new TextNavigation("delete", doc);
    TextSelection sel = null;

    TextNavigation search1 = new TextNavigation("change", doc);
    sel = (TextSelection) search1.nextSelection();

    int i = 0;
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      i++;
      try {
        sel.pasteAtEndOf(item);
      } catch (InvalidNavigationException e) {
        Assert.fail(e.getMessage());
      }
    }
    int j = 0;
    search = new TextNavigation("deletechange", doc);
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
    Assert.assertTrue(i == j);
View Full Code Here

   * style
   */
  @Test
  public void testApplyStyle() {
    search = null;
    search = new TextNavigation("delete", doc);
    OdfOfficeAutomaticStyles autoStyles = null;
    try {
      autoStyles = doc.getContentDom().getAutomaticStyles();
    } catch (Exception e1) {
      Assert.fail("Failed with " + e1.getClass().getName() + ": '" + e1.getMessage() + "'");
View Full Code Here

   * 'SIMPLE' with 'Odf Toolkit'
   */
  @Test
  public void testReplacewith() {
    search = null;
    search = new TextNavigation("SIMPLE", doc);

    TextSelection nextSelect = null;
    TextNavigation nextsearch = new TextNavigation("next", doc);
    nextSelect = (TextSelection) nextsearch.nextSelection();

    // replace all the "SIMPLE" to "Odf Toolkit"
    // except the sentence
    // "Task5.Change the SIMPLE to Odf Toolkit, and bold them."
    OdfStyle style = new OdfStyle(contentDOM);
    style.setProperty(StyleTextPropertiesElement.FontWeight, "bold");
    style.setStyleFamilyAttribute("text");
    int i = 0;
    while (search.hasNext()) {
      if (i > 0) {
        TextSelection item = (TextSelection) search.nextSelection();
        try {
          item.replaceWith("Odf Toolkit");
          item.applyStyle(style);
        } catch (InvalidNavigationException e) {
          Assert.fail(e.getMessage());
        }
      }
      i++;
    }

    search = new TextNavigation("Odf Toolkit", doc);
    int j = 0;
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.common.navigation.TextNavigation

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.