1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki

File XWikiException.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
66% of files have more coverage

Code metrics

10
44
19
1
474
264
25
0.57
2.32
19
1.32

Classes

Class Line # Actions
XWikiException 28 44 0% 25 25
0.6575342465.8%
 

Contributing tests

This file is covered by 20 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki;
21   
22    import java.text.MessageFormat;
23   
24    import org.apache.commons.lang3.exception.ExceptionUtils;
25    import org.slf4j.Logger;
26    import org.slf4j.LoggerFactory;
27   
 
28    public class XWikiException extends Exception
29    {
30    private static final Logger LOGGER = LoggerFactory.getLogger(XWikiException.class);
31   
32    private int module;
33   
34    private int code;
35   
36    private Object[] args;
37   
38    // Module list
39    public static final int MODULE_XWIKI = 0;
40   
41    public static final int MODULE_XWIKI_CONFIG = 1;
42   
43    public static final int MODULE_XWIKI_DOC = 2;
44   
45    public static final int MODULE_XWIKI_STORE = 3;
46   
47    public static final int MODULE_XWIKI_RENDERING = 4;
48   
49    public static final int MODULE_XWIKI_PLUGINS = 5;
50   
51    public static final int MODULE_XWIKI_PERLPLUGINS = 6;
52   
53    public static final int MODULE_XWIKI_CLASSES = 7;
54   
55    public static final int MODULE_XWIKI_USER = 8;
56   
57    public static final int MODULE_XWIKI_ACCESS = 9;
58   
59    public static final int MODULE_XWIKI_EMAIL = 10;
60   
61    public static final int MODULE_XWIKI_APP = 11;
62   
63    public static final int MODULE_XWIKI_EXPORT = 12;
64   
65    public static final int MODULE_XWIKI_DIFF = 13;
66   
67    public static final int MODULE_XWIKI_GROOVY = 14;
68   
69    public static final int MODULE_XWIKI_NOTIFICATION = 15;
70   
71    public static final int MODULE_XWIKI_CACHE = 16;
72   
73    public static final int MODULE_XWIKI_CONTENT = 17;
74   
75    public static final int MODULE_XWIKI_XMLRPC = 18;
76   
77    public static final int MODULE_XWIKI_GWT_API = 19;
78   
79    // Error list
80    public static final int ERROR_XWIKI_UNKNOWN = 0;
81   
82    public static final int ERROR_XWIKI_NOT_IMPLEMENTED = 1;
83   
84    public static final int ERROR_XWIKI_DOES_NOT_EXIST = 2;
85   
86    public static final int ERROR_XWIKI_INIT_FAILED = 3;
87   
88    public static final int ERROR_XWIKI_MKDIR = 4;
89   
90    public static final int ERROR_XWIKI_DOC_CUSTOMDOCINVOCATIONERROR = 5;
91   
92    // Config
93    public static final int ERROR_XWIKI_CONFIG_FILENOTFOUND = 1001;
94   
95    public static final int ERROR_XWIKI_CONFIG_FORMATERROR = 1002;
96   
97    // Doc
98    public static final int ERROR_XWIKI_DOC_EXPORT = 2001;
99   
100    public static final int ERROR_DOC_XML_PARSING = 2002;
101   
102    public static final int ERROR_DOC_RCS_PARSING = 2003;
103   
104    // Store
105    public static final int ERROR_XWIKI_STORE_CLASSINVOCATIONERROR = 3001;
106   
107    public static final int ERROR_XWIKI_STORE_FILENOTFOUND = 3002;
108   
109    public static final int ERROR_XWIKI_STORE_ARCHIVEFORMAT = 3003;
110   
111    public static final int ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT = 3004;
112   
113    public static final int ERROR_XWIKI_STORE_MIGRATION = 3005;
114   
115    public static final int ERROR_XWIKI_STORE_MISC = 3006;
116   
117    public static final int ERROR_XWIKI_STORE_RCS_SAVING_FILE = 3101;
118   
119    public static final int ERROR_XWIKI_STORE_RCS_READING_FILE = 3102;
120   
121    public static final int ERROR_XWIKI_STORE_RCS_DELETING_FILE = 3103;
122   
123    public static final int ERROR_XWIKI_STORE_RCS_READING_REVISIONS = 3103;
124   
125    public static final int ERROR_XWIKI_STORE_RCS_READING_VERSION = 3104;
126   
127    public static final int ERROR_XWIKI_STORE_RCS_SEARCH = 3111;
128   
129    public static final int ERROR_XWIKI_STORE_RCS_LOADING_ATTACHMENT = 3221;
130   
131    public static final int ERROR_XWIKI_STORE_RCS_SAVING_ATTACHMENT = 3222;
132   
133    public static final int ERROR_XWIKI_STORE_RCS_SEARCHING_ATTACHMENT = 3223;
134   
135    public static final int ERROR_XWIKI_STORE_RCS_DELETING_ATTACHMENT = 3224;
136   
137    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_DOC = 3201;
138   
139    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_DOC = 3202;
140   
141    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_DOC = 3203;
142   
143    public static final int ERROR_XWIKI_STORE_HIBERNATE_CANNOT_DELETE_UNLOADED_DOC = 3204;
144   
145    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS = 3203;
146   
147    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_VERSION = 3204;
148   
149    public static final int ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION = 3205;
150   
151    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT = 3211;
152   
153    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT = 3212;
154   
155    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT = 3213;
156   
157    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_CLASS = 3221;
158   
159    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_CLASS = 3222;
160   
161    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCH = 3223;
162   
163    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT = 3231;
164   
165    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT = 3232;
166   
167    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_ATTACHMENT = 3233;
168   
169    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT_LIST = 3234;
170   
171    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCHING_ATTACHMENT = 3235;
172   
173    public static final int ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DOC = 3236;
174   
175    public static final int ERROR_XWIKI_STORE_HIBERNATE_SWITCH_DATABASE = 3301;
176   
177    public static final int ERROR_XWIKI_STORE_HIBERNATE_CREATE_DATABASE = 3401;
178   
179    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETE_DATABASE = 3402;
180   
181    public static final int ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DATABASE = 3403;
182   
183    public static final int ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION = 4001;
184   
185    public static final int ERROR_XWIKI_RENDERING_GROOVY_EXCEPTION = 4002;
186   
187    public static final int ERROR_XWIKI_PERLPLUGIN_START_EXCEPTION = 6001;
188   
189    public static final int ERROR_XWIKI_PERLPLUGIN_START = 6002;
190   
191    public static final int ERROR_XWIKI_PERLPLUGIN_PERLSERVER_EXCEPTION = 6003;
192   
193    public static final int ERROR_XWIKI_CLASSES_FIELD_DOES_NOT_EXIST = 7001;
194   
195    public static final int ERROR_XWIKI_CLASSES_FIELD_INVALID = 7002;
196   
197    public static final int ERROR_XWIKI_CLASSES_DIFF = 7003;
198   
199    public static final int ERROR_XWIKI_CLASSES_CUSTOMCLASSINVOCATIONERROR = 7004;
200   
201    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION = 7005;
202   
203    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_IN_METACLASS = 7006;
204   
205    public static final int ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY = 7007;
206   
207    public static final int ERROR_XWIKI_USER_INIT = 8001;
208   
209    public static final int ERROR_XWIKI_USER_CREATE = 8002;
210   
211    public static final int ERROR_XWIKI_USER_INACTIVE = 8003;
212   
213    public static final int ERROR_XWIKI_ACCESS_DENIED = 9001;
214   
215    public static final int ERROR_XWIKI_ACCESS_TOKEN_INVALID = 9002;
216   
217    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS = 9003;
218   
219    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_GROUPS = 9004;
220   
221    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_ADDING_USERS = 9005;
222   
223    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_LISTING_USERS = 9006;
224   
225    public static final int ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG = 10001;
226   
227    public static final int ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL = 10002;
228   
229    public static final int ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL = 10003;
230   
231    public static final int ERROR_XWIKI_EMAIL_CONNECT_FAILED = 10004;
232   
233    public static final int ERROR_XWIKI_EMAIL_LOGIN_FAILED = 10005;
234   
235    public static final int ERROR_XWIKI_EMAIL_SEND_FAILED = 10006;
236   
237    public static final int ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST = 11001;
238   
239    public static final int ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY = 11002;
240   
241    public static final int ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND = 11003;
242   
243    public static final int ERROR_XWIKI_APP_CREATE_USER = 11004;
244   
245    public static final int ERROR_XWIKI_APP_VALIDATE_USER = 11005;
246   
247    public static final int ERROR_XWIKI_APP_INVALID_CHARS = 11006;
248   
249    public static final int ERROR_XWIKI_APP_URL_EXCEPTION = 11007;
250   
251    public static final int ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION = 11008;
252   
253    public static final int ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION = 11009;
254   
255    public static final int ERROR_XWIKI_APP_REDIRECT_EXCEPTION = 11010;
256   
257    public static final int ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION = 11011;
258   
259    public static final int ERROR_XWIKI_APP_SERVICE_NOT_FOUND = 11012;
260   
261    public static final int ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = 11013;
262   
263    public static final int ERROR_XWIKI_APP_JAVA_HEAP_SPACE = 11014;
264   
265    public static final int ERROR_XWIKI_APP_EXPORT = 11015;
266   
267    public static final int ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE = 11016;
268   
269    public static final int ERROR_XWIKI_EXPORT_XSL_FILE_NOT_FOUND = 12001;
270   
271    public static final int ERROR_XWIKI_EXPORT_PDF_FOP_FAILED = 12002;
272   
273    public static final int ERROR_XWIKI_EXPORT_XSL_FAILED = 12003;
274   
275    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LOCK = 13006;
276   
277    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LOCK = 13007;
278   
279    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LOCK = 13008;
280   
281    public static final int ERROR_XWIKI_STORE_HIBERNATE_INVALID_MAPPING = 13009;
282   
283    public static final int ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED = 13010;
284   
285    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LINKS = 13011;
286   
287    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LINKS = 13012;
288   
289    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LINKS = 13013;
290   
291    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_BACKLINKS = 13014;
292   
293    public static final int ERROR_XWIKI_DIFF_CONTENT_ERROR = 13021;
294   
295    public static final int ERROR_XWIKI_DIFF_RENDERED_ERROR = 13022;
296   
297    public static final int ERROR_XWIKI_DIFF_METADATA_ERROR = 13023;
298   
299    public static final int ERROR_XWIKI_DIFF_CLASS_ERROR = 13024;
300   
301    public static final int ERROR_XWIKI_DIFF_OBJECT_ERROR = 13025;
302   
303    public static final int ERROR_XWIKI_DIFF_ATTACHMENT_ERROR = 13026;
304   
305    public static final int ERROR_XWIKI_DIFF_XML_ERROR = 13027;
306   
307    public static final int ERROR_XWIKI_STORE_SEARCH_NOTIMPL = 13200;
308   
309    public static final int ERROR_XWIKI_GROOVY_COMPILE_FAILED = 14001;
310   
311    public static final int ERROR_XWIKI_GROOVY_EXECUTION_FAILED = 14002;
312   
313    public static final int ERROR_XWIKI_NOTIFICATION = 15001;
314   
315    public static final int ERROR_CACHE_INITIALIZING = 16001;
316   
317    // Content errors
318    public static final int ERROR_XWIKI_CONTENT_LINK_INVALID_TARGET = 22000;
319   
320    public static final int ERROR_XWIKI_CONTENT_LINK_INVALID_URI = 22001;
321   
 
322  5334 toggle public XWikiException(int module, int code, String message, Throwable e, Object[] args)
323    {
324  5334 super(message, e);
325   
326  5334 setModule(module);
327  5334 setCode(code);
328  5334 setArgs(args);
329   
330  5334 if (LOGGER.isTraceEnabled()) {
331  0 LOGGER.trace(getMessage(), e);
332    }
333    }
334   
335    /**
336    * @since 7.1M1
337    */
 
338  0 toggle public XWikiException(String message, Throwable e)
339    {
340  0 this(MODULE_XWIKI, ERROR_XWIKI_UNKNOWN, message, e);
341    }
342   
 
343  112 toggle public XWikiException(int module, int code, String message, Throwable e)
344    {
345  112 this(module, code, message, e, null);
346    }
347   
 
348  4842 toggle public XWikiException(int module, int code, String message)
349    {
350  4842 this(module, code, message, null, null);
351    }
352   
 
353  3 toggle public XWikiException()
354    {
355    }
356   
 
357  0 toggle public int getModule()
358    {
359  0 return this.module;
360    }
361   
 
362  142 toggle public String getModuleName()
363    {
364  142 return String.valueOf(this.module);
365    }
366   
 
367  5334 toggle public void setModule(int module)
368    {
369  5334 this.module = module;
370    }
371   
 
372  827 toggle public int getCode()
373    {
374  827 return this.code;
375    }
376   
 
377  5334 toggle public void setCode(int code)
378    {
379  5334 this.code = code;
380    }
381   
382    /**
383    * @deprecated since 5.2M2, use {@link #getCause()} instead
384    */
 
385  0 toggle @Deprecated
386    public Throwable getException()
387    {
388  0 return getCause();
389    }
390   
391    /**
392    * @deprecated since 5.2M2, use {@link #initCause(Throwable)} instead
393    */
 
394  0 toggle @Deprecated
395    public void setException(Throwable exception)
396    {
397  0 initCause(exception);
398    }
399   
 
400  0 toggle public Object[] getArgs()
401    {
402  0 return this.args;
403    }
404   
 
405  5334 toggle public void setArgs(Object[] args)
406    {
407  5334 this.args = args;
408    }
409   
 
410  142 toggle @Override
411    public String getMessage()
412    {
413  143 StringBuilder buffer = new StringBuilder();
414   
415  142 buffer.append("Error number ");
416  142 buffer.append(getCode());
417  142 buffer.append(" in ");
418  143 buffer.append(getModuleName());
419   
420  143 String message = super.getMessage();
421  143 if (message != null) {
422  143 buffer.append(": ");
423  143 if (this.args == null) {
424  41 buffer.append(message);
425    } else {
426  101 MessageFormat msgFormat = new MessageFormat(message);
427  101 try {
428  101 buffer.append(msgFormat.format(this.args));
429    } catch (Exception e) {
430  0 buffer.append("Cannot format message [" + message + "] with args ");
431  0 for (int i = 0; i < this.args.length; i++) {
432  0 if (i != 0) {
433  0 buffer.append(",");
434    }
435  0 buffer.append(this.args[i]);
436    }
437    }
438    }
439    }
440   
441  142 return buffer.toString();
442    }
443   
444    /**
445    * Has no effect.
446    *
447    * @deprecated since 5.2M2, the message should be passed to the constructor
448    */
 
449  0 toggle @Deprecated
450    public void setMessage(String message)
451    {
452   
453    }
454   
 
455  31 toggle public String getFullMessage()
456    {
457  31 StringBuilder buffer = new StringBuilder(getMessage());
458  31 buffer.append("\n");
459  31 buffer.append(getStackTraceAsString());
460  31 buffer.append("\n");
461   
462  31 return buffer.toString();
463    }
464   
 
465  31 toggle public String getStackTraceAsString()
466    {
467  31 return ExceptionUtils.getStackTrace(this);
468    }
469   
 
470  0 toggle public String getStackTraceAsString(Throwable e)
471    {
472  0 return ExceptionUtils.getStackTrace(e);
473    }
474    }