Examples of TextNavigation


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

    // currtenItem with TextDocument, TextNavigation.nextSelection will
    // search from the inserted Content,
    // it will make you into a loop if the Search keyword also can be found
    // in the inserted Content.
    int i = 0;
    search = new TextNavigation("SIMPLE", doc);
    TextSelection currtenTextSelection, nextTextSelection = null;
    while (search.hasNext()) {
      if (nextTextSelection != null) {
        currtenTextSelection = nextTextSelection;
      } else {
        currtenTextSelection = (TextSelection) search.nextSelection();
      }
      nextTextSelection = (TextSelection) search.nextSelection();
      if (currtenTextSelection != null) {
       
        try {
          currtenTextSelection.replaceWith(sourcedoc);
          i++;
        } catch (Exception e) {
          e.printStackTrace();
          Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
        }
      }
    }
    if (nextTextSelection != null) {
      try {
        nextTextSelection.replaceWith(sourcedoc);
        i++;
      } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
      }
    }
    search = new TextNavigation("Hello1 from SIMPLE source document!", doc);
    int j = 0;
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
View Full Code Here

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

  }
  private void verifyReplaceWithTableByBasicCases(String fileName) {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities
          .getAbsolutePath(fileName));
      search = new TextNavigation("#1", doc);
      while (search.hasNext()) {
        OdfElement description = search.nextSelection().getElement();
        OdfElement replacement = (OdfElement) description
            .getNextSibling();
        Assert.assertNotNull(replacement);
        Assert.assertTrue(replacement instanceof TableTableElement);
      }
      search = new TextNavigation("#2", doc);
      while (search.hasNext()) {
        OdfElement description = search.nextSelection().getElement();
        String contents;
        do {
          OdfElement replacement = (OdfElement) description
              .getNextSibling();
          Assert.assertNotNull(replacement);
          contents = TextExtractor.getText(replacement);
          if (contents.contains("<<target>>")) {
            Assert.fail();
          }
        } while (contents.startsWith("#"));
      }
      search = new TextNavigation("#3", doc);
      OdfElement description = search.nextSelection().getElement();
      Node replacement = description.getNextSibling();
      Assert.assertTrue(replacement instanceof TableTableElement);
      Table table = Table.getInstance((TableTableElement) replacement);
      String breakBefore = table.getStyleHandler()
View Full Code Here

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

  }
  private void verifyReplaceWithImageByBasicCases(String fileName) {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities
          .getAbsolutePath(fileName));
      search = new TextNavigation("#2", doc);
      while (search.hasNext()) {
        OdfElement description = search.nextSelection().getElement();
        Node replacement = description.getNextSibling();
        NodeList children = replacement.getChildNodes();
        Assert.assertNotNull(children);
View Full Code Here

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

  }
  private void verifyReplaceWithParagraphByBasicCases(String fileName) {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities
          .getAbsolutePath(fileName));
      search = new TextNavigation("#1", doc);
      while (search.hasNext()) {
        OdfElement description = search.nextSelection().getElement();
        OdfElement replacement = (OdfElement) description
            .getNextSibling();
        Assert.assertNotNull(replacement);
        Assert.assertEquals("Hello2 from source document!",
            TextExtractor.getText(replacement));
      }
      search = new TextNavigation("#2", doc);
      while (search.hasNext()) {
        OdfElement description = search.nextSelection().getElement();
        String contents;
        do {
          OdfElement replacement = (OdfElement) description
              .getNextSibling();
          Assert.assertNotNull(replacement);
          contents = TextExtractor.getText(replacement);
          if (contents.contains("<<target>>")) {
            Assert.fail();
          }
        } while (contents.startsWith("#"));
      }
      search = new TextNavigation("#3", doc);
      OdfElement description = search.nextSelection().getElement();
      TextParagraphElementBase replacement = (TextParagraphElementBase) description
          .getNextSibling();
      Assert.assertEquals("Hello2 from source document!",
          TextExtractor.getText(replacement));
View Full Code Here

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

  }
  private void verifyReplaceWithTextDocumentByBasicCases(String fileName) {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities
          .getAbsolutePath(fileName));
      search = new TextNavigation("This is the first paragraph", doc);
      Assert.assertNotNull(search.hasNext());
      TextParagraphElementBase pElement = (TextParagraphElementBase) search
          .nextSelection().getElement();
      Node nextPElement = pElement.getNextSibling();
      Assert.assertTrue(nextPElement instanceof TextParagraphElementBase);
View Full Code Here

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

   *            the reference paragraph to replace.
   */
  public Paragraph replaceWithParagraph(Paragraph paragraph) {
    this.sourceParagraph=paragraph;
    if (search instanceof TextNavigation) {
      TextNavigation textSearch = (TextNavigation) search;
    int leftLength = textSelection.getText().length();
    int index = textSelection.getIndex();
      boolean continued = false;
      if (textSearch != null
          && textSearch.getReplacedItem() != null
          && textSearch.getReplacedItem().getElement() == this.textSelection
              .getElement()) {
        continued = true;
      } else {
        textSearch.setHandlePageBreak(false);
      }
      prepareParagraphContainer(leftLength, index, continued);
      Selection.SelectionManager.unregisterItem(this.textSelection);
      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);
      }
    }
    return paragraphContainer;
  }
View Full Code Here

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

    }
    if (handleBreak && !posInPara.equals("whole"))
      cleanBreakProperty(origParagraph);
  }
  private void cleanBreakProperty(Paragraph paragraph) {
    TextNavigation search = this.textSelection.getTextNavigation();
    if (search == null)
      throw new IllegalStateException("Navigation is null");
    OdfStyleBase styleElement = paragraph.getStyleHandler()
        .getStyleElementForRead();
    String name = styleElement.getAttribute("style:name");
    String newName = null;
    OdfElement modifiedStyleElement = search
        .getModifiedStyleElement(styleElement);
    if (modifiedStyleElement == null) {
      modifiedStyleElement = (OdfElement) styleElement.cloneNode(true);
      search.addModifiedStyleElement(styleElement, modifiedStyleElement);
      NodeList paragraphProperties = modifiedStyleElement
          .getElementsByTagName("style:paragraph-properties");
      if (paragraphProperties != null
          && paragraphProperties.getLength() > 0) {
        StyleParagraphPropertiesElement property = (StyleParagraphPropertiesElement) paragraphProperties
View Full Code Here

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

    this.sourceTable=table;
    if (search instanceof TextNavigation) {
    int leftLength = textSelection.getText().length();
    int index = textSelection.getIndex();
      boolean continued = false;
      TextNavigation textSearch = (TextNavigation) search;
      if (textSearch != null
          && textSearch.getReplacedItem() != null
          && textSearch.getReplacedItem().getElement() == this.textSelection
              .getElement()) {
        continued = true;
      } else {
        textSearch.setHandlePageBreak(false);
      }
      preparetableContainer(leftLength, index, continued);
      Selection.SelectionManager.unregisterItem(this.textSelection);
      if (textSearch != null) {
        textSearch.setReplacedItem(this.textSelection);
        Paragraph lastParagraph = getLastParagraphInTable(tableContainer);
        OdfElement newStartPoint;
        if (lastParagraph != null) {
          newStartPoint = lastParagraph.getOdfElement();
        } else {
          newStartPoint = tableContainer.getOdfElement();
        }
        String content = TextExtractor.getText(newStartPoint);
        TextSelection selected = newTextSelection(textSearch,
            this.textSelection.getText(), newStartPoint,
            content.length() - 1);
        textSearch.setSelectedItem(selected);
      }
    }
    return tableContainer;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.