use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class URLEditorTests method testStandardURI.
@Test
public void testStandardURI() throws Exception {
PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText("mailto:juergen.hoeller@interface21.com");
Object value = urlEditor.getValue();
assertTrue(value instanceof URL);
URL url = (URL) value;
assertEquals(url.toExternalForm(), urlEditor.getAsText());
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class URLEditorTests method testWithNonExistentResource.
@Test(expected = IllegalArgumentException.class)
public void testWithNonExistentResource() throws Exception {
PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening");
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class AbstractPropertyBindingResult method getCustomEditor.
/**
* Retrieve the custom PropertyEditor for the given field, if any.
* @param fixedField the fully qualified field name
* @return the custom PropertyEditor, or {@code null}
*/
protected PropertyEditor getCustomEditor(String fixedField) {
Class<?> targetType = getPropertyAccessor().getPropertyType(fixedField);
PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField);
if (editor == null) {
editor = BeanUtils.findEditorByConvention(targetType);
}
return editor;
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class AbstractPropertyBindingResult method findEditor.
/**
* This implementation exposes a PropertyEditor adapter for a Formatter,
* if applicable.
*/
@Override
public PropertyEditor findEditor(String field, Class<?> valueType) {
Class<?> valueTypeForLookup = valueType;
if (valueTypeForLookup == null) {
valueTypeForLookup = getFieldType(field);
}
PropertyEditor editor = super.findEditor(field, valueTypeForLookup);
if (editor == null && this.conversionService != null) {
TypeDescriptor td = null;
if (field != null) {
TypeDescriptor ptd = getPropertyAccessor().getPropertyTypeDescriptor(fixedField(field));
if (valueType == null || valueType.isAssignableFrom(ptd.getType())) {
td = ptd;
}
}
if (td == null) {
td = TypeDescriptor.valueOf(valueTypeForLookup);
}
if (this.conversionService.canConvert(TypeDescriptor.valueOf(String.class), td)) {
editor = new ConvertingPropertyEditorAdapter(this.conversionService, td);
}
}
return editor;
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class ResourceEditorTests method sunnyDay.
@Test
public void sunnyDay() throws Exception {
PropertyEditor editor = new ResourceEditor();
editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
Resource resource = (Resource) editor.getValue();
assertNotNull(resource);
assertTrue(resource.exists());
}
Aggregations