Consistent use of StringUtils.toStringArray

This commit is contained in:
Juergen Hoeller
2018-02-16 19:48:43 +01:00
parent 350f318d2e
commit 6d11b40353
27 changed files with 125 additions and 137 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@@ -60,7 +61,7 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean
if (locations.isEmpty()) {
locations.add("/WEB-INF/");
}
builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@@ -58,7 +59,7 @@ public class ScriptTemplateConfigurerBeanDefinitionParser extends AbstractSimple
for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location"));
}
builder.addPropertyValue("scripts", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("scripts", StringUtils.toStringArray(locations));
}
builder.addPropertyValue("engineName", element.getAttribute("engine-name"));
if (element.hasAttribute("render-object")) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@@ -58,7 +59,7 @@ public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefin
for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location"));
}
builder.addPropertyValue("definitions", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("definitions", StringUtils.toStringArray(locations));
}
if (element.hasAttribute("check-refresh")) {
builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -21,8 +21,8 @@ import java.util.Arrays;
import java.util.List;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptor;
@@ -88,8 +88,8 @@ public class InterceptorRegistration {
return this.interceptor;
}
String[] include = toArray(this.includePatterns);
String[] exclude = toArray(this.excludePatterns);
String[] include = StringUtils.toStringArray(this.includePatterns);
String[] exclude = StringUtils.toStringArray(this.excludePatterns);
MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor);
if (this.pathMatcher != null) {
@@ -99,8 +99,4 @@ public class InterceptorRegistration {
return mappedInterceptor;
}
private static String[] toArray(List<String> list) {
return (CollectionUtils.isEmpty(list) ? null : list.toArray(new String[list.size()]));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -31,11 +31,10 @@ import org.springframework.web.servlet.ModelAndView;
* Also provides matching logic to test if the interceptor applies to a given request path.
*
* <p>A MappedInterceptor can be registered directly with any
* {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping
* AbstractHandlerMethodMapping}. Furthermore, beans of type MappedInterceptor
* are automatically detected by {@code AbstractHandlerMethodMapping} (including
* ancestor ApplicationContext's) which effectively means the interceptor is
* registered "globally" with all handler mappings.
* {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping}.
* Furthermore, beans of type {@code MappedInterceptor} are automatically detected by
* {@code AbstractHandlerMethodMapping} (including ancestor ApplicationContext's) which
* effectively means the interceptor is registered "globally" with all handler mappings.
*
* @author Keith Donald
* @author Rossen Stoyanchev
@@ -55,7 +54,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
/**
* Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths
* @param includePatterns the path patterns to map (empty for matching to all paths)
* @param interceptor the HandlerInterceptor instance to map to the given patterns
*/
public MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor) {
@@ -64,8 +63,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
/**
* Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths
* @param excludePatterns the path patterns to exclude
* @param includePatterns the path patterns to map (empty for matching to all paths)
* @param excludePatterns the path patterns to exclude (empty for no specific excludes)
* @param interceptor the HandlerInterceptor instance to map to the given patterns
*/
public MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) {
@@ -132,8 +131,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
* @param pathMatcher a path matcher for path pattern matching
*/
public boolean matches(String lookupPath, PathMatcher pathMatcher) {
PathMatcher pathMatcherToUse = (this.pathMatcher != null) ? this.pathMatcher : pathMatcher;
if (this.excludePatterns != null) {
PathMatcher pathMatcherToUse = (this.pathMatcher != null ? this.pathMatcher : pathMatcher);
if (!ObjectUtils.isEmpty(this.excludePatterns)) {
for (String pattern : this.excludePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return false;
@@ -143,14 +142,12 @@ public final class MappedInterceptor implements HandlerInterceptor {
if (ObjectUtils.isEmpty(this.includePatterns)) {
return true;
}
else {
for (String pattern : this.includePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return true;
}
for (String pattern : this.includePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) {
return true;
}
return false;
}
return false;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -131,7 +131,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
prefixedPatterns.add(versionPrefix + pattern);
}
}
return addVersionStrategy(new FixedVersionStrategy(version), prefixedPatterns.toArray(new String[0]));
return addVersionStrategy(new FixedVersionStrategy(version), StringUtils.toStringArray(prefixedPatterns));
}
/**