Search in sources :

Example 31 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class XSLTProcessor method transform.

private void transform(final Node source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtils.appendChild(parentPage, parent, children.item(i), true);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}
Also used : DomText(com.gargoylesoftware.htmlunit.html.DomText) Node(com.gargoylesoftware.htmlunit.javascript.host.dom.Node) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) NodeList(org.w3c.dom.NodeList) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 32 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class HtmlSerializerNormalizedText method appendDomNode.

/**
 * Process {@link HtmlHiddenInput}.
 *
 * @param builder the StringBuilder to add to
 * @param domNode the target to process
 */
protected void appendDomNode(final HtmlSerializerTextBuilder builder, final DomNode domNode) {
    boolean block = false;
    if (!(domNode instanceof HtmlBody)) {
        final SgmlPage page = domNode.getPage();
        final WebWindow window = page.getEnclosingWindow();
        if (page != null && // TODO
        page.getWebClient().isJavaScriptEngineEnabled() && window.getWebClient().getOptions().isCssEnabled()) {
            if (domNode instanceof DomElement) {
                final String display = window.getComputedStyle((DomElement) domNode, null).getDisplay();
                block = "block".equals(display);
            }
        } else if (domNode instanceof HtmlElement) {
            block = DisplayStyle.BLOCK == ((HtmlElement) domNode).getDefaultStyleDisplay();
        }
    }
    if (block) {
        builder.appendBlockSeparator();
    }
    appendChildren(builder, domNode);
    if (block) {
        builder.appendBlockSeparator();
    }
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlBody(com.gargoylesoftware.htmlunit.html.HtmlBody) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Example 33 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class HtmlSerializerVisibleText method appendInlineFrame.

/**
 * Process {@link HtmlInlineFrame}.
 *
 * @param builder the StringBuilder to add to
 * @param htmlInlineFrame the target to process
 * @param mode the {@link Mode} to use for processing
 */
protected void appendInlineFrame(final HtmlSerializerTextBuilder builder, final HtmlInlineFrame htmlInlineFrame, final Mode mode) {
    if (isDisplayed(htmlInlineFrame)) {
        builder.appendBlockSeparator();
        final Page page = htmlInlineFrame.getEnclosedPage();
        if (page instanceof SgmlPage) {
            builder.append(((SgmlPage) page).asNormalizedText(), mode);
        }
        builder.appendBlockSeparator();
    }
}
Also used : SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) Page(com.gargoylesoftware.htmlunit.Page)

Example 34 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class XmlSerializer method asXml.

/**
 * @param node a node
 * @return the xml representation according to the setting of this serializer
 * @throws IOException in case of problem saving resources
 */
public String asXml(final DomElement node) throws IOException {
    builder_.setLength(0);
    indent_.setLength(0);
    final SgmlPage page = node.getPage();
    if (null != page && page.isHtmlPage()) {
        final Charset charsetName = page.getCharset();
        if (charsetName != null && node instanceof HtmlHtml) {
            builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>\n");
        }
    }
    printXml(node);
    final String response = builder_.toString();
    builder_.setLength(0);
    return response;
}
Also used : SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) Charset(java.nio.charset.Charset)

Example 35 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class ScriptElementSupport method isExecutionNeeded.

/**
 * Indicates if script execution is necessary and/or possible.
 *
 * @param element the element
 * @param ignoreAttachedToPage don't do the isAttachedToPage check
 * @param ignorePageIsAncestor don't do the element.getPage().isAncestorOf(element) check
 * @return {@code true} if the script should be executed
 */
private static boolean isExecutionNeeded(final DomElement element, final boolean ignoreAttachedToPage, final boolean ignorePageIsAncestor) {
    final ScriptElement script = (ScriptElement) element;
    if (script.isExecuted() || script.wasCreatedByDomParser()) {
        return false;
    }
    if (!ignoreAttachedToPage && !element.isAttachedToPage()) {
        return false;
    }
    // If JavaScript is disabled, we don't need to execute.
    final SgmlPage page = element.getPage();
    if (!page.getWebClient().isJavaScriptEnabled()) {
        return false;
    }
    // If innerHTML or outerHTML is being parsed
    final HtmlPage htmlPage = element.getHtmlPageOrNull();
    if (htmlPage != null && htmlPage.isParsingHtmlSnippet()) {
        return false;
    }
    // If the script node is nested in an iframe, a noframes, or a noscript node, we don't need to execute.
    for (DomNode o = element; o != null; o = o.getParentNode()) {
        if (o instanceof HtmlInlineFrame || o instanceof HtmlNoFrames) {
            return false;
        }
    }
    // because another script set window.location.href), and we don't need to execute.
    if (page.getEnclosingWindow() != null && page.getEnclosingWindow().getEnclosedPage() != page) {
        return false;
    }
    // If the script language is not JavaScript, we can't execute.
    final String t = element.getAttributeDirect("type");
    final String l = element.getAttributeDirect("language");
    if (!isJavaScript(element, t, l)) {
        // Browsers are also not warning about this.
        if (LOG.isDebugEnabled()) {
            LOG.debug("Script is not JavaScript (type: '" + t + "', language: '" + l + "'). Skipping execution.");
        }
        return false;
    }
    // If it isn't yet part of the page, don't execute the script; it's probably just being cloned.
    return ignorePageIsAncestor || element.getPage().isAncestorOf(element);
}
Also used : SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Aggregations

SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)38 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)10 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)7 DomDocumentFragment (com.gargoylesoftware.htmlunit.html.DomDocumentFragment)5 DomText (com.gargoylesoftware.htmlunit.html.DomText)5 Page (com.gargoylesoftware.htmlunit.Page)4 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)4 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)3 Node (com.gargoylesoftware.htmlunit.javascript.host.dom.Node)3 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)3 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)2 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)2 JsxConstructor (com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)2 DocumentFragment (com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentFragment)2 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)2 PointerEvent (com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent)2