View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.ecm.webui.utils;
18  
19  import java.security.AccessControlException;
20  
21  import javax.jcr.AccessDeniedException;
22  import javax.jcr.InvalidItemStateException;
23  import javax.jcr.InvalidSerializedDataException;
24  import javax.jcr.ItemExistsException;
25  import javax.jcr.ItemNotFoundException;
26  import javax.jcr.LoginException;
27  import javax.jcr.NoSuchWorkspaceException;
28  import javax.jcr.PathNotFoundException;
29  import javax.jcr.ReferentialIntegrityException;
30  import javax.jcr.RepositoryException;
31  import javax.jcr.UnsupportedRepositoryOperationException;
32  import javax.jcr.ValueFormatException;
33  import javax.jcr.lock.LockException;
34  import javax.jcr.nodetype.ConstraintViolationException;
35  import javax.jcr.nodetype.NoSuchNodeTypeException;
36  import javax.jcr.version.VersionException;
37  
38  import org.exoplatform.services.log.Log;
39  import org.exoplatform.services.log.ExoLogger;
40  import org.exoplatform.web.application.ApplicationMessage;
41  import org.exoplatform.webui.core.UIApplication;
42  import org.exoplatform.webui.exception.MessageException;
43  
44  /**
45   * Created by The eXo Platform SARL Author : Dang Van Minh
46   * minh.dang@exoplatform.com May 8, 2008 3:18:06 PM
47   */
48  public class JCRExceptionManager {
49  
50    /**
51     * Logger.
52     */
53    private static final Log LOG  = ExoLogger.getLogger(JCRExceptionManager.class.getName());
54  
55    /**
56     * Process.
57     *
58     * @param uiApp the ui app
59     * @param e the e
60     * @param messageKey the message key
61     * @throws Exception the exception
62     */
63    public static void process(UIApplication uiApp,Exception e,String messageKey) throws Exception{
64      if (LOG.isErrorEnabled()) {
65        LOG.error("The following error occurs : " + e);
66      }
67      if(e instanceof LoginException) {
68        if(messageKey == null) messageKey = "LoginException.msg";
69      } else if(e instanceof AccessDeniedException) {
70        if(messageKey == null) messageKey = "AccessDeniedException.msg";
71      } else if(e instanceof NoSuchWorkspaceException) {
72        if(messageKey == null) messageKey = "NoSuchWorkspaceException.msg";
73      } else if(e instanceof ItemNotFoundException) {
74        if(messageKey == null) messageKey = "ItemNotFoundException.msg";
75      } else if(e instanceof ItemExistsException) {
76        if(messageKey == null) messageKey = "ItemExistsException.msg";
77      } else if(e instanceof ConstraintViolationException) {
78        if(messageKey == null) messageKey = "ConstraintViolationException.msg";
79      } else if(e instanceof InvalidItemStateException) {
80        if(messageKey == null) messageKey = "InvalidItemStateException.msg";
81      } else if(e instanceof ReferentialIntegrityException) {
82        if(messageKey == null) messageKey = "ReferentialIntegrityException.msg";
83      } else if(e instanceof LockException) {
84        if(messageKey == null) messageKey = "LockException.msg";
85      } else if(e instanceof NoSuchNodeTypeException) {
86        if(messageKey == null) messageKey = "NoSuchNodeTypeException.msg";
87      } else if(e instanceof VersionException) {
88        if(messageKey == null) messageKey = "VersionException.msg";
89      } else if(e instanceof PathNotFoundException) {
90        if(messageKey == null) messageKey = "PathNotFoundException.msg";
91      } else if(e instanceof ValueFormatException) {
92        if(messageKey == null) messageKey = "ValueFormatException.msg";
93      } else if(e instanceof InvalidSerializedDataException) {
94        if(messageKey == null) messageKey = "InvalidSerializedDataException.msg";
95      } else if(e instanceof RepositoryException) {
96        if(messageKey == null) messageKey = "RepositoryException.msg";
97      } else if(e instanceof AccessControlException) {
98        if(messageKey == null) messageKey = "AccessControlException.msg";
99      } else if(e instanceof UnsupportedRepositoryOperationException) {
100       if(messageKey == null) messageKey = "UnsupportedRepositoryOperationException.msg";
101     } else if(e instanceof MessageException) {
102       if(messageKey == null) messageKey = ((MessageException)e).getDetailMessage().getMessageKey();
103     } else {
104       throw e;
105     }
106     uiApp.addMessage(new ApplicationMessage(messageKey,
107                                             null,
108                                             ApplicationMessage.WARNING));
109   }
110 
111   /**
112    * Process.
113    *
114    * @param uiApp the ui app
115    * @param e the e
116    * @throws Exception the exception
117    */
118   public static void process(UIApplication uiApp, Exception e) throws Exception {
119     process(uiApp,e,null) ;
120   }
121 }