pull/3452/head
Phillip Webb 10 years ago
parent 7dcb79b3b3
commit ef39634e30

@ -54,13 +54,11 @@ public class ResourceProperties implements ResourceLoaderAware {
SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
}
private static final String[] STATIC_INDEX_HTML_RESOURCES;
static {
STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
}
}
/**
* Locations of static resources. Defaults to classpath:[/META-INF/resources/,
* /resources/, /static/, /public/] plus context:/ (the root of the servlet context).
*/
private String[] staticLocations = RESOURCE_LOCATIONS;
/**
* Cache period for the resources served by the resource handler, in seconds.
@ -74,12 +72,6 @@ public class ResourceProperties implements ResourceLoaderAware {
private final Chain chain = new Chain();
/**
* Locations of static resources. Defaults to classpath:[/META-INF/resources/,
* /resources/, /static/, /public/] plus context:/ (the root of the servlet context).
*/
private String[] staticLocations = RESOURCE_LOCATIONS;
private ResourceLoader resourceLoader;
@Override
@ -87,6 +79,54 @@ public class ResourceProperties implements ResourceLoaderAware {
this.resourceLoader = resourceLoader;
}
public String[] getStaticLocations() {
return this.staticLocations;
}
public void setStaticLocations(String[] staticLocations) {
this.staticLocations = staticLocations;
}
public Resource getWelcomePage() {
for (String location : getStaticWelcomePageLocations()) {
Resource resource = this.resourceLoader.getResource(location);
if (resource.exists()) {
try {
resource.getURL();
return resource;
}
catch (IOException ex) {
// Ignore
}
}
}
return null;
}
private String[] getStaticWelcomePageLocations() {
String[] result = new String[this.staticLocations.length];
for (int i = 0; i < result.length; i++) {
String location = this.staticLocations[i];
if (!location.endsWith("/")) {
location = location + "/";
}
result[i] = location + "index.html";
}
return result;
}
public List<Resource> getFaviconLocations() {
List<Resource> locations = new ArrayList<Resource>(
CLASSPATH_RESOURCE_LOCATIONS.length + 1);
if (this.resourceLoader != null) {
for (String location : CLASSPATH_RESOURCE_LOCATIONS) {
locations.add(this.resourceLoader.getResource(location));
}
}
locations.add(new ClassPathResource("/"));
return Collections.unmodifiableList(locations);
}
public Integer getCachePeriod() {
return this.cachePeriod;
}
@ -258,52 +298,4 @@ public class ResourceProperties implements ResourceLoaderAware {
}
public String[] getStaticLocations() {
return this.staticLocations;
}
public void setStaticLocations(String[] staticLocations) {
this.staticLocations = staticLocations;
}
private String[] getStaticWelcomePageLocations() {
String[] result = new String[this.staticLocations.length];
for (int i = 0; i < result.length; i++) {
String location = this.staticLocations[i];
if (!location.endsWith("/")) {
location = location + "/";
}
result[i] = location + "index.html";
}
return result;
}
public List<Resource> getFaviconLocations() {
List<Resource> locations = new ArrayList<Resource>(
CLASSPATH_RESOURCE_LOCATIONS.length + 1);
if (this.resourceLoader != null) {
for (String location : CLASSPATH_RESOURCE_LOCATIONS) {
locations.add(this.resourceLoader.getResource(location));
}
}
locations.add(new ClassPathResource("/"));
return Collections.unmodifiableList(locations);
}
public Resource getWelcomePage() {
for (String location : getStaticWelcomePageLocations()) {
Resource resource = this.resourceLoader.getResource(location);
if (resource.exists()) {
try {
resource.getURL();
return resource;
}
catch (IOException ex) {
// Ignore
}
}
}
return null;
}
}

Loading…
Cancel
Save