1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.validator; |
20 | |
|
21 | |
import java.util.Collection; |
22 | |
|
23 | |
import javax.faces.FacesException; |
24 | |
import javax.faces.application.FacesMessage; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class ValidatorException |
30 | |
extends FacesException |
31 | |
{ |
32 | |
private static final long serialVersionUID = 5965885122446047949L; |
33 | |
private FacesMessage _facesMessage; |
34 | |
private Collection<FacesMessage> _facesMessages; |
35 | |
|
36 | |
public ValidatorException(Collection<FacesMessage> messages) |
37 | |
{ |
38 | 0 | super(facesMessagesToString(messages)); |
39 | 0 | _facesMessages = messages; |
40 | 0 | } |
41 | |
|
42 | |
public ValidatorException(Collection<FacesMessage> messages, Throwable cause) |
43 | |
{ |
44 | 0 | super(facesMessagesToString(messages),cause); |
45 | 0 | _facesMessages = messages; |
46 | 0 | } |
47 | |
|
48 | |
public ValidatorException(FacesMessage message) |
49 | |
{ |
50 | 4 | super(facesMessageToString(message)); |
51 | 4 | _facesMessage = message; |
52 | 4 | } |
53 | |
|
54 | |
public ValidatorException(FacesMessage message, |
55 | |
Throwable cause) |
56 | |
{ |
57 | 0 | super(facesMessageToString(message), cause); |
58 | 0 | _facesMessage = message; |
59 | 0 | } |
60 | |
|
61 | |
public FacesMessage getFacesMessage() |
62 | |
{ |
63 | 2 | return _facesMessage; |
64 | |
} |
65 | |
|
66 | |
public Collection<FacesMessage> getFacesMessages() |
67 | |
{ |
68 | 2 | return _facesMessages; |
69 | |
} |
70 | |
|
71 | |
private static String facesMessageToString(FacesMessage message) |
72 | |
{ |
73 | 4 | String summary = message.getSummary(); |
74 | 4 | String detail = message.getDetail(); |
75 | |
|
76 | 4 | if (summary != null) |
77 | |
{ |
78 | 2 | if (detail != null) |
79 | |
{ |
80 | 2 | return summary + ": " + detail; |
81 | |
} |
82 | |
|
83 | 0 | return summary; |
84 | |
} |
85 | |
|
86 | 2 | return detail != null ? detail : ""; |
87 | |
} |
88 | |
|
89 | |
private static String facesMessagesToString(Collection<FacesMessage> messages) |
90 | |
{ |
91 | 0 | if (messages == null || messages.isEmpty()) |
92 | |
{ |
93 | 0 | return ""; |
94 | |
} |
95 | 0 | StringBuilder sb = new StringBuilder(); |
96 | |
|
97 | 0 | String separator = ""; |
98 | 0 | for (FacesMessage message : messages) |
99 | |
{ |
100 | 0 | if (message != null) |
101 | |
{ |
102 | 0 | String summary = message.getSummary(); |
103 | 0 | String detail = message.getDetail(); |
104 | |
|
105 | 0 | if (summary != null) |
106 | |
{ |
107 | 0 | sb.append(separator); |
108 | 0 | sb.append(summary); |
109 | 0 | if (detail != null) |
110 | |
{ |
111 | 0 | sb.append(": "); |
112 | 0 | sb.append(detail); |
113 | |
} |
114 | 0 | separator = ", "; |
115 | |
} |
116 | |
} |
117 | 0 | } |
118 | 0 | return sb.toString(); |
119 | |
} |
120 | |
} |