本文整理匯總了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();
}