Example usage for com.google.gwt.dom.client MetaElement getContent

List of usage examples for com.google.gwt.dom.client MetaElement getContent

Introduction

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

Prototype

public String getContent() 

Source Link

Document

Associated information.

Usage

From source file:cc.kune.common.client.utils.MetaUtils.java

License:GNU Affero Public License

/**
 * Get the value of meta information writen in the html page. The meta
 * information is a html tag with name of meta usually placed inside the the
 * head section with two attributes: id and content. For example:
 * /* w ww  .  j  a  va  2s .c  om*/
 * <code>&lt;meta name="name" value="userName" /&gt;</code>
 *
 * @param name the name
 * @return the value of the attribute 'content' or null if not found
 */
public static String get(final String name) {
    final NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        final MetaElement metaTag = ((MetaElement) tags.getItem(i));
        if (metaTag.getName().equals(name)) {
            return metaTag.getContent();
        }
    }
    return null;
}

From source file:com.arcbees.facebook.client.JavaScriptFacebook.java

License:Apache License

@Override
public void injectFacebookApi(final FacebookCallback facebookCallback) {

    String locale = "en_US";

    // get the correct locale from meta tag gwt:property facebooklocale
    final NodeList<Element> metas = Document.get().getElementsByTagName("meta");

    for (int i = 0; i < metas.getLength(); i++) {
        final MetaElement m = MetaElement.as(metas.getItem(i));

        if ("gwt:property".equals(m.getName())) {
            String content = m.getContent();
            if (content.contains("facebooklocale")) {
                locale = content.replaceFirst(".*\\=", "").trim();
            }//from  ww w  .  j ava 2s .c o  m
        }
    }

    Element firstElement = Document.get().getBody().getFirstChildElement();

    Element fbRoot = Document.get().createDivElement();
    fbRoot.setId(FB_ROOT);

    firstElement.getParentNode().insertBefore(fbRoot, firstElement);

    ScriptElement fbScript = Document.get().createScriptElement();
    fbScript.setSrc(FB_SCRIPT_SRC1 + locale + FB_SCRIPT_SRC2);
    fbScript.setType(FB_SCRIPT_TYPE);

    fbRoot.getParentNode().insertAfter(fbScript, fbRoot);

    Timer ensureFbIsLoaded = new Timer() {
        @Override
        public void run() {
            if (isLoaded()) {
                facebookCallback.onSuccess();

                cancel();
            }
        }
    };

    ensureFbIsLoaded.scheduleRepeating(100);
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findTitle() {
    mTitle = "";/*from  w  ww  . ja  v  a  2  s.co  m*/

    if (mAllMeta.getLength() == 0)
        return;

    // Make sure there's a <title> element.
    NodeList<Element> titles = mRoot.getElementsByTagName("TITLE");
    if (titles.getLength() == 0)
        return;

    // Extract title text from meta tag with "title" as name.
    for (int i = 0; i < mAllMeta.getLength(); i++) {
        MetaElement meta = MetaElement.as(mAllMeta.getItem(i));
        if (meta.getName().equalsIgnoreCase("title")) {
            mTitle = meta.getContent();
            break;
        }
    }
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findDate() {
    mDate = "";/*from ww  w .ja va  2  s.  c o  m*/

    // Get date from any element that includes the "dateline" class.
    Element elem = DomUtil.getFirstElementWithClassName(mRoot, "dateline");
    if (elem != null) {
        // Use javascript textContent (instead of javascript innerText) to include invisible
        // text.
        mDate = DomUtil.javascriptTextContent(elem);
    } else { // Otherwise, get date from meta tag with "displaydate" as name.
        for (int i = 0; i < mAllMeta.getLength(); i++) {
            MetaElement meta = MetaElement.as(mAllMeta.getItem(i));
            if (meta.getName().equalsIgnoreCase("displaydate")) {
                mDate = meta.getContent();
                break;
            }
        }
    }
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findCopyright() {
    mCopyright = "";

    // Get copyright from meta tag with "copyright" as name.
    for (int i = 0; i < mAllMeta.getLength(); i++) {
        MetaElement meta = MetaElement.as(mAllMeta.getItem(i));
        if (meta.getName().equalsIgnoreCase("copyright")) {
            mCopyright = meta.getContent();
            break;
        }//from  w  ww  .ja va  2  s  .c  o m
    }
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findOptOut() {
    mDoneOptOut = true;//from   w w w.j  av a 2  s. co  m

    // Get optout from meta tag with "IE_RM_OFF" as name.
    for (int i = 0; i < mAllMeta.getLength(); i++) {
        MetaElement meta = MetaElement.as(mAllMeta.getItem(i));
        if (meta.getName().equalsIgnoreCase("IE_RM_OFF")) {
            mOptOut = meta.getContent().equalsIgnoreCase("true");
            break;
        }
    }
}

From source file:com.dom_distiller.client.OpenGraphProtocolParser.java

License:Open Source License

private void parseMetaTags(Element root) {
    NodeList<Element> allMeta = null;
    if (DomUtil.supportQuerySelectorAll(root)) {
        if (doPrefixFiltering) {
            // Attribute selectors with prefix
            // https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
            // TODO(wychen): Test the logic here in Chrome on Android.
            String query = "";
            for (Map.Entry<Prefix, String> entry : mPrefixes.entrySet()) {
                query += "meta[property^=\"" + entry.getValue() + "\"],";
            }//from  w  w  w  . ja va 2  s  . c  o  m
            query = query.substring(0, query.length() - 1);

            allMeta = DomUtil.querySelectorAll(root, query);
        } else {
            allMeta = DomUtil.querySelectorAll(root, "meta[property]");
        }
    } else {
        allMeta = root.getElementsByTagName("META");
    }

    for (int i = 0; i < allMeta.getLength(); i++) {
        MetaElement meta = MetaElement.as(allMeta.getItem(i));
        String property = meta.getAttribute("property").toLowerCase();

        // Only store properties that we care about for distillation.
        for (int j = 0; j < mProperties.length; j++) {
            String prefixWithColon = mPrefixes.get(mProperties[j].mPrefix) + ":";
            // Note that property.equals() won't work here because |mProperties| uses "image:"
            // (IMAGE_STRUCT_PROP_PFX) for all image structured properties, so as to prevent
            // repetitive property name comparison - here and then again in ImageParser.
            if (!property.startsWith(prefixWithColon + mProperties[j].mName))
                continue;
            property = property.substring(prefixWithColon.length());

            boolean addProperty = true;
            if (mProperties[j].mParser != null) {
                addProperty = mProperties[j].mParser.parse(property, meta.getContent(), mPropertyTable);
            }
            if (addProperty)
                mPropertyTable.put(mProperties[j].mName, meta.getContent());
        }
    }
}

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

public static String getGwtProperty(String name) {
    final NodeList<com.google.gwt.dom.client.Element> meta = Document.get().getElementsByTagName("meta");

    for (int i = 0; i < meta.getLength(); i++) {
        final MetaElement m = MetaElement.as(meta.getItem(i));
        if (m != null && "gwt:property".equals(m.getName())) {
            String[] kv = m.getContent().split("=", 2);
            if (kv[0] != null && kv[0].equals(name)) {
                return kv.length > 1 ? kv[1] : "";
            }/*from   w w  w .  j av a  2  s .  co  m*/
        }
    }
    return null;
}

From source file:fr.putnami.pwt.core.service.client.CsrfController.java

License:Open Source License

private void init() {
    NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        MetaElement metaTag = (MetaElement) tags.getItem(i);
        String metaName = metaTag.getName();
        String metaContent = metaTag.getContent();
        if (META_NAME_CSRF_TOKEN.equals(metaName) && !Strings.isNullOrEmpty(metaContent)) {
            this.token = metaContent;
        }//  ww  w. j av  a 2s .c  o m
        if (META_NAME_CSRF_HEADER.equals(META_NAME_CSRF_HEADER) && !Strings.isNullOrEmpty(metaContent)) {
            this.header = metaContent;
        }
    }
}

From source file:org.chromium.distiller.OpenGraphProtocolParser.java

License:Open Source License

private void parseMetaTags(Element root) {
    NodeList<Element> allMeta = null;
    if (doPrefixFiltering) {
        // Attribute selectors with prefix
        // https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
        String query = "";
        for (Map.Entry<Prefix, String> entry : mPrefixes.entrySet()) {
            query += "meta[property^=\"" + entry.getValue() + "\"],";
        }//from   ww w.  j a v a  2s.  co  m
        query = query.substring(0, query.length() - 1);

        allMeta = DomUtil.querySelectorAll(root, query);
    } else {
        allMeta = DomUtil.querySelectorAll(root, "meta[property]");
    }

    for (int i = 0; i < allMeta.getLength(); i++) {
        MetaElement meta = MetaElement.as(allMeta.getItem(i));
        String property = meta.getAttribute("property").toLowerCase();

        // Only store properties that we care about for distillation.
        for (int j = 0; j < mProperties.length; j++) {
            String prefixWithColon = mPrefixes.get(mProperties[j].mPrefix) + ":";
            // Note that property.equals() won't work here because |mProperties| uses "image:"
            // (IMAGE_STRUCT_PROP_PFX) for all image structured properties, so as to prevent
            // repetitive property name comparison - here and then again in ImageParser.
            if (!property.startsWith(prefixWithColon + mProperties[j].mName))
                continue;
            property = property.substring(prefixWithColon.length());

            boolean addProperty = true;
            if (mProperties[j].mParser != null) {
                addProperty = mProperties[j].mParser.parse(property, meta.getContent(), mPropertyTable);
            }
            if (addProperty)
                mPropertyTable.put(mProperties[j].mName, meta.getContent());
        }
    }
}