本文整理汇总了Java中org.owasp.html.HtmlSanitizer类的典型用法代码示例。如果您正苦于以下问题:Java HtmlSanitizer类的具体用法?Java HtmlSanitizer怎么用?Java HtmlSanitizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HtmlSanitizer类属于org.owasp.html包,在下文中一共展示了HtmlSanitizer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createPolicy
import org.owasp.html.HtmlSanitizer; //导入依赖的package包/类
HtmlSanitizer.Policy createPolicy(ImageAwareHtmlRenderer htmlRenderer) {
return Sanitizers.FORMATTING
.and(LINKS)
.and(IFRAME)
.and(Sanitizers.IMAGES)
.apply(htmlRenderer);
}
示例3: 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));
}
示例4: 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();
}