File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\markup\RawHtmlMarkupFormatter.java.html

1 package hudson.markup;
2
3 import com.google.common.base.Throwables;
4 import hudson.Extension;
5 import org.kohsuke.stapler.DataBoundConstructor;
6 import org.owasp.html.Handler;
7 import org.owasp.html.HtmlSanitizer;
8 import org.owasp.html.HtmlStreamRenderer;
9
10 import java.io.IOException;
11 import java.io.Writer;
12
13 /**
14 * {@link MarkupFormatter} that treats the input as the raw html.
15 * This is the backward compatible behaviour.
16 *
17 * @author Kohsuke Kawaguchi
18 */
19 public class RawHtmlMarkupFormatter extends MarkupFormatter {
20
21 final boolean disableSyntaxHighlighting;
22
23 @DataBoundConstructor
24 public RawHtmlMarkupFormatter(final boolean disableSyntaxHighlighting) {
25 this.disableSyntaxHighlighting = disableSyntaxHighlighting;
26 }
27
28 public boolean isDisableSyntaxHighlighting() {
29 return disableSyntaxHighlighting;
30 }
31
32 @Override
33 public void translate(String markup, Writer output) throws IOException {
34 HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
35 output,
36 // Receives notifications on a failure to write to the output.
37 new Handler<IOException>() {
38 public void handle(IOException ex) {
39 Throwables.propagate(ex); // System.out suppresses IOExceptions
40 }
41 },
42 // Our HTML parser is very lenient, but this receives notifications on
43 // truly bizarre inputs.
44 new Handler<String>() {
45 public void handle(String x) {
46 throw new Error(x);
47 }
48 }
49 );
50 // Use the policy defined above to sanitize the HTML.
51 HtmlSanitizer.sanitize(markup, MyspacePolicy.POLICY_DEFINITION.apply(renderer));
52 }
53
54 public String getCodeMirrorMode() {
55 return disableSyntaxHighlighting ? null : "htmlmixed";
56 }
57
58 public String getCodeMirrorConfig() {
59 return "mode:'text/html'";
60 }
61
62 @Extension
63 public static class DescriptorImpl extends MarkupFormatterDescriptor {
64 @Override
65 public String getDisplayName() {
66 return "Raw HTML";
67 }
68 }
69
70 public static final MarkupFormatter INSTANCE = new RawHtmlMarkupFormatter(false);
71 }
72