Package org.waveprotocol.wave.model.document.raw.impl

Examples of org.waveprotocol.wave.model.document.raw.impl.Node


  public void testFindById() {
    MutableDocument<Node, Element, Text> doc = getDoc(
        "<x id=\"x\">hello</x><y id=\"y\"><yy id=\"y\">blah</yy>yeah</y><z>final</z>");

    Element root = doc.getDocumentElement();
    Node x = root.getFirstChild();
    Node z = root.getLastChild();
    Node y = z.getPreviousSibling();

    int firstLoc = doc.getLocation(x);
    assertSame(firstLoc, DocHelper.findLocationById(doc, "x"));
    assertSame(x, DocHelper.findElementById(doc, "x"));
    assertSame(firstLoc + 7, DocHelper.findLocationById(doc, "y"));
View Full Code Here


        "<x id=\"x\">hello</x>" +
        "<aroundy><y id=\"y\"><yy id=\"y\">blah</yy>yeah</y></aroundy>" +
        "<z>final</z>");

    Element root = doc.getDocumentElement();
    Node x = root.getFirstChild();
    Node z = root.getLastChild();
    Node aroundy = z.getPreviousSibling();
    Node y = aroundy.getFirstChild();
    Node yy = y.getFirstChild();

    assertSame(null, DocHelper.findElementById(doc, x.asElement(), "y"));
    assertSame(y, DocHelper.findElementById(doc, aroundy.asElement(), "y"));
    assertSame(y, DocHelper.findElementById(doc, y.asElement(), "y"));
    assertSame(null, DocHelper.findElementById(doc, z.asElement(), "y"));
    assertSame(yy, DocHelper.findElementById(doc, yy.asElement(), "y"));
  }
View Full Code Here

    assertSame(yy, DocHelper.findElementById(doc, yy.asElement(), "y"));
  }

  public void testMatchingElement() {
    MutableDocument<Node, Element, Text> doc = getDoc("<x/>hello");
    Node n = doc.getDocumentElement().getFirstChild();
    assertFalse(DocHelper.isMatchingElement(doc, n.getNextSibling(), "x"));
    assertFalse(DocHelper.isMatchingElement(doc, n, "y"));
    assertTrue(DocHelper.isMatchingElement(doc, n, "x"));
  }
View Full Code Here

    assertSame(afterY, DocHelper.jumpOut(doc, afterY, IS_X));
  }

  public void testJumpOutPreservesIdentityWherePossible() {
    MutableDocument<Node, Element, Text> doc = getDoc("<x/>hello");
    Node x = doc.getDocumentElement().getFirstChild();

    Point<Node> afterX = Point.after(doc, x);
    Point<Node> inText = Point.inText(x.getNextSibling(), 2);
    Point<Node> inX = Point.end(x);
    assertSame(afterX, DocHelper.jumpOut(doc, afterX, DocHelper.ROOT_PREDICATE));
    assertSame(inText, DocHelper.jumpOut(doc, inText, DocHelper.ROOT_PREDICATE));
    assertSame(inX, DocHelper.jumpOut(doc, inX, IS_X));
  }
View Full Code Here

    create(a);

    // GWT doesn't define subList.
    Element top = (Element) doc.getDocumentElement().getFirstChild();
    Node n1 = doc.getFirstChild(top);
    Node n2 = doc.getLastChild(top);
    List<Element> all = elementsInner(doc, top);
    List<Element> els = Arrays.asList(all.get(0), all.get(1));

    Builder b = at(0);
    Attributes attrs = attrs("x", "1", "y", "2");
View Full Code Here

        "<x>hello</x><y><yy>blah</yy>yeah</y><z>final</z>", null, null, null,
        DocumentSchema.NO_SCHEMA_CONSTRAINTS).document();

    int i;
    Element root = doc.getDocumentElement();
    Node x = root.getFirstChild();
    Node z = root.getLastChild();
    Node y = z.getPreviousSibling();

    for (Node end : new Node[]{z, root, null}) {
      i = 0;
      for (Node n : DocIterate.deep(doc, z.getFirstChild(), end)) {
        assertSame(z.getFirstChild(), n);
        i++;
      }
      assertEquals(1, i);

      i = 0;
      for (Node n : DocIterate.deep(doc, z, end)) {
        assertSame(i == 0 ? z : z.getFirstChild(), n);
        i++;
      }
      assertEquals(2, i);

      i = 0;
      for (Node n : DocIterate.deep(doc, root, end)) {
        switch (i) {
          case 0: assertSame(root, n); break;
          case 3: assertSame(y, n); break;
          case 4: assertSame(y.getFirstChild(), n); break;
          case 5: assertSame(y.getFirstChild().getFirstChild(), n); break;
          case 6: assertSame(y.getFirstChild().getNextSibling(), n); break;
          default: assertNotNull(n); break;
        }
        i++;
      }
      assertEquals(end == z ? 7 : 9, i);
View Full Code Here

    assertSame(null, doc.getVisibleNode(null));
  }

  public void testNullReturnedForInvalidNodes() {
    BasicFilteringView doc = parse("");
    Node invalidNode = parse("<x>a<y>b</y>c</x>").getNode(0);
    assertSame(null, doc.getFirstChild(invalidNode));
    assertSame(null, doc.getLastChild(invalidNode));
    assertSame(null, doc.getNextSibling(invalidNode));
    assertSame(null, doc.getPreviousSibling(invalidNode));
    assertSame(null, doc.getParentElement(invalidNode));
View Full Code Here

    }

    @Override
    protected FilteredView.Skip getSkipLevel(Node node) {
      // Check if it's in the document, for validity
      Node find = node;
      while (find != getDocumentElement()) {
        if (find == null) {
          return Skip.INVALID;
        }
        find = find.getParentElement();
      }

      Element e = asElement(node);
      if (e == null) {
        return Skip.NONE;
View Full Code Here

        return Skip.NONE;
      }
    }

    protected Node getNode(int ... xmlPoint) {
      Node current = getDocumentElement();
      for (int i = 0; i < xmlPoint.length; i++) {
        current = current.getFirstChild();
        for (int remaining = xmlPoint[i]; remaining > 0; remaining--) {
          current = current.getNextSibling();
        }
      }
      return current;
    }
View Full Code Here

   * @return Number of children the specified element has.
   */
  public static <N, E extends N, T extends N> int countChildren(
      ReadableDocument<Node, Element, Text> doc, Element elem) {
    int children = 0;
    Node currentChild = doc.getFirstChild(elem);

    while (currentChild != null) {
      children++;
      currentChild = doc.getNextSibling(currentChild);
    }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.raw.impl.Node

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.