Java 类com.google.gwt.dom.client.MetaElement 实例源码

项目:dom-distiller    文件:IEReadingViewParser.java   
private void findTitle() {
    init();
    mTitle = "";

    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;
        }
    }
}
项目:dom-distiller    文件:IEReadingViewParser.java   
private void findDate() {
    init();
    mDate = "";

    // 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;
            }
        }
    }
}
项目:putnami-web-toolkit    文件:DocumentMeta.java   
/**
 * Return the first meta tag from the head section with name matching. <br>
 * If createIfMissing the tag is created and added at the end of the head section.<br>
 * <p>
 * <strong>Note : </strong> the name is case insensitive
 * </p>
 *
 * @param name the name attribute of the metta tag
 * @param createIfMissing create the tag in the head section if missing
 * @return meta tag element or null
 */
public static MetaElement getDescriptionTag(String name, boolean createIfMissing) {
    Document doc = Document.get();
    HeadElement head = doc.getHead();
    assert head != null : "No head section found in the document";
    assert name != null : "the name must not be null";

    NodeList<Element> tags = head.getElementsByTagName("meta");
    MetaElement metaTag = null;
    for (int i = 0; i < tags.getLength(); i++) {
        metaTag = (MetaElement) tags.getItem(i);
        if (name.equalsIgnoreCase(metaTag.getName())) {
            return metaTag;
        }
    }
    if (createIfMissing) {
        metaTag = doc.createMetaElement();
        metaTag.setName(name);
        head.appendChild(metaTag);
    }
    return metaTag;
}
项目:fns-projects    文件:RestModule.java   
@Provides
@Singleton
public XSRFToken provideXSRFToken() {
    XSRFToken xsrfToken = new XSRFToken();

    // get the CSRF token from the HTML document and initialize the
    // XSRFToken
    NodeList<MetaElement> metaTags = Document.get().getElementsByTagName(MetaElement.TAG).cast();
    for (int i = 0; i < metaTags.getLength(); i++) {
        if (metaTags.getItem(i).getName().equals("X-CSRF-TOKEN")) {
            xsrfToken.setToken(metaTags.getItem(i).getContent());
            break;
        }
    }

    return xsrfToken;
}
项目:touchkit    文件:Ios7HomeScreenWebAppHackLoader.java   
/**
 * Modifies viewport tag to include both width=device-width AND
 * height=device-height. The latter is not generally known or used, but
 * seems to prevent ios from changing screen size when virtual keyboard pops
 * on. This is how it works in Safari, Android, mobile IE and in previous
 * version of iOS home screen web apps.
 * <p>
 * Instead of "device-height" we use pixel height reported by
 * window.innerHeight. On orientation changes that must be updated.
 */
private void addHeightToViewPort() {
    MetaElement item = getViewportTag();
    if (item != null) {
        String attribute = item.getContent();
        if (!attribute.contains("width")) {
            attribute += ",width=device-width";
        }
        int viewPortHeight = getWindowInnerHeight();
        if (!attribute.contains("height")) {
            attribute += ",height=" + viewPortHeight;
        } else {
            attribute = updateViewPortHeight(attribute, viewPortHeight);
        }
        item.setContent(attribute);
    }
}
项目:demo-gwt-springboot    文件:DemoGwtWebApp.java   
private void addMetaElements() {
    logger.info("Add viewport");
    MetaElement element = Document.get().createMetaElement();
    element.setName("viewport");
    element.setContent("width=device-width, initial-scale=1.0");

    NodeList<Element> node = Document.get().getElementsByTagName("head");
    Element elementHead = node.getItem(0);
    elementHead.appendChild(element);
}
项目:dom-distiller    文件:OpenGraphProtocolParser.java   
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() + "\"],";
        }
        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());
        }
    }
}
项目:dom-distiller    文件:IEReadingViewParser.java   
private void findCopyright() {
    init();
    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;
        }
    }
}
项目:dom-distiller    文件:IEReadingViewParser.java   
private void findOptOut() {
    init();
    mDoneOptOut = true;

    // 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;
        }
    }
}
项目:dom-distiller    文件:TestUtil.java   
public static MetaElement createMetaProperty(String property,
        String content) {
    MetaElement m = Document.get().createMetaElement();
    m.setAttribute("property", property);
    m.setContent(content);
    return m;
}
项目:firefly    文件: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] : "";
            }
        }
    }
    return null;
}
项目:adan    文件:Schedule.java   
public double getZoneId(){
    double zone = -1000;
    NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        MetaElement metaTag = ((MetaElement) tags.getItem(i));
        if (metaTag.getName().equals("timezone-id")) {
            zone = Double.parseDouble(metaTag.getContent());
        }
    }
    GWT.log(zone +"");
    return zone;
}
项目:putnami-web-toolkit    文件:CsrfController.java   
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;
        }
        if (META_NAME_CSRF_HEADER.equals(META_NAME_CSRF_HEADER) && !Strings.isNullOrEmpty(metaContent)) {
            this.header = metaContent;
        }
    }
}
项目:touchkit    文件:Ios7HomeScreenWebAppHackLoader.java   
private MetaElement getViewportTag() {
    NodeList<Element> metas = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < metas.getLength(); i++) {
        MetaElement item = metas.getItem(i).cast();
        if ("viewport".equals(item.getAttribute("name"))) {
            return item;
        }
    }
    return null;
}
项目:dom-distiller    文件:TestUtil.java   
public static MetaElement createMetaName(String name, String content) {
    MetaElement m = Document.get().createMetaElement();
    m.setName(name);
    m.setContent(content);
    return m;
}
项目:touchkit    文件:Ios7HomeScreenWebAppHackLoader.java   
private void fixHtmlHeightToWindowInnerHeight() {
    final MetaElement tag = getViewportTag();
    int viewPortHeight = getWindowInnerHeight();
    String c = updateViewPortHeight(tag.getContent(), viewPortHeight);
    tag.setContent(c);
}