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 @Deprecated
43 public class ErrorContainer implements Serializable {
44 private final MessageMap errorMap;
45 private final int errorCount;
46
47
48
49
50
51
52 public ErrorContainer(MessageMap errorMap) {
53 this.errorMap = errorMap;
54 this.errorCount = errorMap.getErrorCount();
55 }
56
57
58
59
60 public int getErrorCount() {
61 if (hasFormatterError()) {
62 return 0;
63 }
64 return errorCount;
65 }
66
67
68
69
70 public List getErrorPropertyList() {
71 List properties = new ArrayList();
72
73 for (Iterator iter = errorMap.getAllPropertiesWithErrors().iterator(); iter.hasNext();) {
74 properties.add(iter.next());
75 }
76
77 return properties;
78 }
79
80
81
82
83
84 private boolean hasFormatterError() {
85 if (errorMap.getErrorCount()>0) {
86 for (String errorKey : errorMap.getAllPropertiesWithErrors()) {
87 List errorValues = errorMap.getMessages(errorKey);
88 for (ErrorMessage errorMessage : (List<ErrorMessage>)errorValues) {
89 if (errorMessage.getErrorKey().equals(RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_FORMATTING_ERROR)) {
90 return true;
91 }
92 }
93 }
94 }
95 return false;
96 }
97
98
99
100
101
102 public ActionMessages getRequestErrors() {
103 ActionMessages requestErrors = new ActionMessages();
104 for (Iterator iter = errorMap.getAllPropertiesWithErrors().iterator(); iter.hasNext();) {
105 String property = (String) iter.next();
106 List errorList = (List) errorMap.getErrorMessagesForProperty(property);
107
108 for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
109 ErrorMessage errorMessage = (ErrorMessage) iterator.next();
110
111
112 requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters()));
113 }
114 }
115 return requestErrors;
116 }
117 }