Removed all dependencies of FESI. Yay!

This commit is contained in:
hns 2001-09-09 18:05:52 +00:00
parent 7d4cbdeb48
commit 83d696e98b

View file

@ -6,8 +6,6 @@ package helma.framework.core;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import helma.framework.*; import helma.framework.*;
import FESI.Data.*;
import FESI.Exceptions.*;
import helma.scripting.*; import helma.scripting.*;
import helma.scripting.fesi.*; import helma.scripting.fesi.*;
import helma.objectmodel.INode; import helma.objectmodel.INode;
@ -87,24 +85,14 @@ public class Skin {
/** /**
* Render this skin * Render this skin
*/ */
public void render (RequestEvaluator reval, ESObject thisObject, ESObject paramObject) throws RedirectException { public void render (RequestEvaluator reval, Object thisObject, HashMap paramObject) throws RedirectException {
if (parts == null) if (parts == null)
return; return;
IPathElement elem = null;
if (thisObject != null) {
try {
elem = (IPathElement) thisObject.toJavaObject ();
} catch (ClassCastException wrongClass) {
throw new RuntimeException ("Can't render a skin on something that is not a path element: "+wrongClass);
}
}
for (int i=0; i<parts.length; i++) { for (int i=0; i<parts.length; i++) {
if (parts[i] instanceof Macro) if (parts[i] instanceof Macro)
((Macro) parts[i]).render (reval, thisObject, elem, paramObject); ((Macro) parts[i]).render (reval, thisObject, paramObject);
else else
reval.res.write (parts[i]); reval.res.write (parts[i]);
} }
@ -237,7 +225,7 @@ public class Skin {
/** /**
* Render the macro given a handler object * Render the macro given a handler object
*/ */
public void render (RequestEvaluator reval, ESObject thisObject, IPathElement elem, ESObject paramObject) throws RedirectException { public void render (RequestEvaluator reval, Object thisObject, HashMap paramObject) throws RedirectException {
if (sandbox != null && !sandbox.contains (getFullName ())) { if (sandbox != null && !sandbox.contains (getFullName ())) {
String h = handler == null ? "global" : handler; String h = handler == null ? "global" : handler;
@ -256,30 +244,33 @@ public class Skin {
try { try {
ESObject handlerObject = null; Object handlerObject = null;
ESValue[] arguments = new ESValue[1]; Object[] arguments = new Object[1];
ESRequestData par = new ESRequestData (reval); ESRequestData par = new ESRequestData (reval);
par.setData (parameters); par.setData (parameters);
arguments[0] = par; arguments[0] = par;
// flag to tell whether we found our invocation target object
boolean objectFound = true;
if (handler != null) { if (handler != null) {
if ("currentuser".equalsIgnoreCase (handler)) { if ("currentuser".equalsIgnoreCase (handler)) {
// as a special convention, we use "currentuser" to access macros in the current user object // as a special convention, we use "currentuser" to access macros in the current user object
handlerObject = reval.getNodeWrapper (reval.user.getNode ()); handlerObject = reval.user.getNode ();
} else if (elem != null) { } else if (thisObject != null) {
// not a global macro - need to find handler object // not a global macro - need to find handler object
// was called with this object - check it or its parents for matching prototype // was called with this object - check it or its parents for matching prototype
if (!handler.equalsIgnoreCase ("this") && !handler.equalsIgnoreCase (elem.getPrototype ())) { if (!handler.equalsIgnoreCase ("this") && !handler.equalsIgnoreCase (app.getPrototypeName (thisObject))) {
// the handler object is not what we want // the handler object is not what we want
IPathElement n = elem; Object n = thisObject;
// walk down parent chain to find handler object // walk down parent chain to find handler object
while (n != null) { while (n != null) {
if (handler.equalsIgnoreCase (n.getPrototype())) { if (handler.equalsIgnoreCase (app.getPrototypeName (n))) {
handlerObject = reval.getElementWrapper (n); handlerObject = n;
break; break;
} }
n = n.getParentElement (); n = app.getParentElement (n);
} }
} else { } else {
// we already have the right handler object // we already have the right handler object
@ -292,22 +283,27 @@ public class Skin {
// go check request path for an object with matching prototype // go check request path for an object with matching prototype
int l = reval.reqPath.size(); int l = reval.reqPath.size();
for (int i=l-1; i>=0; i--) { for (int i=l-1; i>=0; i--) {
IPathElement pathelem = (IPathElement) reval.reqPath.getProperty (i).toJavaObject (); Object pathelem = reval.reqPath.getProperty (i).toJavaObject ();
if (handler.equalsIgnoreCase (pathelem.getPrototype ())) { if (handler.equalsIgnoreCase (app.getPrototypeName (pathelem))) {
handlerObject = (ESNode) reval.reqPath.getProperty(i); handlerObject = pathelem;
break; break;
} }
} }
} }
// the macro handler object couldn't be found
if (handlerObject == null)
objectFound = false;
} else { } else {
// this is a global macro with no handler specified // this is a global macro with no handler specified
handlerObject = reval.global; handlerObject = null;
} }
if (handlerObject != null) { if (objectFound) {
ESValue v = handlerObject.doIndirectCall (reval.evaluator, handlerObject, name+"_macro", arguments); Object v = reval.invokeDirectFunction (handlerObject, name+"_macro", arguments);
if (v != ESUndefined.theUndefined && v != ESNull.theNull) // ESValue v = handlerObject.doIndirectCall (reval.evaluator, handlerObject, name+"_macro", arguments);
if (v != null)
reval.res.write (v); reval.res.write (v);
} else { } else {
String msg = "[HopMacro unhandled: "+getFullName()+"]"; String msg = "[HopMacro unhandled: "+getFullName()+"]";
@ -319,6 +315,7 @@ public class Skin {
} catch (ConcurrencyException concur) { } catch (ConcurrencyException concur) {
throw concur; throw concur;
} catch (Exception x) { } catch (Exception x) {
x.printStackTrace();
String msg = "[HopMacro error: "+x+"]"; String msg = "[HopMacro error: "+x+"]";
reval.res.write (" "+msg+" "); reval.res.write (" "+msg+" ");
app.logEvent (msg); app.logEvent (msg);
@ -344,16 +341,14 @@ public class Skin {
reval.res.write (encode (value.toString (), encoding)); reval.res.write (encode (value.toString (), encoding));
} }
private void renderFromParam (RequestEvaluator reval, ESObject paramObject) { private void renderFromParam (RequestEvaluator reval, HashMap paramObject) {
String encoding = (String) parameters.get ("encoding"); String encoding = (String) parameters.get ("encoding");
if (paramObject == null) if (paramObject == null)
reval.res.write ("[HopMacro error: Skin requires a parameter object]"); reval.res.write ("[HopMacro error: Skin requires a parameter object]");
else { else {
try { Object value = paramObject.get (name);
ESValue value = paramObject.getProperty (name, name.hashCode()); if (value != null)
if (value != null && value != ESUndefined.theUndefined && value != ESNull.theNull)
reval.res.write (encode (value.toString (), encoding)); reval.res.write (encode (value.toString (), encoding));
} catch (EcmaScriptException ignore) {}
} }
} }