jvanzyl 01/06/27 11:56:05
Modified: src/java/org/apache/turbine Turbine.java
TurbineConstants.java
src/java/org/apache/turbine/util/template
TemplateNavigation.java
Log:
- Turbine now uses an instance of ModuleLoader. this is a start in a move
toward having an instance of ModuleLoader in each (sub)application.
- use nothing but constants from TurbineConstants in Turbine
Revision Changes Path
1.61 +195 -39 jakarta-turbine/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- Turbine.java 2001/06/18 01:15:17 1.60
+++ Turbine.java 2001/06/27 18:56:00 1.61
@@ -59,14 +59,15 @@
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Properties;
+import java.util.Vector;
+import java.util.Iterator;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.turbine.modules.ActionLoader;
-import org.apache.turbine.modules.PageLoader;
+import org.apache.turbine.modules.ModuleLoader;
import org.apache.turbine.modules.actions.sessionvalidator.SessionValidator;
import org.apache.turbine.util.DynamicURI;
import org.apache.turbine.util.Log;
@@ -76,7 +77,6 @@
import org.apache.turbine.util.security.AccessControlList;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.template.TurbineTemplate;
-
import org.apache.log4j.Category;
import org.apache.velocity.runtime.configuration.Configuration;
@@ -111,7 +111,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: Turbine.java,v 1.60 2001/06/18 01:15:17 jon Exp $
+ * @version $Id: Turbine.java,v 1.61 2001/06/27 18:56:00 jvanzyl Exp $
*/
public class Turbine
extends HttpServlet
@@ -145,9 +145,12 @@
* execution?
*/
private static boolean firstDoGet = true;
-
+
+ /**
+ * Turbine application configuration.
+ */
private static Configuration configuration;
-
+
/**
* This init method will load the default resources from a
* properties file.
@@ -238,6 +241,36 @@
// a value of 'true' will be started when
// the service manager is initialized.
serviceManager.init();
+
+ // Set up the module loader for Turbine. Eventually
+ // an instance of ModuleLoader will be used for each
+ // application running under Turbine but we are trying,
+ // for the time being to work in a BC fashion.
+ moduleLoader = new ModuleLoader();
+ moduleLoader.addModuleType(ACTIONS);
+ moduleLoader.addModuleType(PAGES);
+ moduleLoader.addModuleType(NAVIGATIONS);
+ moduleLoader.addModuleType(LAYOUTS);
+ moduleLoader.addModuleType(SCREENS);
+
+ //!! Jobs should not be modules, but are being
+ // included for BC.
+ moduleLoader.addModuleType(JOBS);
+
+ // Add the default set of modules which live within
+ // the org.apache.turbine.module namespace.
+ moduleLoader.addModulePackage(DEFAULT_MODULE_PACKAGE);
+
+ // Grab our list of module packages so that we can
+ // add them to the search list of the ModuleLoader.
+ Vector modulePackages = configuration.getVector(MODULE_PACKAGES);
+
+ Iterator i = modulePackages.iterator();
+
+ while (i.hasNext())
+ {
+ moduleLoader.addModulePackage((String) i.next());
+ }
}
catch ( Exception e )
{
@@ -323,9 +356,10 @@
init(data);
// Get the instance of the Session Validator.
- SessionValidator sessionValidator = (SessionValidator)ActionLoader
- .getInstance().getInstance(configuration.getString(
- "action.sessionvalidator"));
+ SessionValidator sessionValidator = (SessionValidator)
+ moduleLoader.getModule(ACTIONS, configuration.getString(
+ ACTION_SESSION_VALIDATOR));
+
// if this is the redirected stage of the initial request,
// check that the session is now not new.
@@ -394,8 +428,7 @@
// as the session is new take this opportunity to
// set the session timeout if specified in TR.properties
- int timeout =
- configuration.getInt("session.timeout", -1);
+ int timeout = configuration.getInt(SESSION_TIMEOUT, -1);
if (timeout != -1)
{
@@ -408,19 +441,21 @@
}
// Fill in the screen and action variables.
- data.setScreen ( data.getParameters().getString("screen") );
- data.setAction ( data.getParameters().getString("action") );
+ data.setScreen (data.getParameters().getString(SCREEN));
+ data.setAction (data.getParameters().getString(ACTION));
// Special case for login and logout, this must happen before the
// session validator is executed in order either to allow a user to
// even login, or to ensure that the session validator gets to
// mandate its page selection policy for non-logged in users
// after the logout has taken place.
- if ( data.hasAction()
- && data.getAction().equalsIgnoreCase(configuration
- .getString("action.login"))
- || data.getAction().equalsIgnoreCase(configuration
- .getString("action.logout")))
+ if ( data.hasAction()
+ &&
+ data.getAction().equalsIgnoreCase(
+ configuration.getString(ACTION_LOGIN))
+ ||
+ data.getAction().equalsIgnoreCase(
+ configuration.getString(ACTION_LOGOUT)))
{
// If a User is logging in, we should refresh the
// session here. Invalidating session and starting a
@@ -433,8 +468,8 @@
// associated with the previous User. Currently the
// only keys stored in the session are "turbine.user"
// and "turbine.acl".
- if (data.getAction().equalsIgnoreCase(configuration
- .getString("action.login")))
+ if (data.getAction().equalsIgnoreCase(
+ configuration.getString(ACTION_LOGIN)))
{
String[] names = data.getSession().getValueNames();
if (names != null)
@@ -445,7 +480,8 @@
}
}
}
- ActionLoader.getInstance().exec ( data, data.getAction() );
+
+ moduleLoader.getModule(ACTIONS, data.getAction()).execute(data);
data.setAction(null);
}
@@ -457,16 +493,16 @@
// screen other than Login, you need to change that within
// TurbineResources.properties...screen.homepage; or, you
// can specify your own SessionValidator action.
- ActionLoader.getInstance().exec(
- data,configuration.getString("action.sessionvalidator") );
+ moduleLoader.getModule(ACTIONS,
+ configuration.getString(ACTION_SESSION_VALIDATOR)).execute(data);
// Put the Access Control List into the RunData object, so
// it is easily available to modules. It is also placed
// into the session for serialization. Modules can null
// out the ACL to force it to be rebuilt based on more
// information.
- ActionLoader.getInstance().exec(
- data,configuration.getString("action.accesscontroller"));
+ moduleLoader.getModule(ACTIONS,
+ configuration.getString(ACTION_ACCESS_CONTROLLER)).execute(data);
// Start the execution phase. DefaultPage will execute the
// appropriate action as well as get the Layout from the
@@ -496,10 +532,10 @@
// if they wish but the DefaultPage should work in
// most cases.
defaultPage = configuration.getString(
- "page.default", "DefaultPage");
+ PAGE_DEFAULT, DEFAULT_PAGE_MODULE);
}
- PageLoader.getInstance().exec(data, defaultPage);
+ moduleLoader.getModule(PAGES, defaultPage).execute(data);
// If a module has set data.acl = null, remove acl from
// the session.
@@ -629,22 +665,20 @@
data.setStackTrace(StringUtils.stackTrace(t),t);
// setup the screen
- data.setScreen(
- configuration.getString("screen.error"));
+ data.setScreen(configuration.getString(SCREEN_ERROR));
// do more screen setup for template execution if needed
if (data.getTemplateInfo() != null)
{
data.getTemplateInfo().setScreenTemplate(
- configuration.getString("template.error"));
+ configuration.getString(TEMPLATE_ERROR));
}
// Make sure to not execute an action.
data.setAction ("");
- PageLoader.getInstance()
- .exec(data, configuration.getString(
- "page.default", "DefaultPage"));
+ moduleLoader.getModule(PAGES, configuration.getString(
+ PAGE_DEFAULT, DEFAULT_PAGE_MODULE)).execute(data);
data.getResponse().setContentType( data.getContentType() );
data.getResponse().setStatus ( data.getStatusCode() );
@@ -719,15 +753,70 @@
// for example, might want to process something
// and place it within the webapp space. Having
// these values stored here makes this possible.
-
+
+ /**
+ * Server name.
+ */
private static String serverName;
+
+ /**
+ * Server port.
+ */
private static String serverPort;
+
+ /**
+ * Server scheme.
+ */
private static String serverScheme;
+
+ /**
+ * Script name.
+ */
private static String scriptName;
+
+ /**
+ * Application root. The base directory for the
+ * application. In this case the webapp root in
+ * the servlet container.
+ */
private static String applicationRoot;
+
+ /**
+ * Servlet config for this Turbine webapp.
+ */
private static ServletConfig servletConfig;
+
+ /**
+ * Servlet context for this Turbine webapp.
+ */
private static ServletContext servletContext;
+
+ /**
+ * ModuleLoader for this Turbine webapp. Eventually
+ * there will be one per app, but we want to
+ * move gradually.
+ */
+ private static ModuleLoader moduleLoader;
+ /**
+ * Get the ModuleLoader for this Turbine webapp.
+ * Eventually we will want to be able to grab a ModuleLoader
+ * by app name, or app identifier.
+ *
+ * @return ModuleLoader
+ */
+ public static ModuleLoader getModuleLoader()
+ {
+ return moduleLoader;
+ }
+
+ /**
+ * Save some information about this servlet so that
+ * it can be utilized by object instances that do not
+ * have direct access to RunData.
+ *
+ * @param RunData
+ */
public void saveServletInfo(RunData data)
{
serverName = data.getRequest().getServerName();
@@ -735,57 +824,124 @@
serverScheme = data.getRequest().getScheme();
scriptName = applicationRoot + data.getRequest().getServletPath();
}
-
- public void setApplicationRoot(String applicationRoot)
+
+ /**
+ * Set the application root for the webapp.
+ *
+ * @param String app root
+ */
+ public static void setApplicationRoot(String v)
{
- this.applicationRoot = applicationRoot;
+ applicationRoot = v;
}
-
+
+ /**
+ * Get the application root.
+ *
+ * @return String app root.
+ */
public static String getApplicationRoot()
{
return applicationRoot;
}
+ /**
+ * Get the expanded path relative to the app root.
+ *
+ * @param String path.
+ */
+ public static String getRealPath(String path)
+ {
+ return getApplicationRoot() + "/" + path;
+ }
+
+ /**
+ * Get the server name.
+ *
+ * @return String server name.
+ */
public static String getServerName()
{
return serverName;
}
+ /**
+ * Get the server port.
+ *
+ * @return String server port.
+ */
public static String getServerPort()
{
return serverPort;
}
+ /**
+ * Get the server scheme.
+ *
+ * @return String server scheme.
+ */
public static String getServerScheme()
{
return serverScheme;
}
+ /**
+ * Get the script name. This is the initial script name.
+ * Actually this is probably not needed any more. I'll
+ * check. jvz.
+ *
+ * @return String initial script name.
+ */
public static String getScriptName()
{
return scriptName;
}
+ /**
+ * Set the servlet config for this turbine webapp.
+ *
+ * @param ServletConfig
+ */
public static void setTurbineServletConfig(ServletConfig s)
{
servletConfig = s;
}
+ /**
+ * Get the servlet config for this turbine webapp.
+ *
+ * @return ServletConfig
+ */
public static ServletConfig getTurbineServletConfig()
{
return servletConfig;
}
+ /**
+ * Set the servlet context for this turbine webapp.
+ *
+ * @param ServletContext
+ */
public static void setTurbineServletContext(ServletContext s)
{
servletContext = s;
}
+ /**
+ * Get the servlet context for this turbine webapp.
+ *
+ * @return ServletContext
+ */
public static ServletContext getTurbineServletContext()
{
return servletContext;
}
-
+
+ /**
+ * Get the configuration for this turbine webapp.
+ *
+ * @return Configuration
+ */
public static Configuration getConfiguration()
{
return configuration;
1.10 +24 -1
jakarta-turbine/src/java/org/apache/turbine/TurbineConstants.java
Index: TurbineConstants.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/TurbineConstants.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TurbineConstants.java 2001/06/14 15:07:54 1.9
+++ TurbineConstants.java 2001/06/27 18:56:00 1.10
@@ -228,11 +228,16 @@
public static final String LAYOUT_DEFAULT = "layout.default";
/**
- * Default page.
+ * Default page property.
*/
public static final String PAGE_DEFAULT = "page.default";
/**
+ * Default Page module if one isn't specified in TRP.
+ */
+ public static final String DEFAULT_PAGE_MODULE = "DefaultPage";
+
+ /**
* Map building. This will probably be Torque generated at
* some point.
*/
@@ -281,5 +286,23 @@
*/
public static final String DEFAULT_TURBINE_RESOURCES =
"/WEB-INF/conf/TurbineResources.properties";
+
+ public static final String ACTIONS = "actions";
+ public static final String PAGES = "pages";
+ public static final String LAYOUTS = "layouts";
+ public static final String NAVIGATIONS = "navigations";
+ public static final String SCREENS = "screens";
+
+ //!! I don't think jobs should be part of the module system
+ // at all but will be left for BC for now.
+ public static final String JOBS = "scheduledjobs";
+
+ public static final String DEFAULT_MODULE_PACKAGE =
+ "org.apache.turbine.modules";
+
+ public static final String SESSION_TIMEOUT = "session.timeout";
+
+ public static final String SCREEN = "screen";
+ public static final String ACTION = "action";
}
1.4 +11 -15
jakarta-turbine/src/java/org/apache/turbine/util/template/TemplateNavigation.java
Index: TemplateNavigation.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/template/TemplateNavigation.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TemplateNavigation.java 2001/05/06 17:06:47 1.3
+++ TemplateNavigation.java 2001/06/27 18:56:03 1.4
@@ -55,15 +55,11 @@
*/
import org.apache.ecs.ConcreteElement;
-import org.apache.ecs.GenericElement;
-
-import org.apache.turbine.modules.NavigationLoader;
-
+import org.apache.turbine.Turbine;
import org.apache.turbine.services.Service;
import org.apache.turbine.services.ServiceBroker;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.template.TemplateService;
-
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
@@ -79,7 +75,7 @@
* </code>
*
* @author <a href="[EMAIL PROTECTED]">Dave Bryson</a>
- * @version $Id: TemplateNavigation.java,v 1.3 2001/05/06 17:06:47 jvanzyl Exp $
+ * @version $Id: TemplateNavigation.java,v 1.4 2001/06/27 18:56:03 jvanzyl Exp $
*/
public class TemplateNavigation
{
@@ -126,18 +122,18 @@
try
{
module = ((TemplateService)TurbineServices.getInstance()
- .getService(TemplateService.SERVICE_NAME))
- .getNavigationName(template);
- ConcreteElement results = NavigationLoader.getInstance()
- .eval(data, module);
- returnValue = results.toString();
+ .getService(TemplateService.SERVICE_NAME))
+ .getNavigationName(template);
+
+ return Turbine.getModuleLoader().getModule(
+ Turbine.NAVIGATIONS, module).evaluate(data);
}
catch (Exception e)
{
- String message = ("Error processing navigation template:" +
- this.template +
- " using module: " +
- module);
+ String message = (
+ "Error processing navigation template:" + this.template +
+ " using module: " + module);
+
Log.error(message, e);
returnValue = message;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]