/*
* If we don't get a properly formed templateName then
* there's not much we can do. So we'll forget about
* trying to search any more paths for the template.
*/
throw new ResourceNotFoundException(
"Need to specify a file name or file path!");
}
String template = StringUtils.normalizePath(templateName);
if ( template == null || template.length() == 0 )
{
String msg = "File resource error : argument " + template +
" contains .. and may be trying to access " +
"content outside of template root. Rejected.";
log.error("FileResourceLoader : " + msg);
throw new ResourceNotFoundException ( msg );
}
int size = paths.size();
for (int i = 0; i < size; i++)
{
String path = (String) paths.get(i);
InputStream inputStream = null;
try
{
inputStream = findTemplate(path, template);
}
catch (IOException ioe)
{
log.error("While loading Template " + template + ": ", ioe);
}
if (inputStream != null)
{
/*
* Store the path that this template came
* from so that we can check its modification
* time.
*/
templatePaths.put(templateName, path);
return inputStream;
}
}
/*
* We have now searched all the paths for
* templates and we didn't find anything so
* throw an exception.
*/
throw new ResourceNotFoundException("FileResourceLoader : cannot find " + template);
}