public static String readString(File source) throws IOException { return readString(source, fileUtilParams.encoding); }
public static String readString(String source) throws IOException { return readString(file(source), fileUtilParams.encoding); }
public static String readString(String source, String encoding) throws IOException { return readString(file(source), encoding); }
/** * @see #readString(File, String) */ public static String readString(final String source, final String encoding) throws IOException { return readString(file(source), encoding); }
/** * Loads properties from the file in provided encoding. */ public Props load(final File file, final String encoding) throws IOException { parse(FileUtil.readString(file, encoding)); return this; }
/** * @see #readString(String, String) */ public static String readString(final String source) throws IOException { return readString(source, encoding()); }
/** * @see #readString(File, String) */ public static String readString(final File source) throws IOException { return readString(source, encoding()); }
private String readFile(String fileName) { try { return FileUtil.readString(new File(testDataRoot, fileName)); } catch (IOException ignore) { return null; } }
/** * Reads test file and returns its content optionally stripped. */ protected String read(String filename, boolean strip) throws IOException { String data = FileUtil.readString(new File(testDataRoot, filename)); if (strip) { data = strip(data); } return data; }
@Test void testCleanHtml() throws IOException { File ff = new File(testAdapterRoot, "clean.html"); LagartoParser lagartoParser = new LagartoParser(FileUtil.readString(ff)); StringBuilder out = new StringBuilder(); TagWriter tagWriter = new TagWriter(out); StripHtmlTagAdapter stripHtmlTagAdapter = new StripHtmlTagAdapter(tagWriter); lagartoParser.parse(stripHtmlTagAdapter); ff = new File(testAdapterRoot, "clean-out.html"); assertEquals(FileUtil.readString(ff), out.toString()); }
private NodeSelector createNodeFilter() throws IOException { File file = new File(testDataRoot, "one.html"); String html = FileUtil.readString(file); return new NodeSelector(new LagartoDOMBuilder().parse(html)); } }
@Test void testGroupOfSelectors() throws IOException { File file = new File(testDataRoot, "one.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); List<Node> nodes = new NodeSelector(document).select("em, b, b"); assertEquals(9, nodes.size()); assertTrue(document.check()); }
@Test void testClassWithTabs() throws IOException { File file = new File(testDataRoot, "class-tabs.html"); String htmlContent = FileUtil.readString(file); Document document = new LagartoDOMBuilder().parse(htmlContent); List<Node> nodes = new NodeSelector(document).select(".hey"); assertEquals(1, nodes.size()); Node n = nodes.get(0); assertEquals("div", n.getNodeName()); assertEquals("jodd", n.getAttribute("id")); }
@Test 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; }); }
@Test 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; }); }
@Test void testIssue23_0() throws IOException { 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()); }
@Test void testIssue23_1() throws IOException { 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()); }
@Test void testUpheaWebXml() throws IOException { File file = new File(testDataRoot, "uphea-web.xml"); String xmlContent = FileUtil.readString(file); LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); lagartoDOMBuilder.enableXmlMode(); Document doc = lagartoDOMBuilder.parse(xmlContent); xmlContent = StringUtil.removeChars(xmlContent, "\n\r\t"); assertEquals(xmlContent, doc.getHtml()); assertTrue(doc.check()); }
@Test void testXmlAndSingleQuotes() throws IOException { File file = new File(testDataRoot, "people2.xml"); String xmlContent = FileUtil.readString(file); LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); lagartoDOMBuilder.enableXmlMode(); Document xml = lagartoDOMBuilder.parse(xmlContent); XmlDeclaration xmlDeclaration = (XmlDeclaration) xml.getChild(0); assertEquals("1.0", xmlDeclaration.getVersion()); assertEquals("UTF-8", xmlDeclaration.getEncoding()); } }
@Test void testPreserveCC() throws IOException { File file = new File(testDataRoot, "preserve-cc.html"); String expectedResult = FileUtil.readString(file); Jerry.JerryParser jerryParser = new Jerry.JerryParser(); ((LagartoDOMBuilder) jerryParser.getDOMBuilder()).enableHtmlMode(); ((LagartoDOMBuilder) jerryParser.getDOMBuilder()).getConfig().setEnableConditionalComments(false); Jerry jerry = jerryParser.parse(expectedResult); String result = jerry.html(); assertEquals(expectedResult, result); }