Package jodd.lagarto.dom

Examples of jodd.lagarto.dom.Document


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


  public void testNonQuotedAttributeValue() {
    String html = "<a href=123>xxx</a>";

    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);
    Document document = lagartoDOMBuilder.parse(html);

    assertEquals("<a href=\"123\">xxx</a>", document.getHtml());
    assertTrue(document.check());

    html = "<a href=../org/w3c/dom/'http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-list'>xxx</a>";

    lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);
    document = lagartoDOMBuilder.parse(html);
    assertTrue(document.check());

    assertEquals("<a href=\"../org/w3c/dom/'http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-list'\">xxx</a>", document.getHtml());
  }
View Full Code Here

    File file = new File(testDataRoot, "index-4-v0.html");

    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);
    lagartoDOMBuilder.getConfig().setCollectErrors(true);
    Document doc = lagartoDOMBuilder.parse(FileUtil.readString(file));
    assertTrue(doc.check());

    assertEquals(1, doc.getErrors().size());
  }
View Full Code Here

    File file = new File(testDataRoot, "index-4-v1.html");

    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);
    lagartoDOMBuilder.getConfig().setCollectErrors(true);
    Document doc = lagartoDOMBuilder.parse(FileUtil.readString(file));
    assertTrue(doc.check());

    assertEquals(1, doc.getErrors().size());
  }
View Full Code Here

    File file = new File(testDataRoot, "index-4.html");

    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);
    lagartoDOMBuilder.getConfig().setCollectErrors(true);
    Document document = lagartoDOMBuilder.parse(FileUtil.readString(file));
    assertTrue(document.check());

    // (1564 open DTs + 1564 open DDs) 1 open P
    assertEquals(19, document.getErrors().size());

    Jerry doc = Jerry.jerry(FileUtil.readString(file));
    assertEquals(16, doc.$("td.NavBarCell1").size());
    assertEquals(2, doc.$("table td.NavBarCell1Rev").size());
View Full Code Here

    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    lagartoDOMBuilder.enableXmlMode();
    lagartoDOMBuilder.getConfig().setCalculatePosition(true);

    Document doc = lagartoDOMBuilder.parse(FileUtil.readString(file));
    assertTrue(doc.check());

    Element cfgTestElement = (Element) doc.getChild(1);

    assertEquals("cfg:test", cfgTestElement.getNodeName());

    Element cfgNode = (Element) cfgTestElement.getChild(0);
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

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.