use of com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method initialize.
/**
* Initializes this window.
* @param webWindow the web window corresponding to this window
* @param pageToEnclose the page that will become the enclosing page
*/
public void initialize(final WebWindow webWindow, final Page pageToEnclose) {
webWindow_ = webWindow;
webWindow_.setScriptableObject(this);
windowProxy_ = new WindowProxy(webWindow_);
if (pageToEnclose instanceof XmlPage) {
document_ = new XMLDocument();
} else {
document_ = new HTMLDocument();
}
document_.setParentScope(this);
document_.setPrototype(getPrototype(document_.getClass()));
document_.setWindow(this);
if (pageToEnclose instanceof SgmlPage) {
final SgmlPage page = (SgmlPage) pageToEnclose;
document_.setDomNode(page);
if (page.isHtmlPage()) {
final HtmlPage htmlPage = (HtmlPage) page;
htmlPage.addAutoCloseable(this);
}
}
documentProxy_ = new DocumentProxy(webWindow_);
navigator_ = new Navigator();
navigator_.setParentScope(this);
navigator_.setPrototype(getPrototype(navigator_.getClass()));
screen_ = new Screen(getWebWindow().getScreen());
screen_.setParentScope(this);
screen_.setPrototype(getPrototype(screen_.getClass()));
history_ = new History();
history_.setParentScope(this);
history_.setPrototype(getPrototype(history_.getClass()));
location_ = new Location();
location_.setParentScope(this);
location_.setPrototype(getPrototype(location_.getClass()));
location_.initialize(this, pageToEnclose);
final Console console = new Console();
console.setWebWindow(webWindow_);
console.setParentScope(this);
console.setPrototype(getPrototype(console.getClass()));
console_ = console;
applicationCache_ = new ApplicationCache();
applicationCache_.setParentScope(this);
applicationCache_.setPrototype(getPrototype(applicationCache_.getClass()));
// like a JS new Object()
final Context ctx = Context.getCurrentContext();
controllers_ = ctx.newObject(this);
if (webWindow_ instanceof TopLevelWindow) {
final WebWindow opener = ((TopLevelWindow) webWindow_).getOpener();
if (opener != null) {
opener_ = opener.getScriptableObject();
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument in project htmlunit by HtmlUnit.
the class DOMImplementation method createDocument.
/**
* Creates an {@link XMLDocument}.
*
* @param namespaceURI the URI that identifies an XML namespace
* @param qualifiedName the qualified name of the document to instantiate
* @param doctype the document types of the document
* @return the newly created {@link XMLDocument}
*/
@JsxFunction
public XMLDocument createDocument(final String namespaceURI, final String qualifiedName, final DocumentType doctype) {
final XMLDocument document = new XMLDocument(getWindow().getWebWindow());
document.setParentScope(getParentScope());
document.setPrototype(getPrototype(document.getClass()));
if (qualifiedName != null && !qualifiedName.isEmpty()) {
final XmlPage page = (XmlPage) document.getDomNodeOrDie();
page.appendChild(page.createElementNS("".equals(namespaceURI) ? null : namespaceURI, qualifiedName));
}
return document;
}
use of com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument in project htmlunit by HtmlUnit.
the class DOMParser method parseFromString.
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* Parses the given Unicode string into a DOM document.
* @param scriptable the ScriptableObject this belongs to
* @param str the Unicode string to be parsed
* @param type the MIME type of the string -
* <code>text/html</code>, <code>text/xml</code>, <code>application/xml</code>,
* <code>application/xhtml+xml</code>, <code>image/svg+xml</code>. Must not be {@code null}.
* @return the generated document
* @throws IOException in case of error
*/
public static Document parseFromString(final HtmlUnitScriptable scriptable, final String str, final Object type) throws IOException {
if (type == null || Undefined.isUndefined(type)) {
throw Context.reportRuntimeError("Missing 'type' parameter");
}
if (MimeType.TEXT_XML.equals(type) || MimeType.APPLICATION_XML.equals(type) || MimeType.APPLICATION_XHTML.equals(type) || "image/svg+xml".equals(type)) {
final XMLDocument document = new XMLDocument();
document.setParentScope(scriptable.getParentScope());
document.setPrototype(scriptable.getPrototype(XMLDocument.class));
document.loadXML(str);
return document;
}
if (MimeType.TEXT_HTML.equals(type)) {
final WebWindow webWindow = scriptable.getWindow().getWebWindow();
final WebClient webClient = webWindow.getWebClient();
final WebResponse webResponse = new StringWebResponse(str, webWindow.getEnclosedPage().getUrl());
// a similar impl is in
// com.gargoylesoftware.htmlunit.javascript.host.dom.DOMImplementation.createHTMLDocument(Object)
final HtmlPage page = new HtmlPage(webResponse, webWindow);
page.setEnclosingWindow(null);
final Window window = webWindow.getScriptableObject();
// document knows the window but is not the windows document
final HTMLDocument document = new HTMLDocument();
document.setParentScope(window);
document.setPrototype(window.getPrototype(document.getClass()));
// document.setWindow(window);
document.setDomNode(page);
final HTMLParser htmlParser = webClient.getPageCreator().getHtmlParser();
htmlParser.parse(webResponse, page, false, true);
return page.getScriptableObject();
}
return null;
}
Aggregations