| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.util; |
| 17 | |
|
| 18 | |
|
| 19 | |
import org.apache.commons.lang.StringEscapeUtils; |
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 22 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 23 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 24 | |
import org.springframework.util.AutoPopulatingList; |
| 25 | |
|
| 26 | |
import java.io.Serializable; |
| 27 | |
import java.util.ArrayList; |
| 28 | |
import java.util.Iterator; |
| 29 | |
import java.util.LinkedHashMap; |
| 30 | |
import java.util.List; |
| 31 | |
import java.util.Map; |
| 32 | |
import java.util.Set; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public class MessageMap implements Serializable { |
| 42 | |
|
| 43 | |
private static final long serialVersionUID = -2328635367656516150L; |
| 44 | |
|
| 45 | 21 | private List<String> errorPath = new ArrayList<String>(); |
| 46 | 21 | private Map<String, AutoPopulatingList<ErrorMessage>> errorMessages = new LinkedHashMap<String, AutoPopulatingList<ErrorMessage>>(); |
| 47 | 21 | private Map<String, AutoPopulatingList<ErrorMessage>> warningMessages = new LinkedHashMap<String, AutoPopulatingList<ErrorMessage>>(); |
| 48 | 21 | private Map<String, AutoPopulatingList<ErrorMessage>> infoMessages = new LinkedHashMap<String, AutoPopulatingList<ErrorMessage>>(); |
| 49 | |
|
| 50 | 42 | public MessageMap() {} |
| 51 | |
|
| 52 | 0 | public MessageMap(MessageMap messageMap) { |
| 53 | 0 | this.errorPath = messageMap.errorPath; |
| 54 | 0 | this.errorMessages = messageMap.errorMessages; |
| 55 | 0 | this.warningMessages = messageMap.warningMessages; |
| 56 | 0 | this.infoMessages = messageMap.infoMessages; |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
|
| 60 | |
public void merge(MessageMap messageMap){ |
| 61 | 0 | if(messageMap != null){ |
| 62 | 0 | if(messageMap.hasErrors()){ |
| 63 | 0 | merge(messageMap.getErrorMessages(), errorMessages); |
| 64 | |
} |
| 65 | 0 | if(messageMap.hasInfo()){ |
| 66 | 0 | merge(messageMap.getInfoMessages(), infoMessages); |
| 67 | |
} |
| 68 | 0 | if(messageMap.hasWarnings()){ |
| 69 | 0 | merge(messageMap.getWarningMessages(), warningMessages); |
| 70 | |
} |
| 71 | |
|
| 72 | |
} |
| 73 | |
|
| 74 | 0 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
protected void merge(Map<String, AutoPopulatingList<ErrorMessage>> messagesFrom, Map<String, AutoPopulatingList<ErrorMessage>> messagesTo){ |
| 84 | 0 | for(String key : messagesFrom.keySet()){ |
| 85 | |
|
| 86 | 0 | if(messagesTo.containsKey(key)){ |
| 87 | |
|
| 88 | 0 | AutoPopulatingList<ErrorMessage> tal = messagesFrom.get(key); |
| 89 | 0 | AutoPopulatingList<ErrorMessage> parentList = messagesTo.get(key); |
| 90 | |
|
| 91 | 0 | for(Object o :tal){ |
| 92 | |
|
| 93 | 0 | if ( !parentList.contains( o ) ) { |
| 94 | 0 | parentList.add((ErrorMessage)o); |
| 95 | |
} |
| 96 | |
} |
| 97 | |
|
| 98 | 0 | }else{ |
| 99 | 0 | messagesTo.put(key, messagesFrom.get(key)); |
| 100 | |
} |
| 101 | |
|
| 102 | |
} |
| 103 | |
|
| 104 | 0 | } |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public AutoPopulatingList<ErrorMessage> putError(String propertyName, String errorKey, String... errorParameters) { |
| 116 | 63 | return putMessageInMap(errorMessages, propertyName, errorKey, true, true, errorParameters); |
| 117 | |
} |
| 118 | |
|
| 119 | |
public AutoPopulatingList<ErrorMessage> putWarning(String propertyName, String messageKey, String... messageParameters) { |
| 120 | 0 | return putMessageInMap(warningMessages, propertyName, messageKey, true, true, messageParameters); |
| 121 | |
} |
| 122 | |
|
| 123 | |
public AutoPopulatingList<ErrorMessage> putInfo(String propertyName, String messageKey, String... messageParameters) { |
| 124 | 0 | return putMessageInMap(infoMessages, propertyName, messageKey, true, true, messageParameters); |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public AutoPopulatingList<ErrorMessage> putErrorWithoutFullErrorPath(String propertyName, String errorKey, String... errorParameters) { |
| 137 | 0 | return putMessageInMap(errorMessages, propertyName, errorKey, false, true, errorParameters); |
| 138 | |
} |
| 139 | |
|
| 140 | |
public AutoPopulatingList<ErrorMessage> putWarningWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) { |
| 141 | 0 | return putMessageInMap(warningMessages, propertyName, messageKey, false, true, messageParameters); |
| 142 | |
} |
| 143 | |
|
| 144 | |
public AutoPopulatingList<ErrorMessage> putInfoWithoutFullErrorPath(String propertyName, String messageKey, String... messageParameters) { |
| 145 | 0 | return putMessageInMap(infoMessages, propertyName, messageKey, false, true, messageParameters); |
| 146 | |
} |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public AutoPopulatingList<ErrorMessage> putErrorForSectionId(String sectionId, String errorKey, String... errorParameters) { |
| 158 | 0 | return putErrorWithoutFullErrorPath(sectionId, errorKey, errorParameters); |
| 159 | |
} |
| 160 | |
|
| 161 | |
public AutoPopulatingList<ErrorMessage> putWarningForSectionId(String sectionId, String messageKey, String... messageParameters) { |
| 162 | 0 | return putWarningWithoutFullErrorPath(sectionId, messageKey, messageParameters); |
| 163 | |
} |
| 164 | |
|
| 165 | |
public AutoPopulatingList<ErrorMessage> putInfoForSectionId(String sectionId, String messageKey, String... messageParameters) { |
| 166 | 0 | return putInfoWithoutFullErrorPath(sectionId, messageKey, messageParameters); |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
private AutoPopulatingList<ErrorMessage> putMessageInMap(Map<String, AutoPopulatingList<ErrorMessage>> messagesMap, String propertyName, String messageKey, boolean withFullErrorPath, boolean escapeHtmlMessageParameters, String... messageParameters) { |
| 180 | 63 | if (StringUtils.isBlank(propertyName)) { |
| 181 | 0 | throw new IllegalArgumentException("invalid (blank) propertyName"); |
| 182 | |
} |
| 183 | 63 | if (StringUtils.isBlank(messageKey)) { |
| 184 | 0 | throw new IllegalArgumentException("invalid (blank) errorKey"); |
| 185 | |
} |
| 186 | |
|
| 187 | |
|
| 188 | 63 | AutoPopulatingList<ErrorMessage> errorList = null; |
| 189 | 63 | String propertyKey = getKeyPath(propertyName, withFullErrorPath); |
| 190 | 63 | if (messagesMap.containsKey(propertyKey)) { |
| 191 | 19 | errorList = messagesMap.get(propertyKey); |
| 192 | |
} |
| 193 | |
else { |
| 194 | 44 | errorList = new AutoPopulatingList<ErrorMessage>(ErrorMessage.class); |
| 195 | |
} |
| 196 | |
|
| 197 | 63 | if (escapeHtmlMessageParameters && messageParameters != null) { |
| 198 | 63 | String[] filteredMessageParameters = new String[messageParameters.length]; |
| 199 | 111 | for (int i = 0; i < messageParameters.length; i++) { |
| 200 | 48 | filteredMessageParameters[i] = StringEscapeUtils.escapeHtml(messageParameters[i]); |
| 201 | |
} |
| 202 | 63 | messageParameters = filteredMessageParameters; |
| 203 | |
} |
| 204 | |
|
| 205 | |
|
| 206 | 63 | ErrorMessage errorMessage = new ErrorMessage(messageKey, messageParameters); |
| 207 | |
|
| 208 | 63 | if ( !errorList.contains( errorMessage ) ) { |
| 209 | 62 | errorList.add(errorMessage); |
| 210 | |
} |
| 211 | |
|
| 212 | 63 | return messagesMap.put(propertyKey, errorList); |
| 213 | |
} |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
public boolean replaceError(String propertyName, String targetKey, String replaceKey, String... replaceParameters) { |
| 226 | 4 | return replaceError(propertyName, targetKey, true, replaceKey, replaceParameters); |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
public boolean replaceErrorWithoutFullErrorPath(String propertyName, String targetKey, String replaceKey, String... replaceParameters) { |
| 242 | 0 | return replaceError(propertyName, targetKey, false, replaceKey, replaceParameters); |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
private boolean replaceError(String propertyName, String targetKey, boolean withFullErrorPath, String replaceKey, String... replaceParameters) { |
| 257 | 4 | boolean replaced = false; |
| 258 | |
|
| 259 | 4 | if (StringUtils.isBlank(propertyName)) { |
| 260 | 0 | throw new IllegalArgumentException("invalid (blank) propertyName"); |
| 261 | |
} |
| 262 | 4 | if (StringUtils.isBlank(targetKey)) { |
| 263 | 0 | throw new IllegalArgumentException("invalid (blank) targetKey"); |
| 264 | |
} |
| 265 | 4 | if (StringUtils.isBlank(replaceKey)) { |
| 266 | 0 | throw new IllegalArgumentException("invalid (blank) replaceKey"); |
| 267 | |
} |
| 268 | |
|
| 269 | |
|
| 270 | 4 | AutoPopulatingList<ErrorMessage> errorList = null; |
| 271 | 4 | String propertyKey = getKeyPath(propertyName, withFullErrorPath); |
| 272 | 4 | if (errorMessages.containsKey(propertyKey)) { |
| 273 | 3 | errorList = errorMessages.get(propertyKey); |
| 274 | |
|
| 275 | |
|
| 276 | 9 | for (int i = 0; i < errorList.size(); ++i) { |
| 277 | 6 | ErrorMessage em = errorList.get(i); |
| 278 | |
|
| 279 | |
|
| 280 | 6 | if (em.getErrorKey().equals(targetKey)) { |
| 281 | 2 | ErrorMessage rm = new ErrorMessage(replaceKey, replaceParameters); |
| 282 | 2 | errorList.set(i, rm); |
| 283 | 2 | replaced = true; |
| 284 | |
} |
| 285 | |
} |
| 286 | |
} |
| 287 | |
|
| 288 | 4 | return replaced; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
public boolean fieldHasMessage(String fieldName, String errorKey) { |
| 300 | 4 | boolean found = false; |
| 301 | |
|
| 302 | 4 | List<ErrorMessage> fieldMessages = errorMessages.get(fieldName); |
| 303 | 4 | if (fieldMessages != null) { |
| 304 | 4 | for (Iterator<ErrorMessage> i = fieldMessages.iterator(); !found && i.hasNext();) { |
| 305 | 7 | ErrorMessage errorMessage = i.next(); |
| 306 | 7 | found = errorMessage.getErrorKey().equals(errorKey); |
| 307 | 7 | } |
| 308 | |
} |
| 309 | |
|
| 310 | 4 | return found; |
| 311 | |
} |
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
public int countFieldMessages(String fieldName) { |
| 320 | 2 | int count = 0; |
| 321 | |
|
| 322 | 2 | List<ErrorMessage> fieldMessages = errorMessages.get(fieldName); |
| 323 | 2 | if (fieldMessages != null) { |
| 324 | 2 | count = fieldMessages.size(); |
| 325 | |
} |
| 326 | |
|
| 327 | 2 | return count; |
| 328 | |
} |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
public boolean containsMessageKey(String messageKey) { |
| 335 | 12 | ErrorMessage foundMessage = null; |
| 336 | |
|
| 337 | 12 | if (!hasNoErrors()) { |
| 338 | 12 | for (Iterator<Map.Entry<String, AutoPopulatingList<ErrorMessage>>> i = getAllPropertiesAndErrors().iterator(); (foundMessage == null) && i.hasNext();) { |
| 339 | 20 | Map.Entry<String, AutoPopulatingList<ErrorMessage>> e = i.next(); |
| 340 | 20 | AutoPopulatingList<ErrorMessage> entryErrorList = e.getValue(); |
| 341 | 20 | for (Iterator<ErrorMessage> j = entryErrorList.iterator(); j.hasNext();) { |
| 342 | 32 | ErrorMessage em = j.next(); |
| 343 | 32 | if (messageKey.equals(em.getErrorKey())) { |
| 344 | 4 | foundMessage = em; |
| 345 | |
} |
| 346 | 32 | } |
| 347 | 20 | } |
| 348 | |
} |
| 349 | |
|
| 350 | 12 | return (foundMessage != null); |
| 351 | |
} |
| 352 | |
|
| 353 | |
|
| 354 | |
private int getMessageCount(Map<String, AutoPopulatingList<ErrorMessage>> messageMap) { |
| 355 | 6 | int messageCount = 0; |
| 356 | 6 | for (Iterator<String> iter = messageMap.keySet().iterator(); iter.hasNext();) { |
| 357 | 12 | String errorKey = iter.next(); |
| 358 | 12 | List<ErrorMessage> errors = messageMap.get(errorKey); |
| 359 | 12 | messageCount += errors.size(); |
| 360 | 12 | } |
| 361 | |
|
| 362 | 6 | return messageCount; |
| 363 | |
} |
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
public int getErrorCount() { |
| 371 | 6 | return getMessageCount(errorMessages); |
| 372 | |
} |
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
public int getWarningCount() { |
| 380 | 0 | return getMessageCount(warningMessages); |
| 381 | |
} |
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
public int getInfoCount() { |
| 389 | 0 | return getMessageCount(infoMessages); |
| 390 | |
} |
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
public AutoPopulatingList<ErrorMessage> getMessages(String path) { |
| 397 | 6 | return errorMessages.get(path); |
| 398 | |
} |
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
public void addToErrorPath(String parentName) { |
| 406 | 3 | errorPath.add(parentName); |
| 407 | 3 | } |
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
public List<String> getErrorPath() { |
| 415 | 0 | return errorPath; |
| 416 | |
} |
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
public boolean removeFromErrorPath(String parentName) { |
| 425 | 3 | return errorPath.remove(parentName); |
| 426 | |
} |
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
public void clearErrorPath() { |
| 432 | 0 | errorPath.clear(); |
| 433 | 0 | } |
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
public String getKeyPath(String propertyName, boolean prependFullErrorPath) { |
| 444 | 78 | String keyPath = ""; |
| 445 | |
|
| 446 | 78 | if (KRADConstants.GLOBAL_ERRORS.equals(propertyName)) { |
| 447 | 1 | return KRADConstants.GLOBAL_ERRORS; |
| 448 | |
} |
| 449 | |
|
| 450 | 77 | if (!errorPath.isEmpty() && prependFullErrorPath) { |
| 451 | 5 | keyPath = StringUtils.join(errorPath.iterator(), "."); |
| 452 | 5 | keyPath += (keyPath!=null && keyPath.endsWith("."))?propertyName:"." + propertyName; |
| 453 | |
} |
| 454 | |
else { |
| 455 | 72 | keyPath = propertyName; |
| 456 | |
} |
| 457 | |
|
| 458 | 77 | return keyPath; |
| 459 | |
} |
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
public List<String> getPropertiesWithErrors() { |
| 465 | 5 | List<String> properties = new ArrayList<String>(); |
| 466 | |
|
| 467 | 5 | for (Iterator<String> iter = errorMessages.keySet().iterator(); iter.hasNext();) { |
| 468 | 25 | properties.add(iter.next()); |
| 469 | |
} |
| 470 | |
|
| 471 | 5 | return properties; |
| 472 | |
} |
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
public List<String> getPropertiesWithWarnings() { |
| 478 | 0 | List<String> properties = new ArrayList<String>(warningMessages.keySet()); |
| 479 | 0 | return properties; |
| 480 | |
} |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
public List<String> getPropertiesWithInfo() { |
| 486 | 0 | List<String> properties = new ArrayList<String>(infoMessages.keySet()); |
| 487 | 0 | return properties; |
| 488 | |
} |
| 489 | |
|
| 490 | |
public void clearErrorMessages() { |
| 491 | 0 | errorMessages.clear(); |
| 492 | 0 | } |
| 493 | |
|
| 494 | |
public boolean doesPropertyHaveError(String key) { |
| 495 | 0 | return errorMessages.containsKey(key); |
| 496 | |
} |
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
public boolean containsKeyMatchingPattern(String pattern) { |
| 502 | 4 | List<String> simplePatterns = new ArrayList<String>(); |
| 503 | 4 | List<String> wildcardPatterns = new ArrayList<String>(); |
| 504 | 4 | String[] patterns = pattern.split(","); |
| 505 | 28 | for (int i = 0; i < patterns.length; i++) { |
| 506 | 24 | String s = patterns[i]; |
| 507 | 24 | if (s.endsWith("*")) { |
| 508 | 16 | wildcardPatterns.add(s.substring(0, s.length() - 1)); |
| 509 | |
} |
| 510 | |
else { |
| 511 | 8 | simplePatterns.add(s); |
| 512 | |
} |
| 513 | |
} |
| 514 | 4 | for (Iterator<String> keys = errorMessages.keySet().iterator(); keys.hasNext();) { |
| 515 | 6 | String key = keys.next(); |
| 516 | 6 | if (simplePatterns.contains(key)) { |
| 517 | 1 | return true; |
| 518 | |
} |
| 519 | 5 | for (Iterator<String> wildcardIterator = wildcardPatterns.iterator(); wildcardIterator.hasNext();) { |
| 520 | 18 | String wildcard = wildcardIterator.next(); |
| 521 | 18 | if (key.startsWith(wildcard)) { |
| 522 | 1 | return true; |
| 523 | |
} |
| 524 | 17 | } |
| 525 | 4 | } |
| 526 | 2 | return false; |
| 527 | |
} |
| 528 | |
|
| 529 | |
public Set<Map.Entry<String, AutoPopulatingList<ErrorMessage>>> getAllPropertiesAndErrors() { |
| 530 | 13 | return errorMessages.entrySet(); |
| 531 | |
} |
| 532 | |
|
| 533 | |
public AutoPopulatingList<ErrorMessage> getErrorMessagesForProperty(String propertyName) { |
| 534 | 1 | return errorMessages.get(propertyName); |
| 535 | |
} |
| 536 | |
|
| 537 | |
public AutoPopulatingList<ErrorMessage> getWarningMessagesForProperty(String propertyName) { |
| 538 | 0 | return warningMessages.get(propertyName); |
| 539 | |
} |
| 540 | |
|
| 541 | |
public AutoPopulatingList<ErrorMessage> getInfoMessagesForProperty(String propertyName) { |
| 542 | 0 | return infoMessages.get(propertyName); |
| 543 | |
} |
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
public List<AutoPopulatingList<ErrorMessage>> getErrorMessagesForProperty( |
| 557 | |
String propertyName, boolean allowWildcard) { |
| 558 | 0 | List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); |
| 559 | 0 | if (allowWildcard) { |
| 560 | 0 | boolean wildcard = false; |
| 561 | 0 | if (propertyName.endsWith("*")) { |
| 562 | 0 | wildcard = true; |
| 563 | 0 | propertyName = propertyName.substring(0, |
| 564 | |
propertyName.length() - 1); |
| 565 | |
} |
| 566 | 0 | for (Iterator<String> keys = errorMessages.keySet().iterator(); keys |
| 567 | 0 | .hasNext();) { |
| 568 | 0 | String key = keys.next(); |
| 569 | 0 | if (!wildcard && propertyName.equals(key)) { |
| 570 | 0 | foundMessages.add(errorMessages.get(key)); |
| 571 | 0 | break; |
| 572 | 0 | } else if (wildcard && key.startsWith(propertyName)) { |
| 573 | 0 | foundMessages.add(errorMessages.get(key)); |
| 574 | |
} |
| 575 | 0 | } |
| 576 | 0 | } else { |
| 577 | 0 | foundMessages.add(getErrorMessagesForProperty(propertyName)); |
| 578 | |
} |
| 579 | |
|
| 580 | 0 | return foundMessages; |
| 581 | |
} |
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
public List<AutoPopulatingList<ErrorMessage>> getWarningMessagesForProperty( |
| 595 | |
String propertyName, boolean allowWildcard) { |
| 596 | 0 | List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); |
| 597 | 0 | if (allowWildcard) { |
| 598 | 0 | boolean wildcard = false; |
| 599 | 0 | if (propertyName.endsWith("*")) { |
| 600 | 0 | wildcard = true; |
| 601 | 0 | propertyName = propertyName.substring(0, |
| 602 | |
propertyName.length() - 1); |
| 603 | |
} |
| 604 | 0 | for (Iterator<String> keys = warningMessages.keySet().iterator(); keys |
| 605 | 0 | .hasNext();) { |
| 606 | 0 | String key = keys.next(); |
| 607 | 0 | if (!wildcard && propertyName.equals(key)) { |
| 608 | 0 | foundMessages.add(warningMessages.get(key)); |
| 609 | 0 | break; |
| 610 | 0 | } else if (wildcard && key.startsWith(propertyName)) { |
| 611 | 0 | foundMessages.add(warningMessages.get(key)); |
| 612 | |
} |
| 613 | 0 | } |
| 614 | 0 | } else { |
| 615 | 0 | foundMessages.add(getWarningMessagesForProperty(propertyName)); |
| 616 | |
} |
| 617 | |
|
| 618 | 0 | return foundMessages; |
| 619 | |
} |
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
|
| 625 | |
|
| 626 | |
|
| 627 | |
|
| 628 | |
|
| 629 | |
|
| 630 | |
|
| 631 | |
|
| 632 | |
public List<AutoPopulatingList<ErrorMessage>> getInfoMessagesForProperty( |
| 633 | |
String propertyName, boolean allowWildcard) { |
| 634 | 0 | List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); |
| 635 | 0 | if (allowWildcard) { |
| 636 | 0 | boolean wildcard = false; |
| 637 | 0 | if (propertyName.endsWith("*")) { |
| 638 | 0 | wildcard = true; |
| 639 | 0 | propertyName = propertyName.substring(0, |
| 640 | |
propertyName.length() - 1); |
| 641 | |
} |
| 642 | 0 | for (Iterator<String> keys = infoMessages.keySet().iterator(); keys |
| 643 | 0 | .hasNext();) { |
| 644 | 0 | String key = keys.next(); |
| 645 | 0 | if (!wildcard && propertyName.equals(key)) { |
| 646 | 0 | foundMessages.add(infoMessages.get(key)); |
| 647 | 0 | break; |
| 648 | 0 | } else if (wildcard && key.startsWith(propertyName)) { |
| 649 | 0 | foundMessages.add(infoMessages.get(key)); |
| 650 | |
} |
| 651 | 0 | } |
| 652 | 0 | } else { |
| 653 | 0 | foundMessages.add(getInfoMessagesForProperty(propertyName)); |
| 654 | |
} |
| 655 | |
|
| 656 | 0 | return foundMessages; |
| 657 | |
} |
| 658 | |
|
| 659 | |
public boolean hasErrors() { |
| 660 | 0 | return !errorMessages.isEmpty(); |
| 661 | |
} |
| 662 | |
|
| 663 | |
public boolean hasNoErrors() { |
| 664 | 12 | return errorMessages.isEmpty(); |
| 665 | |
} |
| 666 | |
|
| 667 | |
public boolean hasWarnings() { |
| 668 | 0 | return !warningMessages.isEmpty(); |
| 669 | |
} |
| 670 | |
|
| 671 | |
public boolean hasNoWarnings() { |
| 672 | 0 | return warningMessages.isEmpty(); |
| 673 | |
} |
| 674 | |
|
| 675 | |
public boolean hasInfo() { |
| 676 | 0 | return !infoMessages.isEmpty(); |
| 677 | |
} |
| 678 | |
|
| 679 | |
public boolean hasNoInfo() { |
| 680 | 0 | return infoMessages.isEmpty(); |
| 681 | |
} |
| 682 | |
|
| 683 | |
public boolean hasMessages() { |
| 684 | 0 | if (!errorMessages.isEmpty() |
| 685 | |
|| !warningMessages.isEmpty() |
| 686 | |
|| !infoMessages.isEmpty()) { |
| 687 | 0 | return true; |
| 688 | |
} |
| 689 | 0 | return false; |
| 690 | |
} |
| 691 | |
|
| 692 | |
public boolean hasNoMessages() { |
| 693 | 0 | if (errorMessages.isEmpty() |
| 694 | |
&& warningMessages.isEmpty() |
| 695 | |
&& infoMessages.isEmpty()) { |
| 696 | 0 | return true; |
| 697 | |
} |
| 698 | 0 | return false; |
| 699 | |
} |
| 700 | |
|
| 701 | |
public Set<String> getAllPropertiesWithErrors() { |
| 702 | 0 | return errorMessages.keySet(); |
| 703 | |
} |
| 704 | |
|
| 705 | |
public Set<String> getAllPropertiesWithWarnings() { |
| 706 | 0 | return warningMessages.keySet(); |
| 707 | |
} |
| 708 | |
|
| 709 | |
public Set<String> getAllPropertiesWithInfo() { |
| 710 | 0 | return infoMessages.keySet(); |
| 711 | |
} |
| 712 | |
|
| 713 | |
public AutoPopulatingList<ErrorMessage> removeAllErrorMessagesForProperty(String property) { |
| 714 | 1 | return errorMessages.remove(property); |
| 715 | |
} |
| 716 | |
|
| 717 | |
public AutoPopulatingList<ErrorMessage> removeAllWarningMessagesForProperty(String property) { |
| 718 | 0 | return warningMessages.remove(property); |
| 719 | |
} |
| 720 | |
|
| 721 | |
public AutoPopulatingList<ErrorMessage> removeAllInfoMessagesForProperty(String property) { |
| 722 | 0 | return infoMessages.remove(property); |
| 723 | |
} |
| 724 | |
|
| 725 | |
public int getNumberOfPropertiesWithErrors() { |
| 726 | 0 | return errorMessages.size(); |
| 727 | |
} |
| 728 | |
|
| 729 | |
public Map<String, AutoPopulatingList<ErrorMessage>> getErrorMessages() { |
| 730 | 0 | return this.errorMessages; |
| 731 | |
} |
| 732 | |
|
| 733 | |
public Map<String, AutoPopulatingList<ErrorMessage>> getWarningMessages() { |
| 734 | 0 | return this.warningMessages; |
| 735 | |
} |
| 736 | |
|
| 737 | |
public Map<String, AutoPopulatingList<ErrorMessage>> getInfoMessages() { |
| 738 | 0 | return this.infoMessages; |
| 739 | |
} |
| 740 | |
|
| 741 | |
@Override |
| 742 | |
public boolean equals(Object o) { |
| 743 | 12 | return EqualsBuilder.reflectionEquals(this, o); |
| 744 | |
} |
| 745 | |
|
| 746 | |
@Override |
| 747 | |
public int hashCode() { |
| 748 | 0 | return HashCodeBuilder.reflectionHashCode(this); |
| 749 | |
} |
| 750 | |
|
| 751 | |
@Override |
| 752 | |
public String toString() { |
| 753 | 0 | return ToStringBuilder.reflectionToString(this); |
| 754 | |
} |
| 755 | |
} |