KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > log > renderer > html > LogMessagesRenderer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.log.renderer.html;
6
7 import java.util.List JavaDoc;
8 import javax.faces.component.UIComponent;
9 import javax.faces.context.FacesContext;
10 import javax.faces.context.ResponseWriter ;
11 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
12 import org.exoplatform.portlets.log.component.UILogMessages;
13 import org.exoplatform.services.log.LogMessage;
14 import org.exoplatform.services.log.impl.ExoLog;
15 import java.io.IOException JavaDoc;
16
17
18 public class LogMessagesRenderer extends HtmlBasicRenderer {
19   private static String JavaDoc SCRIPT =
20     "<script type='text/javascript'>\n" +
21     " function showLogDetail(id, button) {\n" +
22     " var block = document.getElementById(id);\n" +
23     " if(block.style.display == 'none') { \n" +
24     " block.style.display = 'block' ; \n" +
25     " } else {\n" +
26     " block.style.display = 'none' ; \n" +
27     " } \n" +
28     " }\n" +
29     "</script>\n" ;
30
31   protected String JavaDoc levelAsString( int level ) {
32     if (ExoLog.FATAL == level) return "FATAL";
33     else if (ExoLog.ERROR == level) return "ERROR";
34     else if (ExoLog.WARN == level) return "WARNING";
35     else if (ExoLog.INFO == level) return "INFO";
36     else if (ExoLog.DEBUG == level) return "DEBUG";
37     else if (ExoLog.TRACE == level) return "TRACE";
38     return null;
39   }
40
41   public void encodeBegin( FacesContext context, UIComponent component ) throws IOException JavaDoc {
42     UILogMessages uiLogMessages = (UILogMessages) component;
43     ResponseWriter w = context.getResponseWriter() ;
44     //String actionURL = context.getExternalContext().encodeActionURL(null) ;
45
w.write("<table class='UILogMessages'>\n");
46     w.write(SCRIPT);
47     List JavaDoc list = uiLogMessages.getLogMessages() ;
48     for (int i = 0 ; i < list.size(); i++) {
49       LogMessage lm = (LogMessage) list.get(i);
50       String JavaDoc detail = lm.getDetail() ;
51       w.write("<tr>");
52       w. write("<td>"); w.write(lm.getName()); w.write("</td>");
53       w. write("<td>");
54       w. write("[" + levelAsString( lm.getType()) + "]");
55       w. write("</td>");
56       w. write("<td width='100%'>") ;
57       if (detail == null) {
58         w. write(lm.getMessage());
59       } else {
60         w. write("<a HREF=\"javascript:showLogDetail('msg-"+ i +"', this)\">") ;
61         w. write(lm.getMessage()) ;
62         w. write("</a>");
63         w. write("<div id='msg-" + i + "' style='display: none'>") ;
64         w. write("<pre>") ;
65         w. write(detail);
66         w. write("</pre>") ;
67         w. write("</div>") ;
68       }
69       w. write("</td>");
70       w.write("</tr>\n");
71     }
72     w.write("</table>");
73   }
74 }
Popular Tags