KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > mvc > multiaction > AbstractUrlMethodNameResolver


1 /*
2  * Copyright 2002-2005 the original author or authors.
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.springframework.web.servlet.mvc.multiaction;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.springframework.web.util.UrlPathHelper;
25
26 /**
27  * Abstract base class for URL-based MethodNameResolver implementations.
28  *
29  * <p>Provides infrastructure for mapping handlers to URLs and configurable
30  * URL lookup. For information on the latter, see <code>alwaysUseFullPath</code>
31  * and <code>urlDecode</code> properties.
32  *
33  * @author Juergen Hoeller
34  * @since 14.01.2004
35  * @see #setAlwaysUseFullPath
36  * @see #setUrlDecode
37  */

38 public abstract class AbstractUrlMethodNameResolver implements MethodNameResolver {
39
40     /** Logger available to subclasses */
41     protected final Log logger = LogFactory.getLog(getClass());
42
43     private UrlPathHelper urlPathHelper = new UrlPathHelper();
44
45
46     /**
47      * Set if URL lookup should always use full path within current servlet
48      * context. Else, the path within the current servlet mapping is used
49      * if applicable (i.e. in the case of a ".../*" servlet mapping in web.xml).
50      * Default is "false".
51      * @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath
52      */

53     public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
54         this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
55     }
56
57     /**
58      * Set if context path and request URI should be URL-decoded.
59      * Both are returned <i>undecoded</i> by the Servlet API,
60      * in contrast to the servlet path.
61      * <p>Uses either the request encoding or the default encoding according
62      * to the Servlet spec (ISO-8859-1).
63      * <p>Note: Setting this to "true" requires JDK 1.4 if the encoding differs
64      * from the VM's platform default encoding, as JDK 1.3's URLDecoder class
65      * does not offer a way to specify the encoding.
66      * @see org.springframework.web.util.UrlPathHelper#setUrlDecode
67      */

68     public void setUrlDecode(boolean urlDecode) {
69         this.urlPathHelper.setUrlDecode(urlDecode);
70     }
71
72     /**
73      * Set the UrlPathHelper to use for resolution of lookup paths.
74      * <p>Use this to override the default UrlPathHelper with a custom subclass,
75      * or to share common UrlPathHelper settings across multiple MethodNameResolvers
76      * and HandlerMappings.
77      * @see org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#setUrlPathHelper
78      */

79     public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
80         this.urlPathHelper = urlPathHelper;
81     }
82
83
84     /**
85      * Retrieves the URL path to use for lookup and delegates to
86      * <code>getHandlerMethodNameForUrlPath</code>.
87      * Converts <code>null</code> values to NoSuchRequestHandlingMethodExceptions.
88      * @see #getHandlerMethodNameForUrlPath
89      */

90     public final String JavaDoc getHandlerMethodName(HttpServletRequest JavaDoc request)
91             throws NoSuchRequestHandlingMethodException {
92
93         String JavaDoc urlPath = this.urlPathHelper.getLookupPathForRequest(request);
94         String JavaDoc name = getHandlerMethodNameForUrlPath(urlPath);
95         if (name == null) {
96             throw new NoSuchRequestHandlingMethodException(request);
97         }
98         if (logger.isDebugEnabled()) {
99             logger.debug("Returning handler method name '" + name + "' for lookup path: " + urlPath);
100         }
101         return name;
102     }
103
104     /**
105      * Return a method name that can handle this request, based on the
106      * given lookup path. Called by <code>getHandlerMethodName</code>.
107      * @param urlPath the URL path to use for lookup,
108      * according to the settings in this class
109      * @return a method name that can handle this request.
110      * Should return null if no matching method found.
111      * @see #getHandlerMethodName
112      * @see #setAlwaysUseFullPath
113      * @see #setUrlDecode
114      */

115     protected abstract String JavaDoc getHandlerMethodNameForUrlPath(String JavaDoc urlPath);
116
117 }
118
Popular Tags