import com.google.common.html.HtmlEscapers;
import org.apache.commons.lang.StringEscapeUtils;
import org.jsoup.nodes.Document;
import org.owasp.esapi.ESAPI;
import org.owasp.validator.html.AntiSamy;
import org.owasp.validator.html.Policy;
import org.owasp.validator.html.PolicyException;
import org.owasp.validator.html.ScanException;
import org.owasp.validator.html.util.HTMLEntityEncoder;
import org.springframework.web.util.HtmlUtils;

import java.io.File;
import java.util.regex.Pattern;

/**
 * Created by user on 2018/6/13.
 */
public class Tester {
    private static AntiSamy antiSamy = new AntiSamy();
    private static Policy ebaypolicy ;
    private static Policy simplePolcy ;
    private static Policy esapiPolicy;

    static {
        try {
            ebaypolicy = Policy.getInstance(new File("D:\\schafflerws\\cftech-platform\\cftech-common-web\\src\\main\\resources\\antisamy\\antisamy-ebay.xml"));
        } catch (PolicyException e) {
            e.printStackTrace();
        }

        try {
            simplePolcy = Policy.getInstance(new File("D:\\schafflerws\\cftech-platform\\cftech-common-web\\src\\main\\resources\\antisamy\\antisamy-schaffler-tinymce.xml"));
        } catch (PolicyException e) {
            e.printStackTrace();
        }

        try {
            esapiPolicy = Policy.getInstance(new File("D:\\schafflerws\\cftech-platform\\cftech-common-web\\src\\main\\resources\\esapi\\antisamy-esapi.xml"));
        } catch (PolicyException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[]args) throws PolicyException, ScanException {
//        String info = antiSamy.scan("== - \\ // javascript:alert(1)<a></a><div title='goods'><ul class='red' style='width:80px;text-decoration:underlines'>123 < > 13 132&  '' \" dad : ; ; a ; ; ',daw % # $  sad        啊司法</ul></div><kk href='qqqq'>dadwd</kk>",simplePolcy).getCleanHTML();
//        System.out.println(info);
//        System.out.println(HtmlUtils.htmlUnescape(info));
//        System.out.println( HtmlUtils.htmlEscape(HtmlUtils.htmlUnescape(info)));
//        System.out.println(HTMLEntityEncoder.htmlEntityEncode(info));

//        Pattern pat = Pattern.compile("^(/assets/|/static/|/mobile/|/a/materialUpload/upload).*");
//        System.out.println(pat.matcher("/a/materialUpload/upload?encode=utf-8&cosconfigId=0&categoryId=109").matches());
//        String v = ESAPI.encoder().canonicalize("dadad&dasd");
//        System.out.println(v);
          //  String info = antiSamy.scan("{\"title\":\"测试\",\"type\":\"SINGLESEL\",\"max\":\"1\",\"min\":\"1\",\"options\":[{\"label\":\"1\",\"name\":\"￥{sad}我“wa啊完成'pcdaldsda”faf“万达wq;”daw~~''大武当;:;想到的''\\\\\\\"\\\\\\\"?\\\\\\\"    \\\\\\\" ' ' ;  345&p13;s ad打算的\"}]}",simplePolcy);


    }
}
