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

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


   * @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


  }

  /** Check that walking a subtree correctly works. */
  public void testWalkSubtree() {
    RawDocumentImpl doc;
    Node A, B, C, S, T;
    ReadableTreeWalker<Node, Element, Text> walker;
    doc = DocProviders.ROJO.parse("<a><b><c x=\"y\"></c>sub</b>child</a>");
    A = doc.getDocumentElement();
    B = doc.getFirstChild(A);
    C = doc.getFirstChild(B);
View Full Code Here

    RawDocumentImpl rawDoc = RawDocumentImpl.PROVIDER.parse("<doc><p></p></doc>");
    IndexedDocumentImpl<Node, Element, Text, ?> doc =
        new IndexedDocumentImpl<Node, Element, Text, Void>(rawDoc, annotations,
            DocumentSchema.NO_SCHEMA_CONSTRAINTS);

    Node element = doc.getDocumentElement().getFirstChild();

    // element is valid
    assertEquals(0, doc.getLocation(element));

    doc.consumeAndReturnInvertible(Nindo.deleteElement(0));
View Full Code Here

  public void testMoveNodes() throws Exception {
    // simple move
    init("<root><before/><from/></root>");
    Element root = doc.getDocumentElement().getFirstChild().asElement();
    Node from = root.getLastChild();
    doc.moveSiblings(Point.start(doc, root), from, null);
    assertOperationResult("<root><from/><before/></root>");

    // move with attributes and children
    init("<root><before/> stuff <from> child <sub/></from> more <attr x=\"x\" y=\"z\"/> end</root>");
    root = doc.getDocumentElement().getFirstChild().asElement();
    Node stuff = root.getFirstChild().getNextSibling();
    from = stuff.getNextSibling();
    doc.moveSiblings(Point.before(doc, stuff), from, root.getLastChild());
    assertOperationResult(
        "<root><before/><from> child <sub/></from> more <attr x=\"x\" y=\"z\"/> stuff  end</root>");

    // move with annotations
View Full Code Here

  public void testSampleLocations1() {
    IndexedDocument<Node, Element, Text> document = createEmptyDocument();
    try {
      document.consume(element("p"));
      document.consume(characters("a", 1, 1));
      Node testNode = document.getDocumentElement().getFirstChild();
      assertNotNull(testNode);
      testNode = testNode.getFirstChild();
      assertNotNull(testNode);
      assertEquals(1, document.getLocation(testNode));
      assertEquals(1, testNode.getIndexingContainer().size());
      document.consume(characters("b", 2, 1));
      assertEquals(1, document.getLocation(testNode));
      assertEquals(2, testNode.getIndexingContainer().size());
      document.consume(characters("c", 3, 1));
      assertEquals(1, document.getLocation(testNode));
      assertEquals(3, testNode.getIndexingContainer().size());
    } catch (OperationException e) {
      fail(e.toString());
    }
  }
View Full Code Here

  /***/
  public void testGetNextSiblingElementBackwards() {
    ReadableWDocument<Node, Element, Text> doc = DocProviders.POJO.parse(
        "<div>abc<p>def<q>hij</q></p><p>def<q>hij</q></p></div>");
    Element previous = null;
    Node node = doc.getFirstChild(doc.getDocumentElement());
    while (node != null) {
      Element p = doc.asElement(node);
      if (p != null) {
        if (previous == null) {
          // p is the very first element among nodes of doc.
View Full Code Here

        "<top>abc<p>def<q>hij</q></p><p>def<q>hij</q></p></top>");

    Element top = (Element) doc.getDocumentElement().getFirstChild();
    assertEquals(25, DocHelper.getItemSize(doc, top));

    Node text = doc.getFirstChild(top);
    assertEquals(3, DocHelper.getItemSize(doc, text));

    Node pWithSibling = doc.getNextSibling(text);
    assertEquals(10, DocHelper.getItemSize(doc, pWithSibling));

    Node pWithoutSibling = doc.getNextSibling(pWithSibling);
    assertEquals(10, DocHelper.getItemSize(doc, pWithoutSibling));
  }
View Full Code Here

          }
          // There's only one possibility to test - so quit after this.
          pointBias = 50;
          boundaryPoint = point;
        } else {
          Node nodeBefore, nodeAfter, parent;
          if (point.isInTextNode()) {
            if (point.getTextOffset() == 0) {
              nodeAfter = point.getContainer();
              nodeBefore = doc.getPreviousSibling(nodeAfter);
            } else {
              nodeBefore = point.getContainer();
              nodeAfter = doc.getNextSibling(nodeBefore);
            }
            parent = point.getContainer().getParentElement();
          } else {
            nodeAfter = point.getNodeAfter();
            parent = point.getContainer();
            if (nodeAfter == null) {
              nodeBefore = point.getContainer().getLastChild();
            } else {
              nodeBefore = nodeAfter.getPreviousSibling();
            }
          }
          Text textNodeBefore = doc.asText(nodeBefore);
          Text textNodeAfter = doc.asText(nodeAfter);
          switch (pointBias) {
          case 0:
            if (textNodeBefore != null) {
              boundaryPoint = Point.<Node>inText(textNodeBefore, textNodeBefore.getLength());
            }
            break;
          case 1:
            if (textNodeAfter != null) {
              boundaryPoint = Point.<Node>inText(textNodeAfter, 0);
            }
            break;
          case 2:
            boundaryPoint = Point.inElement(parent, nodeAfter);
            break;
          }
        }

        if (boundaryPoint != null) {
          if (returnNextNode) {
            Node n = DocHelper.ensureNodeBoundaryReturnNextNode(boundaryPoint, doc, doc);
            if (nextNodeLocation >= 0) {
              assertEquals(nextNodeLocation, doc.getLocation(n));
            } else {
              assertNull(n);
            }
View Full Code Here

        assertEquals(2, point.getTextOffset());
      }
    });

    final TestDocumentContext<Node, Element, Text> cxt5 = createSliceTestCxt();
    Node last = cxt5.getIndexedDoc().getDocumentElement().getLastChild();
    Point<Node> point = DocHelper.transparentSlice(Point.<Node>end(last), cxt5);
    assertEquals("he^llo<x>t^<a><b><c>TT</c>here^</b>" +
        " how^</a> are you</x>y^eah<p><r></r><q></q></p>",
        XmlStringBuilder.innerXml(cxt5.annotatableContent()).toString());
    assertSame(last, point.getContainer());
    assertNull(point.getNodeAfter());

    point = DocHelper.transparentSlice(Point.<Node>inElement(
        last, last.getLastChild()), cxt5);
    assertEquals("he^llo<x>t^<a><b><c>TT</c>here^</b>" +
        " how^</a> are you</x>y^eah<p><r></r><q></q></p>",
        XmlStringBuilder.innerXml(cxt5.annotatableContent()).toString());
    assertSame(last, point.getContainer());
    assertSame(last.getLastChild(), point.getNodeAfter());

  }
View Full Code Here

  public void testGetNextNodeDepthFirst() {
    MutableDocument<Node, Element, Text> doc = getDoc(
        "<x>hello</x><y><yy>blah</yy>yeah</y><w/><z>final</z>");
    Element root = doc.getDocumentElement();
    Node x = root.getFirstChild();
    Node y = x.getNextSibling();
    Node w = y.getNextSibling();
    Node yy = y.getFirstChild();
    Node z = root.getLastChild();
    assertSame(y, DocHelper.getNextNodeDepthFirst(doc, x, null, false));
    assertSame(y, DocHelper.getNextNodeDepthFirst(doc, x, root, false));

    assertSame(x.getFirstChild(), DocHelper.getNextNodeDepthFirst(doc, x, x, true));
    assertSame(x.getFirstChild(), DocHelper.getNextNodeDepthFirst(doc, x, root, true));
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.