KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > stats > printers > HtmlTablePrinter


1 /*
2  * $Id: HtmlTablePrinter.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.stats.printers;
12
13 import org.apache.commons.lang.StringUtils;
14
15 import java.io.OutputStream JavaDoc;
16 import java.io.Writer JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.StringTokenizer JavaDoc;
19
20 /**
21  * <code>HtmlTablePrinter</code> prints event processing stats as a HTML table
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public class HtmlTablePrinter extends AbstractTablePrinter
27 {
28
29     public HtmlTablePrinter(Writer JavaDoc out)
30     {
31         super(out);
32     }
33
34     public HtmlTablePrinter(OutputStream JavaDoc out)
35     {
36         super(out);
37     }
38
39     public void print(Collection JavaDoc stats)
40     {
41         println("<font size='8'><table valign='top'>");
42         String JavaDoc[][] 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 JavaDoc getProviderStatsHtml(String JavaDoc stats)
92     {
93         if (StringUtils.isEmpty(StringUtils.trim(stats)))
94         {
95             return "";
96         }
97
98         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
99         buf.append("<table>");
100         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(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 JavaDoc 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