diff options
Diffstat (limited to 'spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java')
-rw-r--r-- | spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java b/spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java index 06d2ee5d..8cffcc78 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -33,6 +33,7 @@ import org.springframework.beans.propertyeditors.ClassEditor; import org.springframework.beans.propertyeditors.FileEditor; import org.springframework.beans.propertyeditors.InputSourceEditor; import org.springframework.beans.propertyeditors.InputStreamEditor; +import org.springframework.beans.propertyeditors.PathEditor; import org.springframework.beans.propertyeditors.ReaderEditor; import org.springframework.beans.propertyeditors.URIEditor; import org.springframework.beans.propertyeditors.URLEditor; @@ -43,6 +44,7 @@ import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.ResourceArrayPropertyEditor; import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.ClassUtils; /** * PropertyEditorRegistrar implementation that populates a given @@ -58,6 +60,19 @@ import org.springframework.core.io.support.ResourcePatternResolver; */ public class ResourceEditorRegistrar implements PropertyEditorRegistrar { + private static Class<?> pathClass; + + static { + try { + pathClass = ClassUtils.forName("java.nio.file.Path", ResourceEditorRegistrar.class.getClassLoader()); + } + catch (ClassNotFoundException ex) { + // Java 7 Path class not available + pathClass = null; + } + } + + private final PropertyResolver propertyResolver; private final ResourceLoader resourceLoader; @@ -103,6 +118,9 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar { doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor)); doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor)); doRegisterEditor(registry, File.class, new FileEditor(baseEditor)); + if (pathClass != null) { + doRegisterEditor(registry, pathClass, new PathEditor(baseEditor)); + } doRegisterEditor(registry, Reader.class, new ReaderEditor(baseEditor)); doRegisterEditor(registry, URL.class, new URLEditor(baseEditor)); |