Java Code Examples for org.jsoup.nodes.Attributes#put()

The following examples show how to use org.jsoup.nodes.Attributes#put() . 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: Cleaner.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private ElementMeta createSafeElement(Element sourceEl) {
    String sourceTag = sourceEl.tagName();
    Attributes destAttrs = new Attributes();
    Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
    int numDiscarded = 0;

    Attributes sourceAttrs = sourceEl.attributes();
    for (Attribute sourceAttr : sourceAttrs) {
        if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
            destAttrs.put(sourceAttr);
        else
            numDiscarded++;
    }
    Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
    destAttrs.addAll(enforcedAttrs);

    return new ElementMeta(dest, numDiscarded);
}
 
Example 2
Source File: Cleaner.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private ElementMeta createSafeElement(Element sourceEl) {
    String sourceTag = sourceEl.tagName();
    Attributes destAttrs = new Attributes();
    Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
    int numDiscarded = 0;

    Attributes sourceAttrs = sourceEl.attributes();
    for (Attribute sourceAttr : sourceAttrs) {
        if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
            destAttrs.put(sourceAttr);
        else
            numDiscarded++;
    }
    Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
    destAttrs.addAll(enforcedAttrs);

    return new ElementMeta(dest, numDiscarded);
}
 
Example 3
Source File: Whitelist.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
Attributes getEnforcedAttributes(String tagName) {
    Attributes attrs = new Attributes();
    TagName tag = TagName.valueOf(tagName);
    if (enforcedAttributes.containsKey(tag)) {
        Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
        for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
            attrs.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return attrs;
}
 
Example 4
Source File: Whitelist.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
Attributes getEnforcedAttributes(String tagName) {
    Attributes attrs = new Attributes();
    TagName tag = TagName.valueOf(tagName);
    if (enforcedAttributes.containsKey(tag)) {
        Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
        for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
            attrs.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return attrs;
}
 
Example 5
Source File: ParserSettingsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test @MultiLocaleTest public void attributesCaseNormalization() throws Exception {
    ParseSettings parseSettings = new ParseSettings(false, false);
    Attributes attributes = new Attributes();
    attributes.put("ITEM", "1");

    Attributes normalizedAttributes = parseSettings.normalizeAttributes(attributes);

    assertEquals("item", normalizedAttributes.asList().get(0).getKey());
}
 
Example 6
Source File: Whitelist.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
Attributes getEnforcedAttributes(String tagName) {
    Attributes attrs = new Attributes();
    TagName tag = TagName.valueOf(tagName);
    if (enforcedAttributes.containsKey(tag)) {
        Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
        for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
            attrs.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return attrs;
}
 
Example 7
Source File: ParserSettingsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test @MultiLocaleTest public void attributesCaseNormalization() throws Exception {
    ParseSettings parseSettings = new ParseSettings(false, false);
    Attributes attributes = new Attributes();
    attributes.put("ITEM", "1");

    Attributes normalizedAttributes = parseSettings.normalizeAttributes(attributes);

    assertEquals("item", normalizedAttributes.asList().get(0).getKey());
}
 
Example 8
Source File: Whitelist.java    From jsoup-learning with MIT License 5 votes vote down vote up
Attributes getEnforcedAttributes(String tagName) {
    Attributes attrs = new Attributes();
    TagName tag = TagName.valueOf(tagName);
    if (enforcedAttributes.containsKey(tag)) {
        Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
        for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
            attrs.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return attrs;
}
 
Example 9
Source File: SishuokWhitelist.java    From es with Apache License 2.0 5 votes vote down vote up
Attributes getEnforcedAttributes(String tagName) {
    Attributes attrs = new Attributes();
    TagName tag = TagName.valueOf(tagName);
    if (enforcedAttributes.containsKey(tag)) {
        Map<AttributeKey, AttributeValue> keyVals = enforcedAttributes.get(tag);
        for (Map.Entry<AttributeKey, AttributeValue> entry : keyVals.entrySet()) {
            attrs.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }
    return attrs;
}