Package jodd.lagarto.dom

Examples of jodd.lagarto.dom.Document


  /**
   * Sets the HTML contents of each element in the set of matched elements.
   */
  public Jerry html(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      node.removeAllChilds();

      // clone to preserve for next iteration
      // as nodes will be detached from parent
      Document workingDoc = doc.clone();

      node.addChild(workingDoc.getChildNodes());
    }
    return this;
  }
View Full Code Here


  /**
   * Inserts content, specified by the parameter, to the end of each
   * element in the set of matched elements.
   */
  public Jerry append(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      Document workingDoc = doc.clone();
      node.addChild(workingDoc);
    }
    return this;
  }
View Full Code Here

  /**
   * Inserts content, specified by the parameter, before each
   * element in the set of matched elements.
   */
  public Jerry before(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      Document workingDoc = doc.clone();
      node.insertBefore(workingDoc, node);
    }
    return this;
  }
View Full Code Here

  /**
   * Wraps an HTML structure around each element in the set of matched elements.
   * Returns the original set of elements for chaining purposes.
   */
  public Jerry wrap(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      Document workingDoc = doc.clone();
      Node inmostNode = workingDoc;
      while (inmostNode.hasChildNodes()) {
        inmostNode = inmostNode.getFirstChild();
      }

      // replace
      Node parent = node.getParentNode();
      int index = node.getSiblingIndex();
      inmostNode.addChild(node);
      parent.insertChild(workingDoc.getFirstChild(), index);
    }

    return this;
  }
View Full Code Here

    /**
     * Invokes parsing on {@link DOMBuilder}.
     */
    public Jerry parse(char[] content) {
      Document doc = domBuilder.parse(content);
      return new Jerry(domBuilder, doc);
    }
View Full Code Here

    /**
     * Invokes parsing on {@link DOMBuilder}.
     */
    public Jerry parse(String content) {
      Document doc = domBuilder.parse(content);
      return new Jerry(domBuilder, doc);
    }
View Full Code Here

    ((LagartoDOMBuilder) jerryParser.getDOMBuilder()).enableHtmlMode();

    // default, case not sensitive

    Jerry doc = jerryParser.parse(str);
    Document document = (Document) doc.get(0);
    Element divNode = (Element) document.getChild(0);
    assertEquals("div", divNode.getNodeName());
    assertNotNull(divNode.getAttribute("myattr"));
    assertNotNull(divNode.getAttribute("myAttr"));

    Element divNode2 = (Element) doc.$("div[myattr=aaa]").nodes[0];
    assertSame(divNode, divNode2);

    assertEquals("<div id=\"one\" myattr=\"aaa\">xxx</div>", doc.html());

    // case sensitive

    ((LagartoDOMBuilder) jerryParser.getDOMBuilder()).getConfig().setCaseSensitive(true);

    doc = jerryParser.parse(str);
    document = (Document) doc.get(0);
    divNode = (Element) document.getChild(0);
    assertEquals("dIV", divNode.getNodeName());
    assertNull(divNode.getAttribute("myattr"));

    assertEquals("<dIV id=\"one\" myAttr=\"aaa\">xxx</dIV>", doc.html());
View Full Code Here

  /**
   * Sets the HTML contents of each element in the set of matched elements.
   */
  public Jerry html(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      node.removeAllChilds();

      // clone to preserve for next iteration
      // as nodes will be detached from parent
      Document workingDoc = doc.clone();

      node.addChild(workingDoc.getChildNodes());
    }
    return this;
  }
View Full Code Here

  /**
   * Inserts content, specified by the parameter, to the end of each
   * element in the set of matched elements.
   */
  public Jerry append(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      Document workingDoc = doc.clone();
      node.addChild(workingDoc.getChildNodes());
    }
    return this;
  }
View Full Code Here

  /**
   * Inserts content, specified by the parameter, before each
   * element in the set of matched elements.
   */
  public Jerry before(String html) {
    final Document doc = builder.parse(html);

    for (Node node : nodes) {
      Document workingDoc = doc.clone();
      node.insertBefore(workingDoc.getChildNodes(), node);
    }
    return this;
  }
View Full Code Here

TOP

Related Classes of jodd.lagarto.dom.Document

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.