From 346c8c87974061dc565300a0fdec61810575e9b3 Mon Sep 17 00:00:00 2001 From: mdb Date: Fri, 2 Nov 2001 02:30:24 +0000 Subject: [PATCH] Be more robust and log a warning if we're used without first properly setting the servlet context into the application context. git-svn-id: https://samskivert.googlecode.com/svn/trunk@415 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../velocity/ServletContextResourceLoader.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/velocity/ServletContextResourceLoader.java b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextResourceLoader.java index f0109241..200f294d 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/ServletContextResourceLoader.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/ServletContextResourceLoader.java @@ -1,5 +1,5 @@ // -// $Id: ServletContextResourceLoader.java,v 1.1 2001/11/02 02:03:23 mdb Exp $ +// $Id: ServletContextResourceLoader.java,v 1.2 2001/11/02 02:30:24 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -50,6 +50,13 @@ public class ServletContextResourceLoader extends ResourceLoader // the web framework was kind enough to slip this into the runtime // instance when it started up _sctx = (ServletContext)rsvc.getApplicationContext(); + if (_sctx == null) { + rsvc.warn("ServletContextResourceLoader: servlet context " + + "was not supplied as application context. A " + + "user of the servlet context resource loader " + + "must call Velocity.setApplicationContext(" + + "getServletContext())."); + } rsvc.info("ServletContextResourceLoader : initialization complete."); } @@ -68,6 +75,14 @@ public class ServletContextResourceLoader extends ResourceLoader public InputStream getResourceStream (String path) throws ResourceNotFoundException { + // make sure we were properly initialized + if (_sctx == null) { + String errmsg = "ServletContextResourceLoader not properly " + + "initialized. Can't load resources."; + throw new ResourceNotFoundException(errmsg); + } + + // load it on up InputStream stream = _sctx.getResourceAsStream(path); if (stream == null) { String errmsg = "Unable to load resource via servlet context " +