1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.exceptions.report.renderer;
17
18 import java.util.List;
19
20 import com.thoughtworks.qdox.model.DocletTag;
21 import com.thoughtworks.qdox.model.JavaAnnotatedElement;
22
23 import de.smartics.exceptions.report.utils.InlineJavadocTags;
24
25
26
27
28 public final class JavadocRenderer
29 {
30
31
32
33
34
35
36
37
38
39 private final RendererFactory factory;
40
41
42
43
44
45
46
47
48
49
50 public JavadocRenderer(final RendererFactory factory)
51 {
52 this.factory = factory;
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public String render(final JavaAnnotatedElement doc)
72 {
73 final StringBuilder buffer = new StringBuilder(256);
74
75 renderInlineTags(doc, buffer);
76 renderTags(doc, buffer);
77
78 return buffer.toString();
79 }
80
81 private void renderInlineTags(final JavaAnnotatedElement doc,
82 final StringBuilder buffer)
83 {
84 final InlineJavadocTags tags = new InlineJavadocTags(doc);
85
86 for (final DocletTag tag : tags)
87 {
88 final String tagName = tag.getName();
89 if ("link".equals(tagName))
90 {
91 final LinkTagRenderer renderer = factory.createLinkTagRenderer();
92 renderer.render(buffer, tag);
93 }
94 else if ("linkplain".equals(tagName))
95 {
96 final LinkPlainTagRenderer renderer =
97 factory.createLinkPlainTagRenderer();
98 renderer.render(buffer, tag);
99 }
100 else if ("literal".equals(tagName))
101 {
102 final LiteralTagRenderer renderer = factory.createLiteralTagRenderer();
103 renderer.render(buffer, tag);
104 }
105 else if ("code".equals(tagName))
106 {
107 final CodeTagRenderer renderer = factory.createCodeTagRenderer();
108 renderer.render(buffer, tag);
109 }
110 else if ("value".equals(tagName))
111 {
112 final ValueTagRenderer renderer = factory.createValueTagRenderer();
113 renderer.render(buffer, tag);
114 }
115 else
116 {
117 final TextRenderer renderer = factory.createTextRenderer();
118 renderer.render(buffer, tag.getValue());
119 }
120 }
121 }
122
123 private void renderTags(final JavaAnnotatedElement doc,
124 final StringBuilder buffer)
125 {
126 final List<DocletTag> tags = doc.getTags();
127
128 if (!tags.isEmpty())
129 {
130 final TagListRenderer listRenderer = factory.createTagListRenderer();
131 listRenderer.renderListStart(buffer);
132 for (final DocletTag tag : tags)
133 {
134 final String tagName = tag.getName();
135 if ("see".equals(tagName))
136 {
137 final SeeTagRenderer renderer = factory.createSeeTagRenderer();
138 renderer.render(buffer, tag);
139 }
140 else if ("version".equals(tagName))
141 {
142 final SinceTagRenderer renderer = factory.createSinceTagRenderer();
143 renderer.render(buffer, tag);
144 }
145 else if ("since".equals(tagName))
146 {
147 final VersionTagRenderer renderer =
148 factory.createVersionTagRenderer();
149 renderer.render(buffer, tag);
150 }
151 }
152 listRenderer.renderListEnd(buffer);
153 }
154 }
155
156
157
158 }