Modified things further. Moved message manager management entirely into
the default application. Derived applications now simply provide a message bundle path if they want a message manager. Also now pass an application reference to the logic instances when they are invoked so that they can easily access application-wide resources. git-svn-id: https://samskivert.googlecode.com/svn/trunk@91 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Application.java,v 1.2 2001/03/04 06:25:48 mdb Exp $
|
// $Id: Application.java,v 1.3 2001/03/04 06:37:51 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.webmacro;
|
package com.samskivert.webmacro;
|
||||||
|
|
||||||
@@ -36,24 +36,84 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If an application wishes to make use of the translation facilities
|
* Returns the message manager in effect for this application, if one
|
||||||
* provided by the message manager, it can instantiate one and make it
|
* is in effect.
|
||||||
* available through this member function. This allows framework
|
|
||||||
* components like the <code>MsgTool</code> to make use of the
|
|
||||||
* application's message bundles.
|
|
||||||
*/
|
*/
|
||||||
public MessageManager getMessageManager ()
|
public MessageManager getMessageManager ()
|
||||||
|
{
|
||||||
|
return _msgmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If an application wishes to make use of the translation facilities
|
||||||
|
* provided by the message manager, it need only provide the path to
|
||||||
|
* its message resource bundle via this member function. Using a
|
||||||
|
* message manager allows framework components like the
|
||||||
|
* <code>MsgTool</code> to make use of the application's message
|
||||||
|
* bundles.
|
||||||
|
*/
|
||||||
|
protected String getMessageBundlePath ()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default application implementation takes the base URI and base
|
* A convenience function for translating messages.
|
||||||
* package as defined in the application declaration in the servlet
|
|
||||||
* configuration and uses those to determine whether or not a given
|
|
||||||
* URI maps to this application.
|
|
||||||
*/
|
*/
|
||||||
public void setConfig (String baseURI, String basePkg)
|
public final String translate (WebContext ctx, String msg)
|
||||||
|
{
|
||||||
|
return _msgmgr.getMessage(ctx.getRequest(), msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience function for translating messages.
|
||||||
|
*/
|
||||||
|
public final String translate (WebContext ctx, String msg, Object arg)
|
||||||
|
{
|
||||||
|
return _msgmgr.getMessage(ctx.getRequest(), msg,
|
||||||
|
new Object[]{ arg });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience function for translating messages.
|
||||||
|
*/
|
||||||
|
public final String translate (WebContext ctx, String msg,
|
||||||
|
Object arg1, Object arg2)
|
||||||
|
{
|
||||||
|
return _msgmgr.getMessage(ctx.getRequest(), msg,
|
||||||
|
new Object[]{ arg1, arg2 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience function for translating messages.
|
||||||
|
*/
|
||||||
|
public final String translate (WebContext ctx, String msg,
|
||||||
|
Object arg1, Object arg2, Object arg3)
|
||||||
|
{
|
||||||
|
return _msgmgr.getMessage(ctx.getRequest(), msg,
|
||||||
|
new Object[]{ arg1, arg2, arg3 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience function for translating messages.
|
||||||
|
*/
|
||||||
|
public final String translate (WebContext ctx, String msg,
|
||||||
|
Object[] args)
|
||||||
|
{
|
||||||
|
return _msgmgr.getMessage(ctx.getRequest(), msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs initializations common to all applications. We could put
|
||||||
|
* this in init() and require application derived classes to call
|
||||||
|
* super.init() but people would forget to do so and be confused.
|
||||||
|
*
|
||||||
|
* <p> The default application implementation takes the base URI and
|
||||||
|
* base package as defined in the application declaration in the
|
||||||
|
* servlet configuration and uses those to determine whether or not a
|
||||||
|
* given URI maps to this application.
|
||||||
|
*/
|
||||||
|
public void preInit (String baseURI, String basePkg)
|
||||||
{
|
{
|
||||||
// remove any trailing slash
|
// remove any trailing slash
|
||||||
if (baseURI.endsWith("/")) {
|
if (baseURI.endsWith("/")) {
|
||||||
@@ -68,6 +128,12 @@ public class Application
|
|||||||
} else {
|
} else {
|
||||||
_basePkg = basePkg;
|
_basePkg = basePkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// instantiate our message manager if the application wants one
|
||||||
|
String bpath = getMessageBundlePath();
|
||||||
|
if (bpath != null) {
|
||||||
|
_msgmgr = new MessageManager(bpath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,48 +161,9 @@ public class Application
|
|||||||
return _basePkg + uri;
|
return _basePkg + uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience function for translating messages.
|
|
||||||
*/
|
|
||||||
public final String translate (WebContext ctx, String msg)
|
|
||||||
{
|
|
||||||
MessageManager msgmgr = getMessageManager();
|
|
||||||
return msgmgr.getMessage(ctx.getRequest(), msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience function for translating messages.
|
|
||||||
*/
|
|
||||||
public final String translate (WebContext ctx, String msg, Object arg)
|
|
||||||
{
|
|
||||||
MessageManager msgmgr = getMessageManager();
|
|
||||||
return msgmgr.getMessage(ctx.getRequest(), msg, new Object[]{ arg });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience function for translating messages.
|
|
||||||
*/
|
|
||||||
public final String translate (WebContext ctx, String msg, Object arg1,
|
|
||||||
Object arg2)
|
|
||||||
{
|
|
||||||
MessageManager msgmgr = getMessageManager();
|
|
||||||
return msgmgr.getMessage(ctx.getRequest(), msg,
|
|
||||||
new Object[]{ arg1, arg2 });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience function for translating messages.
|
|
||||||
*/
|
|
||||||
public final String translate (WebContext ctx, String msg, Object arg1,
|
|
||||||
Object arg2, Object arg3)
|
|
||||||
{
|
|
||||||
MessageManager msgmgr = getMessageManager();
|
|
||||||
return msgmgr.getMessage(ctx.getRequest(), msg,
|
|
||||||
new Object[]{ arg1, arg2, arg3 });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String _baseURI;
|
protected String _baseURI;
|
||||||
protected String _basePkg;
|
protected String _basePkg;
|
||||||
|
protected MessageManager _msgmgr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the default file extension.
|
* This is the default file extension.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DispatcherServlet.java,v 1.8 2001/03/04 06:22:17 mdb Exp $
|
// $Id: DispatcherServlet.java,v 1.9 2001/03/04 06:37:51 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.webmacro;
|
package com.samskivert.webmacro;
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ public class DispatcherServlet extends WMServlet
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now initialize the applicaiton
|
// now initialize the applicaiton
|
||||||
app.setConfig(baseURI, basePkg);
|
app.preInit(baseURI, basePkg);
|
||||||
app.init(getServletContext());
|
app.init(getServletContext());
|
||||||
|
|
||||||
// finally add it to our list
|
// finally add it to our list
|
||||||
@@ -240,7 +240,7 @@ public class DispatcherServlet extends WMServlet
|
|||||||
// execute it if it exists
|
// execute it if it exists
|
||||||
Logic logic = resolveLogic(app, path);
|
Logic logic = resolveLogic(app, path);
|
||||||
if (logic != null) {
|
if (logic != null) {
|
||||||
logic.invoke(ctx);
|
logic.invoke(app, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Logic.java,v 1.1 2001/03/01 21:06:22 mdb Exp $
|
// $Id: Logic.java,v 1.2 2001/03/04 06:37:51 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.webmacro;
|
package com.samskivert.webmacro;
|
||||||
|
|
||||||
@@ -22,9 +22,11 @@ public interface Logic
|
|||||||
* converted into friendly error messages using the exception mapping
|
* converted into friendly error messages using the exception mapping
|
||||||
* services.
|
* services.
|
||||||
*
|
*
|
||||||
|
* @param app The application that generated this logic instance (used
|
||||||
|
* to access application-wide resources).
|
||||||
* @param context The WebMacro context in scope for this request.
|
* @param context The WebMacro context in scope for this request.
|
||||||
*
|
*
|
||||||
* @see ExceptionMap
|
* @see ExceptionMap
|
||||||
*/
|
*/
|
||||||
public void invoke (WebContext context) throws Exception;
|
public void invoke (Application app, WebContext context) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user