KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > model > Information


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.faces.core.component.model;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10 import java.util.ResourceBundle JavaDoc ;
11
12 import javax.faces.application.FacesMessage;
13 import javax.faces.context.FacesContext;
14 import javax.faces.context.ResponseWriter;
15 import org.exoplatform.faces.core.component.InformationProvider;
16 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
17 import org.exoplatform.faces.core.Util ;
18 import org.exoplatform.faces.application.ExoFacesMessage;
19 /**
20  * Jun 9, 2004
21  * @author: Tuan Nguyen
22  * @email: tuan08@users.sourceforge.net
23  * @version: $Id: Information.java,v 1.5 2004/09/21 03:41:33 tuan08 Exp $
24  */

25 public class Information {
26   private List JavaDoc messages_ ;
27   
28   public Information() {
29     messages_ = new ArrayList JavaDoc(5) ;
30   }
31   
32   public boolean hasMessage() { return messages_.size() > 0 ;}
33   public List JavaDoc getMessages() { return messages_ ; }
34   public void addMessage(FacesMessage message) { messages_.add(message) ; }
35   public void clearMessages() { messages_.clear() ; }
36   
37   static public void renderBodyInformation(FacesContext context, InformationProvider iprovider) throws IOException JavaDoc {
38     ResponseWriter w = context.getResponseWriter() ;
39     List JavaDoc messages = iprovider.getMessages() ;
40     ResourceBundle JavaDoc res = Util.getApplicationResourceBundle();
41     w.write("<table width='100%'>") ;
42     for (int i = 0; i < messages.size() ; i++) {
43       ExoFacesMessage m = (ExoFacesMessage) messages.get(i) ;
44       String JavaDoc detail = m.getDetail(res) ;
45       if(detail == null) detail = "" ;
46       w.write("<tr>") ;
47       if(m.getSeverity() == FacesMessage.SEVERITY_ERROR) {
48         w.write("<td class='portlet-msg-error'>") ;
49         w. write("error: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ;
50       } else if (m.getSeverity() == FacesMessage.SEVERITY_WARN) {
51         w.write("<td class='portlet-msg-alert'>") ;
52         w. write("warning: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ;
53       } else {
54         w.write("<td class='portlet-msg-info'>") ;
55         w. write("info: ") ; w.write(m.getSummary(res)) ;w.write("<br/>") ;
56       }
57       w. write(detail) ;
58       w. write("</td>") ;
59       w.write("</tr>") ;
60     }
61     w. write("<tr>") ;
62     w. write("<td align='center'>") ;
63     String JavaDoc baseUrl = HtmlBasicRenderer.getBaseURL(context);
64     HtmlBasicRenderer.appendLink(w, "Back", baseUrl, HtmlBasicRenderer.EMPTY_PARAMS, null) ;
65     w. write("<td>") ;
66     w. write("</tr>") ;
67     w.write("</table>") ;
68     iprovider.clearMessages() ;
69     iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ;
70   }
71   
72   
73   static public void renderFooterInformation(FacesContext context, InformationProvider iprovider) throws IOException JavaDoc {
74     ResponseWriter w = context.getResponseWriter() ;
75     List JavaDoc messages = iprovider.getMessages() ;
76     ResourceBundle JavaDoc res = Util.getApplicationResourceBundle();
77     w.write("<div style='color: red;'>") ;
78     for (int i = 0; i < messages.size() ; i++) {
79       try {
80       ExoFacesMessage m = (ExoFacesMessage) messages.get(i) ;
81       if(m.getSeverity() == FacesMessage.SEVERITY_ERROR) {
82         w.write("error: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ;
83       } else if (m.getSeverity() == FacesMessage.SEVERITY_WARN) {
84         w.write("warning: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ;
85       } else {
86         w.write("info: ") ; w.write(m.getSummary(res)) ;w.write("<br/>") ;
87       }
88       } catch (Throwable JavaDoc t) { t.printStackTrace() ;}
89     }
90      w.write("</div>") ;
91     iprovider.clearMessages() ;
92     iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ;
93   }
94 }
95
Popular Tags