reverted scripting environment refactoring from HEAD branch,
will go into separate branch.
This commit is contained in:
parent
b46b664d94
commit
ca66d7ba90
9 changed files with 258 additions and 337 deletions
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
package helma.scripting;
|
package helma.scripting;
|
||||||
|
|
||||||
import helma.framework.core.Application;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the interface that must be implemented to make a scripting environment
|
* This is the interface that must be implemented to make a scripting environment
|
||||||
|
@ -16,26 +16,45 @@ public interface ScriptingEnvironment {
|
||||||
/**
|
/**
|
||||||
* Initialize the environment using the given properties
|
* Initialize the environment using the given properties
|
||||||
*/
|
*/
|
||||||
public void init (Application app, Properties props) throws ScriptingException;
|
public void init (Properties props) throws ScriptingException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate a source file on a given type/class/prototype
|
|
||||||
*/
|
|
||||||
public void evaluate (File file, String type) throws ScriptingException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke a function on some object, using the given arguments and global vars.
|
* Invoke a function on some object, using the given arguments and global vars.
|
||||||
*/
|
*/
|
||||||
public Object invoke (Object thisObject, String functionName, Object[] args, HashMap globals) throws ScriptingException;
|
public Object invoke (Object thisObject, Object[] args, HashMap globals) throws ScriptingException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a property on an object
|
|
||||||
*/
|
|
||||||
public Object get (Object thisObject, String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if a function by that name is defined for that object.
|
|
||||||
*/
|
|
||||||
public boolean hasFunction (Object thisObject, String functionName) throws ScriptingException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,11 @@ public class ESAppNode extends ESNode {
|
||||||
private Application app;
|
private Application app;
|
||||||
private DatePrototype createtime;
|
private DatePrototype createtime;
|
||||||
|
|
||||||
public ESAppNode (INode node, FesiEvaluator eval) throws EcmaScriptException {
|
public ESAppNode (INode node, RequestEvaluator eval) throws EcmaScriptException {
|
||||||
super (eval.getPrototype("hopobject"), eval.getEvaluator(), node, eval);
|
super (eval.esNodePrototype, eval.evaluator, node, eval);
|
||||||
app = eval.getApplication();
|
app = eval.app;
|
||||||
createtime = new DatePrototype (evaluator, node.created());
|
createtime = new DatePrototype (eval.evaluator, node.created());
|
||||||
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
FunctionPrototype fp = (FunctionPrototype) eval.evaluator.getFunctionPrototype();
|
||||||
putHiddenProperty("getThreads", new AppCountThreads ("getThreads", evaluator, fp));
|
putHiddenProperty("getThreads", new AppCountThreads ("getThreads", evaluator, fp));
|
||||||
putHiddenProperty("getMaxThreads", new AppCountEvaluators ("getMaxThreads", evaluator, fp));
|
putHiddenProperty("getMaxThreads", new AppCountEvaluators ("getMaxThreads", evaluator, fp));
|
||||||
putHiddenProperty("getFreeThreads", new AppCountFreeEvaluators ("getFreeThreads", evaluator, fp));
|
putHiddenProperty("getFreeThreads", new AppCountFreeEvaluators ("getFreeThreads", evaluator, fp));
|
||||||
|
|
|
@ -107,3 +107,54 @@ public class ESGenericObject extends ObjectPrototype {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,13 @@ public class ESNode extends ObjectPrototype {
|
||||||
NodeHandle handle;
|
NodeHandle handle;
|
||||||
DbMapping dbmap;
|
DbMapping dbmap;
|
||||||
Throwable lastError = null;
|
Throwable lastError = null;
|
||||||
FesiEvaluator eval;
|
RequestEvaluator eval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used to create transient cache nodes
|
* Constructor used to create transient cache nodes
|
||||||
*/
|
*/
|
||||||
public ESNode (INode node, FesiEvaluator eval) {
|
public ESNode (INode node, RequestEvaluator eval) {
|
||||||
super (eval.getPrototype("hopobject"), eval.getEvaluator());
|
super (eval.esNodePrototype, eval.evaluator);
|
||||||
this.eval = eval;
|
this.eval = eval;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
cache = null;
|
cache = null;
|
||||||
|
@ -51,7 +51,7 @@ public class ESNode extends ObjectPrototype {
|
||||||
handle = null;
|
handle = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, FesiEvaluator eval) {
|
public ESNode (ESObject prototype, Evaluator evaluator, Object obj, RequestEvaluator eval) {
|
||||||
super (prototype, evaluator);
|
super (prototype, evaluator);
|
||||||
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
|
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
|
||||||
this.eval = eval;
|
this.eval = eval;
|
||||||
|
|
|
@ -27,8 +27,8 @@ public class ESUser extends ESNode {
|
||||||
/** if the user is online, this is his/her online session object */
|
/** if the user is online, this is his/her online session object */
|
||||||
public User user;
|
public User user;
|
||||||
|
|
||||||
public ESUser (INode node, FesiEvaluator eval, User user) {
|
public ESUser (INode node, RequestEvaluator eval, User user) {
|
||||||
super (eval.getPrototype("user"), eval.getEvaluator(), node, eval);
|
super (eval.esUserPrototype, eval.evaluator, node, eval);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
cache = user.getCache ();
|
cache = user.getCache ();
|
||||||
|
|
|
@ -1,164 +0,0 @@
|
||||||
// FesiScriptingEnvironment.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 2002
|
|
||||||
|
|
||||||
package helma.scripting.fesi;
|
|
||||||
|
|
||||||
import helma.scripting.*;
|
|
||||||
import helma.scripting.fesi.extensions.*;
|
|
||||||
import helma.framework.core.*;
|
|
||||||
import helma.objectmodel.INode;
|
|
||||||
import helma.objectmodel.db.DbMapping;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.File;
|
|
||||||
import FESI.Data.*;
|
|
||||||
import FESI.Interpreter.*;
|
|
||||||
import FESI.Exceptions.*;
|
|
||||||
import Acme.LruHashtable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the implementation of ScriptingEnvironment for the FESI EcmaScript interpreter.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class FesiEvaluator {
|
|
||||||
|
|
||||||
// the application we're running in
|
|
||||||
Application app;
|
|
||||||
|
|
||||||
// The FESI evaluator
|
|
||||||
Evaluator evaluator;
|
|
||||||
|
|
||||||
// the globa object
|
|
||||||
GlobalObject global;
|
|
||||||
|
|
||||||
// caching table for JavaScript object wrappers
|
|
||||||
LruHashtable wrappercache;
|
|
||||||
|
|
||||||
// table containing JavaScript prototypes
|
|
||||||
Hashtable prototypes;
|
|
||||||
|
|
||||||
|
|
||||||
// extensions loaded by this evaluator
|
|
||||||
static String[] extensions = new String[] {
|
|
||||||
"FESI.Extensions.BasicIO",
|
|
||||||
"FESI.Extensions.FileIO",
|
|
||||||
"helma.xmlrpc.fesi.FesiRpcExtension",
|
|
||||||
"helma.scripting.fesi.extensions.ImageExtension",
|
|
||||||
"helma.scripting.fesi.extensions.FtpExtension",
|
|
||||||
"FESI.Extensions.JavaAccess",
|
|
||||||
"FESI.Extensions.OptionalRegExp"};
|
|
||||||
|
|
||||||
public FesiEvaluator (Application app) {
|
|
||||||
this.app = app;
|
|
||||||
wrappercache = new LruHashtable (100, .80f);
|
|
||||||
prototypes = new Hashtable ();
|
|
||||||
initEvaluator ();
|
|
||||||
initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// init Script Evaluator
|
|
||||||
private void initEvaluator () {
|
|
||||||
try {
|
|
||||||
evaluator = new Evaluator();
|
|
||||||
// evaluator.reval = this;
|
|
||||||
global = evaluator.getGlobalObject();
|
|
||||||
for (int i=0; i<extensions.length; i++)
|
|
||||||
evaluator.addExtension (extensions[i]);
|
|
||||||
HopExtension hopx = new HopExtension (app);
|
|
||||||
hopx.initializeExtension (this);
|
|
||||||
MailExtension mailx = (MailExtension) evaluator.addExtension ("helma.scripting.fesi.extensions.MailExtension");
|
|
||||||
mailx.setProperties (this.app.props);
|
|
||||||
Database dbx = (Database) evaluator.addExtension ("helma.scripting.fesi.extensions.Database");
|
|
||||||
dbx.setApplication (app);
|
|
||||||
|
|
||||||
// fake a cache member like the one found in ESNodes
|
|
||||||
global.putHiddenProperty ("cache", new ESNode (new TransientNode ("cache"), this));
|
|
||||||
global.putHiddenProperty ("undefined", ESUndefined.theUndefined);
|
|
||||||
ESAppNode appnode = new ESAppNode (app.appnode, this);
|
|
||||||
global.putHiddenProperty ("app", appnode);
|
|
||||||
reqPath = new ArrayPrototype (evaluator.getArrayPrototype(), evaluator);
|
|
||||||
reqData = new ESMapWrapper (this);
|
|
||||||
resData = new ESMapWrapper (this);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Cannot initialize interpreter");
|
|
||||||
System.err.println("Error: " + e);
|
|
||||||
e.printStackTrace ();
|
|
||||||
throw new RuntimeException (e.getMessage ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the FESI Evaluator object wrapped by this object.
|
|
||||||
*/
|
|
||||||
public Evaluator getEvaluator () {
|
|
||||||
return evaluator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the application we're running in
|
|
||||||
*/
|
|
||||||
public Application getApplication () {
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the object prototype for a prototype name
|
|
||||||
*/
|
|
||||||
public ObjectPrototype getPrototype (String protoName) {
|
|
||||||
if (protoName == null)
|
|
||||||
return null;
|
|
||||||
return (ObjectPrototype) prototypes.get (protoName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register an object prototype for a certain prototype name.
|
|
||||||
*/
|
|
||||||
public void putPrototype (String protoName, ObjectPrototype op) {
|
|
||||||
if (protoName != null && op != null)
|
|
||||||
prototypes.put (protoName, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a script wrapper for an implemntation of helma.objectmodel.INode
|
|
||||||
*/
|
|
||||||
public ESNode getNodeWrapper (INode n) {
|
|
||||||
|
|
||||||
if (n == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
ESNode esn = (ESNode) wrappercache.get (n);
|
|
||||||
if (esn == null || esn.getNode() != n) {
|
|
||||||
String protoname = n.getPrototype ();
|
|
||||||
ObjectPrototype op = null;
|
|
||||||
|
|
||||||
// set the DbMapping of the node according to its prototype.
|
|
||||||
// this *should* be done on the objectmodel level, but isn't currently
|
|
||||||
// for embedded nodes since there's not enough type info at the objectmodel level
|
|
||||||
// for those nodes.
|
|
||||||
if (protoname != null && protoname.length() > 0 && n.getDbMapping () == null) {
|
|
||||||
n.setDbMapping (app.getDbMapping (protoname));
|
|
||||||
}
|
|
||||||
|
|
||||||
op = getPrototype (protoname);
|
|
||||||
|
|
||||||
// no prototype found for this node?
|
|
||||||
if (op == null)
|
|
||||||
op = getPrototype("hopobject");
|
|
||||||
|
|
||||||
|
|
||||||
DbMapping dbm = n.getDbMapping ();
|
|
||||||
if (dbm != null && dbm.isInstanceOf ("user"))
|
|
||||||
esn = new ESUser (n, this, null);
|
|
||||||
else
|
|
||||||
esn = new ESNode (op, evaluator, n, this);
|
|
||||||
|
|
||||||
wrappercache.put (n, esn);
|
|
||||||
// app.logEvent ("Wrapper for "+n+" created");
|
|
||||||
}
|
|
||||||
|
|
||||||
return esn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
// FesiScriptingEnvironment.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 2002
|
|
||||||
|
|
||||||
package helma.scripting.fesi;
|
|
||||||
|
|
||||||
import helma.scripting.*;
|
|
||||||
import helma.framework.core.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.File;
|
|
||||||
import FESI.Data.*;
|
|
||||||
import FESI.Interpreter.*;
|
|
||||||
import FESI.Exceptions.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the implementation of ScriptingEnvironment for the FESI EcmaScript interpreter.
|
|
||||||
*/
|
|
||||||
public class FesiScriptingEnvironment {
|
|
||||||
|
|
||||||
Application app;
|
|
||||||
Properties props;
|
|
||||||
HashMap evaluators;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the environment using the given properties
|
|
||||||
*/
|
|
||||||
public void init (Application app, Properties props) throws ScriptingException {
|
|
||||||
this.app = app;
|
|
||||||
this.props = props;
|
|
||||||
evaluators = new HashMap ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate a source file on a given type/class/prototype
|
|
||||||
*/
|
|
||||||
public void evaluate (File file, String type) throws ScriptingException {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoke a function on some object, using the given arguments and global vars.
|
|
||||||
*/
|
|
||||||
public Object invoke (Object thisObject, String functionName, Object[] args, HashMap globals) throws ScriptingException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a property on an object
|
|
||||||
*/
|
|
||||||
public Object get (Object thisObject, String key) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if a function by that name is defined for that object.
|
|
||||||
*/
|
|
||||||
public boolean hasFunction (Object thisObject, String functionName) throws ScriptingException {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -25,21 +25,21 @@ import org.xml.sax.InputSource;
|
||||||
public class HopExtension {
|
public class HopExtension {
|
||||||
|
|
||||||
protected Application app;
|
protected Application app;
|
||||||
protected FesiEvaluator fesi;
|
protected RequestEvaluator reval;
|
||||||
|
|
||||||
public HopExtension (Application app) {
|
public HopExtension () {
|
||||||
this.app = app;
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the evaluator after the extension is loaded.
|
* Called by the evaluator after the extension is loaded.
|
||||||
*/
|
*/
|
||||||
public void initializeExtension (FesiEvaluator fesi) throws EcmaScriptException {
|
public void initializeExtension (RequestEvaluator reval) throws EcmaScriptException {
|
||||||
|
|
||||||
this.fesi = fesi;
|
|
||||||
Evaluator evaluator = fesi.getEvaluator ();
|
|
||||||
|
|
||||||
|
this.reval = reval;
|
||||||
|
this.app = reval.app;
|
||||||
|
Evaluator evaluator = reval.evaluator;
|
||||||
GlobalObject go = evaluator.getGlobalObject();
|
GlobalObject go = evaluator.getGlobalObject();
|
||||||
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
||||||
|
|
||||||
|
@ -57,39 +57,39 @@ public class HopExtension {
|
||||||
dp.putHiddenProperty ("format", new DatePrototypeFormat ("format", evaluator, fp));
|
dp.putHiddenProperty ("format", new DatePrototypeFormat ("format", evaluator, fp));
|
||||||
|
|
||||||
// generic (Java wrapper) object prototype
|
// generic (Java wrapper) object prototype
|
||||||
ObjectPrototype esObjectPrototype = new ObjectPrototype (op, evaluator);
|
reval.esObjectPrototype = new ObjectPrototype (op, evaluator);
|
||||||
// the Node prototype
|
// the Node prototype
|
||||||
ObjectPrototype esNodePrototype = new ObjectPrototype(op, evaluator);
|
reval.esNodePrototype = new ObjectPrototype(op, evaluator);
|
||||||
// the User prototype
|
// the User prototype
|
||||||
ObjectPrototype esUserPrototype = new ObjectPrototype (esNodePrototype, evaluator);
|
reval.esUserPrototype = new ObjectPrototype (reval.esNodePrototype, evaluator);
|
||||||
// the Node constructor
|
// the Node constructor
|
||||||
ESObject node = new NodeConstructor ("Node", fp, fesi);
|
ESObject node = new NodeConstructor ("Node", fp, reval);
|
||||||
|
|
||||||
// register the default methods of Node objects in the Node prototype
|
// register the default methods of Node objects in the Node prototype
|
||||||
esNodePrototype.putHiddenProperty ("add", new NodeAdd ("add", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("add", new NodeAdd ("add", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("addAt", new NodeAddAt ("addAt", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("addAt", new NodeAddAt ("addAt", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("remove", new NodeRemove ("remove", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("remove", new NodeRemove ("remove", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("link", new NodeLink ("link", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("link", new NodeLink ("link", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("list", new NodeList ("list", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("list", new NodeList ("list", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("set", new NodeSet ("set", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("set", new NodeSet ("set", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("get", new NodeGet ("get", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("get", new NodeGet ("get", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("count", new NodeCount ("count", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("count", new NodeCount ("count", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("contains", new NodeContains ("contains", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("contains", new NodeContains ("contains", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("size", new NodeCount ("size", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("size", new NodeCount ("size", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("editor", new NodeEditor ("editor", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("editor", new NodeEditor ("editor", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("path", new NodeHref ("path", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("path", new NodeHref ("path", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("invalidate", new NodeInvalidate ("invalidate", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("invalidate", new NodeInvalidate ("invalidate", evaluator, fp));
|
||||||
esNodePrototype.putHiddenProperty ("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false));
|
reval.esNodePrototype.putHiddenProperty ("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false));
|
||||||
esNodePrototype.putHiddenProperty ("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true));
|
reval.esNodePrototype.putHiddenProperty ("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true));
|
||||||
esNodePrototype.putHiddenProperty ("clearCache", new NodeClearCache ("clearCache", evaluator, fp));
|
reval.esNodePrototype.putHiddenProperty ("clearCache", new NodeClearCache ("clearCache", evaluator, fp));
|
||||||
|
|
||||||
// default methods for generic Java wrapper object prototype.
|
// default methods for generic Java wrapper object prototype.
|
||||||
// This is a small subset of the methods in esNodePrototype.
|
// This is a small subset of the methods in esNodePrototype.
|
||||||
esObjectPrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
reval.esObjectPrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
|
||||||
esObjectPrototype.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false));
|
reval.esObjectPrototype.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false));
|
||||||
esObjectPrototype.putHiddenProperty("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true));
|
reval.esObjectPrototype.putHiddenProperty("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true));
|
||||||
|
|
||||||
// methods that give access to properties and global user lists
|
// methods that give access to properties and global user lists
|
||||||
go.putHiddenProperty("Node", node); // register the constructor for a plain Node object.
|
go.putHiddenProperty("Node", node); // register the constructor for a plain Node object.
|
||||||
|
@ -117,22 +117,17 @@ public class HopExtension {
|
||||||
go.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, true, false));
|
go.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, true, false));
|
||||||
go.putHiddenProperty("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, true, true));
|
go.putHiddenProperty("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, true, true));
|
||||||
go.putHiddenProperty("authenticate", new GlobalAuthenticate ("authenticate", evaluator, fp));
|
go.putHiddenProperty("authenticate", new GlobalAuthenticate ("authenticate", evaluator, fp));
|
||||||
// don't allow script writers to shut down Helma... ;-)
|
|
||||||
go.deleteProperty("exit", "exit".hashCode());
|
go.deleteProperty("exit", "exit".hashCode());
|
||||||
|
|
||||||
// and some methods for session management from JS...
|
// and some methods for session management from JS...
|
||||||
esUserPrototype.putHiddenProperty("logon", new UserLogin ("logon", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("logon", new UserLogin ("logon", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("login", new UserLogin ("login", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("login", new UserLogin ("login", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("register", new UserRegister ("register", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("register", new UserRegister ("register", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("logout", new UserLogout ("logout", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("logout", new UserLogout ("logout", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("onSince", new UserOnSince ("onSince", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("onSince", new UserOnSince ("onSince", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("lastActive", new UserLastActive ("lastActive", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("lastActive", new UserLastActive ("lastActive", evaluator, fp));
|
||||||
esUserPrototype.putHiddenProperty("touch", new UserTouch ("touch", evaluator, fp));
|
reval.esUserPrototype.putHiddenProperty("touch", new UserTouch ("touch", evaluator, fp));
|
||||||
|
|
||||||
// register object prototypes with FesiEvaluator
|
|
||||||
fesi.putPrototype ("global", go);
|
|
||||||
fesi.putPrototype ("hopobject", esNodePrototype);
|
|
||||||
fesi.putPrototype ("user", esUserPrototype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NodeAdd extends BuiltinFunctionObject {
|
class NodeAdd extends BuiltinFunctionObject {
|
||||||
|
@ -432,7 +427,7 @@ public class HopExtension {
|
||||||
if (unode == null)
|
if (unode == null)
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
else
|
else
|
||||||
return fesi.getNodeWrapper (unode);
|
return reval.getNodeWrapper (unode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,13 +542,12 @@ public class HopExtension {
|
||||||
}
|
}
|
||||||
public ESValue callFunction (ESObject thisObj, ESValue[] arguments) throws EcmaScriptException {
|
public ESValue callFunction (ESObject thisObj, ESValue[] arguments) throws EcmaScriptException {
|
||||||
if (arguments.length < 1 || arguments.length > 2 || arguments[0] ==null || arguments[0] == ESNull.theNull)
|
if (arguments.length < 1 || arguments.length > 2 || arguments[0] ==null || arguments[0] == ESNull.theNull)
|
||||||
throw new EcmaScriptException ("renderSkin requires one argument containing the skin name and an optional parameter object argument");
|
throw new EcmaScriptException ("renderSkin must be called with one Skin argument and an optional parameter argument");
|
||||||
try {
|
try {
|
||||||
Skin skin = null;
|
Skin skin = null;
|
||||||
ESObject thisObject = global ? null : thisObj;
|
ESObject thisObject = global ? null : thisObj;
|
||||||
HashMap params = null;
|
HashMap params = null;
|
||||||
if (arguments.length > 1 && arguments[1] instanceof ESObject) {
|
if (arguments.length > 1 && arguments[1] instanceof ESObject) {
|
||||||
// create an parameter object to pass to the skin
|
|
||||||
ESObject paramObject = (ESObject) arguments[1];
|
ESObject paramObject = (ESObject) arguments[1];
|
||||||
params = new HashMap ();
|
params = new HashMap ();
|
||||||
for (Enumeration en=paramObject.getProperties(); en.hasMoreElements(); ) {
|
for (Enumeration en=paramObject.getProperties(); en.hasMoreElements(); ) {
|
||||||
|
@ -569,13 +563,13 @@ public class HopExtension {
|
||||||
skin = (Skin) obj;
|
skin = (Skin) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object javaObject = thisObject == null ? null : thisObject.toJavaObject ();
|
|
||||||
if (skin == null)
|
if (skin == null)
|
||||||
skin = app.getSkin (javaObject, arguments[0].toString ());
|
skin = reval.getSkin (thisObject, arguments[0].toString ());
|
||||||
if (asString)
|
if (asString)
|
||||||
reval.res.pushStringBuffer ();
|
reval.res.pushStringBuffer ();
|
||||||
|
Object javaObj = thisObject == null ? null : thisObject.toJavaObject ();
|
||||||
if (skin != null)
|
if (skin != null)
|
||||||
skin.render (reval, javaObject, params);
|
skin.render (reval, javaObj, params);
|
||||||
else
|
else
|
||||||
reval.res.write ("[Skin not found: "+arguments[0]+"]");
|
reval.res.write ("[Skin not found: "+arguments[0]+"]");
|
||||||
if (asString)
|
if (asString)
|
||||||
|
@ -605,7 +599,7 @@ public class HopExtension {
|
||||||
}
|
}
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
return fesi.getNodeWrapper (user);
|
return reval.getNodeWrapper (user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,7 +616,7 @@ public class HopExtension {
|
||||||
if (user == null || user.getUID() == null)
|
if (user == null || user.getUID() == null)
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
user.touch ();
|
user.touch ();
|
||||||
return fesi.getNodeWrapper (user.getNode ());
|
return reval.getNodeWrapper (user.getNode ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +653,7 @@ public class HopExtension {
|
||||||
User u = (User) e.nextElement ();
|
User u = (User) e.nextElement ();
|
||||||
// Note: we previously sorted out duplicate users - now we simply enumerate all active sessions.
|
// Note: we previously sorted out duplicate users - now we simply enumerate all active sessions.
|
||||||
// if (u.uid == null || !visited.containsKey (u.uid)) {
|
// if (u.uid == null || !visited.containsKey (u.uid)) {
|
||||||
theArray.setElementAt (fesi.getNodeWrapper (u), i++);
|
theArray.setElementAt (reval.getNodeWrapper (u), i++);
|
||||||
// if (u.uid != null) visited.put (u.uid, u);
|
// if (u.uid != null) visited.put (u.uid, u);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
@ -898,6 +892,17 @@ public class HopExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* class NodePath extends BuiltinFunctionObject {
|
||||||
|
NodePath (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||||
|
super (fp, evaluator, name, 1);
|
||||||
|
}
|
||||||
|
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||||
|
INode n = ((ESNode) thisObject).getNode ();
|
||||||
|
String tmpname = arguments[0].toString ();
|
||||||
|
return new ESString (app.getNodePath (n, tmpname));
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
class NodeSetParent extends BuiltinFunctionObject {
|
class NodeSetParent extends BuiltinFunctionObject {
|
||||||
NodeSetParent (String name, Evaluator evaluator, FunctionPrototype fp) {
|
NodeSetParent (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||||
super (fp, evaluator, name, 2);
|
super (fp, evaluator, name, 2);
|
||||||
|
@ -984,6 +989,73 @@ public class HopExtension {
|
||||||
return b.toString ();
|
return b.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getNodeChooserDD (String name, INode collection, INode target, String teaser) {
|
||||||
|
StringBuffer buffer = new StringBuffer ("<select name=\"");
|
||||||
|
buffer.append (name);
|
||||||
|
buffer.append ("\">");
|
||||||
|
if (collection.contains (target) == -1) {
|
||||||
|
buffer.append ("<option value=>");
|
||||||
|
buffer.append (HtmlEncoder.encodeAll (teaser));
|
||||||
|
}
|
||||||
|
if (collection != null) {
|
||||||
|
int l = collection.numberOfNodes ();
|
||||||
|
for (int i=0; i<l; i++) {
|
||||||
|
INode next = collection.getSubnodeAt (i);
|
||||||
|
buffer.append ("<option value=\"");
|
||||||
|
buffer.append (next.getID ());
|
||||||
|
if (target == next)
|
||||||
|
buffer.append ("\" selected=\"true");
|
||||||
|
buffer.append ("\">");
|
||||||
|
String cname = next.getString ("name", false);
|
||||||
|
if (cname == null) cname = next.getName ();
|
||||||
|
buffer.append (HtmlEncoder.encodeAll (cname));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer.append ("</select>");
|
||||||
|
return buffer.toString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNodeChooserRB (String name, INode collection, INode target) {
|
||||||
|
StringBuffer buffer = new StringBuffer ();
|
||||||
|
if (collection != null) {
|
||||||
|
int l = collection.numberOfNodes ();
|
||||||
|
for (int i=0; i<l; i++) {
|
||||||
|
INode next = collection.getSubnodeAt (i);
|
||||||
|
buffer.append ("<input type=radio name=\"");
|
||||||
|
buffer.append (name);
|
||||||
|
buffer.append ("\" value=\"");
|
||||||
|
buffer.append (next.getElementName ()+"\"");
|
||||||
|
if (target == next)
|
||||||
|
buffer.append (" checked");
|
||||||
|
buffer.append (">");
|
||||||
|
String cname = next.getString ("name", false);
|
||||||
|
if (cname == null) cname = next.getName ();
|
||||||
|
buffer.append (HtmlEncoder.encodeAll (cname));
|
||||||
|
buffer.append ("<br>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer.toString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNodeChooserCB (String name, INode collection, INode target) {
|
||||||
|
StringBuffer buffer = new StringBuffer ();
|
||||||
|
if (collection != null) {
|
||||||
|
int l = collection.numberOfNodes ();
|
||||||
|
for (int i=0; i<l; i++) {
|
||||||
|
INode next = collection.getSubnodeAt (i);
|
||||||
|
buffer.append ("<input type=checkbox name=\"");
|
||||||
|
buffer.append (name);
|
||||||
|
buffer.append ("\" value=");
|
||||||
|
buffer.append (next.getElementName ());
|
||||||
|
if (target.contains (next) > -1)
|
||||||
|
buffer.append (" checked");
|
||||||
|
buffer.append (">");
|
||||||
|
buffer.append (HtmlEncoder.encodeAll (next.getName ()));
|
||||||
|
buffer.append ("<br>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer.toString ();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ import FESI.Interpreter.*;
|
||||||
|
|
||||||
public class NodeConstructor extends BuiltinFunctionObject {
|
public class NodeConstructor extends BuiltinFunctionObject {
|
||||||
|
|
||||||
FesiEvaluator fesi;
|
RequestEvaluator reval;
|
||||||
String typename;
|
String typename;
|
||||||
|
|
||||||
public NodeConstructor (String name, FunctionPrototype fp, FesiEvaluator fesi) {
|
public NodeConstructor (String name, FunctionPrototype fp, RequestEvaluator reval) {
|
||||||
super(fp, fesi.getEvaluator (), name, 1);
|
super(fp, reval.evaluator, name, 1);
|
||||||
typename = name;
|
typename = name;
|
||||||
this.fesi = fesi;
|
this.reval = reval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ESValue callFunction(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
public ESValue callFunction(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||||
|
@ -31,33 +31,35 @@ public class NodeConstructor extends BuiltinFunctionObject {
|
||||||
|
|
||||||
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||||
ESNode node = null;
|
ESNode node = null;
|
||||||
Application app = fesi.getApplication ();
|
|
||||||
if ("Node".equals (typename) || "hopobject".equalsIgnoreCase (typename)) {
|
if ("Node".equals (typename) || "hopobject".equalsIgnoreCase (typename)) {
|
||||||
String nodeName = null;
|
if (arguments.length == 0) {
|
||||||
if (arguments.length == 0)
|
Node n = new Node ((String) null, (String) null, reval.app.getWrappedNodeManager ());
|
||||||
nodeName = arguments[0].toString();
|
node = new ESNode (reval.esNodePrototype, this.evaluator, n, reval);
|
||||||
Node n = new Node (nodeName, (String) null, app.getWrappedNodeManager ());
|
reval.objectcache.put (node.getNode (), node);
|
||||||
node = new ESNode (fesi.getPrototype ("hopobject"), this.evaluator, n, fesi);
|
} else {
|
||||||
fesi.putObjectWrapper (node.getNode (), node);
|
Node n = new Node (arguments[0].toString(), (String) null, reval.app.getWrappedNodeManager ());
|
||||||
|
node = new ESNode (reval.esNodePrototype, this.evaluator, n, reval);
|
||||||
|
reval.objectcache.put (node.getNode (), node);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Typed nodes are instantiated as helma.objectmodel.db.Node from the beginning
|
// Typed nodes are instantiated as helma.objectmodel.db.Node from the beginning
|
||||||
// even if we don't know yet if they are going to be stored in a database. The reason
|
// even if we don't know yet if they are going to be stored in a database. The reason
|
||||||
// is that we want to be able to use the specail features like subnode relations even for
|
// is that we want to be able to use the specail features like subnode relations even for
|
||||||
// transient nodes.
|
// transient nodes.
|
||||||
ObjectPrototype op = fesi.getPrototype (typename);
|
ObjectPrototype op = reval.getPrototype (typename);
|
||||||
Node n = new Node (typename, typename, app.getWrappedNodeManager ());
|
Node n = new Node (typename, typename, reval.app.getWrappedNodeManager ());
|
||||||
node = new ESNode (op, fesi.getEvaluator (), n, fesi);
|
node = new ESNode (op, reval.evaluator, n, reval);
|
||||||
node.setPrototype (typename);
|
node.setPrototype (typename);
|
||||||
node.getNode ().setDbMapping (app.getDbMapping (typename));
|
node.getNode ().setDbMapping (reval.app.getDbMapping (typename));
|
||||||
try {
|
try {
|
||||||
// first try calling "constructor", if that doesn't work, try calling a function
|
// first try calling "constructor", if that doesn't work, try calling a function
|
||||||
// with the name of the type.
|
// with the name of the type.
|
||||||
// HACK: There is an incompatibility problem here, because the property
|
// HACK: There is an incompatibility problem here, because the property
|
||||||
// constructor is defined as the constructor of the object by EcmaScript.
|
// constructor is defined as the constructor of the object by EcmaScript.
|
||||||
if (op.getProperty("constructor", "constructor".hashCode()) instanceof ConstructedFunctionObject)
|
if (op.getProperty("constructor", "constructor".hashCode()) instanceof ConstructedFunctionObject)
|
||||||
node.doIndirectCall (fesi.getEvaluator(), node, "constructor", arguments);
|
node.doIndirectCall (reval.evaluator, node, "constructor", arguments);
|
||||||
else
|
else
|
||||||
node.doIndirectCall (fesi.getEvaluator(), node, typename, arguments);
|
node.doIndirectCall (reval.evaluator, node, typename, arguments);
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -69,7 +71,7 @@ public class NodeConstructor extends BuiltinFunctionObject {
|
||||||
|
|
||||||
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
public ESValue getProperty(String propertyName, int hash) throws EcmaScriptException {
|
||||||
if ("prototype".equals (propertyName))
|
if ("prototype".equals (propertyName))
|
||||||
return fesi.getPrototype (typename);
|
return reval.getPrototype (typename);
|
||||||
return super.getProperty(propertyName, hash);
|
return super.getProperty(propertyName, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue