001 /** 002 * Copyright 2005-2012 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 package edu.sampleu.demo.kitchensink; 017 018 import org.apache.commons.lang.StringUtils; 019 import java.beans.PropertyEditorSupport; 020 import java.io.Serializable; 021 022 /** 023 * @author Kuali Rice Team (rice.collab@kuali.org) 024 */ 025 public class UITestPropertyEditor extends PropertyEditorSupport implements Serializable { 026 private static final long serialVersionUID = -4113846709722954737L; 027 028 /** 029 * @see java.beans.PropertyEditorSupport#getAsText() 030 */ 031 @Override 032 public String getAsText() { 033 Object obj = this.getValue(); 034 035 if (obj == null) { 036 return null; 037 } 038 039 String displayValue = obj.toString(); 040 if (displayValue.length() > 3) { 041 displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3); 042 } 043 044 return displayValue; 045 } 046 047 /** 048 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String) 049 */ 050 @Override 051 public void setAsText(String text) { 052 String value = text; 053 if (StringUtils.contains(value, "-")) { 054 value = StringUtils.replaceOnce(value, "-", ""); 055 } 056 057 this.setValue(value); 058 } 059 060 }