Package org.odftoolkit.simple.common.navigation

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


  }
  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

  }
  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

  }
  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

   *            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

    }
    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

    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

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.