Package org.outerj.daisy.diff.html.dom.helper

Examples of org.outerj.daisy.diff.html.dom.helper.LastCommonParentResult


    Node nextLeaf = null;
    if (before < getRangeCount())
      nextLeaf = getTextNode(before);

    while (deletedNodes.size() > 0) {
      LastCommonParentResult prevResult, nextResult;
      if (prevLeaf != null) {
        prevResult = prevLeaf.getLastCommonParent(deletedNodes.get(0));
      } else {
        prevResult = new LastCommonParentResult();
        prevResult.setLastCommonParent(getBodyNode());
        prevResult.setIndexInLastCommonParent(-1);
      }
      if (nextLeaf != null) {
        nextResult = nextLeaf.getLastCommonParent(deletedNodes
            .get(deletedNodes.size() - 1));
      } else {
        nextResult = new LastCommonParentResult();
        nextResult.setLastCommonParent(getBodyNode());
        nextResult.setIndexInLastCommonParent(getBodyNode()
            .getNbChildren());
      }

      if (prevResult.getLastCommonParentDepth() == nextResult
          .getLastCommonParentDepth()) {
        // We need some metric to choose which way to add...
        if (deletedNodes.get(0).getParent() == deletedNodes.get(
            deletedNodes.size() - 1).getParent()
            && prevResult.getLastCommonParent() == nextResult
                .getLastCommonParent()) {
          // The difference is not in the parent
          prevResult.setLastCommonParentDepth(prevResult
              .getLastCommonParentDepth() + 1);

        } else {
          // The difference is in the parent, so compare them
          // now THIS is tricky
          double distancePrev = deletedNodes.get(0).getParent()
              .getMatchRatio(prevResult.getLastCommonParent());
          double distanceNext = deletedNodes.get(
              deletedNodes.size() - 1).getParent().getMatchRatio(
              nextResult.getLastCommonParent());

          if (distancePrev <= distanceNext) {
            // insert after the previous node
            prevResult.setLastCommonParentDepth(prevResult
                .getLastCommonParentDepth() + 1);
          } else {
            // insert before the next node
            nextResult.setLastCommonParentDepth(nextResult
                .getLastCommonParentDepth() + 1);
          }
        }

      }

      if (prevResult.getLastCommonParentDepth() > nextResult
          .getLastCommonParentDepth()) {
     
        // Inserting at the front
        if(inlineResult) {
          if (prevResult.isSplittingNeeded()) {
            prevLeaf.getParent().splitUntill(
            prevResult.getLastCommonParent(), prevLeaf, true);
          }
          prevLeaf = deletedNodes.remove(0).copyTree();
          prevLeaf.setParent(prevResult.getLastCommonParent());
          prevResult.getLastCommonParent().addChild(
            prevResult.getIndexInLastCommonParent() + 1,
            prevLeaf);
        } else {
          deletedNodes.remove(0);
        }

      } else if (prevResult.getLastCommonParentDepth() < nextResult
          .getLastCommonParentDepth()) {
        // Inserting at the back
        if (nextResult.isSplittingNeeded()) {
          boolean splitOccured = nextLeaf.getParent().splitUntill(
              nextResult.getLastCommonParent(), nextLeaf, false);
View Full Code Here


   */
  public LastCommonParentResult getLastCommonParent(Node other) {
    if (other == null)
      throw new IllegalArgumentException("The given TextNode is null");

    LastCommonParentResult result = new LastCommonParentResult();

    // note that these lists are never null,
    // but sometimes are empty.
    List<TagNode> myParents = getParentTree();
    List<TagNode> otherParents = other.getParentTree();

    int i = 1;
    boolean isSame = true;
    while (isSame && i < myParents.size() && i < otherParents.size()) {
      if (!myParents.get(i).isSameTag(otherParents.get(i))) {
        isSame = false;
      } else {
        // After the while, the index i-1 must be the last common parent
        i++;
      }
    }

    result.setLastCommonParentDepth(i - 1);
    result.setLastCommonParent(myParents.get(i - 1));

    if (!isSame) {// found different parent
      result.setIndexInLastCommonParent(myParents.get(i - 1).getIndexOf(
          myParents.get(i)));
      result.setSplittingNeeded();
    } else if (myParents.size() < otherParents.size()) {
      // current node is not so deeply nested
      result.setIndexInLastCommonParent(myParents.get(i - 1).getIndexOf(
          this));
    } else if (myParents.size() > otherParents.size()) {
      // All tags matched but there are tags left in this tree -
      // other node is not so deeply nested
      result.setIndexInLastCommonParent(myParents.get(i - 1).getIndexOf(
          myParents.get(i)));
      result.setSplittingNeeded();
    } else {
      // All tags matched until the very last one in both trees
      // or there were no tags besides the BODY
      result.setIndexInLastCommonParent(myParents.get(i - 1).getIndexOf(
          this));
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of org.outerj.daisy.diff.html.dom.helper.LastCommonParentResult

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.