Implement per-HTTP method action names, e.g. main_action_post.
The methods that were handled by Helma traditionally (GET, POST, HEAD) are still mapped to actions without method name in case no per-method action is defined.
This commit is contained in:
parent
4d0d1b33bb
commit
05753dc7e5
1 changed files with 32 additions and 11 deletions
|
@ -171,7 +171,7 @@ public final class RequestEvaluator implements Runnable {
|
||||||
String errorAction = app.props.getProperty("error",
|
String errorAction = app.props.getProperty("error",
|
||||||
"error");
|
"error");
|
||||||
|
|
||||||
action = getAction(currentElement, errorAction);
|
action = getAction(currentElement, errorAction, null);
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
throw new RuntimeException(error);
|
throw new RuntimeException(error);
|
||||||
|
@ -181,7 +181,7 @@ public final class RequestEvaluator implements Runnable {
|
||||||
currentElement = root;
|
currentElement = root;
|
||||||
requestPath.add(null, currentElement);
|
requestPath.add(null, currentElement);
|
||||||
|
|
||||||
action = getAction(currentElement, null);
|
action = getAction(currentElement, null, req.getMethod());
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
throw new FrameworkException("Action not found");
|
throw new FrameworkException("Action not found");
|
||||||
|
@ -219,7 +219,7 @@ public final class RequestEvaluator implements Runnable {
|
||||||
// try to interpret it as action name.
|
// try to interpret it as action name.
|
||||||
if (i == (ntokens - 1)) {
|
if (i == (ntokens - 1)) {
|
||||||
action = getAction(currentElement,
|
action = getAction(currentElement,
|
||||||
pathItems[i]);
|
pathItems[i], req.getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
|
@ -239,7 +239,7 @@ public final class RequestEvaluator implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
action = getAction(currentElement, null);
|
action = getAction(currentElement, null, req.getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
|
@ -262,7 +262,7 @@ public final class RequestEvaluator implements Runnable {
|
||||||
"notfound");
|
"notfound");
|
||||||
|
|
||||||
currentElement = root;
|
currentElement = root;
|
||||||
action = getAction(currentElement, notFoundAction);
|
action = getAction(currentElement, notFoundAction, null);
|
||||||
|
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
throw new FrameworkException(notfound.getMessage());
|
throw new FrameworkException(notfound.getMessage());
|
||||||
|
@ -938,15 +938,36 @@ public final class RequestEvaluator implements Runnable {
|
||||||
* Check if an action with a given name is defined for a scripted object. If it is,
|
* Check if an action with a given name is defined for a scripted object. If it is,
|
||||||
* return the action's function name. Otherwise, return null.
|
* return the action's function name. Otherwise, return null.
|
||||||
*/
|
*/
|
||||||
public String getAction(Object obj, String action) {
|
public String getAction(Object obj, String action, String method) {
|
||||||
if (obj == null) {
|
if (obj == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (action == null)
|
||||||
|
action = "main";
|
||||||
|
|
||||||
|
StringBuffer buffer = new StringBuffer(action).append("_action");
|
||||||
|
|
||||||
|
// append HTTP method to action name
|
||||||
|
if (method != null) {
|
||||||
|
// record length so we can check without method
|
||||||
|
// afterwards for GET, POST, HEAD requests
|
||||||
|
int length = buffer.length();
|
||||||
|
|
||||||
|
// append _methodname
|
||||||
|
buffer.append('_').append(method.toLowerCase());
|
||||||
|
if (scriptingEngine.hasFunction(obj, buffer.toString()))
|
||||||
|
return buffer.toString();
|
||||||
|
|
||||||
|
// cut off method in case it has been appended
|
||||||
|
buffer.setLength(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
String act = (action == null) ? "main_action" : (action + "_action");
|
// if no method specified or "ordinary" request try action without method
|
||||||
|
if (method == null || "GET".equalsIgnoreCase(method) ||
|
||||||
if (scriptingEngine.hasFunction(obj, act)) {
|
"POST".equalsIgnoreCase(method) ||
|
||||||
return act;
|
"HEAD".equalsIgnoreCase(method)) {
|
||||||
|
if (scriptingEngine.hasFunction(obj, buffer.toString()))
|
||||||
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue