1 package net.sf.statcvs.pages.xml;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5
6 import net.sf.statcvs.Messages;
7 import net.sf.statcvs.model.Author;
8 import net.sf.statcvs.model.Directory;
9 import net.sf.statcvs.pages.DirectoryPageMaker;
10 import net.sf.statcvs.pages.ReportSuiteMaker;
11
12
13
14
15
16
17
18
19 public final class XML {
20 private static final SimpleDateFormat OUTPUT_DATE_FORMAT = new SimpleDateFormat(Messages.getString("DATE_FORMAT"));
21 private static final SimpleDateFormat OUTPUT_DATE_TIME_FORMAT = new SimpleDateFormat(Messages.getString("DATE_TIME_FORMAT"));
22
23
24
25
26
27
28
29 public static String getLink(final String link, final String linkName) {
30 return getLink(link, linkName, "", "");
31 }
32
33
34
35
36
37
38
39
40
41 public static String getLink(final String link, final String linkName, final String prefix, final String suffix) {
42 if (link == null) {
43 return prefix + escape(linkName) + suffix;
44 }
45 return "<a href=\"" + escape(link) + "\">" + prefix + escape(linkName) + suffix + "</a>";
46 }
47
48
49
50
51
52
53 public static String getAuthorLink(final Author author) {
54 return escape(author.getName());
55 }
56
57
58
59
60
61
62 public static String getAuthorIdLink(final Author author) {
63 return escape(author.getName());
64 }
65
66
67
68
69
70
71 public static String getDate(final Date date) {
72 return OUTPUT_DATE_FORMAT.format(date);
73 }
74
75
76
77
78
79
80 public static String getDateAndTime(final Date date) {
81 return OUTPUT_DATE_TIME_FORMAT.format(date);
82 }
83
84
85
86
87
88
89 public static String getDirectoryLink(final Directory directory) {
90 final String caption = directory.isRoot() ? "/" : directory.getPath();
91 return escape(DirectoryPageMaker.getURL(directory)) + escape(caption);
92 }
93
94
95
96
97
98
99 public static String getIcon(final String iconFilename) {
100 final StringBuffer result = new StringBuffer("<img src=\"");
101 result.append(escape(iconFilename)).append("\" width=\"");
102 result.append(ReportSuiteMaker.ICON_WIDTH).append("\" height=\"");
103 result.append(ReportSuiteMaker.ICON_HEIGHT).append("\" alt=\"\"/>");
104 return result.toString();
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 public static String escapeAuthorName(final String authorName) {
121 return authorName.replaceAll("#", "_").replaceAll("\\\\", "_");
122 }
123
124 public static String escapeDirectoryName(String directoryName) {
125 if (!directoryName.startsWith("/")) {
126 directoryName = "/" + directoryName;
127 }
128 return directoryName.substring(0, directoryName.length() - 1).replaceAll("/", "_");
129 }
130
131
132
133
134
135
136
137 public static String escape(final String text) {
138 final String result = text;
139
140
141
142 return result;
143 }
144
145
146
147
148
149 private XML() {
150 }
151 }