Example usage for com.google.gwt.dom.client LinkElement as

List of usage examples for com.google.gwt.dom.client LinkElement as

Introduction

In this page you can find the example usage for com.google.gwt.dom.client LinkElement as.

Prototype

public static LinkElement as(Element elem) 

Source Link

Document

Assert that the given Element is compatible with this class and automatically typecast it.

Usage

From source file:com.vaadin.client.ResourceLoader.java

License:Apache License

/**
 * Creates a new resource loader. You should generally not create you own
 * resource loader, but instead use {@link ResourceLoader#get()} to get an
 * instance./*from  ww w .ja  va 2s  .  c om*/
 */
protected ResourceLoader() {
    Document document = Document.get();
    head = document.getElementsByTagName("head").getItem(0);

    // detect already loaded scripts and stylesheets
    NodeList<Element> scripts = document.getElementsByTagName("script");
    for (int i = 0; i < scripts.getLength(); i++) {
        ScriptElement element = ScriptElement.as(scripts.getItem(i));
        String src = element.getSrc();
        if (src != null && src.length() != 0) {
            loadedResources.add(src);
        }
    }

    NodeList<Element> links = document.getElementsByTagName("link");
    for (int i = 0; i < links.getLength(); i++) {
        LinkElement linkElement = LinkElement.as(links.getItem(i));
        String rel = linkElement.getRel();
        String href = linkElement.getHref();
        if ("stylesheet".equalsIgnoreCase(rel) && href != null && href.length() != 0) {
            loadedResources.add(href);
        }
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Reads CSS strings and resources injected by {@link Styles#inject} from
 * the UIDL stream./* w  w w. ja  v  a  2 s  .c o  m*/
 * 
 * @param uidl
 *            The uidl which contains "css-resource" and "css-string" tags
 */
private void injectCSS(UIDL uidl) {

    /*
     * Search the UIDL stream for CSS resources and strings to be injected.
     */
    for (Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
        UIDL cssInjectionsUidl = (UIDL) it.next();

        // Check if we have resources to inject
        if (cssInjectionsUidl.getTag().equals("css-resource")) {
            String url = getWidget().connection.translateVaadinUri(cssInjectionsUidl.getStringAttribute("url"));
            LinkElement link = LinkElement.as(DOM.createElement(LinkElement.TAG));
            link.setRel("stylesheet");
            link.setHref(url);
            link.setType("text/css");
            getHead().appendChild(link);
            // Check if we have CSS string to inject
        } else if (cssInjectionsUidl.getTag().equals("css-string")) {
            for (Iterator<?> it2 = cssInjectionsUidl.getChildIterator(); it2.hasNext();) {
                StyleInjector.injectAtEnd((String) it2.next());
                StyleInjector.flush();
            }
        }
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Internal helper for removing any stylesheet with the given URL
 * /*from  w  w  w.j  av  a  2 s. co m*/
 * @since 7.3
 * @param url
 *            the url to match with existing stylesheets
 */
private void removeStylesheet(String url) {
    NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG);
    for (int i = 0; i < linkTags.getLength(); i++) {
        LinkElement link = LinkElement.as(linkTags.getItem(i));
        if (!"stylesheet".equals(link.getRel())) {
            continue;
        }
        if (!"text/css".equals(link.getType())) {
            continue;
        }
        if (url.equals(link.getHref())) {
            getHead().removeChild(link);
        }
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

/**
 * Finds a link tag for a style sheet with the given URL
 * /*from w  ww  .  j a v  a  2 s.  co  m*/
 * @since 7.3
 * @param url
 *            the URL of the style sheet
 * @return the link tag or null if no matching link tag was found
 */
private LinkElement findStylesheetTag(String url) {
    NodeList<Element> linkTags = getHead().getElementsByTagName(LinkElement.TAG);
    for (int i = 0; i < linkTags.getLength(); i++) {
        final LinkElement link = LinkElement.as(linkTags.getItem(i));
        if ("stylesheet".equals(link.getRel()) && "text/css".equals(link.getType())
                && url.equals(link.getHref())) {
            return link;
        }
    }
    return null;
}

From source file:edu.caltech.ipac.firefly.ui.TitleFlasher.java

private static void findFavIcon() {
    Document doc = Document.get();
    NodeList<Element> eleList = doc.getElementsByTagName("link");
    for (int i = 0; (i < eleList.getLength()); i++) {
        Element e = eleList.getItem(i);
        LinkElement le = LinkElement.as(e);
        if ("image/x-icon".equals(le.getType())) {
            if (!StringUtils.isEmpty(le.getHref())) {
                favIconElement = le;/*  www. j ava 2 s .  c  om*/
                String favIcon = le.getHref();
                break;
            }
        }
    }
}

From source file:fr.putnami.pwt.core.theme.client.DefaultThemeController.java

License:Open Source License

/**
 * Removes all link tags in the head if not initialized.
 *//*from  w  w  w.  j a v  a 2  s  .  c o  m*/
private void removeCssLinks() {
    if (this.isInit) {
        return;
    }
    this.isInit = true;
    // Remove all existing link element
    NodeList<Element> links = this.getHead().getElementsByTagName(LinkElement.TAG);
    int size = links.getLength();
    for (int i = 0; i < size; i++) {
        LinkElement elem = LinkElement.as(links.getItem(0));
        if ("stylesheet".equals(elem.getRel())) {
            elem.removeFromParent();
        }
    }
}