Package hudson.markup

Source Code of hudson.markup.HtmlPolicyBuilder2

package hudson.markup;

import com.google.common.base.Predicate;
import org.owasp.html.HtmlPolicyBuilder;

import java.util.regex.Pattern;

/**
* {@link HtmlPolicyBuilder} with additional
* functions to simplify transcoding policy definition
* from OWASP AntiSamy policy files.
*
* @author Kohsuke Kawaguchi
*/
class HtmlPolicyBuilder2 extends HtmlPolicyBuilder {
    public void tag(String names, Object... attributes) {
        String[] tags = names.split(",");
        for (int i=0; i<attributes.length; i++) {
            String attName = (String)attributes[i];
            if (i+1<attributes.length) {
                Object operand = attributes[i+1];
                if (operand instanceof Predicate) {
                    Predicate p = (Predicate) operand;
                    allowAttributes(attName).matching(p).onElements(tags);
                    i++;
                    continue;
                }

                if (operand instanceof Pattern) {
                    Pattern p = (Pattern) operand;
                    allowAttributes(attName).matching(p).onElements(tags);
                    i++;
                    continue;
                }
            }

            // operand-less
            allowAttributes(attName).onElements(tags);
        }
        allowElements(tags);
    }
}
TOP

Related Classes of hudson.markup.HtmlPolicyBuilder2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.