From: Juergen H. <jho...@us...> - 2006-04-21 00:14:23
|
Update of /cvsroot/springframework/spring/src/org/springframework/beans/propertyeditors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19629/src/org/springframework/beans/propertyeditors Modified Files: Tag: mbranch-1-2 ByteArrayPropertyEditor.java CharacterEditor.java Added Files: Tag: mbranch-1-2 CharArrayPropertyEditor.java Log Message: backported fixes and enhancements from 2.0 M4 (HEAD) Index: CharacterEditor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/beans/propertyeditors/CharacterEditor.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** CharacterEditor.java 2 Aug 2005 14:27:05 -0000 1.2 --- CharacterEditor.java 21 Apr 2006 00:13:48 -0000 1.2.4.1 *************** *** 1,4 **** /* ! * Copyright 2002-2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); --- 1,4 ---- /* ! * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); *************** *** 29,32 **** --- 29,33 ---- * * @author Juergen Hoeller + * @author Rob Harrop * @since 1.2 * @see java.lang.Character *************** *** 35,38 **** --- 36,44 ---- public class CharacterEditor extends PropertyEditorSupport { + private static final String UNICODE_PREFIX = "\\u"; + + private static final int UNICODE_LENGTH = 6; + + private final boolean allowEmpty; *************** *** 40,52 **** /** * Create a new CharacterEditor instance. ! * <p>The "allowEmpty" parameter states if an empty String should ! * be allowed for parsing, i.e. get interpreted as null value. ! * Else, an IllegalArgumentException gets thrown in that case. ! * @param allowEmpty if empty strings should be allowed */ public CharacterEditor(boolean allowEmpty) { this.allowEmpty = allowEmpty; } ! public void setAsText(String text) throws IllegalArgumentException { --- 46,59 ---- /** * Create a new CharacterEditor instance. ! * <p>The "allowEmpty" parameter controls whether an empty String is ! * to be allowed in parsing, i.e. be interpreted as ! * the <code>null</code> value. Else, an IllegalArgumentException gets ! * thrown in that case. ! * @param allowEmpty if empty strings are to be allowed */ public CharacterEditor(boolean allowEmpty) { this.allowEmpty = allowEmpty; } ! public void setAsText(String text) throws IllegalArgumentException { *************** *** 55,61 **** setValue(null); } else if (text.length() != 1) { ! throw new IllegalArgumentException( ! "String [" + text + "] with length " + text.length() + " cannot be converted to char type"); } else { --- 62,72 ---- setValue(null); } + else if (text.startsWith(UNICODE_PREFIX) && text.length() == UNICODE_LENGTH) { + int code = Integer.parseInt(text.substring(UNICODE_PREFIX.length()), 16); + setValue(new Character((char) code)); + } else if (text.length() != 1) { ! throw new IllegalArgumentException("String [" + text + "] with length " + ! text.length() + " cannot be converted to char type"); } else { Index: ByteArrayPropertyEditor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java,v retrieving revision 1.7 retrieving revision 1.7.4.1 diff -C2 -d -r1.7 -r1.7.4.1 *** ByteArrayPropertyEditor.java 27 May 2005 19:49:56 -0000 1.7 --- ByteArrayPropertyEditor.java 21 Apr 2006 00:13:48 -0000 1.7.4.1 *************** *** 1,4 **** /* ! * Copyright 2002-2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); --- 1,4 ---- /* ! * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); *************** *** 30,34 **** public void setAsText(String text) { ! setValue(text.getBytes()); } --- 30,34 ---- public void setAsText(String text) { ! setValue(text != null ? text.getBytes() : null); } --- NEW FILE: CharArrayPropertyEditor.java --- /* * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; /** * Editor for char arrays. Strings will simply be converted to * their corresponding char representations. * * @author Juergen Hoeller * @since 1.2.8 * @see String#toCharArray() */ public class CharArrayPropertyEditor extends PropertyEditorSupport { public void setAsText(String text) { setValue(text != null ? text.toCharArray() : null); } public String getAsText() { char[] value = (char[]) getValue(); return (value != null ? new String(value) : ""); } } |