1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.exception; |
17 | |
|
18 | |
import org.apache.commons.fileupload.FileUploadException; |
19 | |
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException; |
20 | |
import org.seasar.framework.exception.SRuntimeException; |
21 | |
|
22 | |
public class FileUploadRuntimeException extends SRuntimeException { |
23 | |
|
24 | |
private static final long serialVersionUID = -4519684364519402697L; |
25 | |
|
26 | |
public FileUploadRuntimeException(final FileUploadException cause) { |
27 | 0 | super(messageCode(cause), args(cause), cause); |
28 | 0 | } |
29 | |
|
30 | |
private static String messageCode(final FileUploadException cause) { |
31 | |
final String messageCode; |
32 | 0 | if (cause instanceof SizeLimitExceededException) { |
33 | 0 | messageCode = "ECUB0202"; |
34 | |
} else { |
35 | 0 | messageCode = "ECUB0201"; |
36 | |
} |
37 | 0 | return messageCode; |
38 | |
} |
39 | |
|
40 | |
private static Object[] args(final FileUploadException cause) { |
41 | |
final Object[] args; |
42 | 0 | if (cause instanceof SizeLimitExceededException) { |
43 | 0 | final SizeLimitExceededException sle = (SizeLimitExceededException) cause; |
44 | 0 | args = new Object[] { sle.getPermittedSize(), sle.getActualSize() }; |
45 | 0 | } else { |
46 | 0 | args = new Object[] { cause }; |
47 | |
} |
48 | 0 | return args; |
49 | |
} |
50 | |
} |