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 */ 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 */ 030public class DelegationTypeFormatter extends Formatter { 031 private static final long serialVersionUID = -4109390572922205211L; 032 /* 033 protected Object convertToObject(String target) { 034 if (Formatter.isEmptyValue(target)) 035 return null; 036 037 String stringValue = target.getClass().isArray() ? unwrapString(target) : (String) target; 038 stringValue = stringValue.trim().toUpperCase(); 039 040 return KewApiConstants.DELEGATION_TYPES.get(stringValue); 041 if (TRUE_VALUES.contains(stringValue)) 042 return Boolean.TRUE; 043 if (FALSE_VALUES.contains(stringValue)) 044 return Boolean.FALSE; 045 046 // begin Kuali Foundation modification 047 // was: throw new FormatException(CONVERT_MSG + stringValue); 048 throw new FormatException("converting", RiceKeyConstants.ERROR_BOOLEAN, stringValue); 049 // end Kuali Foundation modification 050 } 051*/ 052 public Object format(Object target) { 053 if (target == null) { 054 return null; 055 } 056 // begin Kuali Foundation modification 057 if (target instanceof String) { 058 DelegationType delegationType = DelegationType.fromCode(((String) target).trim().toUpperCase()); 059 if (delegationType != null) { 060 return delegationType.getLabel(); 061 } else { 062 return KewApiConstants.DELEGATION_BOTH_LABEL; 063 } 064 } else { 065 return ""; 066 } 067 } 068}