dlr 2002/10/10 11:09:10
Modified: src/java/org/apache/velocity/runtime/resource/loader
FileResourceLoader.java
Log:
Hand-merged patch by Ilkka Priha <[EMAIL PROTECTED]>:
"FileReousrceLoader currently repeats argument validation within its
search loop. Moving this outside would optimize performance and
memory consumption (simple change, but diff seems to make it look
complicated)."
Revision Changes Path
1.17 +32 -36
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
Index: FileResourceLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -u -r1.16 -r1.17
--- FileResourceLoader.java 10 Oct 2002 17:19:32 -0000 1.16
+++ FileResourceLoader.java 10 Oct 2002 18:09:10 -0000 1.17
@@ -124,48 +124,44 @@
public synchronized InputStream getResourceStream(String templateName)
throws ResourceNotFoundException
{
- String template = null;
- int size = paths.size();
-
- for (int i = 0; i < size; i++)
+ /*
+ * Make sure we have a valid templateName.
+ */
+ if (templateName == null || templateName.length() == 0)
{
- String path = (String) paths.get(i);
-
/*
- * Make sure we have a valid templateName.
+ * 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.
*/
- if (templateName == null || templateName.length() == 0)
- {
- /*
- * 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!");
- }
+ throw new ResourceNotFoundException(
+ "Need to specify a file name or file path!");
+ }
- 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.";
+ 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.";
- rsvc.error( "FileResourceLoader : " + msg );
+ rsvc.error( "FileResourceLoader : " + msg );
- throw new ResourceNotFoundException ( msg );
- }
+ throw new ResourceNotFoundException ( msg );
+ }
- /*
- * if a / leads off, then just nip that :)
- */
- if ( template.startsWith("/") )
- {
- template = template.substring(1);
- }
+ /*
+ * if a / leads off, then just nip that :)
+ */
+ if (template.startsWith("/"))
+ {
+ template = template.substring(1);
+ }
+ int size = paths.size();
+ for (int i = 0; i < size; i++)
+ {
+ String path = (String) paths.get(i);
InputStream inputStream = findTemplate(path, template);
if (inputStream != null)
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>