1
package com.xunjie.game.answer.web.utils;
2
3
import java.util.List;
4
5
import com.opensymphony.xwork2.ActionInvocation;
6
import com.opensymphony.xwork2.ActionSupport;
7
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
8
import com.xunjie.game.answer.common.CommException;
9
10
public class CommExceptionInterceptor extends AbstractInterceptor {
11
12
public String intercept(ActionInvocation invocation) throws Exception {
13
String result = null;
14
try {
15
result = invocation.invoke();
16
} catch (CommException exception) {
17
18
ActionSupport as = (ActionSupport)invocation.getAction();
19
processBaseException(as, exception);
20
21
List exceptions = exception.getExceptions();
22
if (exceptions != null && !exceptions.isEmpty()) {
23
for (int i = 0; i < exceptions.size(); i++) {
24
CommException subEX = (CommException) exceptions.get(i);
25
processBaseException(as, subEX);
26
}
27
}
28
throw exception;
29
}
30
return result;
31
}
32
33
private void processBaseException(ActionSupport action, CommException commException) {
34
String messageKey = commException.getMessageKey();
35
String[] args = commException.getMessageArgs();
36
37
if (args != null && args.length > 0) {
38
String s = action.getText(messageKey, args);
39
action.addActionError(s);
40
} else {
41
String s = action.getText(messageKey);
42
action.addActionError(s);
43
}
44
}
45
}
46

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46
