Search in sources :

Example 1 with HTMLLinkElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement in project htmlunit by HtmlUnit.

the class HtmlLink method executeEvent.

private void executeEvent(final String type) {
    final Object scriptable = getScriptableObject();
    final HTMLLinkElement link = (HTMLLinkElement) scriptable;
    final Event event = new Event(this, type);
    link.executeEventLocally(event);
}
Also used : HTMLLinkElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event)

Example 2 with HTMLLinkElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement in project htmlunit by HtmlUnit.

the class HtmlLink method onAllChildrenAddedToPage.

/**
 * {@inheritDoc}
 */
@Override
public void onAllChildrenAddedToPage(final boolean postponed) {
    if (getOwnerDocument() instanceof XmlPage) {
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Link node added: " + asXml());
    }
    if (!isStyleSheetLink()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Link type '" + getRelAttribute() + "' not supported (" + asXml().replaceAll("[\\r\\n]", "") + ").");
        }
        return;
    }
    final WebClient webClient = getPage().getWebClient();
    if (!webClient.getOptions().isCssEnabled()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stylesheet Link found but ignored because css support is disabled (" + asXml().replaceAll("[\\r\\n]", "") + ").");
        }
        return;
    }
    if (!webClient.isJavaScriptEngineEnabled()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stylesheet Link found but ignored because javascript engine is disabled (" + asXml().replaceAll("[\\r\\n]", "") + ").");
        }
        return;
    }
    final PostponedAction action = new PostponedAction(getPage(), "Loading of link " + this) {

        @Override
        public void execute() {
            final HTMLLinkElement linkElem = HtmlLink.this.getScriptableObject();
            // force loading, caching inside the link
            linkElem.getSheet();
        }
    };
    final AbstractJavaScriptEngine<?> engine = webClient.getJavaScriptEngine();
    if (postponed) {
        engine.addPostponedAction(action);
    } else {
        try {
            action.execute();
        } catch (final RuntimeException e) {
            throw e;
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : HTMLLinkElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) PostponedAction(com.gargoylesoftware.htmlunit.javascript.PostponedAction) WebClient(com.gargoylesoftware.htmlunit.WebClient) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

HTMLLinkElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 PostponedAction (com.gargoylesoftware.htmlunit.javascript.PostponedAction)1 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)1 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1