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
This commit is contained in:
+16
-1
@@ -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
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// 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
|
// the web framework was kind enough to slip this into the runtime
|
||||||
// instance when it started up
|
// instance when it started up
|
||||||
_sctx = (ServletContext)rsvc.getApplicationContext();
|
_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.");
|
rsvc.info("ServletContextResourceLoader : initialization complete.");
|
||||||
}
|
}
|
||||||
@@ -68,6 +75,14 @@ public class ServletContextResourceLoader extends ResourceLoader
|
|||||||
public InputStream getResourceStream (String path)
|
public InputStream getResourceStream (String path)
|
||||||
throws ResourceNotFoundException
|
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);
|
InputStream stream = _sctx.getResourceAsStream(path);
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
String errmsg = "Unable to load resource via servlet context " +
|
String errmsg = "Unable to load resource via servlet context " +
|
||||||
|
|||||||
Reference in New Issue
Block a user