org.jsoup.nodes.Attribute#getKey ( )源码实例Demo

下面列出了org.jsoup.nodes.Attribute#getKey ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: astor   文件: W3CDom.java
/**
 * Finds any namespaces defined in this element. Returns any tag prefix.
 */
private String updateNamespaces(org.jsoup.nodes.Element el) {
    // scan the element for namespace declarations
    // like: xmlns="blah" or xmlns:prefix="blah"
    Attributes attributes = el.attributes();
    for (Attribute attr : attributes) {
        String key = attr.getKey();
        String prefix;
        if (key.equals(xmlnsKey)) {
            prefix = "";
        } else if (key.startsWith(xmlnsPrefix)) {
            prefix = key.substring(xmlnsPrefix.length());
        } else {
            continue;
        }
        namespaces.put(prefix, attr.getValue());
    }

    // get the element prefix if any
    int pos = el.tagName().indexOf(":");
    return pos > 0 ? el.tagName().substring(0, pos) : "";
}
 
源代码2 项目: astor   文件: W3CDom.java
/**
 * Finds any namespaces defined in this element. Returns any tag prefix.
 */
private String updateNamespaces(org.jsoup.nodes.Element el) {
    // scan the element for namespace declarations
    // like: xmlns="blah" or xmlns:prefix="blah"
    Attributes attributes = el.attributes();
    for (Attribute attr : attributes) {
        String key = attr.getKey();
        String prefix;
        if (key.equals(xmlnsKey)) {
            prefix = "";
        } else if (key.startsWith(xmlnsPrefix)) {
            prefix = key.substring(xmlnsPrefix.length());
        } else {
            continue;
        }
        namespaces.put(prefix, attr.getValue());
    }

    // get the element prefix if any
    int pos = el.tagName().indexOf(":");
    return pos > 0 ? el.tagName().substring(0, pos) : "";
}
 
源代码3 项目: astor   文件: W3CDom.java
/**
 * Finds any namespaces defined in this element. Returns any tag prefix.
 */
private String updateNamespaces(org.jsoup.nodes.Element el) {
    // scan the element for namespace declarations
    // like: xmlns="blah" or xmlns:prefix="blah"
    Attributes attributes = el.attributes();
    for (Attribute attr : attributes) {
        String key = attr.getKey();
        String prefix;
        if (key.equals(xmlnsKey)) {
            prefix = "";
        } else if (key.startsWith(xmlnsPrefix)) {
            prefix = key.substring(xmlnsPrefix.length());
        } else {
            continue;
        }
        namespaces.put(prefix, attr.getValue());
    }

    // get the element prefix if any
    int pos = el.tagName().indexOf(":");
    return pos > 0 ? el.tagName().substring(0, pos) : "";
}
 
源代码4 项目: flow   文件: Html.java
private void setAttribute(Attribute attribute) {
    String name = attribute.getKey();
    String value = attribute.getValue();
    if (value == null) {
        value = "";
    }
    getElement().setAttribute(name, value);
}
 
源代码5 项目: astor   文件: Whitelist.java
/**
 * Test if the supplied attribute is allowed by this whitelist for this tag
 * @param tagName tag to consider allowing the attribute in
 * @param el element under test, to confirm protocol
 * @param attr attribute under test
 * @return true if allowed
 */
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
    TagName tag = TagName.valueOf(tagName);
    AttributeKey key = AttributeKey.valueOf(attr.getKey());

    Set<AttributeKey> okSet = attributes.get(tag);
    if (okSet != null && okSet.contains(key)) {
        if (protocols.containsKey(tag)) {
            Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
            // ok if not defined protocol; otherwise test
            return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
        } else { // attribute found, no protocols defined, so OK
            return true;
        }
    }
    // might be an enforced attribute?
    Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
    if (enforcedSet != null) {
        Attributes expect = getEnforcedAttributes(tagName);
        String attrKey = attr.getKey();
        if (expect.hasKeyIgnoreCase(attrKey)) {
            return expect.getIgnoreCase(attrKey).equals(attr.getValue());
        }
    }
    // no attributes defined for tag, try :all tag
    return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
 
源代码6 项目: astor   文件: Whitelist.java
/**
 * Test if the supplied attribute is allowed by this whitelist for this tag
 * @param tagName tag to consider allowing the attribute in
 * @param el element under test, to confirm protocol
 * @param attr attribute under test
 * @return true if allowed
 */
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
    TagName tag = TagName.valueOf(tagName);
    AttributeKey key = AttributeKey.valueOf(attr.getKey());

    Set<AttributeKey> okSet = attributes.get(tag);
    if (okSet != null && okSet.contains(key)) {
        if (protocols.containsKey(tag)) {
            Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
            // ok if not defined protocol; otherwise test
            return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
        } else { // attribute found, no protocols defined, so OK
            return true;
        }
    }
    // might be an enforced attribute?
    Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
    if (enforcedSet != null) {
        Attributes expect = getEnforcedAttributes(tagName);
        String attrKey = attr.getKey();
        if (expect.hasKeyIgnoreCase(attrKey)) {
            return expect.getIgnoreCase(attrKey).equals(attr.getValue());
        }
    }
    // no attributes defined for tag, try :all tag
    return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
 
 方法所在类
 同类方法