001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kns.util; 017 018import org.apache.struts.action.ActionMessage; 019import org.apache.struts.action.ActionMessages; 020import org.kuali.rice.krad.util.ErrorMessage; 021import org.kuali.rice.krad.util.MessageMap; 022 023import java.io.Serializable; 024import java.util.Iterator; 025import java.util.List; 026import java.util.Set; 027 028/** 029 * 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 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 * 033 * @deprecated Only used in KNS classes, use KRAD. 034 */ 035@Deprecated 036public abstract class MessageContainer implements Serializable { 037 private MessageMap errorMap; 038 039 protected MessageContainer(MessageMap errorMap) { 040 this.errorMap = errorMap; 041 } 042 043 protected MessageMap getMessageMap() { 044 return errorMap; 045 } 046 047 public ActionMessages getRequestMessages() { 048 ActionMessages requestErrors = new ActionMessages(); 049 for (Iterator<String> iter = getMessagePropertyNames().iterator(); iter.hasNext();) { 050 String property = iter.next(); 051 List errorList = (List) getMessagesForProperty(property); 052 053 for (Iterator iterator = errorList.iterator(); iterator.hasNext();) { 054 ErrorMessage errorMessage = (ErrorMessage) iterator.next(); 055 056 // add ActionMessage with any parameters 057 requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters())); 058 } 059 } 060 return requestErrors; 061 } 062 063 public abstract int getMessageCount(); 064 065 public abstract List<String> getMessagePropertyList(); 066 067 protected abstract Set<String> getMessagePropertyNames(); 068 069 protected abstract List getMessagesForProperty(String propertyName); 070}