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

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


    LocalDocument<Node, Element, Text> doc = cxt.annotatableContent();
    Text zText = doc.getDocumentElement().getFirstChild().getNextSibling().getFirstChild().asText();

    // First transparent part, moving the Z inside
    Element trans = doc.transparentCreate("S", Attributes.EMPTY_MAP,
        zText.getParentElement(), zText);
    cxt.annotatableContent().transparentMove(trans, zText, null, null);

    // Second transparent part, deep transparent (contains another transparent element)
    Element lastP = doc.getDocumentElement().getLastChild().asElement();
    trans = cxt.annotatableContent().transparentCreate("T", Attributes.EMPTY_MAP, lastP, null);
    cxt.annotatableContent().transparentCreate("U", Attributes.EMPTY_MAP, trans, null);
    return cxt;
  }
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.
          assertNull(DocHelper.getPreviousSiblingElement(doc, p));
        } else {
View Full Code Here

   */
  public void testGetItemSize() {
    ReadableWDocument<Node, Element, Text> doc = DocProviders.POJO.parse(
        "<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));

View Full Code Here

      assertNull(DocHelper.getElementWithTagName(doc, ""));
    }
    {
      // Container is excluded from search.
      doc = getDoc("<x><y></y></x>");
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      assertNull(DocHelper.getElementWithTagName(doc, "x", container));

      // Finds direct child match.
      Element expectedY = doc.getFirstChild(container).asElement();
      assertSame(expectedY, DocHelper.getElementWithTagName(doc, "y", container));

      // Finds deeper child match.
      assertSame(expectedY, DocHelper.getElementWithTagName(doc, "y"));
    }
    {
      doc = getDoc("<x><y></y><z></z></x>");
      // Finds a non-first-sibling match.
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      Element expectedZ = doc.getLastChild(container).asElement();
      assertSame(expectedZ, DocHelper.getElementWithTagName(doc, "z"));
    }
    {
      doc = getDoc("<x><y><z></z></y></x>");
      // Doesn't search above subtree.
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      Element y = doc.getFirstChild(container).asElement();
      assertNull(DocHelper.getElementWithTagName(doc, "x", y));
    }
    {
      doc = getDoc("<x><y></y></x><z></z>");
      // Doesn't search right of subtree.
      Element x = doc.getFirstChild(doc.getDocumentElement()).asElement();
      assertNull(DocHelper.getElementWithTagName(doc, "z", x));
    }
    {
      doc = getDoc("<y><x></x></y><x></x>");
      // Finds leftmost match.
      Element expectedX = doc.getFirstChild(doc.getFirstChild(
          doc.getDocumentElement())).asElement();
      assertSame(expectedX, DocHelper.getElementWithTagName(doc, "x"));
    }
  }
View Full Code Here

      assertNull(DocHelper.getLastElementWithTagName(doc, ""));
    }
    {
      // Container is excluded from search.
      doc = getDoc("<x><y></y></x>");
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      assertNull(DocHelper.getLastElementWithTagName(doc, "x", container));

      // Finds direct child match.
      Element expectedY = doc.getFirstChild(container).asElement();
      assertSame(expectedY, DocHelper.getLastElementWithTagName(doc, "y", container));

      // Finds deeper child match.
      assertSame(expectedY, DocHelper.getLastElementWithTagName(doc, "y"));
    }
    {
      doc = getDoc("<x><y></y><z></z></x>");
      // Finds a non-last-sibling match.
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      Element expectedY = doc.getFirstChild(container).asElement();
      assertSame(expectedY, DocHelper.getLastElementWithTagName(doc, "y"));
    }
    {
      doc = getDoc("<x><y><z></z></y></x>");
      // Doesn't search above subtree.
      Element container = doc.getFirstChild(doc.getDocumentElement()).asElement();
      Element y = doc.getFirstChild(container).asElement();
      assertNull(DocHelper.getLastElementWithTagName(doc, "x", y));
    }
    {
      doc = getDoc("<z></z><x><y></y></x>");
      // Doesn't search left of subtree.
      Element x = doc.getLastChild(doc.getDocumentElement()).asElement();
      assertNull(DocHelper.getLastElementWithTagName(doc, "z", x));
    }
    {
      doc = getDoc("<x></x><y><x></x></y>");
      // Finds rightmost match.
      Element expectedX = doc.getFirstChild(doc.getLastChild(
          doc.getDocumentElement())).asElement();
      assertSame(expectedX, DocHelper.getLastElementWithTagName(doc, "x"));
    }
  }
View Full Code Here

        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(cxt1.annotatableContent()).toString());
        assertEquals("here^", ((Text)point.getNodeAfter()).getData());

        Element c = node.getParentElement();
        cxt1.annotatableContent().transparentMove(c.getParentElement(),
            c, c.getNextSibling(), null);
        point = DocHelper.ensureNodeBoundary(
            DocHelper.transparentSlice(Point.<Node>inText(node, 1), cxt1),
            cxt1.getIndexedDoc(), cxt1.getIndexedDoc());
        assertEquals("he^llo<x>t^<a><b>here^<c>TT</c></b></a>" +
            "<a> how^</a> are you</x>y^eah<p><r></r><q></q></p>",
            XmlStringBuilder.innerXml(cxt1.annotatableContent()).toString());

        assertEquals("a", ((Element)point.getNodeAfter()).getTagName());
        assertEquals("a", ((Element)point.getNodeAfter().getPreviousSibling()).getTagName());

        Point<Node> point2 = DocHelper.transparentSlice(point, cxt1);
        assertEquals("a", ((Element)point2.getNodeAfter()).getTagName());
        assertEquals("a", ((Element)point2.getNodeAfter().getPreviousSibling()).getTagName());

        point2 = DocHelper.transparentSlice(
            Point.end(point2.getNodeAfter().getPreviousSibling()), cxt1);
        assertEquals("a", ((Element)point2.getNodeAfter()).getTagName());
        assertEquals("a", ((Element)point2.getNodeAfter().getPreviousSibling()).getTagName());

        Point<Node> point3 = DocHelper.ensureNodeBoundary(
            DocHelper.transparentSlice(Point.end(point2.getContainer()), cxt1),
            cxt1.getIndexedDoc(), cxt1.getIndexedDoc());
        assertEquals("x", ((Element)point3.getContainer()).getTagName());
        assertNull(point3.getNodeAfter());

        Element a = (Element) point2.getNodeAfter().getPreviousSibling();
        Element d = cxt1.annotatableContent().transparentCreate("d", Attributes.EMPTY_MAP,
            a, null);

        point2 = DocHelper.transparentSlice(Point.<Node>end(a), cxt1);
        assertEquals("a", ((Element)point2.getNodeAfter()).getTagName());
        assertEquals("a", ((Element)point2.getNodeAfter().getPreviousSibling()).getTagName());

        point2 = DocHelper.transparentSlice(Point.<Node>end(d), cxt1);
        assertEquals("a", ((Element)point2.getNodeAfter()).getTagName());
        assertEquals("a", ((Element)point2.getNodeAfter().getPreviousSibling()).getTagName());

        Element x = (Element) point2.getContainer();
        Element e = cxt1.annotatableContent().transparentCreate("e", Attributes.EMPTY_MAP,
            x, null);

        point2 = DocHelper.ensureNodeBoundary(
            DocHelper.transparentSlice(Point.<Node>end(x), cxt1),
            cxt1.getIndexedDoc(), cxt1.getIndexedDoc());
View Full Code Here

  /**
   * Test basic get attribute.
   */
  public void testGetAttributes() {
    init("<p t=\"0\" s=\"hi\">hello</p>");
    Element e = (Element) doc.getFirstChild(doc.getDocumentElement());
    assertEquals("0", doc.getAttribute(e, "t"));
    assertEquals("hi", doc.getAttribute(e, "s"));
  }
View Full Code Here

   * Test set attribute overrides and removes old attributes, as opposed to
   * update.
   */
  public void testSetAttributes() {
    init("<p t=\"0\" s=\"hi\">hello</p>");
    Element e = (Element) doc.getFirstChild(doc.getDocumentElement());
    doc.setElementAttributes(e, new AttributesImpl("just", "this"));
    assertEquals(null, doc.getAttribute(e, "t"));
    assertEquals(null, doc.getAttribute(e, "s"));
    assertEquals("this", doc.getAttribute(e, "just"));
  }
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
    //    0     1  234  567   8   9    10 11     12
    init("<root><b>bo<i>ld</i></b><after/></root>");
    doc.setAnnotation(1, 9, "b", "B"); // around the bs
    doc.setAnnotation(4, 8, "i", "I"); // around the is
    doc.setAnnotation(0, 3, "s", "S"); // overlaps the start
    doc.setAnnotation(7, 12, "e", "E"); // overlaps the end, AND covers the new range

    /*
    <root><b>bo<i>ld</i></b><after/></root>
           B BB B BB  B   B
                I II  I
      S    S S
                      E   E    E E    E

    <root><after/><b>bo<i>ld</i></b></root>
                   B BB B BB  B   B
                        I II  I
      S            S S
             E E              E   E   E

    <?a "s"="S"?><root><?a "e"="E" "s"?><after/><?a "b"="B" "e" "s"="S"?><b>b<?a "s"?>o<?a "i"="I"?><i>ld<?a "e"="E"?></i><?a "i"?></b><?a "b"?></root><?a "e"?>
    */

    root = doc.getDocumentElement().getFirstChild().asElement();
    doc.moveSiblings(Point.end((Node) root), root.getFirstChild(), root.getLastChild());
    assertOperationResult("<?a \"s\"=\"S\"?><root><?a \"e\"=\"E\" \"s\"?><after/>"
        + "<?a \"b\"=\"B\" \"e\" \"s\"=\"S\"?><b>b<?a \"s\"?>o<?a \"i\"=\"I\"?><i>ld"
        + "<?a \"e\"=\"E\"?></i><?a \"i\"?></b><?a \"b\"?></root><?a \"e\"?>");
  }
View Full Code Here

  /**
   * Tests that createChildElement does as it says.
   */
  public void testCreateChildElement() {
    init("<p>first child</p>");
    Element root = doc.getDocumentElement();
    doc.createChildElement(root, "child", Collections.<String, String> emptyMap());
    assertOperationResult("<p>first child</p><child/>");
  }
View Full Code Here

TOP

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

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.