|
1 | 1 | package org.mobilitydata.gtfsvalidator.report.model; |
2 | 2 |
|
3 | 3 | import com.google.gson.JsonObject; |
| 4 | +import com.vladsch.flexmark.html.HtmlRenderer; |
| 5 | +import com.vladsch.flexmark.parser.Parser; |
| 6 | +import com.vladsch.flexmark.util.ast.Document; |
4 | 7 | import java.util.ArrayList; |
5 | 8 | import java.util.List; |
6 | 9 | import org.mobilitydata.gtfsvalidator.notice.Notice; |
| 10 | +import org.mobilitydata.gtfsvalidator.notice.NoticeDocComments; |
7 | 11 | import org.mobilitydata.gtfsvalidator.notice.SeverityLevel; |
| 12 | +import org.mobilitydata.gtfsvalidator.notice.schema.NoticeSchemaGenerator; |
8 | 13 |
|
9 | 14 | /** NoticeView is a wrapper class to display a Notice. */ |
10 | 15 | public class NoticeView { |
11 | 16 | private final Notice notice; |
12 | 17 | private final JsonObject json; |
13 | 18 | private final List<String> fields; |
| 19 | + private final NoticeDocComments comments; |
14 | 20 |
|
15 | 21 | public NoticeView(Notice notice) { |
16 | 22 | this.notice = notice; |
17 | 23 | this.json = notice.getContext().getAsJsonObject(); |
18 | 24 | this.fields = new ArrayList<>(json.keySet()); |
| 25 | + this.comments = NoticeSchemaGenerator.loadComments(notice.getClass()); |
19 | 26 | } |
20 | 27 |
|
21 | 28 | /** |
@@ -55,6 +62,28 @@ public SeverityLevel getSeverityLevel() { |
55 | 62 | return notice.getSeverityLevel(); |
56 | 63 | } |
57 | 64 |
|
| 65 | + /** |
| 66 | + * Returns the description text for the notice. |
| 67 | + * |
| 68 | + * @return description text |
| 69 | + */ |
| 70 | + public String getCommentForField(String field) { |
| 71 | + return comments.getFieldComment(field); |
| 72 | + } |
| 73 | + /** |
| 74 | + * Returns the description text for the notice. |
| 75 | + * |
| 76 | + * @return description text |
| 77 | + */ |
| 78 | + public String getDescription() { |
| 79 | + String markdown = this.comments.getDocComment(); |
| 80 | + |
| 81 | + Parser parser = Parser.builder().build(); |
| 82 | + Document document = parser.parse(markdown == null ? "" : markdown); |
| 83 | + HtmlRenderer renderer = HtmlRenderer.builder().build(); |
| 84 | + return renderer.render(document); |
| 85 | + } |
| 86 | + |
58 | 87 | /** |
59 | 88 | * Returns a descriptive type-specific name for this notice class simple name. |
60 | 89 | * |
|
0 commit comments