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.ExoMessageException; 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 MessageExceptionHandler extends ExceptionHandler { 22 23 public MessageExceptionHandler() { 24 } 25 26 public boolean canHandleError(Throwable error) { 27 return error instanceof ExoMessageException ; 28 } 29 30 public void handle(ExoActionEvent action, Throwable error) { 31 ExoMessageException ex = (ExoMessageException) error ; 32 UIComponent src = action.getComponent() ; 33 InformationProvider iprovider = Util.findInformationProvider(src) ; 34 if(iprovider != null) { 35 ResourceBundle res = Util.getApplicationResourceBundle() ; 36 String message = ex.getMessage(res) ; 37 String stackTrace = null ; 38 if(ex.getSeverity() <= ExoMessageException.WARN) { 39 stackTrace = ExceptionUtil.getStackTrace(new Exception (), 3) ; 40 } 41 iprovider.addMessage(new ExoFacesMessage(FacesMessage.SEVERITY_ERROR, message, stackTrace, ex.getArguments())) ; 42 if(ex.getSeverity() <= ExoMessageException.WARN) { 43 iprovider.setDisplayMessageType(InformationProvider.BODY_MESSAGE_TYPE) ; 44 } else { 45 iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ; 46 } 47 } else { 48 } 50 } 51 } | Popular Tags |