Polishing
This commit is contained in:
parent
bb5b5d52ed
commit
cc33d3fac8
|
|
@ -117,7 +117,7 @@ public class TypeDescriptor implements Serializable {
|
||||||
* constructor is used internally and may also be used by subclasses that support
|
* constructor is used internally and may also be used by subclasses that support
|
||||||
* non-Java languages with extended type systems.
|
* non-Java languages with extended type systems.
|
||||||
* @param resolvableType the resolvable type
|
* @param resolvableType the resolvable type
|
||||||
* @param type the backing type or {@code null} if should be resolved
|
* @param type the backing type (or {@code null} if it should get resolved)
|
||||||
* @param annotations the type annotations
|
* @param annotations the type annotations
|
||||||
*/
|
*/
|
||||||
protected TypeDescriptor(ResolvableType resolvableType, Class<?> type, Annotation[] annotations) {
|
protected TypeDescriptor(ResolvableType resolvableType, Class<?> type, Annotation[] annotations) {
|
||||||
|
|
@ -333,8 +333,8 @@ public class TypeDescriptor implements Serializable {
|
||||||
if (this.resolvableType.isArray()) {
|
if (this.resolvableType.isArray()) {
|
||||||
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
|
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
|
||||||
}
|
}
|
||||||
if (streamAvailable && StreamHelper.isStream(this.type)) {
|
if (streamAvailable && StreamDelegate.isStream(this.type)) {
|
||||||
return StreamHelper.getStreamElementType(this);
|
return StreamDelegate.getStreamElementType(this);
|
||||||
}
|
}
|
||||||
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
|
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
|
||||||
}
|
}
|
||||||
|
|
@ -691,17 +691,18 @@ public class TypeDescriptor implements Serializable {
|
||||||
return new TypeDescriptor(type, null, source.annotations);
|
return new TypeDescriptor(type, null, source.annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner class to avoid a hard dependency on Java 8.
|
* Inner class to avoid a hard dependency on Java 8.
|
||||||
*/
|
*/
|
||||||
@UsesJava8
|
@UsesJava8
|
||||||
private static class StreamHelper {
|
private static class StreamDelegate {
|
||||||
|
|
||||||
private static boolean isStream(Class<?> type) {
|
public static boolean isStream(Class<?> type) {
|
||||||
return Stream.class.isAssignableFrom(type);
|
return Stream.class.isAssignableFrom(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeDescriptor getStreamElementType(TypeDescriptor source) {
|
public static TypeDescriptor getStreamElementType(TypeDescriptor source) {
|
||||||
return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric());
|
return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -44,8 +44,8 @@ import org.springframework.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<Resource> {
|
public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<Resource> {
|
||||||
|
|
||||||
private static final boolean jafPresent =
|
private static final boolean jafPresent = ClassUtils.isPresent(
|
||||||
ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader());
|
"javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader());
|
||||||
|
|
||||||
|
|
||||||
public ResourceHttpMessageConverter() {
|
public ResourceHttpMessageConverter() {
|
||||||
|
|
@ -103,7 +103,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner class to avoid hard-coded JAF dependency.
|
* Inner class to avoid a hard-coded JAF dependency.
|
||||||
*/
|
*/
|
||||||
private static class ActivationMediaTypeFactory {
|
private static class ActivationMediaTypeFactory {
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
|
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
|
||||||
// see if we can find the extended mime.types from the context-support module
|
// See if we can find the extended mime.types from the context-support module...
|
||||||
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
|
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
|
||||||
if (mappingLocation.exists()) {
|
if (mappingLocation.exists()) {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
|
|
@ -140,11 +140,14 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaType getMediaType(Resource resource) {
|
public static MediaType getMediaType(Resource resource) {
|
||||||
if (resource.getFilename() == null) {
|
String filename = resource.getFilename();
|
||||||
return null;
|
if (filename != null) {
|
||||||
|
String mediaType = fileTypeMap.getContentType(filename);
|
||||||
|
if (StringUtils.hasText(mediaType)) {
|
||||||
|
return MediaType.parseMediaType(mediaType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String mediaType = fileTypeMap.getContentType(resource.getFilename());
|
return null;
|
||||||
return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -83,13 +83,14 @@ import org.springframework.web.servlet.support.WebContentGenerator;
|
||||||
*/
|
*/
|
||||||
public class ResourceHttpRequestHandler extends WebContentGenerator implements HttpRequestHandler, InitializingBean {
|
public class ResourceHttpRequestHandler extends WebContentGenerator implements HttpRequestHandler, InitializingBean {
|
||||||
|
|
||||||
private final static Log logger = LogFactory.getLog(ResourceHttpRequestHandler.class);
|
|
||||||
|
|
||||||
private static final boolean jafPresent =
|
|
||||||
ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpRequestHandler.class.getClassLoader());
|
|
||||||
|
|
||||||
private static final String CONTENT_ENCODING = "Content-Encoding";
|
private static final String CONTENT_ENCODING = "Content-Encoding";
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(ResourceHttpRequestHandler.class);
|
||||||
|
|
||||||
|
private static final boolean jafPresent = ClassUtils.isPresent(
|
||||||
|
"javax.activation.FileTypeMap", ResourceHttpRequestHandler.class.getClassLoader());
|
||||||
|
|
||||||
|
|
||||||
private final List<Resource> locations = new ArrayList<Resource>(4);
|
private final List<Resource> locations = new ArrayList<Resource>(4);
|
||||||
|
|
||||||
private final List<ResourceResolver> resourceResolvers = new ArrayList<ResourceResolver>(4);
|
private final List<ResourceResolver> resourceResolvers = new ArrayList<ResourceResolver>(4);
|
||||||
|
|
@ -422,8 +423,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H
|
||||||
getLocations() + ", resolvers=" + getResourceResolvers() + "]";
|
getLocations() + ", resolvers=" + getResourceResolvers() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner class to avoid hard-coded JAF dependency.
|
* Inner class to avoid a hard-coded JAF dependency.
|
||||||
*/
|
*/
|
||||||
private static class ActivationMediaTypeFactory {
|
private static class ActivationMediaTypeFactory {
|
||||||
|
|
||||||
|
|
@ -434,7 +436,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
|
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
|
||||||
// see if we can find the extended mime.types from the context-support module
|
// See if we can find the extended mime.types from the context-support module...
|
||||||
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
|
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
|
||||||
if (mappingLocation.exists()) {
|
if (mappingLocation.exists()) {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
|
|
@ -465,4 +467,4 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue