本文整理汇总了Java中org.owasp.html.HtmlSanitizer.sanitize方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlSanitizer.sanitize方法的具体用法?Java HtmlSanitizer.sanitize怎么用?Java HtmlSanitizer.sanitize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.html.HtmlSanitizer
的用法示例。
在下文中一共展示了HtmlSanitizer.sanitize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sanitize
import org.owasp.html.HtmlSanitizer; //导入方法依赖的package包/类
public Pair<String, List<StreamItemMedia>> sanitize(String input) {
List<StreamItemMedia> media = new ArrayList<>();
Appendable htmlOutput = new StringBuilder();
ImageAwareHtmlRenderer htmlRenderer = new ImageAwareHtmlRenderer(htmlOutput, media);
HtmlSanitizer.sanitize(input, createPolicy(htmlRenderer));
return Pair.of(htmlOutput.toString(), media);
}
示例2: main
import org.owasp.html.HtmlSanitizer; //导入方法依赖的package包/类
/**
* A test-bed that reads HTML from stdin and writes sanitized content to
* stdout.
*/
public static void main(String[] args) throws IOException {
if (args.length != 0) {
System.err.println("Reads from STDIN and writes to STDOUT");
System.exit(-1);
}
System.err.println("[Reading from STDIN]");
// Fetch the HTML to sanitize.
String html = CharStreams.toString(
new InputStreamReader(System.in, Charsets.UTF_8));
// Set up an output channel to receive the sanitized HTML.
HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
System.out,
// Receives notifications on a failure to write to the output.
new Handler<IOException>() {
public void handle(IOException ex) {
Throwables.propagate(ex); // System.out suppresses IOExceptions
}
},
// Our HTML parser is very lenient, but this receives notifications on
// truly bizarre inputs.
new Handler<String>() {
public void handle(String x) {
throw new AssertionError(x);
}
});
// Use the policy defined above to sanitize the HTML.
HtmlSanitizer.sanitize(html, POLICY_DEFINITION.apply(renderer));
}
示例3: sanitize
import org.owasp.html.HtmlSanitizer; //导入方法依赖的package包/类
public static String sanitize(String html) {
StringBuilder sb = new StringBuilder();
HtmlSanitizer.sanitize(html, makePolicy(sb));
return sb.toString();
}