Polish
This commit is contained in:
@@ -84,7 +84,9 @@ public class MessageSourceAutoConfiguration {
|
||||
messageSource
|
||||
.setBasenames(commaDelimitedListToStringArray(trimAllWhitespace(this.basename)));
|
||||
}
|
||||
messageSource.setDefaultEncoding(this.encoding.name());
|
||||
if (this.encoding != null) {
|
||||
messageSource.setDefaultEncoding(this.encoding.name());
|
||||
}
|
||||
messageSource.setCacheSeconds(this.cacheSeconds);
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.jndi.JndiLocatorDelegate;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Session.class)
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.mail;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.activation.MimeType;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
@@ -78,7 +79,9 @@ public class MailSenderAutoConfiguration {
|
||||
}
|
||||
sender.setUsername(this.properties.getUsername());
|
||||
sender.setPassword(this.properties.getPassword());
|
||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
|
||||
if (this.properties.getDefaultEncoding() != null) {
|
||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
|
||||
}
|
||||
if (!this.properties.getProperties().isEmpty()) {
|
||||
sender.setJavaMailProperties(asProperties(this.properties.getProperties()));
|
||||
}
|
||||
@@ -90,10 +93,9 @@ public class MailSenderAutoConfiguration {
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Condition to trigger the creation of a {@link JavaMailSenderImpl}. This kicks
|
||||
* in if either the host or jndi name property is set.
|
||||
* Condition to trigger the creation of a {@link JavaMailSenderImpl}. This kicks in if
|
||||
* either the host or jndi name property is set.
|
||||
*/
|
||||
static class MailSenderCondition extends AnyNestedCondition {
|
||||
|
||||
|
||||
@@ -146,7 +146,9 @@ public abstract class AbstractTemplateViewResolverProperties extends
|
||||
resolver.setPrefix(getPrefix());
|
||||
resolver.setSuffix(getSuffix());
|
||||
resolver.setCache(isCache());
|
||||
resolver.setContentType(getContentType().toString());
|
||||
if (getContentType() != null) {
|
||||
resolver.setContentType(getContentType().toString());
|
||||
}
|
||||
resolver.setViewNames(getViewNames());
|
||||
resolver.setExposeRequestAttributes(isExposeRequestAttributes());
|
||||
resolver.setAllowRequestOverride(isAllowRequestOverride());
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.boot.autoconfigure.template;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -103,8 +101,13 @@ public abstract class AbstractViewResolverProperties {
|
||||
}
|
||||
|
||||
public MimeType getContentType() {
|
||||
return (this.contentType.getCharSet() != null ? this.contentType :
|
||||
new MimeType(this.contentType, cloneParametersWithCustomCharset(this.contentType, this.charset)));
|
||||
if (this.contentType.getCharSet() == null) {
|
||||
Map<String, String> parameters = new LinkedHashMap<String, String>();
|
||||
parameters.put("charset", this.charset.name());
|
||||
parameters.putAll(this.contentType.getParameters());
|
||||
return new MimeType(this.contentType, parameters);
|
||||
}
|
||||
return this.contentType;
|
||||
}
|
||||
|
||||
public void setContentType(MimeType contentType) {
|
||||
@@ -123,11 +126,4 @@ public abstract class AbstractViewResolverProperties {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
private static Map<String,String> cloneParametersWithCustomCharset(MimeType contentType, Charset charset) {
|
||||
LinkedHashMap<String,String> clone = new LinkedHashMap<String, String>();
|
||||
clone.put("charset", charset.name());
|
||||
clone.putAll(contentType.getParameters());
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,9 @@ public class ThymeleafAutoConfiguration {
|
||||
resolver.setPrefix(this.properties.getPrefix());
|
||||
resolver.setSuffix(this.properties.getSuffix());
|
||||
resolver.setTemplateMode(this.properties.getMode());
|
||||
resolver.setCharacterEncoding(this.properties.getEncoding().name());
|
||||
if (this.properties.getEncoding() != null) {
|
||||
resolver.setCharacterEncoding(this.properties.getEncoding().name());
|
||||
}
|
||||
resolver.setCacheable(this.properties.isCache());
|
||||
return resolver;
|
||||
}
|
||||
@@ -212,10 +214,10 @@ public class ThymeleafAutoConfiguration {
|
||||
if (type.getCharSet() != null) {
|
||||
return type.toString();
|
||||
}
|
||||
LinkedHashMap<String,String> clone = new LinkedHashMap<String, String>();
|
||||
clone.put("charset", charset);
|
||||
clone.putAll(type.getParameters());
|
||||
return new MimeType(type, clone).toString();
|
||||
LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
|
||||
parameters.put("charset", charset);
|
||||
parameters.putAll(type.getParameters());
|
||||
return new MimeType(type, parameters).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ThymeleafProperties {
|
||||
/**
|
||||
* Template encoding.
|
||||
*/
|
||||
private Charset encoding = DEFAULT_ENCODING;
|
||||
private Charset encoding = DEFAULT_ENCODING;
|
||||
|
||||
/**
|
||||
* Content-Type value.
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.template;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
@@ -32,10 +31,10 @@ import static org.hamcrest.Matchers.hasToString;
|
||||
*/
|
||||
public class ViewResolverPropertiesTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultContentType() {
|
||||
assertThat(new ViewResolverProperties().getContentType(), hasToString("text/html;charset=UTF-8"));
|
||||
assertThat(new ViewResolverProperties().getContentType(),
|
||||
hasToString("text/html;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,11 +64,12 @@ public class ViewResolverPropertiesTest {
|
||||
ViewResolverProperties properties = new ViewResolverProperties();
|
||||
properties.setContentType(MimeTypeUtils.parseMimeType("text/plain;foo=bar"));
|
||||
properties.setCharset(Charset.forName("UTF-16"));
|
||||
assertThat(properties.getContentType(), hasToString("text/plain;charset=UTF-16;foo=bar"));
|
||||
assertThat(properties.getContentType(),
|
||||
hasToString("text/plain;charset=UTF-16;foo=bar"));
|
||||
}
|
||||
|
||||
|
||||
private static class ViewResolverProperties extends AbstractViewResolverProperties {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -205,7 +205,8 @@ public class ServerPropertiesTests {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.uriEncoding", "US-ASCII");
|
||||
bindProperties(map);
|
||||
assertEquals(Charset.forName("US-ASCII"), this.properties.getTomcat().getUriEncoding());
|
||||
assertEquals(Charset.forName("US-ASCII"), this.properties.getTomcat()
|
||||
.getUriEncoding());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user