1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util;
17
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.apache.struts.action.ActionMessage;
25 import org.apache.struts.action.ActionMessages;
26 import org.kuali.rice.core.api.util.RiceKeyConstants;
27 import org.kuali.rice.krad.util.ErrorMessage;
28 import org.kuali.rice.krad.util.MessageMap;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class ErrorContainer implements Serializable {
43 private final MessageMap errorMap;
44 private final int errorCount;
45
46
47
48
49
50
51 public ErrorContainer(MessageMap errorMap) {
52 this.errorMap = errorMap;
53 this.errorCount = errorMap.getErrorCount();
54 }
55
56
57
58
59 public int getErrorCount() {
60 if (hasFormatterError()) {
61 return 0;
62 }
63 return errorCount;
64 }
65
66
67
68
69 public List getErrorPropertyList() {
70 List properties = new ArrayList();
71
72 for (Iterator iter = errorMap.getAllPropertiesWithErrors().iterator(); iter.hasNext();) {
73 properties.add(iter.next());
74 }
75
76 return properties;
77 }
78
79
80
81
82
83 private boolean hasFormatterError() {
84 if (errorMap.getErrorCount()>0) {
85 for (String errorKey : errorMap.getAllPropertiesWithErrors()) {
86 List errorValues = errorMap.getMessages(errorKey);
87 for (ErrorMessage errorMessage : (List<ErrorMessage>)errorValues) {
88 if (errorMessage.getErrorKey().equals(RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_FORMATTING_ERROR)) {
89 return true;
90 }
91 }
92 }
93 }
94 return false;
95 }
96
97
98
99
100
101 public ActionMessages getRequestErrors() {
102 ActionMessages requestErrors = new ActionMessages();
103 for (Iterator iter = errorMap.getAllPropertiesWithErrors().iterator(); iter.hasNext();) {
104 String property = (String) iter.next();
105 List errorList = (List) errorMap.getErrorMessagesForProperty(property);
106
107 for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
108 ErrorMessage errorMessage = (ErrorMessage) iterator.next();
109
110
111 requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters()));
112 }
113 }
114 return requestErrors;
115 }
116 }