1 5 package org.exoplatform.faces.core.event; 6 7 import java.util.ResourceBundle ; 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 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 error) { 33 return error instanceof ExoPermissionException ; 34 } 35 36 public void handle(ExoActionEvent action, Throwable error) { 37 ExoPermissionException ex = (ExoPermissionException) error ; 38 UIComponent src = action.getComponent() ; 39 InformationProvider iprovider = Util.findInformationProvider(src) ; 40 if(iprovider != null) { 41 String stackTrace = null ; 42 if(showStackTrace_) { 43 stackTrace = ExceptionUtil.getStackTrace(new Exception (), 3) ; 44 } 45 ResourceBundle res = Util.getApplicationResourceBundle() ; 46 String message = ex.getMessage(res) ; 47 iprovider.addMessage(new ExoFacesMessage(FacesMessage.SEVERITY_ERROR, message, stackTrace)) ; 48 iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ; 49 } else { 50 } 52 } 53 } | Popular Tags |