Search in sources :

Example 1 with XMLDocument

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();
        }
    }
}
Also used : Context(net.sourceforge.htmlunit.corejs.javascript.Context) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HTMLDocument(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument) XMLDocument(com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) DocumentProxy(com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy) TopLevelWindow(com.gargoylesoftware.htmlunit.TopLevelWindow)

Example 2 with XMLDocument

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;
}
Also used : XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) XMLDocument(com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 3 with XMLDocument

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;
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HTMLDocument(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument) HTMLParser(com.gargoylesoftware.htmlunit.html.parser.HTMLParser) WebClient(com.gargoylesoftware.htmlunit.WebClient) XMLDocument(com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Aggregations

XMLDocument (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)2 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)2 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)1 StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)1 TopLevelWindow (com.gargoylesoftware.htmlunit.TopLevelWindow)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 HTMLParser (com.gargoylesoftware.htmlunit.html.parser.HTMLParser)1 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 DocumentProxy (com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy)1 Context (net.sourceforge.htmlunit.corejs.javascript.Context)1