InputStream resourceStream = null;
// first, see if we have a preview theme to operate from
if(!StringUtils.isEmpty(resourceRequest.getThemeName())) {
Theme theme = resourceRequest.getTheme();
ThemeResource resource = theme.getResource(resourceRequest.getResourcePath());
if(resource != null) {
resourceLastMod = resource.getLastModified();
resourceStream = resource.getInputStream();
}
}
// second, see if resource comes from weblog's configured shared theme
if(resourceStream == null) {
try {
WeblogTheme weblogTheme = weblog.getTheme();
if(weblogTheme != null) {
ThemeResource resource = weblogTheme.getResource(resourceRequest.getResourcePath());
if(resource != null) {
resourceLastMod = resource.getLastModified();
resourceStream = resource.getInputStream();
}
}
} catch (Exception ex) {
// hmmm, some kind of error getting theme. that's an error.
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
// if not from theme then see if resource is in weblog's upload dir
if(resourceStream == null) {
try {
FileManager fileMgr = WebloggerFactory.getWeblogger().getFileManager();
ThemeResource resource = fileMgr.getFile(weblog,
resourceRequest.getResourcePath());
resourceLastMod = resource.getLastModified();
resourceStream = resource.getInputStream();
} catch (Exception ex) {
// still not found? then we don't have it, 404.
log.debug("Unable to get resource", ex);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;