001/** 002 * Copyright 2005-2017 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 */ 016// begin Kuali Foundation modification 017package org.kuali.rice.kns.web.format; 018// end Kuali Foundation modification 019 020import org.kuali.rice.core.api.delegation.DelegationType; 021import org.kuali.rice.core.web.format.Formatter; 022import org.kuali.rice.kew.api.KewApiConstants; 023 024/** 025 * begin Kuali Foundation modification 026 * This class is used to format boolean values. 027 * end Kuali Foundation modification 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 * 030 * @deprecated Only used by KNS classes, use KRAD. 031 */ 032@Deprecated 033public class DelegationTypeFormatter extends Formatter { 034 private static final long serialVersionUID = -4109390572922205211L; 035 /* 036 protected Object convertToObject(String target) { 037 if (Formatter.isEmptyValue(target)) 038 return null; 039 040 String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target; 041 stringValue = stringValue.trim().toUpperCase(); 042 043 return KewApiConstants.DELEGATION_TYPES.get(stringValue); 044 if (TRUE_VALUES.contains(stringValue)) 045 return Boolean.TRUE; 046 if (FALSE_VALUES.contains(stringValue)) 047 return Boolean.FALSE; 048 049 // begin Kuali Foundation modification 050 // was: throw new FormatException(CONVERT_MSG + stringValue); 051 throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue); 052 // end Kuali Foundation modification 053 } 054*/ 055 public Object format(Object target) { 056 if (target == null) { 057 return null; 058 } 059 // begin Kuali Foundation modification 060 if (target instanceof String) { 061 DelegationType delegationType = DelegationType.fromCode(((String) target).trim().toUpperCase()); 062 if (delegationType != null) { 063 return delegationType.getLabel(); 064 } else { 065 return KewApiConstants.DELEGATION_BOTH_LABEL; 066 } 067 } else { 068 return ""; 069 } 070 } 071}