KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > UIFatalError


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;
6
7 import java.io.*;
8 import javax.faces.context.FacesContext;
9 import javax.faces.context.ResponseWriter;
10 import org.exoplatform.faces.FacesConstants;
11 import org.exoplatform.faces.context.PortletFacesContext;
12 /**
13  * Wed, Dec 22, 2003 @ 23:14
14  * @author: Tuan Nguyen
15  * @email: tuan08@users.sourceforge.net
16  * @version: $Id: UIFatalError.java,v 1.6 2004/11/03 04:24:53 tuan08 Exp $
17  */

18 public class UIFatalError extends UIExoComponentBase {
19     
20   private Throwable JavaDoc exception_ ;
21
22   public UIFatalError(Throwable JavaDoc ex) {
23     setId("UIFatalError") ;
24     exception_ = ex ;
25   }
26
27   public void decode(FacesContext context) {
28     PortletFacesContext pcontext = (PortletFacesContext)context ;
29     pcontext.destroy() ;
30   }
31   
32   final public void encodeBegin(FacesContext context) throws IOException {
33     String JavaDoc baseURL = context.getExternalContext().encodeActionURL(null) ;
34     ResponseWriter w = context.getResponseWriter() ;
35     w.write("<div>");
36     w. write("The portlet has a fatal error. Click here to restart the portlet") ;
37     renderButton(w, baseURL);
38     w.write("</div>");
39     w.write("<div style='border: 1px dashed black>");
40     String JavaDoc message = exception_.getMessage() ;
41     if (message != null) {
42         w.write(exception_.getMessage()) ;
43     }
44     w.write(getStackTrace(exception_));
45     w.write("</div>");
46     
47   }
48   
49   private void renderButton(ResponseWriter w, String JavaDoc baseURL) throws IOException {
50     w.write("<a HREF='"); w.write(baseURL) ;
51     w.write('&'); w.write(FacesConstants.ACTION); w.write("=restart") ;
52     w.write("'>");
53     w.write("Click");
54     w.write("</a>") ;
55   }
56   
57   private String JavaDoc getStackTrace(Throwable JavaDoc t) {
58     ByteArrayOutputStream ostream = new ByteArrayOutputStream() ;
59     PrintStream pstream = new PrintStream(ostream) ;
60     t.printStackTrace(pstream) ;
61     return new String JavaDoc(ostream.toByteArray()) ;
62   }
63   
64   final public void encodeChildren(FacesContext context) throws IOException {
65   }
66
67   final public void encodeEnd(FacesContext context) throws IOException {
68   }
69 }
Popular Tags