Search in sources :

Example 1 with Attributes

use of com.smartandroid.sa.tag.nodes.Attributes in project SmartAndroidSource by jaychou2012.

the class Cleaner method createSafeElement.

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);
}
Also used : Attribute(com.smartandroid.sa.tag.nodes.Attribute) Element(com.smartandroid.sa.tag.nodes.Element) Attributes(com.smartandroid.sa.tag.nodes.Attributes)

Example 2 with Attributes

use of com.smartandroid.sa.tag.nodes.Attributes in project SmartAndroidSource by jaychou2012.

the class Whitelist method getEnforcedAttributes.

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;
}
Also used : Attributes(com.smartandroid.sa.tag.nodes.Attributes) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Attributes (com.smartandroid.sa.tag.nodes.Attributes)2 Attribute (com.smartandroid.sa.tag.nodes.Attribute)1 Element (com.smartandroid.sa.tag.nodes.Element)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1