Revision: 445
http://svn.sourceforge.net/stripes/?rev=445&view=rev
Author: tfenne
Date: 2006-10-20 05:14:57 -0700 (Fri, 20 Oct 2006)
Log Message:
-----------
Merge of 444 onto the 1.4 branch. Gentle refactoring to allow easier
modification of event resolution.
Modified Paths:
--------------
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
2006-10-20 12:13:10 UTC (rev 444)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
2006-10-20 12:14:57 UTC (rev 445)
@@ -379,19 +379,49 @@
* @return String the name of the event submitted, or null if none can be
found
*/
public String getEventName(Class<? extends ActionBean> bean,
ActionBeanContext context) {
- Map<String,Method> mappings = this.eventMappings.get(bean);
+ String event = getEventNameFromRequestParams(bean, context);
+ if (event == null) event = getEventNameFromPath(bean, context);
+ if (event == null) event = getEventNameFromEventNameParam(bean,
context);
+ return event;
+ }
+
+ /**
+ * Loops through the set of known events for the ActionBean to see if the
event
+ * names are present as parameter names in the request. Returns the first
event
+ * name found in the request, or null if none is found.
+ *
+ * @param bean the ActionBean type bound to the request
+ * @param context the ActionBeanContect for the current request
+ * @return String the name of the event submitted, or null if none can be
found
+ */
+ protected String getEventNameFromRequestParams(Class<? extends ActionBean>
bean,
+ ActionBeanContext context) {
+
Map<String,String[]> parameterMap =
context.getRequest().getParameterMap();
-
- // First try the traditional checking based on request parameters
- for (String event : mappings.keySet()) {
+ for (String event : this.eventMappings.get(bean).keySet()) {
if (parameterMap.containsKey(event) ||
parameterMap.containsKey(event + ".x")) {
return event;
}
}
- // Then try to find the event based on the path
+ return null;
+ }
+
+ /**
+ * Looks to see if there is extra path information beyond simply the url
binding of the
+ * bean. If it does and the next /-separated part of the path matches one
of the known
+ * event names for the bean, that event name will be returned, otherwise
null.
+ *
+ * @param bean the ActionBean type bound to the request
+ * @param context the ActionBeanContect for the current request
+ * @return String the name of the event submitted, or null if none can be
found
+ */
+ protected String getEventNameFromPath(Class<? extends ActionBean> bean,
+ ActionBeanContext context) {
+ Map<String,Method> mappings = this.eventMappings.get(bean);
String path = getRequestedPath(context.getRequest());
String binding = getUrlBindingFromPath(path);
+
if (binding != null && path.length() != binding.length()) {
String extra = path.substring(binding.length() + 1);
String event = extra.substring(0, Math.max(extra.indexOf("/"),
extra.length()));
@@ -400,16 +430,28 @@
}
}
- // Lastly if we still haven't picked an event, look for the special
parameter
- String[] name = parameterMap.get(StripesConstants.URL_KEY_EVENT_NAME);
- if (name != null && name.length == 1 && mappings.containsKey(name[0]))
{
+ return null;
+ }
+
+ /**
+ * Looks to see if there is a single non-empty parameter value for the
parameter name
+ * specified by [EMAIL PROTECTED] StripesConstants#URL_KEY_EVENT_NAME}. If
there is, and it
+ * matches a known event it is returned, otherwise returns null.
+ *
+ * @param bean the ActionBean type bound to the request
+ * @param context the ActionBeanContect for the current request
+ * @return String the name of the event submitted, or null if none can be
found
+ */
+ protected String getEventNameFromEventNameParam(Class<? extends
ActionBean> bean,
+ ActionBeanContext context)
{
+ String[] name =
context.getRequest().getParameterValues(StripesConstants.URL_KEY_EVENT_NAME);
+ if (name != null && name.length == 1 &&
this.eventMappings.get(bean).containsKey(name[0])) {
return name[0];
}
return null;
}
-
/**
* Uses the Maps constructed earlier to locate the Method which can handle
the event.
*
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development