当前位置: 首页>>代码示例>>Java>>正文


Java HtmlStreamRenderer类代码示例

本文整理汇总了Java中org.owasp.html.HtmlStreamRenderer的典型用法代码示例。如果您正苦于以下问题:Java HtmlStreamRenderer类的具体用法?Java HtmlStreamRenderer怎么用?Java HtmlStreamRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HtmlStreamRenderer类属于org.owasp.html包,在下文中一共展示了HtmlStreamRenderer类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.owasp.html.HtmlStreamRenderer; //导入依赖的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

示例2: makePolicy

import org.owasp.html.HtmlStreamRenderer; //导入依赖的package包/类
private static Policy makePolicy(Appendable buffer) {
        final HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
                buffer,
                new Handler<IOException>() {
                    public void handle(IOException ex) {
                        throw new RuntimeException(ex);
                    }
                },
                new Handler<String>() {
                    public void handle(String errorMessage) {
                        throw new RuntimeException(errorMessage);
                    }
                });

        return new HtmlPolicyBuilder()
                .allowElements( "h1", "h2", "h3", "h4", "p",
                        "ol", "li", "ul",
                        "i", "u", "b",
                        "blockquote",
                        "a", "br", "div", "img", "span")
                .allowAttributes("href").onElements("a")
                .allowAttributes("src").onElements("img")
                .allowAttributes("width").onElements("img")
                .allowAttributes("height").onElements("img")
                .allowAttributes("alt").onElements("img")
                .allowAttributes("class", "id", "title").globally()
                .allowStandardUrlProtocols()
//                .requireRelNofollowOnLinks()
//                .disallowElements("script")
                .build(renderer);
    }
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:32,代码来源:InfoTextHtmlSanitizer.java

示例3: ImageAwareHtmlRenderer

import org.owasp.html.HtmlStreamRenderer; //导入依赖的package包/类
public ImageAwareHtmlRenderer(Appendable htmlOutput, List<StreamItemMedia> media) {
  this.media = media;
  this.htmlStreamRenderer = HtmlStreamRenderer.create(htmlOutput, Handler.DO_NOTHING, Handler.DO_NOTHING);
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:5,代码来源:ImageAwareHtmlRenderer.java


注:本文中的org.owasp.html.HtmlStreamRenderer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。