return;
}
InputStream is = null;
try {
ResourceProvider resourceProvider;
if (ResourceProvider.class.isAssignableFrom(componentClass)) {
try {
resourceProvider = (ResourceProvider) componentClass.newInstance();
} catch (InstantiationException e) {
response.sendError
(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
"Unable to instantiate resource provider for resource "
+ resource + " for component " + component);
log.error
("Unable to instantiate resource provider for resource "
+ resource + " for component " + component, e);
return;
} catch (IllegalAccessException e) {
response.sendError
(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
"Unable to instantiate resource provider for resource "
+ resource + " for component " + component);
log.error("Unable to instantiate resource provider for resource " + resource + " for component " + component, e);
return;
}
} else {
resourceProvider = new DefaultResourceProvider(componentClass);
}
if (!resourceProvider.exists(context, resource)) {
response.sendError
(HttpServletResponse.SC_NOT_FOUND,
"Unable to find resource " + resource + " for component "
+ component + ". Check that this file is available "
+ "in the classpath in sub-directory "
+ "/resource of the package-directory.");
log.error("Unable to find resource " + resource
+ " for component " + component
+ ". Check that this file is available "
+ "in the classpath in sub-directory "
+ "/resource of the package-directory.");
}
long lastModified
= resourceProvider.getLastModified(context, resource);
if (lastModified < 1) {
// fallback
lastModified = getLastModified();
}
long browserDate = request.getDateHeader("If-Modified-Since");
if (browserDate > -1) {
// normalize to seconds - this should work with any os
lastModified = (lastModified / 1000) * 1000;
browserDate = (browserDate / 1000) * 1000;
if (lastModified == browserDate) {
// the browser already has the correct version
response.setStatus(HttpURLConnection.HTTP_NOT_MODIFIED);
return;
}
}
int contentLength
= resourceProvider.getContentLength(context, resource);
String contentEncoding
= resourceProvider.getEncoding(context, resource);
is = resourceProvider.getInputStream(context, resource);
defineContentHeaders
(request, response, resource, contentLength, contentEncoding);
defineCaching(request, response, resource, lastModified);
writeResource(request, response, is);
} finally {