Search in sources :

Example 1 with Jerry

use of jodd.jerry.Jerry in project jodd by oblac.

the class ParsingProblemsTest method testKelkoo.

@Test
public void testKelkoo() throws Exception {
    File file = new File(testDataRoot, "kelkoo.html");
    Jerry jerry;
    try {
        jerry = Jerry.jerry().parse(FileUtil.readString(file));
    } catch (Exception ex) {
        fail(ex.toString());
        throw ex;
    }
    Element script = (Element) jerry.$("script").get(0);
    assertEquals("script", script.getNodeName());
    assertEquals(6, script.getAttributesCount());
    assertEquals("src", script.getAttribute(0).getName());
    assertEquals("data-config", script.getAttribute(1).getName());
    assertEquals("ext\\u00e9rieur|barbecue,", script.getAttribute(2).getName());
    assertEquals("planchaaccessoires\":\"http:\\", script.getAttribute(3).getName());
    assertEquals("www.kelkoo.fr\"}'", script.getAttribute(4).getName());
    assertEquals("data-adsense-append", script.getAttribute(5).getName());
}
Also used : Element(jodd.lagarto.dom.Element) Jerry(jodd.jerry.Jerry) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Jerry

use of jodd.jerry.Jerry in project jodd by oblac.

the class ParsingProblemsTest method testIssue23.

@Test
public void testIssue23() throws IOException {
    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());
    assertEquals(1, doc.$("dl").size());
    assertEquals(1564, doc.$("dd").size());
    assertEquals(1564, doc.$("dt").size());
    assertEquals(3144, doc.$("dt a").size());
    // http://docs.oracle.com/javase/6/docs/api/index-files/index-4.html
    file = new File(testDataRoot, "index-4-eng.html");
    doc = Jerry.jerry(FileUtil.readString(file));
    assertEquals(16, doc.$("td.NavBarCell1").size());
    assertEquals(2, doc.$("table td.NavBarCell1Rev").size());
    final StringBuilder sb = new StringBuilder();
    doc.$("td.NavBarCell1").each(($this, index) -> {
        sb.append("---\n");
        sb.append($this.text().trim());
        sb.append('\n');
        return true;
    });
    String s = sb.toString();
    s = StringUtil.remove(s, ' ');
    s = StringUtil.remove(s, '\r');
    s = StringUtil.remove(s, ' ');
    s = StringUtil.remove(s, " ");
    assertEquals("---\n" + "Overview\n" + "Package\n" + "Class\n" + "Use\n" + "Tree\n" + "Deprecated\n" + "Index\n" + "Help\n" + "---\n" + "Overview\n" + "---\n" + "Package\n" + "---\n" + "Class\n" + "---\n" + "Use\n" + "---\n" + "Tree\n" + "---\n" + "Deprecated\n" + "---\n" + "Help\n" + "---\n" + "Overview\n" + "Package\n" + "Class\n" + "Use\n" + "Tree\n" + "Deprecated\n" + "Index\n" + "Help\n" + "---\n" + "Overview\n" + "---\n" + "Package\n" + "---\n" + "Class\n" + "---\n" + "Use\n" + "---\n" + "Tree\n" + "---\n" + "Deprecated\n" + "---\n" + "Help\n", s);
}
Also used : LagartoDOMBuilder(jodd.lagarto.dom.LagartoDOMBuilder) Document(jodd.lagarto.dom.Document) Jerry(jodd.jerry.Jerry) File(java.io.File) Test(org.junit.Test)

Example 3 with Jerry

use of jodd.jerry.Jerry in project jodd by oblac.

the class ParsingProblemsTest method testNamespaces.

@Test
public void testNamespaces() throws IOException {
    File file = new File(testDataRoot, "namespace.xml");
    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);
    assertEquals("cfg:node", cfgNode.getNodeName());
    Jerry.JerryParser jerryParser = new Jerry.JerryParser();
    ((LagartoDOMBuilder) jerryParser.getDOMBuilder()).enableXmlMode();
    Jerry jerry = jerryParser.parse(FileUtil.readString(file));
    final StringBuilder result = new StringBuilder();
    jerry.$("cfg\\:test").each(($this, index) -> {
        result.append($this.$("cfg\\:node").text());
        return true;
    });
    assertEquals("This is a text", result.toString());
}
Also used : Element(jodd.lagarto.dom.Element) LagartoDOMBuilder(jodd.lagarto.dom.LagartoDOMBuilder) Document(jodd.lagarto.dom.Document) Jerry(jodd.jerry.Jerry) File(java.io.File) Test(org.junit.Test)

Example 4 with Jerry

use of jodd.jerry.Jerry in project jodd by oblac.

the class SpringApiTest method testPortletUtils.

@Test
public void testPortletUtils() throws IOException {
    File file = new File(testDataRoot, "PortletUtils.html");
    String content = FileUtil.readString(file);
    Jerry.JerryParser jerryParser = new Jerry.JerryParser();
    //jerryParser.getDOMBuilder().setCalculatePosition(true);
    Jerry doc = jerryParser.parse(content);
    // parse
    doc.$("a").each(($this, index) -> {
        assertEquals("<a name=\"navbar_top\"><!-- --></a>", $this.get()[0].getHtml());
        return false;
    });
}
Also used : Jerry(jodd.jerry.Jerry) File(java.io.File) Test(org.junit.Test)

Example 5 with Jerry

use of jodd.jerry.Jerry in project jodd by oblac.

the class SpringApiTest method testAbstractFormController.

@Test
public void testAbstractFormController() throws IOException {
    File file = new File(testDataRoot, "AbstractFormController.html");
    String content = FileUtil.readString(file);
    Jerry.JerryParser jerryParser = new Jerry.JerryParser();
    //jerryParser.getDOMBuilder().setCalculatePosition(true);
    Jerry doc = jerryParser.parse(content);
    // parse
    doc.$("a").each(($this, index) -> {
        assertEquals("<a name=\"navbar_top\"><!-- --></a>", $this.get()[0].getHtml());
        return false;
    });
}
Also used : Jerry(jodd.jerry.Jerry) File(java.io.File) Test(org.junit.Test)

Aggregations

Jerry (jodd.jerry.Jerry)8 File (java.io.File)7 Test (org.junit.Test)7 LagartoDOMBuilder (jodd.lagarto.dom.LagartoDOMBuilder)3 IOException (java.io.IOException)2 Document (jodd.lagarto.dom.Document)2 Element (jodd.lagarto.dom.Element)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1