Package org.odftoolkit.simple.common.navigation

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


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


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

    // T4 is the bold style for text
    OdfStyleBase style = autoStyles.getStyle("T4", OdfStyleFamily.Text);
    Assert.assertNotNull(style);

    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      try {
        item.applyStyle(style);
      } catch (InvalidNavigationException e) {
        Assert.fail(e.getMessage());
      }
    }
View Full Code Here

  @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++;
View Full Code Here

    try {
      TextDocument textDoc = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_COMMENT_FILE));
      search = new TextNavigation("simpleODF", textDoc);
      int i=0;
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        item.addComment("simpleODF should be replaced by Simple ODF.", "devin-"+i);
        i++;
      }
      // there are 7 simpleODF in this test document.
      Assert.assertEquals(7, i);
      textDoc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_COMMENT));
View Full Code Here

  @Test
  public void testAddHref() {
    search = null;
    search = new TextNavigation("^delete", doc);
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      try {
        item.addHref(new URL("http://www.ibm.com"));
      } catch (InvalidNavigationException e) {
        Assert.fail(e.getMessage());
      } catch (MalformedURLException e) {
        Assert.fail(e.getMessage());
        Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
View Full Code Here

  @Test
  public void testCutPattern() {
    search = new TextNavigation("<%([^>]*)%>", doc);

    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      try {
        String text = item.getText();
        text = text.substring(2, text.length() - 2);
        item.replaceWith(text);
      } catch (InvalidNavigationException e) {
        Assert.fail(e.getMessage());
      }
    }

View Full Code Here

   */
  @Test
  public void testTextSelectionContainerElement() {
    search = new TextNavigation("TextSelectionContainer", doc);
    if (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      OdfElement container = item.getContainerElement();
      Node childNode = container.getFirstChild();
      while (childNode != null) {
        String containerText = childNode.getTextContent();
        Assert.assertFalse(container.getTextContent().equals(containerText));
        childNode = childNode.getNextSibling();
      }
    } else {
      Assert.fail("Navigation search nothing.");
    }
    // test selected table cell content in draw:frame.
    search = new TextNavigation("Task", doc);
    if (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      OdfElement container = item.getContainerElement();
      Node childNode = container.getFirstChild();
      while (childNode != null) {
        String containerText = childNode.getTextContent();
        Assert.assertFalse(container.getTextContent().equals(containerText));
        childNode = childNode.getNextSibling();
View Full Code Here

 
  @Test
  public void testGetContainerElement() throws Exception {
    search = new TextNavigation("TextSelectionContainer", doc);
    if (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      URL url = new URL("http://www.IBM.com");
      item.addHref(url);
     
      //save
      //doc.save(ResourceUtilities.getAbsolutePath(TEXT_FILE));
     
      //validate
      OdfElement parentElement = item.getContainerElement();
      Node node = parentElement.getFirstChild().getFirstChild().getNextSibling();
      TextAElement textAele = (TextAElement)node;
      System.out.println(textAele.getXlinkTypeAttribute());
      System.out.println(textAele.getXlinkHrefAttribute());
      Assert.assertEquals("simple", textAele.getXlinkTypeAttribute());
View Full Code Here

      if (textSearch != null) {
        textSearch.setReplacedItem(this.textSelection);
        OdfElement containerElement = paragraphContainer
            .getOdfElement();
        String content = TextExtractor.getText(containerElement);
        TextSelection selected = TextSelection.newTextSelection(
            textSearch, this.textSelection.getText(),
            containerElement, content.length() - 1);
        textSearch.setSelectedItem(selected);
      }
    }
View Full Code Here

TOP

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

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.