KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > event > PermissionExceptionHandler


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.event;
6
7 import java.util.ResourceBundle JavaDoc;
8 import javax.faces.application.FacesMessage;
9 import javax.faces.component.UIComponent;
10 import org.exoplatform.commons.exception.ExoPermissionException;
11 import org.exoplatform.commons.utils.ExceptionUtil;
12 import org.exoplatform.faces.application.ExoFacesMessage;
13 import org.exoplatform.faces.core.Util;
14 import org.exoplatform.faces.core.component.InformationProvider;
15 /**
16  * Jun 3, 2004
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $ID$
20  **/

21 public class PermissionExceptionHandler extends ExceptionHandler {
22   public boolean showStackTrace_ = false ;
23   
24     public PermissionExceptionHandler() {
25   }
26   
27   public PermissionExceptionHandler setShowStackTrace(boolean b) {
28     showStackTrace_ = b ;
29     return this ;
30   }
31   
32   public boolean canHandleError(Throwable JavaDoc error) {
33     return error instanceof ExoPermissionException ;
34   }
35   
36     public void handle(ExoActionEvent action, Throwable JavaDoc error) {
37     ExoPermissionException ex = (ExoPermissionException) error ;
38     UIComponent src = action.getComponent() ;
39     InformationProvider iprovider = Util.findInformationProvider(src) ;
40     if(iprovider != null) {
41       String JavaDoc stackTrace = null ;
42       if(showStackTrace_) {
43         stackTrace = ExceptionUtil.getStackTrace(new Exception JavaDoc(), 3) ;
44       }
45       ResourceBundle JavaDoc res = Util.getApplicationResourceBundle() ;
46       String JavaDoc message = ex.getMessage(res) ;
47       iprovider.addMessage(new ExoFacesMessage(FacesMessage.SEVERITY_ERROR, message, stackTrace)) ;
48       iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ;
49     } else {
50       //System.out.println(ExceptionUtil.getExoStackTrace(error)) ;
51
}
52     }
53 }
Popular Tags