1 |
|
package org.kuali.maven.mojo.s3; |
2 |
|
|
3 |
|
import java.text.SimpleDateFormat; |
4 |
|
import java.util.ArrayList; |
5 |
|
import java.util.Collection; |
6 |
|
import java.util.Date; |
7 |
|
import java.util.List; |
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
|
|
| 0% |
Uncovered Elements: 130 (130) |
Complexity: 25 |
Complexity Density: 0.26 |
|
12 |
|
public class CloudFrontHtmlGenerator { |
13 |
|
HtmlUtils html = new HtmlUtils(); |
14 |
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); |
15 |
|
|
16 |
|
S3BucketContext context; |
17 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
18 |
0
|
public CloudFrontHtmlGenerator() {... |
19 |
0
|
this(null); |
20 |
|
} |
21 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
22 |
0
|
public CloudFrontHtmlGenerator(final S3BucketContext context) {... |
23 |
0
|
super(); |
24 |
0
|
this.context = context; |
25 |
|
} |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
30 |
0
|
protected List<ColumnDecorator> getColumnDecorators() {... |
31 |
0
|
List<ColumnDecorator> columnDecorators = new ArrayList<ColumnDecorator>(); |
32 |
0
|
columnDecorators.add(new ColumnDecorator("image-column", "sort-header", |
33 |
|
"")); |
34 |
0
|
columnDecorators.add(new ColumnDecorator("name-column", "sort-header", |
35 |
|
"Name")); |
36 |
0
|
columnDecorators.add(new ColumnDecorator("last-modified-column", |
37 |
|
"sort-header", "Last Modified")); |
38 |
0
|
columnDecorators.add(new ColumnDecorator("size-column", "sort-header", |
39 |
|
"Size")); |
40 |
0
|
return columnDecorators; |
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
48 |
0
|
protected String getDirectory(final String prefix, final String delimiter) {... |
49 |
0
|
if (prefix == null) { |
50 |
0
|
return delimiter; |
51 |
|
} |
52 |
0
|
if (prefix.endsWith(delimiter)) { |
53 |
0
|
return delimiter |
54 |
|
+ prefix.substring(0, prefix.length() - delimiter.length()); |
55 |
|
} else { |
56 |
0
|
return delimiter + prefix; |
57 |
|
} |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0
|
protected String getHtmlComment() {... |
61 |
0
|
return "<!-- Generated on " + sdf.format(new Date()) + " -->\n"; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0
|
protected String getDocType() {... |
65 |
0
|
return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
0
|
protected String getMeta() {... |
69 |
0
|
return "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0
|
protected String getGoogleAnalyticsJavascript() {... |
73 |
0
|
return "<script type=\"text/javascript\">var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-16781661-1']); _gaq.push(['_setDomainName', '.kuali.org']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>\n"; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 1 |
Complexity Density: 0.03 |
|
79 |
0
|
public String getHtml(final List<String[]> data, final String prefix, final String delimiter) {... |
80 |
0
|
String directory = getDirectory(prefix, delimiter); |
81 |
|
|
82 |
0
|
Tag html = new Tag("html"); |
83 |
0
|
Tag title = new Tag("title"); |
84 |
0
|
Tag head = new Tag("head"); |
85 |
0
|
Tag body = new Tag("body"); |
86 |
0
|
Tag div1 = new Tag("div", "title"); |
87 |
0
|
Tag span1 = new Tag("span", null, "title"); |
88 |
0
|
Tag div2 = new Tag("div", "data"); |
89 |
0
|
Tag div3 = new Tag("div", "footer", "footer-left"); |
90 |
0
|
Tag span2 = new Tag("span", null, "footer-text"); |
91 |
|
|
92 |
0
|
StringBuffer sb = new StringBuffer(); |
93 |
0
|
sb.append(getDocType()); |
94 |
0
|
sb.append(this.html.openTag(html)); |
95 |
0
|
sb.append(this.html.getIndentedContent(getHtmlComment())); |
96 |
0
|
sb.append(this.html.getTag(title, "Directory listing for " + directory)); |
97 |
0
|
sb.append(this.html.openTag(head)); |
98 |
0
|
sb.append(this.html.getIndentedContent("<link href=\"" |
99 |
|
+ context.getCss() |
100 |
|
+ "\" rel=\"stylesheet\" type=\"text/css\"/>\n")); |
101 |
0
|
sb.append(this.html.getIndentedContent(getMeta())); |
102 |
0
|
sb.append(this.html.getIndentedContent(getGoogleAnalyticsJavascript())); |
103 |
0
|
sb.append(this.html.closeTag(head)); |
104 |
0
|
sb.append(this.html.openTag(body)); |
105 |
0
|
sb.append(this.html.openTag(div1)); |
106 |
0
|
sb.append(this.html.getTag(span1, "Directory listing for " + directory)); |
107 |
0
|
sb.append(this.html.closeTag(div1)); |
108 |
0
|
sb.append(this.html.getIndentedContent("<hr>\n")); |
109 |
0
|
sb.append(this.html.openTag(div2)); |
110 |
0
|
sb.append(getHtmlTable(data, getColumnDecorators())); |
111 |
0
|
sb.append(this.html.closeTag(div2)); |
112 |
0
|
sb.append(this.html.getIndentedContent("<hr>\n")); |
113 |
0
|
sb.append(this.html.openTag(div3)); |
114 |
0
|
sb.append(this.html.getTag(span2, context.getAbout())); |
115 |
0
|
sb.append(this.html.closeTag(div3)); |
116 |
0
|
sb.append(this.html.closeTag(body)); |
117 |
0
|
sb.append(this.html.closeTag(html)); |
118 |
0
|
return sb.toString(); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
124 |
0
|
protected String getTableCell(final String content, final ColumnDecorator decorator) {... |
125 |
0
|
Tag td = new Tag("td", decorator.getTableDataClass()); |
126 |
0
|
return html.getTag(td, content); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
0
|
protected boolean isEmpty(final Collection<?> c) {... |
134 |
0
|
return c == null || c.size() == 0; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
140 |
0
|
protected Tag getTableRowTag(final int row) {... |
141 |
0
|
if ((row % 2) == 0) { |
142 |
0
|
return new Tag("tr", "table-tr-odd"); |
143 |
|
} else { |
144 |
0
|
return new Tag("tr"); |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
151 |
0
|
protected String getTableRow(final int row, final String[] data,... |
152 |
|
final List<ColumnDecorator> columnDecorators) { |
153 |
0
|
StringBuffer sb = new StringBuffer(); |
154 |
0
|
Tag tr = getTableRowTag(row); |
155 |
0
|
sb.append(html.openTag(tr)); |
156 |
0
|
for (int i = 0; i < data.length; i++) { |
157 |
0
|
sb.append(getTableCell(data[i], columnDecorators.get(i))); |
158 |
|
} |
159 |
0
|
sb.append(html.closeTag(tr)); |
160 |
0
|
return sb.toString(); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
166 |
0
|
protected String getTableRows(final List<String[]> data,... |
167 |
|
final List<ColumnDecorator> columnDecorators) { |
168 |
0
|
StringBuffer sb = new StringBuffer(); |
169 |
0
|
for (int i = 0; i < data.size(); i++) { |
170 |
0
|
sb.append(getTableRow(i, data.get(i), columnDecorators)); |
171 |
|
} |
172 |
0
|
return sb.toString(); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
178 |
0
|
protected String getTableHeaders(final List<ColumnDecorator> columnDecorators) {... |
179 |
0
|
StringBuffer sb = new StringBuffer(); |
180 |
0
|
for (int i = 0; i < columnDecorators.size(); i++) { |
181 |
0
|
ColumnDecorator decorator = columnDecorators.get(i); |
182 |
0
|
Tag th = new Tag("th", decorator.getTableDataClass()); |
183 |
0
|
sb.append(html.openTag(th)); |
184 |
0
|
sb.append(html.getTag(new Tag("span", decorator.getSpanClass()), |
185 |
|
decorator.getColumnTitle())); |
186 |
0
|
sb.append(html.closeTag(th)); |
187 |
|
} |
188 |
0
|
return sb.toString(); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
194 |
0
|
protected String getHtmlTable(final List<String[]> data,... |
195 |
|
final List<ColumnDecorator> columnDecorators) { |
196 |
0
|
if (isEmpty(data)) { |
197 |
0
|
return ""; |
198 |
|
} |
199 |
0
|
StringBuffer sb = new StringBuffer(); |
200 |
0
|
Tag table = new Tag("table", "mainTable"); |
201 |
0
|
Tag thead = new Tag("thead"); |
202 |
0
|
Tag tr = new Tag("tr"); |
203 |
0
|
Tag tbody = new Tag("tbody"); |
204 |
0
|
sb.append(html.openTag(table)); |
205 |
0
|
sb.append(html.openTag(thead)); |
206 |
0
|
sb.append(html.openTag(tr)); |
207 |
0
|
sb.append(getTableHeaders(columnDecorators)); |
208 |
0
|
sb.append(html.closeTag(tr)); |
209 |
0
|
sb.append(html.closeTag(thead)); |
210 |
0
|
sb.append(html.openTag(tbody)); |
211 |
0
|
sb.append(getTableRows(data, columnDecorators)); |
212 |
0
|
sb.append(html.closeTag(tbody)); |
213 |
0
|
sb.append(html.closeTag(table)); |
214 |
0
|
return sb.toString(); |
215 |
|
} |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
217 |
0
|
public S3BucketContext getContext() {... |
218 |
0
|
return context; |
219 |
|
} |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
221 |
0
|
public void setContext(final S3BucketContext context) {... |
222 |
0
|
this.context = context; |
223 |
|
} |
224 |
|
|
225 |
|
} |