KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > servlet > SelectModule


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.chain.servlet;
18
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.commons.chain.Context;
22 import org.apache.commons.chain.web.servlet.ServletWebContext;
23 import org.apache.struts.Globals;
24 import org.apache.struts.chain.AbstractSelectModule;
25 import org.apache.struts.chain.Constants;
26
27
28 /**
29  * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
30  * instances for the sub-application module to be used for processing
31  * this request.</p>
32  *
33  * @author Craig R. McClanahan
34  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
35  */

36
37 public class SelectModule extends AbstractSelectModule {
38
39
40     // ------------------------------------------------------- Protected Methods
41

42
43     protected String JavaDoc getPrefix(Context context) {
44
45         // Identify the URI from which we will match a module prefix
46
ServletWebContext swcontext = (ServletWebContext) context;
47         HttpServletRequest JavaDoc request = swcontext.getRequest();
48         String JavaDoc uri =
49             (String JavaDoc) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
50         if (uri == null) {
51             uri = request.getServletPath();
52         }
53         if (uri == null) {
54             throw new IllegalArgumentException JavaDoc
55                 ("No path information in request");
56         }
57
58         // Identify the module prefix for the current module
59
String JavaDoc prefix = ""; // Initialize to default prefix
60
String JavaDoc prefixes[] = (String JavaDoc[])
61             swcontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
62         int lastSlash = 0;
63         while (prefix.equals("") &&
64                ((lastSlash = uri.lastIndexOf("/")) > 0)) {
65             uri = uri.substring(0, lastSlash);
66             for (int i = 0; i < prefixes.length; i++) {
67                 if (uri.equals(prefixes[i])) {
68                     prefix = prefixes[i];
69                     break;
70                 }
71             }
72         }
73
74         return (prefix);
75
76     }
77
78
79 }
80
Popular Tags