View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.rice.kns.util;
17  
18  import org.apache.struts.action.ActionMessage;
19  import org.apache.struts.action.ActionMessages;
20  import org.kuali.rice.krad.util.ErrorMessage;
21  import org.kuali.rice.krad.util.MessageMap;
22  
23  import java.io.Serializable;
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.Set;
27  
28  /**
29   * An adapter whose subclasses will make either an {@link org.kuali.rice.krad.util.MessageMap}'s warning or info messages available to the JSP layer
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   * @deprecated Only used in KNS classes, use KRAD.
34   */
35  @Deprecated
36  public abstract class MessageContainer implements Serializable {
37  	private MessageMap errorMap;
38  	
39  	protected MessageContainer(MessageMap errorMap) {
40  		this.errorMap = errorMap;
41  	}
42  	
43  	protected MessageMap getMessageMap() {
44  		return errorMap;
45  	}
46  	
47      public ActionMessages getRequestMessages() {
48          ActionMessages requestErrors = new ActionMessages();
49          for (Iterator<String> iter = getMessagePropertyNames().iterator(); iter.hasNext();) {
50              String property = iter.next();
51              List errorList = (List) getMessagesForProperty(property);
52  
53              for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
54                  ErrorMessage errorMessage = (ErrorMessage) iterator.next();
55  
56                  // add ActionMessage with any parameters
57                  requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters()));
58              }
59          }
60          return requestErrors;
61      }
62      
63      public abstract int getMessageCount();
64      
65      public abstract List<String> getMessagePropertyList();
66  
67      protected abstract Set<String> getMessagePropertyNames();
68      
69      protected abstract List getMessagesForProperty(String propertyName);
70  }