com.gargoylesoftware.htmlunit.Cache Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HTMLStyleElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the associated sheet.
 * @see <a href="http://www.xulplanet.com/references/objref/HTMLStyleElement.html">Mozilla doc</a>
 * @return the sheet
 */
@JsxGetter
public CSSStyleSheet getSheet() {
    if (sheet_ != null) {
        return sheet_;
    }

    final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
    final String css = style.getTextContent();

    final Cache cache = getWindow().getWebWindow().getWebClient().getCache();
    final CSSStyleSheetImpl cached = cache.getCachedStyleSheet(css);
    final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest()
            .getUrl().toExternalForm();
    if (cached != null) {
        sheet_ = new CSSStyleSheet(this, cached, uri);
    }
    else {
        sheet_ = new CSSStyleSheet(this, css, uri);
        cache.cache(css, sheet_.getWrappedSheet());
    }

    return sheet_;
}
 
Example #2
Source File: HTMLStyleElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the associated sheet.
 * @see <a href="http://www.xulplanet.com/references/objref/HTMLStyleElement.html">Mozilla doc</a>
 * @return the sheet
 */
@JsxGetter
public CSSStyleSheet getSheet() {
    if (sheet_ != null) {
        return sheet_;
    }

    final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
    final String css = style.getTextContent();

    final Cache cache = getWindow().getWebWindow().getWebClient().getCache();
    final org.w3c.dom.css.CSSStyleSheet cached = cache.getCachedStyleSheet(css);
    final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest()
            .getUrl().toExternalForm();
    if (cached != null) {
        sheet_ = new CSSStyleSheet(this, cached, uri);
    }
    else {
        final InputSource source = new InputSource(new StringReader(css));
        sheet_ = new CSSStyleSheet(this, source, uri);
        cache.cache(css, sheet_.getWrappedSheet());
    }

    return sheet_;
}