No longer get/setApplicationContext(), now get/setApplicationAttribute().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@540 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Application.java,v 1.7 2001/11/06 20:55:51 mdb Exp $
|
||||
// $Id: Application.java,v 1.8 2002/01/24 06:32:38 mdb Exp $
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001 Michael Bayne
|
||||
@@ -23,6 +23,8 @@ package com.samskivert.velocity;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import com.samskivert.Log;
|
||||
import com.samskivert.servlet.IndiscriminateSiteIdentifier;
|
||||
import com.samskivert.servlet.MessageManager;
|
||||
@@ -40,6 +42,14 @@ import com.samskivert.util.StringUtil;
|
||||
*/
|
||||
public class Application
|
||||
{
|
||||
/**
|
||||
* An initialized application automatically registers itself as a
|
||||
* Velocity application attribute so that it can be retrieved by
|
||||
* Velocity plugins using
|
||||
* <code>getApplicationAttribute(VELOCITY_ATTR_KEY)</code>.
|
||||
*/
|
||||
public static final String VELOCITY_ATTR_KEY = "!application!";
|
||||
|
||||
/**
|
||||
* Performs initializations common to all applications. Applications
|
||||
* should override {@link #willInit} to perform initializations that
|
||||
@@ -63,6 +73,10 @@ public class Application
|
||||
// keep this around for later
|
||||
_context = context;
|
||||
|
||||
// stick ourselves into an application attribute so that we can be
|
||||
// accessed by Velocity plugins
|
||||
Velocity.setApplicationAttribute(VELOCITY_ATTR_KEY, this);
|
||||
|
||||
// let the derived application do pre-init stuff
|
||||
willInit(config);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DispatcherServlet.java,v 1.13 2001/11/20 21:33:03 mdb Exp $
|
||||
// $Id: DispatcherServlet.java,v 1.14 2002/01/24 06:32:38 mdb Exp $
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001 Michael Bayne
|
||||
@@ -150,10 +150,6 @@ import com.samskivert.util.StringUtil;
|
||||
*/
|
||||
public class DispatcherServlet extends VelocityServlet
|
||||
{
|
||||
/**
|
||||
* We load our velocity properties from the classpath rather than from
|
||||
* a file.
|
||||
*/
|
||||
/**
|
||||
* Initialize ourselves and our application.
|
||||
*/
|
||||
@@ -180,13 +176,14 @@ public class DispatcherServlet extends VelocityServlet
|
||||
Log.logStackTrace(t);
|
||||
}
|
||||
|
||||
// stick the application into the Velocity application context
|
||||
Velocity.setApplicationContext(_app);
|
||||
|
||||
// now let velocity initialize itself
|
||||
super.initVelocity(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* We load our velocity properties from the classpath rather than from
|
||||
* a file.
|
||||
*/
|
||||
protected Properties loadConfiguration (ServletConfig config)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ServletContextLogger.java,v 1.3 2001/11/20 21:32:34 mdb Exp $
|
||||
// $Id: ServletContextLogger.java,v 1.4 2002/01/24 06:32:38 mdb Exp $
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001 Michael Bayne
|
||||
@@ -54,22 +54,27 @@ public class ServletContextLogger implements LogSystem
|
||||
// if we weren't constructed with a servlet context, try to obtain
|
||||
// one via the application context
|
||||
if (_sctx == null) {
|
||||
Object context = rsvc.getApplicationContext();
|
||||
if (context != null) {
|
||||
if (context instanceof Application) {
|
||||
_sctx = ((Application)context).getServletContext();
|
||||
} else if (context instanceof ServletContext) {
|
||||
_sctx = (ServletContext)context;
|
||||
}
|
||||
// first look for the servlet context directly
|
||||
_sctx = (ServletContext)
|
||||
rsvc.getApplicationAttribute("ServletContext");
|
||||
}
|
||||
|
||||
// if that didn't work, look for an application
|
||||
if (_sctx == null) {
|
||||
// first look for an application
|
||||
Application app = (Application)rsvc.getApplicationAttribute(
|
||||
Application.VELOCITY_ATTR_KEY);
|
||||
if (app != null) {
|
||||
_sctx = app.getServletContext();
|
||||
}
|
||||
}
|
||||
|
||||
// if we still don't have one, complain
|
||||
if (_sctx == null) {
|
||||
rsvc.warn("ServletContextLogger: servlet context was not " +
|
||||
"supplied as application context. A user of the " +
|
||||
"servlet context logger must call " +
|
||||
"Velocity.setApplicationContext(getServletContext()).");
|
||||
"supplied. A user of the servlet context logger must " +
|
||||
"call Velocity.setApplicationAttribute(" +
|
||||
"\"ServletContext\", getServletContext()).");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ServletContextResourceLoader.java,v 1.3 2001/11/06 04:49:32 mdb Exp $
|
||||
// $Id: ServletContextResourceLoader.java,v 1.4 2002/01/24 06:32:38 mdb Exp $
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001 Michael Bayne
|
||||
@@ -67,13 +67,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();
|
||||
_sctx = (ServletContext)rsvc.getApplicationAttribute("ServletContext");
|
||||
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()).");
|
||||
"must call Velocity.setApplicationAttribute(" +
|
||||
"\"ServletContext\", getServletContext()).");
|
||||
}
|
||||
|
||||
rsvc.info("ServletContextResourceLoader : initialization complete.");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SiteResourceManager.java,v 1.4 2001/11/06 20:16:47 mdb Exp $
|
||||
// $Id: SiteResourceManager.java,v 1.5 2002/01/24 06:32:38 mdb Exp $
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001 Michael Bayne
|
||||
@@ -55,13 +55,12 @@ public class SiteResourceManager extends ResourceManagerImpl
|
||||
|
||||
// the web framework was kind enough to slip this into the runtime
|
||||
// instance when it started up
|
||||
Application app = (Application)rsvc.getApplicationContext();
|
||||
Application app = (Application)rsvc.getApplicationAttribute(
|
||||
Application.VELOCITY_ATTR_KEY);
|
||||
if (app == null) {
|
||||
rsvc.warn("SiteResourceManager: Application reference " +
|
||||
"was not supplied as application context. A " +
|
||||
"user of the site resource manager must supply " +
|
||||
"a reference to the Application instance via " +
|
||||
"Velocity.setApplicationContext().");
|
||||
rsvc.warn("SiteResourceManager: No application was initialized. " +
|
||||
"A user of the site resource manager must ensure that " +
|
||||
"an application is instantiated and initialized.");
|
||||
}
|
||||
|
||||
// get handles on the good stuff
|
||||
|
||||
Reference in New Issue
Block a user