use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class URIEditorTests method classpathURL.
@Test
public void classpathURL() throws Exception {
PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
uriEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class");
Object value = uriEditor.getValue();
assertTrue(value instanceof URI);
URI uri = (URI) value;
assertEquals(uri.toString(), uriEditor.getAsText());
assertTrue(!uri.getScheme().startsWith("classpath"));
}
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;
}
Aggregations