01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.labor.util;
17:
18: import java.util.List;
19:
20: import org.apache.commons.lang.StringUtils;
21: import org.kuali.core.service.KualiConfigurationService;
22: import org.kuali.kfs.context.SpringContext;
23: import org.kuali.module.gl.util.Message;
24:
25: /**
26: * This class provides a set of utilities that can be used to build error message
27: */
28: public class MessageBuilder {
29: private static KualiConfigurationService kualiConfigurationService = SpringContext
30: .getBean(KualiConfigurationService.class);
31:
32: /**
33: * add the given message into the given message list
34: *
35: * @param messageList the given message list
36: * @param message the given message
37: */
38: public static void addMessageIntoList(List<Message> messageList,
39: Message message) {
40: if (message != null) {
41: messageList.add(message);
42: }
43: }
44:
45: /**
46: * Build the error message with the message body and error type
47: */
48: public static Message buildErrorMessage(String errorMessageKey,
49: int errorType) {
50: return MessageBuilder.buildErrorMessage(errorMessageKey, null,
51: errorType);
52: }
53:
54: /**
55: * Build the error message with the message body, invalid value and error type
56: */
57: public static Message buildErrorMessage(String errorMessageKey,
58: String invalidValue, int errorType) {
59: String errorMessageBody = kualiConfigurationService
60: .getPropertyString(errorMessageKey);
61: String errorMessage = formatErrorMessageBody(errorMessageBody,
62: invalidValue);
63: return new Message(errorMessage, errorType);
64: }
65:
66: /**
67: * Format the error message body based on the given error message and invalid value
68: */
69: public static String formatErrorMessageBody(
70: String errorMessageBody, String invalidValue) {
71: String value = StringUtils.isBlank(invalidValue) ? "" : "["
72: + invalidValue + "]";
73: return errorMessageBody + value;
74: }
75: }
|