當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlSanitizer.sanitize方法代碼示例

本文整理匯總了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);
}
 
開發者ID:adrobisch,項目名稱:putput,代碼行數:8,代碼來源:MediaAwareSanitizer.java

示例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));
}
 
開發者ID:OWASP,項目名稱:java-html-sanitizer,代碼行數:33,代碼來源:EbayPolicyExample.java

示例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();
}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:8,代碼來源:InfoTextHtmlSanitizer.java


注:本文中的org.owasp.html.HtmlSanitizer.sanitize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。