1 10 11 package org.mule.management.stats.printers; 12 13 import org.apache.commons.lang.StringUtils; 14 15 import java.io.OutputStream ; 16 import java.io.Writer ; 17 import java.util.Collection ; 18 import java.util.StringTokenizer ; 19 20 26 public class HtmlTablePrinter extends AbstractTablePrinter 27 { 28 29 public HtmlTablePrinter(Writer out) 30 { 31 super(out); 32 } 33 34 public HtmlTablePrinter(OutputStream out) 35 { 36 super(out); 37 } 38 39 public void print(Collection stats) 40 { 41 println("<font size='8'><table valign='top'>"); 42 String [][] table = getTable(stats); 43 boolean endpointStats = false; 44 for (int i = 0; i < table[0].length; i++) 45 { 46 println("<tr valign='top'>"); 47 boolean bold = false; 48 49 for (int j = 0; j < table.length; j++) 50 { 51 if (j == 0 || i == 0 || "-".equals(table[j][i])) 52 { 53 bold = true; 54 print("<td bgcolor='lightgray'><b>"); 55 } 56 else 57 { 58 bold = false; 59 print("<td>"); 60 } 61 if (endpointStats) 62 { 63 64 print(getProviderStatsHtml(table[j][i])); 65 } 66 else 67 { 68 if (endpointStats) 69 { 70 bold = true; 71 print("<b>"); 72 } 73 74 print(("-".equals(table[j][i]) ? "" : table[j][i])); 75 } 76 print((bold ? "</b>" : "") + "</td>"); 77 } 78 println("</tr>"); 79 if ("By Provider".equals(table[0][i])) 80 { 81 endpointStats = true; 82 } 83 else 84 { 85 endpointStats = false; 86 } 87 } 88 println("</table></font>"); 89 } 90 91 protected String getProviderStatsHtml(String stats) 92 { 93 if (StringUtils.isEmpty(StringUtils.trim(stats))) 94 { 95 return ""; 96 } 97 98 StringBuffer buf = new StringBuffer (); 99 buf.append("<table>"); 100 StringTokenizer st = new StringTokenizer (stats, ";"); 101 102 if (st.countTokens() == 0) 103 { 104 buf.append("<tr><td>"); 105 int i = stats.indexOf("="); 106 buf.append(stats.substring(0, i)).append(": "); 107 buf.append("</td><td align=\"right'>"); 108 buf.append(stats.substring(i + 1)); 109 buf.append("</td></tr>"); 110 } 111 else 112 { 113 String token; 114 while (st.hasMoreTokens()) 115 { 116 token = st.nextToken(); 117 buf.append("<tr><td>"); 118 int i = token.indexOf("="); 119 buf.append(token.substring(0, i)).append(": "); 120 buf.append("</td><td align=''right'>"); 121 buf.append(token.substring(i + 1)); 122 buf.append("</td></tr>"); 123 } 124 } 125 buf.append("</table>"); 126 return buf.toString(); 127 } 128 129 } 130 | Popular Tags |