import java.io.IOException;
import org.owasp.html.HtmlPolicyBuilder;
import org.owasp.html.PolicyFactory;

public class SanitizeHTML{
 
	public static void run(Appendable out, String input) throws IOException {

		PolicyFactory policyBuilder = new HtmlPolicyBuilder()
		.allowAttributes("src").onElements("img")
		.allowAttributes("href").onElements("a")
		// Allow some URLs through.
		.allowStandardUrlProtocols()
		.allowElements("a", "label", "h1", "h2", "h3", "h4", "h5", "h6",
                    "p", "i", "b", "u", "strong", "em", "small", "big", "pre", "code",
                    "cite", "samp", "sub", "sup", "strike", "center", "blockquote",
                    "hr", "br", "col", "font", "span", "div", "img",
                    "ul", "ol", "li", "dd”", "dt", "dl", "tbody", "thead", "tfoot",
                    "table", "td", "th", "tr", "colgroup", "fieldset", "legend"
		).toFactory();
    
		String safeHTML = policyBuilder.sanitize(input);
		out.append(safeHTML);  
	
	}
	
    public static void main(String... argv) throws IOException {
		run(System.out, "www.domain.com/<script>alert(‘alert’)</script>index.html");
	}
}