1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.exceptions.report.renderer.html;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19
20 import com.thoughtworks.qdox.model.DocletTag;
21 import com.thoughtworks.qdox.model.JavaAnnotatedElement;
22 import com.thoughtworks.qdox.model.JavaClass;
23 import com.thoughtworks.qdox.model.JavaField;
24
25 import de.smartics.exceptions.report.renderer.SeeTagRenderer;
26
27
28
29
30 public class HtmlSeeTagRenderer implements SeeTagRenderer
31 {
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 @Override
54 public StringBuilder render(final StringBuilder buffer, final DocletTag tag)
55 {
56 final String text = tag.getValue();
57 final String textFragment;
58 final int length = text.length();
59 if (text.startsWith("<"))
60 {
61 textFragment = text;
62 }
63 else if (length > 2 && text.startsWith("\"") && text.endsWith("\""))
64 {
65 textFragment =
66 "<i>" + StringEscapeUtils.escapeHtml(text.substring(1, length - 1))
67 + "</i>";
68 }
69 else if (length > 1 && text.startsWith("#"))
70 {
71 final JavaAnnotatedElement context = tag.getContext();
72 if (context instanceof JavaField)
73 {
74 final JavaClass type = ((JavaField) context).getDeclaringClass();
75 final String fqn = type.getFullyQualifiedName();
76 final String id = text.substring(1);
77 textFragment = "<a href=\"#" + fqn + '_' + id + "\">" + id + "</a>";
78 }
79 else
80 {
81 textFragment = StringEscapeUtils.escapeHtml(text);
82 }
83 }
84 else if (length > 1 && text.contains("#"))
85 {
86 final JavaClass classDoc = Utils.referencedClass(tag);
87 if (classDoc != null && classDoc.isA("de.smartics.exceptions.core.Code"))
88 {
89 final String id = Utils.referencedMemberName(tag);
90 final String fqn = classDoc.getFullyQualifiedName();
91 textFragment =
92 "<a href=\"#" + fqn + '_' + id + "\">" + classDoc.getName() + '.'
93 + id + "</a>";
94 }
95 else
96 {
97 textFragment = StringEscapeUtils.escapeHtml(text);
98 }
99 }
100 else
101 {
102 textFragment = StringEscapeUtils.escapeHtml(text);
103 }
104 buffer.append("<dt>See:</dt><dd>").append(textFragment).append("</dd>\n");
105 return buffer;
106 }
107
108
109
110
111 }