Search in sources :

Example 1 with InputStreamEditor

use of org.springframework.beans.propertyeditors.InputStreamEditor in project spring-framework by spring-projects.

the class PropertyEditorRegistrySupport method createDefaultEditors.

/**
	 * Actually register the default editors for this registry instance.
	 */
private void createDefaultEditors() {
    this.defaultEditors = new HashMap<>(64);
    // Simple editors, without parameterization capabilities.
    // The JDK does not contain a default editor for any of these target types.
    this.defaultEditors.put(Charset.class, new CharsetEditor());
    this.defaultEditors.put(Class.class, new ClassEditor());
    this.defaultEditors.put(Class[].class, new ClassArrayEditor());
    this.defaultEditors.put(Currency.class, new CurrencyEditor());
    this.defaultEditors.put(File.class, new FileEditor());
    this.defaultEditors.put(InputStream.class, new InputStreamEditor());
    this.defaultEditors.put(InputSource.class, new InputSourceEditor());
    this.defaultEditors.put(Locale.class, new LocaleEditor());
    this.defaultEditors.put(Path.class, new PathEditor());
    this.defaultEditors.put(Pattern.class, new PatternEditor());
    this.defaultEditors.put(Properties.class, new PropertiesEditor());
    this.defaultEditors.put(Reader.class, new ReaderEditor());
    this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor());
    this.defaultEditors.put(TimeZone.class, new TimeZoneEditor());
    this.defaultEditors.put(URI.class, new URIEditor());
    this.defaultEditors.put(URL.class, new URLEditor());
    this.defaultEditors.put(UUID.class, new UUIDEditor());
    this.defaultEditors.put(ZoneId.class, new ZoneIdEditor());
    // Default instances of collection editors.
    // Can be overridden by registering custom instances of those as custom editors.
    this.defaultEditors.put(Collection.class, new CustomCollectionEditor(Collection.class));
    this.defaultEditors.put(Set.class, new CustomCollectionEditor(Set.class));
    this.defaultEditors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class));
    this.defaultEditors.put(List.class, new CustomCollectionEditor(List.class));
    this.defaultEditors.put(SortedMap.class, new CustomMapEditor(SortedMap.class));
    // Default editors for primitive arrays.
    this.defaultEditors.put(byte[].class, new ByteArrayPropertyEditor());
    this.defaultEditors.put(char[].class, new CharArrayPropertyEditor());
    // The JDK does not contain a default editor for char!
    this.defaultEditors.put(char.class, new CharacterEditor(false));
    this.defaultEditors.put(Character.class, new CharacterEditor(true));
    // Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor.
    this.defaultEditors.put(boolean.class, new CustomBooleanEditor(false));
    this.defaultEditors.put(Boolean.class, new CustomBooleanEditor(true));
    // The JDK does not contain default editors for number wrapper types!
    // Override JDK primitive number editors with our own CustomNumberEditor.
    this.defaultEditors.put(byte.class, new CustomNumberEditor(Byte.class, false));
    this.defaultEditors.put(Byte.class, new CustomNumberEditor(Byte.class, true));
    this.defaultEditors.put(short.class, new CustomNumberEditor(Short.class, false));
    this.defaultEditors.put(Short.class, new CustomNumberEditor(Short.class, true));
    this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false));
    this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true));
    this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false));
    this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true));
    this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false));
    this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true));
    this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false));
    this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true));
    this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true));
    this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));
    // Only register config value editors if explicitly requested.
    if (this.configValueEditorsActive) {
        StringArrayPropertyEditor sae = new StringArrayPropertyEditor();
        this.defaultEditors.put(String[].class, sae);
        this.defaultEditors.put(short[].class, sae);
        this.defaultEditors.put(int[].class, sae);
        this.defaultEditors.put(long[].class, sae);
    }
}
Also used : FileEditor(org.springframework.beans.propertyeditors.FileEditor) SortedSet(java.util.SortedSet) Set(java.util.Set) CustomBooleanEditor(org.springframework.beans.propertyeditors.CustomBooleanEditor) InputStreamEditor(org.springframework.beans.propertyeditors.InputStreamEditor) LocaleEditor(org.springframework.beans.propertyeditors.LocaleEditor) InputSourceEditor(org.springframework.beans.propertyeditors.InputSourceEditor) SortedSet(java.util.SortedSet) ReaderEditor(org.springframework.beans.propertyeditors.ReaderEditor) StringArrayPropertyEditor(org.springframework.beans.propertyeditors.StringArrayPropertyEditor) CharsetEditor(org.springframework.beans.propertyeditors.CharsetEditor) ZoneIdEditor(org.springframework.beans.propertyeditors.ZoneIdEditor) List(java.util.List) LinkedList(java.util.LinkedList) TimeZoneEditor(org.springframework.beans.propertyeditors.TimeZoneEditor) PropertiesEditor(org.springframework.beans.propertyeditors.PropertiesEditor) UUIDEditor(org.springframework.beans.propertyeditors.UUIDEditor) CustomNumberEditor(org.springframework.beans.propertyeditors.CustomNumberEditor) CurrencyEditor(org.springframework.beans.propertyeditors.CurrencyEditor) Resource(org.springframework.core.io.Resource) URIEditor(org.springframework.beans.propertyeditors.URIEditor) ByteArrayPropertyEditor(org.springframework.beans.propertyeditors.ByteArrayPropertyEditor) ClassArrayEditor(org.springframework.beans.propertyeditors.ClassArrayEditor) ClassEditor(org.springframework.beans.propertyeditors.ClassEditor) ResourceArrayPropertyEditor(org.springframework.core.io.support.ResourceArrayPropertyEditor) CharArrayPropertyEditor(org.springframework.beans.propertyeditors.CharArrayPropertyEditor) BigDecimal(java.math.BigDecimal) PathEditor(org.springframework.beans.propertyeditors.PathEditor) CharacterEditor(org.springframework.beans.propertyeditors.CharacterEditor) BigInteger(java.math.BigInteger) CustomCollectionEditor(org.springframework.beans.propertyeditors.CustomCollectionEditor) PatternEditor(org.springframework.beans.propertyeditors.PatternEditor) SortedMap(java.util.SortedMap) Collection(java.util.Collection) BigInteger(java.math.BigInteger) CustomMapEditor(org.springframework.beans.propertyeditors.CustomMapEditor) URLEditor(org.springframework.beans.propertyeditors.URLEditor)

Example 2 with InputStreamEditor

use of org.springframework.beans.propertyeditors.InputStreamEditor in project spring-framework by spring-projects.

the class ResourceEditorRegistrar method registerCustomEditors.

/**
	 * Populate the given {@code registry} with the following resource editors:
	 * ResourceEditor, InputStreamEditor, InputSourceEditor, FileEditor, URLEditor,
	 * URIEditor, ClassEditor, ClassArrayEditor.
	 * <p>If this registrar has been configured with a {@link ResourcePatternResolver},
	 * a ResourceArrayPropertyEditor will be registered as well.
	 * @see org.springframework.core.io.ResourceEditor
	 * @see org.springframework.beans.propertyeditors.InputStreamEditor
	 * @see org.springframework.beans.propertyeditors.InputSourceEditor
	 * @see org.springframework.beans.propertyeditors.FileEditor
	 * @see org.springframework.beans.propertyeditors.URLEditor
	 * @see org.springframework.beans.propertyeditors.URIEditor
	 * @see org.springframework.beans.propertyeditors.ClassEditor
	 * @see org.springframework.beans.propertyeditors.ClassArrayEditor
	 * @see org.springframework.core.io.support.ResourceArrayPropertyEditor
	 */
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
    ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader, this.propertyResolver);
    doRegisterEditor(registry, Resource.class, baseEditor);
    doRegisterEditor(registry, ContextResource.class, baseEditor);
    doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor));
    doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor));
    doRegisterEditor(registry, File.class, new FileEditor(baseEditor));
    doRegisterEditor(registry, Path.class, new PathEditor(baseEditor));
    doRegisterEditor(registry, Reader.class, new ReaderEditor(baseEditor));
    doRegisterEditor(registry, URL.class, new URLEditor(baseEditor));
    ClassLoader classLoader = this.resourceLoader.getClassLoader();
    doRegisterEditor(registry, URI.class, new URIEditor(classLoader));
    doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
    doRegisterEditor(registry, Class[].class, new ClassArrayEditor(classLoader));
    if (this.resourceLoader instanceof ResourcePatternResolver) {
        doRegisterEditor(registry, Resource[].class, new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader, this.propertyResolver));
    }
}
Also used : FileEditor(org.springframework.beans.propertyeditors.FileEditor) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStreamEditor(org.springframework.beans.propertyeditors.InputStreamEditor) URIEditor(org.springframework.beans.propertyeditors.URIEditor) ContextResource(org.springframework.core.io.ContextResource) Resource(org.springframework.core.io.Resource) ClassArrayEditor(org.springframework.beans.propertyeditors.ClassArrayEditor) ResourceEditor(org.springframework.core.io.ResourceEditor) ClassEditor(org.springframework.beans.propertyeditors.ClassEditor) ResourceArrayPropertyEditor(org.springframework.core.io.support.ResourceArrayPropertyEditor) InputSourceEditor(org.springframework.beans.propertyeditors.InputSourceEditor) ReaderEditor(org.springframework.beans.propertyeditors.ReaderEditor) PathEditor(org.springframework.beans.propertyeditors.PathEditor) URLEditor(org.springframework.beans.propertyeditors.URLEditor)

Aggregations

ClassArrayEditor (org.springframework.beans.propertyeditors.ClassArrayEditor)2 ClassEditor (org.springframework.beans.propertyeditors.ClassEditor)2 FileEditor (org.springframework.beans.propertyeditors.FileEditor)2 InputSourceEditor (org.springframework.beans.propertyeditors.InputSourceEditor)2 InputStreamEditor (org.springframework.beans.propertyeditors.InputStreamEditor)2 PathEditor (org.springframework.beans.propertyeditors.PathEditor)2 ReaderEditor (org.springframework.beans.propertyeditors.ReaderEditor)2 URIEditor (org.springframework.beans.propertyeditors.URIEditor)2 URLEditor (org.springframework.beans.propertyeditors.URLEditor)2 Resource (org.springframework.core.io.Resource)2 ResourceArrayPropertyEditor (org.springframework.core.io.support.ResourceArrayPropertyEditor)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 SortedSet (java.util.SortedSet)1 ByteArrayPropertyEditor (org.springframework.beans.propertyeditors.ByteArrayPropertyEditor)1