1 40 41 package org.dspace.app.statistics; 42 43 import org.dspace.app.statistics.Report; 44 import org.dspace.app.statistics.Stat; 45 import org.dspace.app.statistics.Statistics; 46 import org.dspace.app.statistics.ReportTools; 47 48 import java.text.DateFormat ; 49 50 import java.util.ArrayList ; 51 import java.util.Date ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 import java.util.Map ; 55 import java.util.regex.Matcher ; 56 import java.util.regex.Pattern ; 57 58 63 public class HTMLReport extends Report 64 { 65 68 69 private List blocks = new ArrayList (); 70 71 72 private String pageTitle = null; 73 74 75 private String mainTitle = null; 76 77 78 private Date start = null; 79 80 81 private Date end = null; 82 83 86 public void HTMLReport() 87 { 88 } 90 91 96 public String render() 97 { 98 StringBuffer frag = new StringBuffer (); 99 100 frag.append(header(pageTitle)); 102 frag.append(mainTitle()); 103 frag.append(dateRange()); 104 105 Iterator statSets = blocks.iterator(); 108 while (statSets.hasNext()) 109 { 110 frag.append(navigation()); 111 112 Statistics stats = (Statistics) statSets.next(); 113 frag.append(sectionHeader(stats.getSectionHeader())); 114 frag.append(topLink()); 115 frag.append(blockExplanation(stats.getExplanation())); 116 frag.append(floorInfo(stats.getFloor())); 117 frag.append(statBlock(stats)); 118 } 119 120 frag.append(footer()); 122 123 return frag.toString(); 124 } 125 126 127 132 public String topLink() 133 { 134 String frag = "<div class=\"reportNavigation\"><a HREF=\"#top\">Top</a></div>"; 135 return frag; 136 } 137 138 139 144 public String navigation() 145 { 146 StringBuffer frag = new StringBuffer (); 147 148 frag.append("<div class=\"reportNavigation\">"); 149 frag.append("<a HREF=\"#general_overview\">General Overview</a>"); 150 frag.append(" | "); 151 frag.append("<a HREF=\"#archive_information\">Archive Information</a>"); 152 frag.append(" | "); 153 frag.append("<a HREF=\"#items_viewed\">Items Viewed</a>"); 154 frag.append(" | "); 155 frag.append("<a HREF=\"#all_actions_performed\">All Actions Performed</a>"); 156 frag.append(" | "); 157 frag.append("<a HREF=\"#user_logins\">User Logins</a>"); 158 frag.append(" | "); 159 frag.append("<a HREF=\"#words_searched\">Words Searched</a>"); 160 frag.append(" | "); 161 frag.append("<a HREF=\"#averaging_information\">Averaging Information</a>"); 162 frag.append(" | "); 163 frag.append("<a HREF=\"#log_level_information\">Log Level Information</a>"); 164 frag.append(" | "); 165 frag.append("<a HREF=\"#processing_information\">Processing Information</a>"); 166 frag.append("</div>"); 167 168 return frag.toString(); 169 } 170 171 176 public void addBlock(Statistics stat) 177 { 178 blocks.add(stat); 179 return; 180 } 181 182 183 188 public void setStartDate(Date start) 189 { 190 this.start = start; 191 } 192 193 194 199 public void setEndDate(Date end) 200 { 201 this.end = end; 202 } 203 204 205 211 public String dateRange() 212 { 213 StringBuffer frag = new StringBuffer (); 214 DateFormat df = DateFormat.getDateInstance(); 215 216 frag.append("<div class=\"reportDate\">"); 217 if (start != null) 218 { 219 frag.append(df.format(start)); 220 } 221 else 222 { 223 frag.append("from start of records "); 224 } 225 226 frag.append(" to "); 227 228 if (end != null) 229 { 230 frag.append(df.format(end)); 231 } 232 else 233 { 234 frag.append(" end of records"); 235 } 236 237 frag.append("</div>\n\n"); 238 239 return frag.toString(); 240 } 241 242 243 249 public String mainTitle() 250 { 251 String frag = "<div class=\"reportTitle\"><a name=\"top\">" + mainTitle + "</a></div>\n\n"; 252 return frag; 253 } 254 255 256 262 public void setMainTitle(String name, String serverName) 263 { 264 mainTitle = "Statistics for " + name + " on " + serverName; 265 if (pageTitle == null) 266 { 267 pageTitle = mainTitle; 268 } 269 return; 270 } 271 272 273 278 public String header() 279 { 280 return header(""); 281 } 282 283 289 public String header(String title) 290 { 291 StringBuffer frag = new StringBuffer (); 295 296 frag.append("<style type=\"text/css\">\n"); 297 frag.append("body { font-family: Arial, Helvetica, sans-serif }"); 298 frag.append(".reportTitle { width: 100%; clear: both; text-align: center; font-weight: bold; font-size: 200%; margin: 20px; }\n"); 299 frag.append(".reportSection { width: 100%; clear: both; font-weight: bold; font-size: 160%; margin: 10px; text-align: center; margin-top: 30px; }\n"); 300 frag.append(".reportBlock { border: 1px solid #000000; margin: 10px; }\n"); 301 frag.append(".reportOddRow { background: #dddddd; }\n"); 302 frag.append(".reportEvenRow { background: #bbbbbb; }\n"); 303 frag.append(".reportExplanation { font-style: italic; text-align: center; }\n"); 304 frag.append(".reportDate { font-style: italic; text-align: center; font-size: 120% }\n"); 305 frag.append(".reportFloor { text-align: center; }\n"); 306 frag.append(".rightAlign { text-align: right; }\n"); 307 frag.append(".reportNavigation { text-align: center; }\n"); 308 frag.append("</style>\n"); 309 310 return frag.toString(); 311 } 312 313 314 321 public String sectionHeader(String title) 322 { 323 String aName = title.toLowerCase(); 326 Pattern space = Pattern.compile(" "); 327 Matcher matchSpace = space.matcher(aName); 328 aName = matchSpace.replaceAll("_"); 329 330 String frag = "<div class=\"reportSection\"><a name=\"" + aName + "\">" + title + "</a></div>\n\n"; 331 return frag; 332 } 333 334 335 345 public String statBlock(Statistics content) 346 { 347 StringBuffer frag = new StringBuffer (); 348 Stat[] stats = content.getStats(); 349 350 frag.append("<table align=\"center\" class=\"reportBlock\" cellpadding=\"5\">\n"); 352 353 if (content.getStatName() != null || content.getResultName() != null) 355 { 356 frag.append("\t<tr>\n"); 357 frag.append("\t\t<th>\n"); 358 if (content.getStatName() != null) 359 { 360 frag.append("\t\t\t" + content.getStatName() + "\n"); 361 } 362 else 363 { 364 frag.append("\t\t\t \n"); 365 } 366 frag.append("\t\t</th>\n"); 367 frag.append("\t\t<th>\n"); 368 if (content.getResultName() != null) 369 { 370 frag.append("\t\t\t" + content.getResultName() + "\n"); 371 } 372 else 373 { 374 frag.append("\t\t\t \n"); 375 } 376 frag.append("\t\t</th>\n"); 377 frag.append("\t</tr>\n"); 378 } 379 380 for (int i = 0; i < stats.length; i++) 382 { 383 String style = null; 384 385 if ((i % 2) == 1) 386 { 387 style = "reportOddRow"; 388 } 389 else 390 { 391 style = "reportEvenRow"; 392 } 393 394 frag.append("\t<tr class=\"" + style + "\">\n\t\t<td>\n"); 395 frag.append("\t\t\t"); 396 if (stats[i].getReference() != null) 397 { 398 frag.append("<a HREF=\"" + stats[i].getReference() + "\" "); 399 frag.append("target=\"_blank\">"); 400 } 401 frag.append(stats[i].getKey()); 402 if (stats[i].getReference() != null) 403 { 404 frag.append("</a>"); 405 } 406 frag.append("\n"); 407 frag.append("\t\t</td>\n\t\t<td class=\"rightAlign\">\n"); 408 frag.append("\t\t\t" + ReportTools.numberFormat(stats[i].getValue())); 409 if (stats[i].getUnits() != null) 410 { 411 frag.append(" " + stats[i].getUnits()); 412 } 413 frag.append("\n"); 414 frag.append("\t\t</td>\n\t</tr>\n"); 415 } 416 417 frag.append("</table>\n"); 418 419 return frag.toString(); 420 } 421 422 423 430 public String floorInfo(int floor) 431 { 432 if (floor > 0) 433 { 434 StringBuffer frag = new StringBuffer (); 435 frag.append("<div class=\"reportFloor\">"); 436 frag.append("(more than " + ReportTools.numberFormat(floor) + " times)"); 437 frag.append("</div>\n"); 438 return frag.toString(); 439 } 440 else 441 { 442 return ""; 443 } 444 } 445 446 453 public String blockExplanation(String explanation) 454 { 455 if (explanation != null) 456 { 457 StringBuffer frag = new StringBuffer (); 458 frag.append("<div class=\"reportExplanation\">"); 459 frag.append(explanation); 460 frag.append("</div>\n\n"); 461 return frag.toString(); 462 } 463 else 464 { 465 return ""; 466 } 467 } 468 469 474 public String footer() 475 { 476 return ""; 477 } 478 479 } 480 | Popular Tags |