|
29 | 29 |
|
30 | 30 | public class HtmlAwareController { |
31 | 31 |
|
32 | | - private Parser parser; |
33 | | - private HtmlRenderer htmlRenderer; |
| 32 | + private final Parser parser; |
| 33 | + private final HtmlRenderer htmlRenderer; |
34 | 34 |
|
| 35 | + /** |
| 36 | + * Constructor to generate html code for HTML preview feature in LogEntryEditor or detailed log entry view. |
| 37 | + * @param serviceUrl Olog service url |
| 38 | + */ |
35 | 39 | public HtmlAwareController(String serviceUrl){ |
36 | | - List<Extension> extensions = |
37 | | - Arrays.asList(TablesExtension.create(), ImageAttributesExtension.create()); |
38 | | - this.parser = Parser.builder().extensions(extensions).build(); |
39 | | - htmlRenderer = HtmlRenderer.builder() |
40 | | - .attributeProviderFactory(context -> new OlogAttributeProvider(serviceUrl)) |
41 | | - .extensions(extensions).build(); |
| 40 | + this(new OlogAttributeProvider(serviceUrl)); |
42 | 41 | } |
43 | 42 |
|
44 | 43 | /** |
45 | | - * To create HtmlAwareController object to generate html code for HTML preview feature in LogEntryEditor. |
| 44 | + * Constructor to generate html code for HTML preview feature in LogEntryEditor or detailed log entry view. |
46 | 45 | * @param serviceUrl Olog service url. |
47 | 46 | * @param preview Set true when preview button is clicked. |
48 | 47 | * @param attachments The current attachments list from AttachmentsEditorController. |
49 | 48 | */ |
50 | 49 | public HtmlAwareController(String serviceUrl, boolean preview, List<Attachment> attachments){ |
| 50 | + this(new OlogAttributeProvider(serviceUrl, preview, attachments)); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Private constructor to avoid code duplication. |
| 55 | + * @param ologAttributeProvider The {@link OlogAttributeProvider} particular to the use case. |
| 56 | + */ |
| 57 | + private HtmlAwareController(OlogAttributeProvider ologAttributeProvider){ |
51 | 58 | List<Extension> extensions = |
52 | 59 | Arrays.asList(TablesExtension.create(), ImageAttributesExtension.create()); |
53 | 60 | this.parser = Parser.builder().extensions(extensions).build(); |
54 | 61 | htmlRenderer = HtmlRenderer.builder() |
55 | | - .attributeProviderFactory(context -> new OlogAttributeProvider(serviceUrl, preview, attachments)) |
| 62 | + .escapeHtml(true) |
| 63 | + .attributeProviderFactory(context -> ologAttributeProvider) |
56 | 64 | .extensions(extensions).build(); |
57 | 65 | } |
58 | 66 |
|
|
0 commit comments