Author: henning Date: Sat Nov 4 12:26:57 2006 New Revision: 471259 URL: http://svn.apache.org/viewvc?view=rev&rev=471259 Log: Add C'Tors taking Throwable to ResourceNotFoundException. Clean up the resource loaders using this (actually only one generates RNFE from another exception but this is a good excuse to add some StringUtils sprinkling to String tests...
Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ResourceNotFoundException.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ResourceNotFoundException.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ResourceNotFoundException.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ResourceNotFoundException.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ResourceNotFoundException.java Sat Nov 4 12:26:57 2006 @@ -39,10 +39,26 @@ private static final long serialVersionUID = -4287732191458420347L; /** - * @param exceptionMessage + * @see VelocityException#VelocityException(String) */ - public ResourceNotFoundException(String exceptionMessage) + public ResourceNotFoundException(final String exceptionMessage) { super(exceptionMessage); + } + + /** + * @see VelocityException#VelocityException(String, Throwable) + */ + public ResourceNotFoundException(final String exceptionMessage, final Throwable t) + { + super(exceptionMessage, t); + } + + /** + * @see VelocityException#VelocityException(Throwable) + */ + public ResourceNotFoundException(final Throwable t) + { + super(t); } } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java Sat Nov 4 12:26:57 2006 @@ -41,7 +41,7 @@ /** * @param exceptionMessage The message to register. */ - public VelocityException(String exceptionMessage) + public VelocityException(final String exceptionMessage) { super(exceptionMessage); wrapped = null; @@ -49,10 +49,21 @@ /** * @param exceptionMessage The message to register. + * @param throwable A throwable object that caused the Exception. */ public VelocityException(final String exceptionMessage, final Throwable wrapped) { super(exceptionMessage); + this.wrapped = wrapped; + ExceptionUtils.setCause(this, wrapped); + } + + /** + * @param throwable A throwable object that caused the Exception. + */ + public VelocityException(final Throwable wrapped) + { + super(); this.wrapped = wrapped; ExceptionUtils.setCause(this, wrapped); } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java Sat Nov 4 12:26:57 2006 @@ -21,12 +21,12 @@ import java.io.InputStream; +import org.apache.commons.collections.ExtendedProperties; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.ClassUtils; import org.apache.velocity.util.ExceptionUtils; -import org.apache.velocity.exception.ResourceNotFoundException; - -import org.apache.commons.collections.ExtendedProperties; /** * ClasspathResourceLoader is a simple loader that will load @@ -104,7 +104,7 @@ { InputStream result = null; - if (name == null || name.length() == 0) + if (StringUtils.isEmpty(name)) { throw new ResourceNotFoundException ("No template name provided"); } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java Sat Nov 4 12:26:57 2006 @@ -216,7 +216,7 @@ public synchronized InputStream getResourceStream(final String name) throws ResourceNotFoundException { - if (name == null || name.length() == 0) + if (org.apache.commons.lang.StringUtils.isEmpty(name)) { throw new ResourceNotFoundException ("DataSourceResourceLoader: " + "Template name was empty or null"); Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java Sat Nov 4 12:26:57 2006 @@ -19,23 +19,21 @@ * under the License. */ +import java.io.BufferedInputStream; import java.io.File; -import java.io.InputStream; import java.io.FileInputStream; -import java.io.BufferedInputStream; import java.io.FileNotFoundException; - -import java.util.Collections; +import java.io.InputStream; import java.util.ArrayList; -import java.util.List; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; -import org.apache.velocity.util.StringUtils; -import org.apache.velocity.runtime.resource.Resource; -import org.apache.velocity.exception.ResourceNotFoundException; - import org.apache.commons.collections.ExtendedProperties; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.resource.Resource; +import org.apache.velocity.util.StringUtils; /** * A loader for templates stored on the file system. Treats the template @@ -103,7 +101,7 @@ /* * Make sure we have a valid templateName. */ - if (templateName == null || templateName.length() == 0) + if (org.apache.commons.lang.StringUtils.isEmpty(templateName)) { /* * If we don't get a properly formed templateName then Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java Sat Nov 4 12:26:57 2006 @@ -126,10 +126,10 @@ data = theJar.getInputStream( entry ); } } - catch( Exception fnfe ) + catch(Exception fnfe) { log.error("JarHolder: getResource() error", fnfe); - throw new ResourceNotFoundException( fnfe.getMessage() ); + throw new ResourceNotFoundException(fnfe); } return data; Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java Sat Nov 4 12:26:57 2006 @@ -192,7 +192,7 @@ { InputStream results = null; - if ( source == null || source.length() == 0) + if (org.apache.commons.lang.StringUtils.isEmpty(source)) { throw new ResourceNotFoundException("Need to have a resource!"); } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java?view=diff&rev=471259&r1=471258&r2=471259 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java Sat Nov 4 12:26:57 2006 @@ -25,6 +25,7 @@ import java.net.URLConnection; import java.util.HashMap; import org.apache.commons.collections.ExtendedProperties; +import org.apache.commons.lang.StringUtils; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.resource.Resource; @@ -75,7 +76,7 @@ public synchronized InputStream getResourceStream(String name) throws ResourceNotFoundException { - if (name == null || name.length() == 0) + if (StringUtils.isEmpty(name)) { throw new ResourceNotFoundException("URLResourceLoader : No template name provided"); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]