use of com.gargoylesoftware.htmlunit.html.XHtmlPage in project htmlunit by HtmlUnit.
the class HTMLParserTest method tableWithoutColgroup.
/**
* @throws Exception failure
*/
@Test
public void tableWithoutColgroup() throws Exception {
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "</head>\n" + "<body>\n" + " <table><col width='7'/><col width='1'/><tbody><tr><td>seven</td><td>One</td></tr></tbody></table>\n" + "</body></html>";
final WebClient webClient = getWebClient();
final WebResponse webResponse = new StringWebResponse(html, URL_FIRST);
final XHtmlPage page = new XHtmlPage(webResponse, webClient.getCurrentWindow());
webClient.getCurrentWindow().setEnclosedPage(page);
webClient.getPageCreator().getHtmlParser().parse(webResponse, page, true, false);
final DomElement col = page.getElementsByTagName("col").get(0);
assertEquals(col.getParentNode().getNodeName(), HtmlTableColumnGroup.TAG_NAME);
}
use of com.gargoylesoftware.htmlunit.html.XHtmlPage in project htmlunit by HtmlUnit.
the class DefaultPageCreator method createXHtmlPage.
/**
* Creates an XHtmlPage for this WebResponse.
*
* @param webResponse the page's source
* @param webWindow the WebWindow to place the HtmlPage in
* @return the newly created XHtmlPage
* @throws IOException if the page could not be created
*/
protected XHtmlPage createXHtmlPage(final WebResponse webResponse, final WebWindow webWindow) throws IOException {
final XHtmlPage page = new XHtmlPage(webResponse, webWindow);
webWindow.setEnclosedPage(page);
htmlParser_.parse(webResponse, page, true, false);
return page;
}
use of com.gargoylesoftware.htmlunit.html.XHtmlPage in project htmlunit by HtmlUnit.
the class WebClient method loadHtmlCodeIntoCurrentWindow.
/**
* Parses the given XHtml code string and loads the resulting XHtmlPage into
* the current window.
*
* @param htmlCode the html code as string
* @return the HtmlPage
* @throws IOException in case of error
*/
public HtmlPage loadHtmlCodeIntoCurrentWindow(final String htmlCode) throws IOException {
final HTMLParser htmlParser = getPageCreator().getHtmlParser();
final WebWindow webWindow = getCurrentWindow();
final StringWebResponse webResponse = new StringWebResponse(htmlCode, new URL("http://htmlunit.sourceforge.net/dummy.html"));
final HtmlPage page = new HtmlPage(webResponse, webWindow);
webWindow.setEnclosedPage(page);
htmlParser.parse(webResponse, page, true, false);
return page;
}
use of com.gargoylesoftware.htmlunit.html.XHtmlPage in project htmlunit by HtmlUnit.
the class WebClient method loadXHtmlCodeIntoCurrentWindow.
/**
* Parses the given XHtml code string and loads the resulting XHtmlPage into
* the current window.
*
* @param xhtmlCode the xhtml code as string
* @return the XHtmlPage
* @throws IOException in case of error
*/
public XHtmlPage loadXHtmlCodeIntoCurrentWindow(final String xhtmlCode) throws IOException {
final HTMLParser htmlParser = getPageCreator().getHtmlParser();
final WebWindow webWindow = getCurrentWindow();
final StringWebResponse webResponse = new StringWebResponse(xhtmlCode, new URL("http://htmlunit.sourceforge.net/dummy.html"));
final XHtmlPage page = new XHtmlPage(webResponse, webWindow);
webWindow.setEnclosedPage(page);
htmlParser.parse(webResponse, page, true, false);
return page;
}
use of com.gargoylesoftware.htmlunit.html.XHtmlPage in project htmlunit by HtmlUnit.
the class HtmlUnitNekoDOMBuilder method startElement.
/**
* {@inheritDoc}
*/
@Override
public void startElement(String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException {
if (snippetStartNodeOverwritten_) {
snippetStartNodeOverwritten_ = false;
return;
}
handleCharacters();
final String tagLower = localName.toLowerCase(Locale.ROOT);
if (page_.isParsingHtmlSnippet() && ("html".equals(tagLower) || "body".equals(tagLower))) {
return;
}
if ("head".equals(tagLower)) {
if (headParsed_ == HeadParsed.YES || page_.isParsingHtmlSnippet()) {
return;
}
headParsed_ = lastTagWasSynthesized_ ? HeadParsed.SYNTHESIZED : HeadParsed.YES;
}
if (namespaceURI != null) {
namespaceURI = namespaceURI.trim();
} else // add a head if none was there
if (headParsed_ == HeadParsed.NO && ("body".equals(tagLower) || "frameset".equals(tagLower))) {
final ElementFactory factory = htmlParser_.getElementFactory(page_, null, "head", insideSvg_, false);
final DomElement newElement = factory.createElement(page_, "head", null);
appendChild(currentNode_, newElement);
headParsed_ = HeadParsed.SYNTHESIZED;
}
// If we're adding a body element, keep track of any temporary synthetic ones
// that we may have had to create earlier (for document.write(), for example).
HtmlBody oldBody = null;
if ("body".equals(qName) && page_.getBody() instanceof HtmlBody) {
oldBody = (HtmlBody) page_.getBody();
}
// end tag.
if ("form".equals(tagLower)) {
formWaitingForLostChildren_ = null;
}
// Add the new node.
if (!(page_ instanceof XHtmlPage) && Html.XHTML_NAMESPACE.equals(namespaceURI)) {
namespaceURI = null;
}
final ElementFactory factory = htmlParser_.getElementFactory(page_, namespaceURI, qName, insideSvg_, false);
if (factory == HtmlUnitNekoHtmlParser.SVG_FACTORY) {
namespaceURI = Html.SVG_NAMESPACE;
}
final DomElement newElement = factory.createElementNS(page_, namespaceURI, qName, atts, true);
newElement.setStartLocation(locator_.getLineNumber(), locator_.getColumnNumber());
// parse can't replace everything as it does not buffer elements while parsing
addNodeToRightParent(currentNode_, newElement);
if ("svg".equals(tagLower)) {
insideSvg_ = true;
}
// remove the old body and move its children to the real body element we just added.
if (oldBody != null) {
oldBody.quietlyRemoveAndMoveChildrenTo(newElement);
}
if ("body".equals(tagLower)) {
body_ = (HtmlElement) newElement;
} else if ("meta".equals(tagLower) && page_.hasFeature(META_X_UA_COMPATIBLE)) {
final HtmlMeta meta = (HtmlMeta) newElement;
if ("X-UA-Compatible".equals(meta.getHttpEquivAttribute())) {
final String content = meta.getContentAttribute();
if (content.startsWith("IE=")) {
final String mode = content.substring(3).trim();
final int version = page_.getWebClient().getBrowserVersion().getBrowserVersionNumeric();
try {
int value = Integer.parseInt(mode);
if (value > version) {
value = version;
}
((HTMLDocument) page_.getScriptableObject()).forceDocumentMode(value);
} catch (final Exception e) {
// ignore
}
}
}
} else if (createdByJavascript_ && "script".equals(tagLower)) {
final ScriptElement script = (ScriptElement) newElement;
script.markAsCreatedByDomParser();
}
currentNode_ = newElement;
stack_.push(currentNode_);
}
Aggregations