@Ignore @Test(expected = GadgetException.class) public void testEmptyDocument() throws Exception { boolean exceptionCaught = false; parser.parseDom(""); }
@Override public Document parseDom(String source) throws GadgetException { // TODO: Add support for caching the DOM after evaluation. return parseDomImpl(source); }
@Before public void setUp() throws Exception { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // Require the traversal API DOMImplementation domImpl = registry.getDOMImplementation("XML 1.0 Traversal 2.0"); parser = new VanillaCajaHtmlParser(domImpl, true); serializer = new VanillaCajaHtmlSerializer(); }
@Override protected Document parseDomImpl(String source) throws GadgetException { MessageQueue mq = new SimpleMessageQueue(); try { DomParser parser = getDomParser(source, mq); Document doc = parser.parseDocument().getOwnerDocument(); VanillaCajaHtmlSerializer serializer = new VanillaCajaHtmlSerializer(); HtmlSerialization.attach(doc, serializer, null); return doc; } catch (ParseException e) { throw new GadgetException(GadgetException.Code.HTML_PARSE_ERROR, e.getCajaMessage().toString(), HttpResponse.SC_INTERNAL_SERVER_ERROR); } catch (NullPointerException e) { throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e); } }
@Before public void setUp() throws Exception { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // Require the traversal API DOMImplementation domImpl = registry.getDOMImplementation("XML 1.0 Traversal 2.0"); parser = new VanillaCajaHtmlParser(domImpl, true); serializer = new VanillaCajaHtmlSerializer(); }
@Ignore @Test(expected = GadgetException.class) public void testEmptyDocument() throws Exception { boolean exceptionCaught = false; parser.parseDom(""); }
@Before public void setUp() throws Exception { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // Require the traversal API DOMImplementation domImpl = registry.getDOMImplementation("XML 1.0 Traversal 2.0"); parser = new VanillaCajaHtmlParser(domImpl, true); serializer = new VanillaCajaHtmlSerializer(); }
@Test public void testBadTagBalancing() throws Exception { String html = "<html><head><script src=\"1.js\"></head>" + "<body></body></html>"; String expected = "<html><head><script src=\"1.js\">" + "</head><body></body></html>" + "</script></head><body></body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); } }
@Before public void setUp() throws Exception { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); // Require the traversal API DOMImplementation domImpl = registry.getDOMImplementation("XML 1.0 Traversal 2.0"); parser = new VanillaCajaHtmlParser(domImpl, true); serializer = new VanillaCajaHtmlSerializer(); }
@Test public void testNoHead() throws Exception { String html = "<html><body><a href=\"hello\"></a></body></html>"; String expected = "<html><head></head><body><a href=\"hello\"></a>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testUnbalanced() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><p><embed></p></embed></body></html>"; String expected = "<html><head><script src=\"1.js\"></script></head>" + "<body><p><embed /></p>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testParseAndSerialize() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\"></a></body></html>"; String expected = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\"></a>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testParseAndSerializeNonASCIINotEscaped() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\">\\u200E\\u200F\\u2010\\u0410</a>" + "</body></html>"; assertEquals(html, serializer.serialize(parser.parseDom(html))); }
@Test public void testNonHtml() throws Exception { String html = "var hello=\"world\";"; String expected = "<html><head></head><body>var hello="world";" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testNonHtml() throws Exception { String html = "var hello=\"world\";"; String expected = "<html><head></head><body>var hello="world";" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testBadTagBalancing() throws Exception { String html = "<html><head><script src=\"1.js\"></head>" + "<body></body></html>"; String expected = "<html><head><script src=\"1.js\">" + "</head><body></body></html>" + "</script></head><body></body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); } }
@Test public void testUnbalanced() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><p><embed></p></embed></body></html>"; String expected = "<html><head><script src=\"1.js\"></script></head>" + "<body><p><embed /></p>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testParseAndSerialize() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\"></a></body></html>"; String expected = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\"></a>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }
@Test public void testParseAndSerializeNonASCIINotEscaped() throws Exception { String html = "<html><head><script src=\"1.js\"></script></head>" + "<body><a href=\"hello\">\\u200E\\u200F\\u2010\\u0410</a>" + "</body></html>"; assertEquals(html, serializer.serialize(parser.parseDom(html))); }
@Test public void testNoHead() throws Exception { String html = "<html><body><a href=\"hello\"></a></body></html>"; String expected = "<html><head></head><body><a href=\"hello\"></a>" + "</body></html>"; assertEquals(expected, serializer.serialize(parser.parseDom(html))); }