Author: nbubna
Date: Thu Nov 6 15:35:43 2008
New Revision: 712011
URL: http://svn.apache.org/viewvc?rev=712011&view=rev
Log:
small logging and exception handling improvements
Modified:
velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
Modified:
velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java?rev=712011&r1=712010&r2=712011&view=diff
==============================================================================
---
velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
(original)
+++
velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
Thu Nov 6 15:35:43 2008
@@ -58,6 +58,7 @@
protected HashMap templatePaths = null;
protected ServletContext servletContext = null;
+
/**
* This is abstract in the base class, so we need it.
* <br>
@@ -138,9 +139,10 @@
Exception exception = null;
for (int i = 0; i < paths.length; i++)
{
+ String path = paths[i] + name;
try
{
- result = servletContext.getResourceAsStream(paths[i] + name);
+ result = servletContext.getResourceAsStream(path);
/* save the path and exit the loop if we found the template */
if (result != null)
@@ -149,11 +151,20 @@
break;
}
}
+ catch (NullPointerException npe)
+ {
+ /* no servletContext was set, whine about it! */
+ throw npe;
+ }
catch (Exception e)
{
/* only save the first one for later throwing */
if (exception == null)
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("WebappResourceLoader: Could not load
"+path, e);
+ }
exception = e;
}
}
@@ -162,19 +173,19 @@
/* if we never found the template */
if (result == null)
{
- String msg;
+ String msg = "WebappResourceLoader: Resource '" + name + "' not
found.";
+
+ /* convert to a general Velocity ResourceNotFoundException */
if (exception == null)
{
- msg = "WebappResourceLoader: Resource '" + name + "' not
found.";
+ throw new ResourceNotFoundException(msg);
}
else
{
- msg = exception.getMessage();
+ msg += " Due to: " + exception;
+ throw new ResourceNotFoundException(msg, exception);
}
- /* convert to a general Velocity ResourceNotFoundException */
- throw new ResourceNotFoundException(msg);
}
-
return result;
}