pretty much rewrote request path evaluation code.
the global path object now also makes its elements accessible via prototype name.
This commit is contained in:
parent
9952f9b161
commit
9563372c51
1 changed files with 85 additions and 59 deletions
|
@ -5,6 +5,7 @@ package helma.framework.core;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import helma.objectmodel.*;
|
import helma.objectmodel.*;
|
||||||
|
@ -152,6 +153,13 @@ public class RequestEvaluator implements Runnable {
|
||||||
current = null;
|
current = null;
|
||||||
currentNode = null;
|
currentNode = null;
|
||||||
reqPath.setSize (0);
|
reqPath.setSize (0);
|
||||||
|
// delete path objects-via-prototype
|
||||||
|
for (Enumeration en=reqPath.getAllProperties(); en.hasMoreElements(); ) {
|
||||||
|
String pn = (String) en.nextElement ();
|
||||||
|
if (!"length".equalsIgnoreCase (pn)) try {
|
||||||
|
reqPath.deleteProperty (pn, pn.hashCode ());
|
||||||
|
} catch (Exception ignore) {}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -191,6 +199,7 @@ public class RequestEvaluator implements Runnable {
|
||||||
currentNode = root;
|
currentNode = root;
|
||||||
current = getNodeWrapper (root);
|
current = getNodeWrapper (root);
|
||||||
reqPath.putProperty (0, current);
|
reqPath.putProperty (0, current);
|
||||||
|
reqPath.putHiddenProperty ("root", current);
|
||||||
Prototype p = app.getPrototype (root);
|
Prototype p = app.getPrototype (root);
|
||||||
String errorAction = app.props.getProperty ("error", "error");
|
String errorAction = app.props.getProperty ("error", "error");
|
||||||
action = p.getActionOrTemplate (errorAction);
|
action = p.getActionOrTemplate (errorAction);
|
||||||
|
@ -199,6 +208,7 @@ public class RequestEvaluator implements Runnable {
|
||||||
currentNode = root;
|
currentNode = root;
|
||||||
current = getNodeWrapper (root);
|
current = getNodeWrapper (root);
|
||||||
reqPath.putProperty (0, current);
|
reqPath.putProperty (0, current);
|
||||||
|
reqPath.putHiddenProperty ("root", current);
|
||||||
Prototype p = app.getPrototype (root);
|
Prototype p = app.getPrototype (root);
|
||||||
action = p.getActionOrTemplate (null);
|
action = p.getActionOrTemplate (null);
|
||||||
|
|
||||||
|
@ -208,76 +218,92 @@ public class RequestEvaluator implements Runnable {
|
||||||
// is the next path element a subnode or a property of the last one?
|
// is the next path element a subnode or a property of the last one?
|
||||||
// currently only used for users node
|
// currently only used for users node
|
||||||
boolean isProperty = false;
|
boolean isProperty = false;
|
||||||
|
|
||||||
StringTokenizer st = new StringTokenizer (req.path, "/");
|
StringTokenizer st = new StringTokenizer (req.path, "/");
|
||||||
int ntokens = st.countTokens ();
|
int ntokens = st.countTokens ();
|
||||||
String next = null;
|
// limit path to < 50 tokens
|
||||||
|
if (ntokens > 50)
|
||||||
|
throw new RuntimeException ("Path too long");
|
||||||
|
String[] pathItems = new String [ntokens];
|
||||||
|
for (int i=0; i<ntokens; i++)
|
||||||
|
pathItems[i] = st.nextToken ();
|
||||||
|
|
||||||
currentNode = root;
|
currentNode = root;
|
||||||
reqPath.putProperty (0, getNodeWrapper (currentNode));
|
current = getNodeWrapper (root);
|
||||||
|
reqPath.putProperty (0, current);
|
||||||
|
reqPath.putHiddenProperty ("root", current);
|
||||||
|
|
||||||
// the first token in the path needs to be treated seprerately,
|
for (int i=0; i<ntokens; i++) {
|
||||||
// because "/user" is a shortcut to the current user session, while "/users"
|
|
||||||
// is the mounting point for all users.
|
|
||||||
if (ntokens > 1) {
|
|
||||||
next = st.nextToken ();
|
|
||||||
if ("user".equalsIgnoreCase (next)) {
|
|
||||||
currentNode = user.getNode ();
|
|
||||||
ntokens -=1;
|
|
||||||
if (currentNode != null)
|
|
||||||
reqPath.putProperty (1, getNodeWrapper (currentNode));
|
|
||||||
} else if ("users".equalsIgnoreCase (next)) {
|
|
||||||
currentNode = app.getUserRoot ();
|
|
||||||
ntokens -=1;
|
|
||||||
isProperty = true;
|
|
||||||
} else {
|
|
||||||
currentNode = currentNode.getSubnode (next);
|
|
||||||
ntokens -=1;
|
|
||||||
if (currentNode != null)
|
|
||||||
reqPath.putProperty (1, getNodeWrapper (currentNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=1; i<ntokens; i++) {
|
|
||||||
if (currentNode == null)
|
if (currentNode == null)
|
||||||
throw new FrameworkException ("Object not found.");
|
throw new FrameworkException ("Object not found.");
|
||||||
next = st.nextToken ();
|
|
||||||
if (isProperty) // get next element as property
|
// the first token in the path needs to be treated seprerately,
|
||||||
currentNode = currentNode.getNode (next, false);
|
// because "/user" is a shortcut to the current user session, while "/users"
|
||||||
else // get next element as subnode
|
// is the mounting point for all users.
|
||||||
currentNode = currentNode.getSubnode (next);
|
if (i == 0 && "user".equalsIgnoreCase (pathItems[i])) {
|
||||||
isProperty = false;
|
currentNode = user.getNode ();
|
||||||
if (currentNode != null && currentNode.getState() != INode.VIRTUAL) // add to reqPath array
|
if (currentNode != null) {
|
||||||
reqPath.putProperty (reqPath.size(), getNodeWrapper (currentNode));
|
current = getNodeWrapper (currentNode);
|
||||||
// limit path to < 50 tokens
|
reqPath.putProperty (1, current);
|
||||||
if (i > 50) throw new RuntimeException ("Path too deep");
|
reqPath.putHiddenProperty ("user", current);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (i == 0 && "users".equalsIgnoreCase (pathItems[i])) {
|
||||||
|
currentNode = app.getUserRoot ();
|
||||||
|
isProperty = true;
|
||||||
|
if (currentNode != null) {
|
||||||
|
current = getNodeWrapper (currentNode);
|
||||||
|
reqPath.putProperty (1, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (i == ntokens-1) {
|
||||||
|
Prototype p = app.getPrototype (currentNode);
|
||||||
|
if (p != null)
|
||||||
|
action = p.getActionOrTemplate (pathItems[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == null) {
|
||||||
|
|
||||||
|
if (pathItems[i].length () == 0)
|
||||||
|
continue;
|
||||||
|
if (isProperty) // get next element as property
|
||||||
|
currentNode = currentNode.getNode (pathItems[i], false);
|
||||||
|
else // get next element as subnode
|
||||||
|
currentNode = currentNode.getSubnode (pathItems[i]);
|
||||||
|
isProperty = false;
|
||||||
|
|
||||||
|
// add object to request path if suitable
|
||||||
|
if (currentNode != null) {
|
||||||
|
String pt = currentNode.getPrototype ();
|
||||||
|
if (pt != null) {
|
||||||
|
// add to reqPath array
|
||||||
|
current = getNodeWrapper (currentNode);
|
||||||
|
reqPath.putProperty (reqPath.size(), current);
|
||||||
|
reqPath.putHiddenProperty (pt, current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentNode == null)
|
if (currentNode == null)
|
||||||
throw new FrameworkException ("Object not found.");
|
throw new FrameworkException ("Object not found.");
|
||||||
|
else
|
||||||
|
current = getNodeWrapper (currentNode);
|
||||||
|
|
||||||
Prototype p = app.getPrototype (currentNode);
|
if (action == null) {
|
||||||
next = st.nextToken ();
|
Prototype p = app.getPrototype (currentNode);
|
||||||
if (p != null)
|
|
||||||
action = p.getActionOrTemplate (next);
|
|
||||||
|
|
||||||
if (p == null || action == null) {
|
|
||||||
currentNode = currentNode.getSubnode (next);
|
|
||||||
if (currentNode == null)
|
|
||||||
throw new FrameworkException ("Object or Action '"+next+"' not found.");
|
|
||||||
p = app.getPrototype (currentNode);
|
|
||||||
// add to reqPath array
|
|
||||||
if (currentNode != null && currentNode.getState() != INode.VIRTUAL)
|
|
||||||
reqPath.putProperty (reqPath.size(), getNodeWrapper (currentNode));
|
|
||||||
if (p != null)
|
if (p != null)
|
||||||
action = p.getActionOrTemplate ("main");
|
action = p.getActionOrTemplate (null);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = getNodeWrapper (currentNode);
|
if (action == null)
|
||||||
|
throw new FrameworkException ("Action not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == null)
|
|
||||||
throw new FrameworkException ("Action not found");
|
|
||||||
|
|
||||||
} catch (FrameworkException notfound) {
|
} catch (FrameworkException notfound) {
|
||||||
if (error != null)
|
if (error != null)
|
||||||
// we already have an error and the error template wasn't found,
|
// we already have an error and the error template wasn't found,
|
||||||
|
@ -606,7 +632,7 @@ public class RequestEvaluator implements Runnable {
|
||||||
this.method = functionName;
|
this.method = functionName;
|
||||||
this.esargs = args;
|
this.esargs = args;
|
||||||
this.res = new ResponseTrans ();
|
this.res = new ResponseTrans ();
|
||||||
esresult = ESNull.theNull;
|
esresult = ESNull.theNull;
|
||||||
exception = null;
|
exception = null;
|
||||||
|
|
||||||
checkThread ();
|
checkThread ();
|
||||||
|
@ -629,7 +655,7 @@ public class RequestEvaluator implements Runnable {
|
||||||
this.method = functionName;
|
this.method = functionName;
|
||||||
this.esargs = args;
|
this.esargs = args;
|
||||||
this.res = new ResponseTrans ();
|
this.res = new ResponseTrans ();
|
||||||
esresult = ESNull.theNull;
|
esresult = ESNull.theNull;
|
||||||
exception = null;
|
exception = null;
|
||||||
|
|
||||||
checkThread ();
|
checkThread ();
|
||||||
|
|
Loading…
Add table
Reference in a new issue