craigmcc 01/12/29 11:35:33
Modified: src/share/org/apache/struts/action Action.java
ActionServlet.java
src/share/org/apache/struts/util RequestUtils.java
Log:
As each request passes through the controller servlet, call the new
Request.selectApplication() utility method. This method will identify the
appropriate sub-application by matching prefixes, and then expose two request
attributes that are used for the remainder of the processing:
* The ApplicationConfig object for the current application is exposed
under key Action.APPLICATION_KEY
* The MessageResources object for the current application is exposed
under key Action.MESSAGES_KEY
Now, the remaining logic can be modified to consult these two request
attributes to make decisions that depend on the current sub-application.
NOTE -- This processing is NOT performed on direct requests for JSP pages --
it is only done on requests through the controller. In a Servlet 2.3
environment we will be able to deal with that by moving this logic to a
filter that is mapped to all requests. In the mean time, applications that
will operate in a multi-app controller environment MUST pass all of their
requests through the controller servlet to work properly.
NOTE -- I am assuming that data sources are still accessed directly by their
servlet context attribute keys, and that all data source key names are unique
across sub-applications.
Revision Changes Path
1.31 +20 -7 jakarta-struts/src/share/org/apache/struts/action/Action.java
Index: Action.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Action.java 29 Dec 2001 00:24:46 -0000 1.30
+++ Action.java 29 Dec 2001 19:35:32 -0000 1.31
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v 1.30
2001/12/29 00:24:46 craigmcc Exp $
- * $Revision: 1.30 $
- * $Date: 2001/12/29 00:24:46 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v 1.31
2001/12/29 19:35:32 craigmcc Exp $
+ * $Revision: 1.31 $
+ * $Date: 2001/12/29 19:35:32 $
*
* ====================================================================
*
@@ -108,7 +108,7 @@
* by this Action.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.30 $ $Date: 2001/12/29 00:24:46 $
+ * @version $Revision: 1.31 $ $Date: 2001/12/29 19:35:32 $
*/
public class Action {
@@ -118,10 +118,16 @@
/**
- * The base of the context attributes key under which our
+ * <p>The base of the context attributes key under which our
* <code>ApplicationConfig</code> data structure will be stored. This
* will be suffixed with the actual application prefix (including the
- * leading "/" character) to form the actual attributes key.
+ * leading "/" character) to form the actual attributes key.</p>
+ *
+ * <p>For each request processed by the controller servlet, or a JSP page
+ * using the <code><html:html></code> custom tag, the
+ * <code>ApplicationConfig</code> object for the application selected by
+ * the request URI currently being processed will also be exposed under
+ * this key as a request attribute.</p>
*/
public static final String APPLICATION_KEY =
"org.apache.struts.action.APPLICATION";
@@ -214,8 +220,15 @@
/**
- * The context attributes key under which our application resources are
+ * <p>The context attributes key under which our application resources are
* normally stored, unless overridden when initializing our ActionServlet.
+ * </p>
+ *
+ * <p>For each request processed by the controller servlet, or a JSP page
+ * using the <code><html:html></code> custom tag, the
+ * <code>MessageResources</code> object for the application selected by
+ * the request URI currently being processed will also be exposed under
+ * this key as a request attribute.</p>
*/
public static final String MESSAGES_KEY =
"org.apache.struts.action.MESSAGE";
1.81 +20 -4
jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- ActionServlet.java 29 Dec 2001 00:24:46 -0000 1.80
+++ ActionServlet.java 29 Dec 2001 19:35:32 -0000 1.81
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.80
2001/12/29 00:24:46 craigmcc Exp $
- * $Revision: 1.80 $
- * $Date: 2001/12/29 00:24:46 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.81
2001/12/29 19:35:32 craigmcc Exp $
+ * $Revision: 1.81 $
+ * $Date: 2001/12/29 19:35:32 $
*
* ====================================================================
*
@@ -238,7 +238,7 @@
*
* @author Craig R. McClanahan
* @author Ted Husted
- * @version $Revision: 1.80 $ $Date: 2001/12/29 00:24:46 $
+ * @version $Revision: 1.81 $ $Date: 2001/12/29 19:35:32 $
*/
public class ActionServlet
@@ -1885,6 +1885,9 @@
request = new MultipartRequestWrapper(request);
}
+ // Automatically select the sub-application for this request
+ processApplication(request);
+
// Identify the path component we will use to select a mapping
String path = processPath(request);
if (path == null) {
@@ -2076,6 +2079,19 @@
else
session.setAttribute(attribute, instance);
return (instance);
+
+ }
+
+
+ /**
+ * Identify and record the sub-application that is responsible for
+ * processing this request.
+ *
+ * @param request The servlet request we are processing
+ */
+ protected void processApplication(HttpServletRequest request) {
+
+ RequestUtils.selectApplication(request, getServletContext());
}
1.26 +85 -4
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- RequestUtils.java 21 Nov 2001 18:48:42 -0000 1.25
+++ RequestUtils.java 29 Dec 2001 19:35:33 -0000 1.26
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.25
2001/11/21 18:48:42 oalexeev Exp $
- * $Revision: 1.25 $
- * $Date: 2001/11/21 18:48:42 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.26
2001/12/29 19:35:33 craigmcc Exp $
+ * $Revision: 1.26 $
+ * $Date: 2001/12/29 19:35:33 $
*
* ====================================================================
*
@@ -67,12 +67,14 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -91,6 +93,7 @@
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionServletWrapper;
+import org.apache.struts.config.ApplicationConfig;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;
@@ -102,7 +105,7 @@
*
* @author Craig R. McClanahan
* @author Ted Husted
- * @version $Revision: 1.25 $ $Date: 2001/11/21 18:48:42 $
+ * @version $Revision: 1.26 $ $Date: 2001/12/29 19:35:33 $
*/
public class RequestUtils {
@@ -126,6 +129,13 @@
+ /**
+ * The context attribute under which we store our prefixes list.
+ */
+ private static final String PREFIXES_KEY =
+ "org.apache.struts.util.PREFIXES";
+
+
// --------------------------------------------------------- Public Methods
@@ -977,6 +987,77 @@
pageContext.setAttribute(Action.EXCEPTION_KEY, exception,
PageContext.REQUEST_SCOPE);
+
+ }
+
+
+ /**
+ * Select the sub-application to which the specified request belongs, and
+ * add corresponding request attributes to this request.
+ *
+ * @param request The servlet request we are processing
+ * @param context The ServletContext for this web application
+ */
+ public static void selectApplication(HttpServletRequest request,
+ ServletContext context) {
+
+ // Acquire the path used to compute the sub-application
+ String matchPath = request.getServletPath();
+
+ // Match against the list of sub-application prefixes
+ String prefix = "";
+ String prefixes[] = getApplicationPrefixes(context);
+ for (int i = 0; i < prefixes.length; i++) {
+ if (matchPath.startsWith(prefixes[i])) {
+ prefix = prefixes[i];
+ break;
+ }
+ }
+
+ // Expose the resources for this sub-application
+ ApplicationConfig config = (ApplicationConfig)
+ context.getAttribute(Action.APPLICATION_KEY + prefix);
+ if (config != null)
+ request.setAttribute(Action.APPLICATION_KEY, config);
+ MessageResources resources = (MessageResources)
+ context.getAttribute(Action.MESSAGES_KEY + prefix);
+ if (resources != null)
+ request.setAttribute(Action.MESSAGES_KEY, resources);
+
+ }
+
+
+ /**
+ * Return the list of sub-application prefixes that are defined for
+ * this web application, creating it if necessary. <strong>NOTE</strong> -
+ * the "" prefix for the default application is not included in this list.
+ *
+ * @param context The ServletContext for this web application
+ */
+ public static String[] getApplicationPrefixes(ServletContext context) {
+
+ String prefixes[] = (String[]) context.getAttribute(PREFIXES_KEY);
+ if (prefixes != null) {
+ return (prefixes);
+ }
+
+ ArrayList list = new ArrayList();
+ Enumeration names = context.getAttributeNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ if (!name.startsWith(Action.APPLICATION_KEY)) {
+ continue;
+ }
+ ApplicationConfig config = (ApplicationConfig)
+ context.getAttribute(name);
+ String prefix = name.substring(Action.APPLICATION_KEY.length());
+ if (prefix.length() > 0) {
+ list.add(name);
+ }
+ }
+ prefixes = (String[]) list.toArray(new String[list.size()]);
+ context.setAttribute(PREFIXES_KEY, prefixes);
+ return (prefixes);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>