Remove Fesi scripting engine from Trunk

This commit is contained in:
hns 2003-08-07 16:11:31 +00:00
parent d4b8b3c2af
commit bfc1b8914d
16 changed files with 0 additions and 6877 deletions

View file

@ -1,98 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.Data.ESNull;
import FESI.Data.ESValue;
import FESI.Data.ESWrapper;
import FESI.Exceptions.EcmaScriptException;
import FESI.Interpreter.Evaluator;
import helma.framework.core.ApplicationBean;
import helma.objectmodel.INode;
import helma.util.SystemProperties;
import java.util.Map;
/**
* Wrap a Java Bean for use in EcmaScript.
*/
public class ESBeanWrapper extends ESWrapper {
FesiEngine engine;
/**
* Creates a new ESBeanWrapper object.
*
* @param object ...
* @param engine ...
*/
public ESBeanWrapper(Object object, FesiEngine engine) {
super(object, engine.getEvaluator(), true);
this.engine = engine;
}
/**
* Wrap getProperty, return ESNode if INode would be returned,
* ESMapWrapper if Map would be returned.
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
try {
ESValue val = super.getProperty(propertyName, hash);
if (val instanceof ESWrapper) {
Object theObject = ((ESWrapper) val).getJavaObject();
if (val instanceof ESWrapper && theObject instanceof INode) {
return engine.getNodeWrapper((INode) theObject);
} else if (val instanceof ESWrapper && theObject instanceof Map) {
ESMapWrapper wrapper = new ESMapWrapper(engine, (Map) theObject);
if (theObject instanceof SystemProperties &&
super.getJavaObject() instanceof ApplicationBean) {
wrapper.setReadonly(true);
}
return wrapper;
}
}
return val;
} catch (Exception rte) {
return ESNull.theNull;
}
}
/**
*
*
* @param propertyName ...
* @param propertyValue ...
* @param hash ...
*
* @throws EcmaScriptException ...
*/
public void putProperty(String propertyName, ESValue propertyValue, int hash)
throws EcmaScriptException {
try {
super.putProperty(propertyName, propertyValue, hash);
} catch (Exception rte) {
// create a nice error message
throw new EcmaScriptException("can't set property " + propertyName +
" to this value on " +
getJavaObject().toString());
}
}
}

View file

@ -1,236 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.*;
import helma.framework.IPathElement;
import helma.framework.core.*;
import java.util.*;
/**
* A wrapper for a Java object that may or may not implement the IPathElement interface.
*/
public class ESGenericObject extends ObjectPrototype {
ESWrapper wrapper;
Object wrappedObject;
/**
* Creates a new ESGenericObject object.
*
* @param prototype ...
* @param evaluator ...
* @param obj ...
*/
public ESGenericObject(ESObject prototype, Evaluator evaluator, Object obj) {
super(prototype, evaluator);
wrappedObject = obj;
wrapper = new ESWrapper(obj, evaluator);
}
/**
*
*
* @return ...
*/
public String getESClassName() {
return "GenericObject";
}
/**
*
*
* @return ...
*/
public String toString() {
return wrappedObject.toString();
}
/**
*
*
* @return ...
*/
public String toDetailString() {
return wrapper.toDetailString();
}
/**
*
*
* @param propertyName ...
* @param propertyValue ...
* @param hash ...
*
* @throws EcmaScriptException ...
*/
public void putProperty(String propertyName, ESValue propertyValue, int hash)
throws EcmaScriptException {
wrapper.putProperty(propertyName, propertyValue, hash);
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public boolean hasProperty(String propertyName, int hash)
throws EcmaScriptException {
return super.hasProperty(propertyName, hash) ||
wrapper.hasProperty(propertyName, hash);
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public boolean deleteProperty(String propertyName, int hash)
throws EcmaScriptException {
return wrapper.deleteProperty(propertyName, hash);
}
/**
*
*
* @param i ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(int i) throws EcmaScriptException {
return wrapper.getProperty(i);
}
/**
*
*
* @param index ...
* @param propertyValue ...
*
* @throws EcmaScriptException ...
*/
public void putProperty(int index, ESValue propertyValue)
throws EcmaScriptException {
wrapper.putProperty(index, propertyValue);
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
ESValue val = super.getProperty(propertyName, hash);
if ((val == null) || (val == ESUndefined.theUndefined)) {
val = wrapper.getProperty(propertyName, hash);
}
return val;
}
/**
*
*
* @param evaluator ...
* @param thisObject ...
* @param functionName ...
* @param arguments ...
*
* @return ...
*
* @throws EcmaScriptException ...
* @throws NoSuchMethodException ...
*/
public ESValue doIndirectCall(Evaluator evaluator, ESObject thisObject,
String functionName, ESValue[] arguments)
throws EcmaScriptException, NoSuchMethodException {
if (super.hasProperty(functionName, functionName.hashCode())) {
return super.doIndirectCall(evaluator, thisObject, functionName, arguments);
}
return wrapper.doIndirectCall(evaluator, thisObject, functionName, arguments);
}
/**
*
*
* @return ...
*/
public Enumeration getAllProperties() {
return wrapper.getProperties();
}
/**
*
*
* @return ...
*/
public Enumeration getProperties() {
return wrapper.getProperties();
}
/**
*
*
* @return ...
*/
public Object toJavaObject() {
return wrappedObject;
}
/**
* An ESNode equals another object if it is an ESNode that wraps the same INode
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
*/
public boolean equals(Object what) {
if (what == null) {
return false;
}
if (what == this) {
return true;
}
if (what instanceof ESGenericObject) {
ESGenericObject other = (ESGenericObject) what;
return (wrappedObject.equals(other.wrappedObject));
}
return false;
}
}

View file

@ -1,189 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.Evaluator;
import helma.framework.core.*;
import helma.objectmodel.INode;
import java.util.*;
/**
* An EcmaScript object that makes stuff in a hashtable accessible as its properties
*/
public class ESMapWrapper extends ESWrapper {
private Map data;
private FesiEngine engine;
private boolean readonly = false;
/**
* Creates a new ESMapWrapper object.
*
* @param engine ...
*/
public ESMapWrapper(FesiEngine engine) {
super(new Object(), engine.getEvaluator());
this.engine = engine;
}
/**
* Creates a new ESMapWrapper object.
*
* @param engine ...
* @param data ...
*/
public ESMapWrapper(FesiEngine engine, Map data) {
super(new Object(), engine.getEvaluator());
this.engine = engine;
this.data = data;
}
/**
*
*
* @param readonly ...
*/
public void setReadonly(boolean readonly) {
this.readonly = readonly;
}
/**
*
*
* @param data ...
*/
public void setData(Map data) {
this.data = data;
}
/**
* Overridden to make the object read-only
*/
public void putProperty(String propertyName, ESValue propertyValue, int hash)
throws EcmaScriptException {
if (data == null) {
data = new HashMap();
}
if (propertyValue == ESNull.theNull) {
deleteProperty(propertyName, hash);
} else if (readonly == false) {
data.put(propertyName, propertyValue.toJavaObject());
} else {
throw new EcmaScriptException("object is readonly");
}
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public boolean deleteProperty(String propertyName, int hash)
throws EcmaScriptException {
if (readonly == false) {
data.remove(propertyName);
return true;
} else {
return false;
}
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
if (data == null) {
return ESNull.theNull;
}
Object val = data.get(propertyName);
if (val == null) {
return ESNull.theNull;
}
if (val instanceof String) {
return new ESString((String) val);
} else if (val instanceof INode) {
return engine.getNodeWrapper((INode) val);
} else if (val instanceof Map) {
return new ESMapWrapper(engine, (Map) val);
} else if (val instanceof ESValue) {
return (ESValue) val;
}
return ESLoader.normalizeValue(val, evaluator);
}
/**
*
*
* @return ...
*/
public Enumeration getAllProperties() {
return getProperties();
}
/**
*
*
* @return ...
*/
public Enumeration getProperties() {
Object[] keys = (data == null) ? null : data.keySet().toArray();
return new Enum(keys);
}
class Enum implements Enumeration {
Object[] elements;
int pos;
Enum(Object[] elements) {
this.elements = elements;
pos = 0;
}
public boolean hasMoreElements() {
return (elements != null) && (pos < elements.length);
}
public Object nextElement() {
if ((elements == null) || (pos >= elements.length)) {
throw new NoSuchElementException();
}
return elements[pos++];
}
}
}

View file

@ -1,795 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.*;
import helma.framework.core.*;
import helma.objectmodel.*;
import helma.objectmodel.db.*;
import helma.util.*;
import java.io.*;
import java.util.*;
/**
* An EcmaScript wrapper around a Node object. This is the basic
* HopObject that can be stored in the internal or external databases.
*/
public class ESNode extends ObjectPrototype {
// the INode object wrapped by this ESObject
INode node;
// the cache node - persistent nodes have a transient property as a commodity to
// store temporary stuff.
INode cache;
// the ecmascript wrapper for the cache.
ESNode cacheWrapper;
// The handle of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
NodeHandle handle;
DbMapping dbmap;
Throwable lastError = null;
FesiEngine engine;
/**
* Constructor used to create transient cache nodes
*/
public ESNode(INode node, FesiEngine engine) {
super(engine.getPrototype("hopobject"), engine.getEvaluator());
this.engine = engine;
this.node = node;
cache = null;
cacheWrapper = null;
// this is a transient node, set node handle to null
handle = null;
}
/**
* Creates a new ESNode object.
*
* @param prototype ...
* @param evaluator ...
* @param obj ...
* @param engine ...
*/
public ESNode(ESObject prototype, Evaluator evaluator, Object obj, FesiEngine engine) {
super(prototype, evaluator);
// eval.app.logEvent ("in ESNode constructor: "+o.getClass ());
this.engine = engine;
if (obj == null) {
node = new TransientNode(null);
} else if (obj instanceof ESWrapper) {
node = (INode) ((ESWrapper) obj).getJavaObject();
} else if (obj instanceof INode) {
node = (INode) obj;
} else {
node = new TransientNode(obj.toString());
}
// set node handle to wrapped node
if (node instanceof Node) {
handle = ((Node) node).getHandle();
} else {
handle = null;
}
// cache Node is initialized on demend when it is needed
cache = null;
cacheWrapper = null;
}
/**
* Check if the node has been invalidated. If so, it has to be re-fetched
* from the db via the app's node manager.
*/
protected void checkNode() {
if (node.getState() == INode.INVALID) {
try {
node = handle.getNode(engine.app.getWrappedNodeManager());
} catch (Exception nx) {
}
}
}
/**
*
*
* @return ...
*/
public INode getNode() {
checkNode();
return node;
}
/**
*
*
* @param protoName ...
*/
public void setPrototype(String protoName) {
checkNode();
node.setPrototype(protoName);
}
/**
*
*
* @return ...
*/
public String getPrototypeName() {
return node.getPrototype();
}
/**
*
*
* @return ...
*/
public String getESClassName() {
return "HopObject";
}
/**
*
*
* @return ...
*/
public String toString() {
if (node == null) {
return "<null>";
}
return node.toString();
}
/**
*
*
* @return ...
*/
public String toDetailString() {
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
((node == null) ? "null" : node.toString()) + "]";
}
protected void setError(Throwable e) {
lastError = e;
}
/**
*
*
* @param what ...
*
* @return ...
*/
public boolean add(ESValue[] what) {
checkNode();
for (int i = 0; i < what.length; i++)
if (what[i] instanceof ESNode) {
ESNode esn = (ESNode) what[i];
INode added = node.addNode(esn.getNode());
}
return true;
}
/**
*
*
* @return ...
*/
public ESValue list() {
checkNode();
int l = node.numberOfNodes();
Enumeration e = node.getSubnodes();
ESObject ap = evaluator.getArrayPrototype();
ArrayPrototype theArray = new ArrayPrototype(ap, evaluator);
if (e != null) {
theArray.setSize(l);
for (int i = 0; i < l; i++) {
theArray.setElementAt(engine.getNodeWrapper((INode) e.nextElement()), i);
}
} else {
theArray.setSize(0);
}
return theArray;
}
/**
*
*
* @param what ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public boolean addAt(ESValue[] what) throws EcmaScriptException {
checkNode();
if (what.length < 2) {
throw new EcmaScriptException("Wrong number of arguments");
}
if (!(what[1] instanceof ESNode)) {
throw new EcmaScriptException("Can only add Node objects as subnodes");
}
ESNode esn = (ESNode) what[1];
INode added = node.addNode(esn.getNode(), (int) what[0].toInt32());
return true;
}
/**
* Remove node itself or one or more subnodes.
*/
public boolean remove(ESValue[] args) {
checkNode();
// semantics: if called without arguments, remove self.
// otherwise, remove given subnodes.
if (args.length == 0) {
return node.remove();
} else {
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof ESNode) {
ESNode esn = (ESNode) args[i];
node.removeNode(esn.getNode());
}
}
}
return true;
}
/**
* Invalidate the node itself or a subnode
*/
public boolean invalidate(ESValue[] args) {
if (node instanceof helma.objectmodel.db.Node) {
if (args.length == 0) {
((helma.objectmodel.db.Node) node).invalidate();
} else {
((helma.objectmodel.db.Node) node).invalidateNode(args[0].toString());
}
}
return true;
}
/**
* Check if node is contained in subnodes
*/
public int contains(ESValue[] args) {
checkNode();
if ((args.length == 1) && args[0] instanceof ESNode) {
ESNode esn = (ESNode) args[0];
return node.contains(esn.getNode());
}
return -1;
}
/**
* Prefetch child objects from (relational) database.
*/
public void prefetchChildren(ESValue[] args) throws Exception {
checkNode();
if (!(node instanceof Node)) {
return;
}
int start = 0;
int length = 0;
try {
if (args.length == 0) {
start = 0;
length = 1000;
} else if (args.length == 2) {
if (args[0].isNumberValue()) {
start = args[0].toInt32();
} else {
throw new RuntimeException("Illegal argument in prefetchChildren: " +
args[0]);
}
if (args[1].isNumberValue()) {
length = args[1].toInt32();
} else {
throw new RuntimeException("Illegal argument in prefetchChildren: " +
args[1]);
}
} else {
throw new RuntimeException("Wrong number of arguments in prefetchChildren");
}
} catch (Exception x) {
throw new IllegalArgumentException(x.getMessage());
}
((Node) node).prefetchChildren(start, length);
}
/**
*
*
* @param pval ...
*
* @return ...
*/
public boolean setParent(ESValue[] pval) {
// do a couple of checks: both nodes need to be persistent in order for setParent to make sense.
if (!(node instanceof helma.objectmodel.db.Node)) {
return false;
}
if ((pval == null) || (pval.length < 1) || (pval.length > 2)) {
return false;
}
if (!(pval[0] instanceof ESNode)) {
return false;
}
ESNode esn = (ESNode) pval[0];
INode pn = esn.getNode();
if (!(pn instanceof helma.objectmodel.db.Node)) {
return false;
}
// check if there is an additional string element - if so, it's the property name by which the node is
// accessed, otherwise it will be accessed as anonymous subnode via its id
String propname = null;
if ((pval.length == 2) && (pval[1] != null) && !(pval[1] instanceof ESNull)) {
propname = pval[1].toString();
}
helma.objectmodel.db.Node n = (helma.objectmodel.db.Node) node;
n.setParent((helma.objectmodel.db.Node) pn, propname);
return true;
}
/**
*
*
* @param propertyName ...
* @param propertyValue ...
* @param hash ...
*
* @throws EcmaScriptException ...
*/
public void putProperty(String propertyName, ESValue propertyValue, int hash)
throws EcmaScriptException {
checkNode();
// engine.app.logEvent ("put property called: "+propertyName+", "+propertyValue.getClass());
if ("cache".equalsIgnoreCase(propertyName)) {
throw new EcmaScriptException("Can't modify read-only property \"" +
propertyName + "\".");
}
if ("subnodeRelation".equalsIgnoreCase(propertyName)) {
node.setSubnodeRelation((propertyValue instanceof ESNull) ? null
: propertyValue.toString());
return;
}
// check if the property is write protected, i.e. the type.property file describes it as [readonly]
DbMapping dbm = node.getDbMapping();
if (dbm != null) {
Relation rel = dbm.getPropertyRelation(propertyName);
if ((rel != null) && rel.isReadonly()) {
return;
}
}
if (propertyValue instanceof ESNull || propertyValue instanceof ESUndefined) {
node.unset(propertyName);
} else if (propertyValue instanceof ESString) {
node.setString(propertyName, propertyValue.toString());
} else if (propertyValue instanceof ESBoolean) {
node.setBoolean(propertyName, propertyValue.booleanValue());
} else if (propertyValue instanceof ESNumber) {
node.setFloat(propertyName, propertyValue.doubleValue());
} else if (propertyValue instanceof DatePrototype) {
node.setDate(propertyName, (Date) propertyValue.toJavaObject());
} else if (propertyValue instanceof ESNode) {
// long now = System.currentTimeMillis ();
ESNode esn = (ESNode) propertyValue;
node.setNode(propertyName, esn.getNode());
// engine.app.logEvent ("*** spent "+(System.currentTimeMillis () - now)+" ms to set property "+propertyName);
} else {
// engine.app.logEvent ("got "+propertyValue.getClass ());
// A persistent node can't store anything other than the types above, so throw an exception
// throw new EcmaScriptException ("Can't set a JavaScript Object or Array as property of "+node);
node.setJavaObject(propertyName, propertyValue.toJavaObject());
}
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public boolean deleteProperty(String propertyName, int hash)
throws EcmaScriptException {
checkNode();
// engine.app.logEvent ("delete property called: "+propertyName);
if (node.get(propertyName) != null) {
node.unset(propertyName);
return true;
}
return super.deleteProperty(propertyName, hash);
}
/**
*
*
* @param i ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(int i) throws EcmaScriptException {
checkNode();
INode n = node.getSubnodeAt(i);
if (n == null) {
return ESNull.theNull;
}
return engine.getNodeWrapper(n);
}
/**
*
*
* @param index ...
* @param propertyValue ...
*
* @throws EcmaScriptException ...
*/
public void putProperty(int index, ESValue propertyValue)
throws EcmaScriptException {
checkNode();
if (propertyValue instanceof ESNode) {
ESNode n = (ESNode) propertyValue;
node.addNode(n.getNode(), index);
} else {
throw new EcmaScriptException("Can only add Nodes to Node arrays");
}
}
/**
* Retrieve a property from the node object or the underlying EcmaScript prototype.
* Normally we would first check the node object and then the prototype, but since
* node properties are potentially expensive to look up because they require database
* queries, we do the prototype lookup first. This usually doesn't cause any confusion
* because generally things are divided cleanly between prototype and object - the
* first holds the functions, the latter the mapped data properties.
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
checkNode();
// engine.app.logEvent ("get property called: "+propertyName);
ESValue retval = super.getProperty(propertyName, hash);
if (!(retval instanceof ESUndefined)) {
return retval;
}
return getNodeProperty(propertyName);
}
/**
* Retrieve a property only from the node itself, not the underlying EcmaScript prototype object.
* This is called directly when we call get(x) on a hopobject, since we don't want to return
* the prototype functions in that case.
*/
public ESValue getNodeProperty(String propertyName)
throws EcmaScriptException {
// check for null
if (propertyName == null) {
return ESNull.theNull;
}
// persistent or persistent capable nodes have a cache property that's a transient node.
// it it hasn't requested before, initialize it now
if ("cache".equalsIgnoreCase(propertyName) && node instanceof Node) {
cache = node.getCacheNode();
if (cacheWrapper == null) {
cacheWrapper = new ESNode(cache, engine);
} else {
cacheWrapper.node = cache;
}
return cacheWrapper;
}
if ("subnodeRelation".equalsIgnoreCase(propertyName)) {
String rel = node.getSubnodeRelation();
return (rel == null) ? (ESValue) ESNull.theNull : new ESString(rel);
}
// Everything starting with an underscore is interpreted as internal property
if (propertyName.startsWith("_")) {
return getInternalProperty(propertyName);
}
// this _may_ do a relational query if properties are mapped to a relational type.
IProperty p = node.get(propertyName);
if (p != null) {
if (p.getType() == IProperty.STRING) {
String str = p.getStringValue();
if (str == null) {
return ESNull.theNull;
} else {
return new ESString(str);
}
}
if (p.getType() == IProperty.BOOLEAN) {
return ESBoolean.makeBoolean(p.getBooleanValue());
}
if (p.getType() == IProperty.DATE) {
return new DatePrototype(evaluator, p.getDateValue());
}
if (p.getType() == IProperty.INTEGER) {
return new ESNumber((double) p.getIntegerValue());
}
if (p.getType() == IProperty.FLOAT) {
return new ESNumber(p.getFloatValue());
}
if (p.getType() == IProperty.NODE) {
INode nd = p.getNodeValue();
if (nd == null) {
return ESNull.theNull;
} else {
return engine.getNodeWrapper(nd);
}
}
if (p.getType() == IProperty.JAVAOBJECT) {
return ESLoader.normalizeObject(p.getJavaObjectValue(), evaluator);
}
}
// as last resort, try to get property as anonymous subnode
INode anon = (INode) node.getChildElement(propertyName);
if (anon != null) {
return engine.getNodeWrapper(anon);
}
return ESNull.theNull;
}
/**
* Some internal properties defined for every Node object. These are most commonly
* used for debugging Helma applications.
*/
private ESValue getInternalProperty(String propertyName)
throws EcmaScriptException {
if ("__id__".equals(propertyName) || "_id".equals(propertyName)) {
return new ESString(node.getID());
}
if ("__prototype__".equals(propertyName) || "_prototype".equals(propertyName)) {
String p = node.getPrototype();
if (p == null) {
return ESNull.theNull;
} else {
return new ESString(node.getPrototype());
}
}
if ("__parent__".equals(propertyName) || "_parent".equals(propertyName)) {
INode n = node.getParent();
if (n == null) {
return ESNull.theNull;
} else {
return engine.getNodeWrapper(n);
}
}
// some more internal properties
if ("__name__".equals(propertyName)) {
return new ESString(node.getName());
}
if ("__fullname__".equals(propertyName)) {
return new ESString(node.getFullName());
}
if ("__hash__".equals(propertyName)) {
return new ESString("" + node.hashCode());
}
if ("__node__".equals(propertyName)) {
return new ESWrapper(node, evaluator);
}
if ("__created__".equalsIgnoreCase(propertyName)) {
return new DatePrototype(evaluator, node.created());
}
if ("__lastmodified__".equalsIgnoreCase(propertyName)) {
return new DatePrototype(evaluator, node.lastModified());
}
return ESNull.theNull;
}
/**
*
*
* @return ...
*/
public boolean clearCache() {
checkNode();
node.clearCacheNode();
return true;
}
/**
*
*
* @return ...
*/
public Enumeration getAllProperties() {
return getProperties();
}
/**
*
*
* @return ...
*/
public Enumeration getProperties() {
checkNode();
return node.properties();
}
/**
*
*
* @return ...
*/
public String error() {
if (lastError == null) {
return "";
} else {
String exceptionName = lastError.getClass().getName();
int l = exceptionName.lastIndexOf(".");
if (l > 0) {
exceptionName = exceptionName.substring(l + 1);
}
return exceptionName + ": " + lastError.getMessage();
}
}
/**
*
*/
public void clearError() {
lastError = null;
}
/**
*
*
* @return ...
*/
public Object toJavaObject() {
return getNode();
}
/**
* An ESNode equals another object if it is an ESNode that wraps the same INode
* or the wrapped INode itself. FIXME: doesen't check dbmapping/type!
*/
public boolean equals(Object what) {
if (what == null) {
return false;
}
if (what == this) {
return true;
}
if (what instanceof ESNode) {
ESNode other = (ESNode) what;
if (handle != null) {
return handle.equals(other.handle);
} else {
return (node == other.node);
}
}
return false;
}
/**
*
*
* @param hint ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getDefaultValue(int hint) throws EcmaScriptException {
return new ESString(this.toString());
}
}
// class ESNode

View file

@ -1,260 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.AST.ASTFormalParameterList;
import FESI.AST.ASTStatementList;
import FESI.AST.EcmaScriptTreeConstants;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.*;
import FESI.Parser.*;
import helma.framework.*;
import helma.framework.core.*;
import helma.scripting.*;
import helma.util.Updatable;
import java.io.*;
import java.util.Iterator;
import java.util.Vector;
/**
* An class that updates fesi interpreters with actionfiles and templates.
*/
public class FesiActionAdapter {
Prototype prototype;
Application app;
String functionName;
String sourceName;
// this is the parsed function which can be easily applied to FesiEngine objects
TypeUpdater pfunc;
// this is the parsed function which can be easily applied to FesiEngine objects
TypeUpdater pfuncAsString;
/**
* Creates a new FesiActionAdapter object.
*
* @param action ...
*/
public FesiActionAdapter(ActionFile action) {
prototype = action.getPrototype();
app = action.getApplication();
Reader reader = null;
functionName = action.getFunctionName();
sourceName = action.getSourceName();
try {
reader = action.getReader();
pfunc = parseFunction(functionName,
"arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10",
reader, sourceName);
} catch (Throwable x) {
String message = x.getMessage();
pfunc = new ErrorFeedback(functionName, message);
} finally {
try {
reader.close();
} catch (Exception ignore) {
}
}
// check if this is a template and we need to generate an "_as_string" variant
if (action instanceof Template) {
String content = "res.pushStringBuffer(); " + action.getContent() +
"\r\nreturn res.popStringBuffer();\r\n";
try {
pfuncAsString = parseFunction(functionName + "_as_string",
"arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10",
new StringReader(content), sourceName);
} catch (Throwable x) {
String message = x.getMessage();
pfunc = new ErrorFeedback(functionName + "_as_string", message);
}
} else {
pfuncAsString = null;
}
}
/**
*
*
* @param engine ...
*
* @throws EcmaScriptException ...
*/
public synchronized void updateEvaluator(FesiEngine engine)
throws EcmaScriptException {
if (pfunc != null) {
pfunc.updateEvaluator(engine);
}
if (pfuncAsString != null) {
pfuncAsString.updateEvaluator(engine);
}
}
protected TypeUpdater parseFunction(String funcName, String params, Reader body,
String sourceName)
throws EcmaScriptException {
// ESObject fp = app.eval.evaluator.getFunctionPrototype();
// ConstructedFunctionObject function = null;
ASTFormalParameterList fpl = null;
ASTStatementList sl = null;
FunctionEvaluationSource fes = null;
/* if (body == null || "".equals (body.trim()))
body = ";\r\n";
else
body = body + "\r\n"; */
if (params == null) {
params = "";
} else {
params = params.trim();
}
EcmaScript parser;
StringReader is;
// Special case for empty parameters
if (params.length() == 0) {
fpl = new ASTFormalParameterList(EcmaScriptTreeConstants.JJTFORMALPARAMETERLIST);
} else {
is = new java.io.StringReader(params);
parser = new EcmaScript(is);
try {
fpl = (ASTFormalParameterList) parser.FormalParameterList();
is.close();
} catch (ParseException x) {
throw new EcmaScriptParseException(x,
new FileEvaluationSource(sourceName,
null));
}
}
// this is very very very strange: without the toString, lots of obscure exceptions
// deep inside the parser...
// is = new java.io.StringReader(body.toString ());
try {
parser = new EcmaScript(body);
sl = (ASTStatementList) parser.StatementList();
body.close();
} catch (ParseException x) {
app.logEvent("Error parsing file " + app.getName() + ":" + sourceName + ": " +
x);
throw new EcmaScriptParseException(x,
new FileEvaluationSource(sourceName, null));
} catch (Exception x) {
app.logEvent("Error parsing file " + app.getName() + ":" + sourceName + ": " +
x);
throw new RuntimeException(x.getMessage());
}
fes = new FunctionEvaluationSource(new FileEvaluationSource(sourceName, null),
funcName);
return new ParsedFunction(fpl, sl, fes, null, funcName);
}
interface TypeUpdater {
public void updateEvaluator(FesiEngine engine)
throws EcmaScriptException;
}
class ParsedFunction implements TypeUpdater {
ASTFormalParameterList fpl = null;
ASTStatementList sl = null;
FunctionEvaluationSource fes = null;
String fullFunctionText = null;
String functionName;
public ParsedFunction(ASTFormalParameterList fpl, ASTStatementList sl,
FunctionEvaluationSource fes, String fullFunctionText,
String functionName) {
this.fpl = fpl;
this.sl = sl;
this.fes = fes;
this.fullFunctionText = fullFunctionText;
this.functionName = functionName;
}
public void updateEvaluator(FesiEngine engine)
throws EcmaScriptException {
ObjectPrototype op = engine.getPrototype(prototype.getName());
EcmaScriptVariableVisitor vdvisitor = engine.evaluator.getVarDeclarationVisitor();
Vector vnames = vdvisitor.processVariableDeclarations(sl, fes);
FunctionPrototype fp = ConstructedFunctionObject.makeNewConstructedFunction(engine.evaluator,
functionName,
fes,
fullFunctionText,
fpl.getArguments(),
vnames,
sl);
op.putHiddenProperty(functionName, fp);
}
}
class ErrorFeedback implements TypeUpdater {
String functionName;
String errorMessage;
public ErrorFeedback(String fname, String msg) {
functionName = fname;
errorMessage = msg;
}
public void updateEvaluator(FesiEngine engine)
throws EcmaScriptException {
ObjectPrototype op = engine.getPrototype(prototype.getName());
FunctionPrototype fp = (FunctionPrototype) engine.evaluator.getFunctionPrototype();
FunctionPrototype func = new ThrowException(functionName, engine.evaluator,
fp, errorMessage);
op.putHiddenProperty(functionName, func);
}
}
class ThrowException extends BuiltinFunctionObject {
String message;
ThrowException(String name, Evaluator evaluator, FunctionPrototype fp,
String message) {
super(fp, evaluator, name, 1);
this.message = (message == null) ? "No error message available" : message;
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
throw new EcmaScriptException(message);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
throw new EcmaScriptException(message);
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,164 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.*;
import helma.framework.core.*;
import helma.objectmodel.db.Node;
/**
* A constructor for user defined data types. This first constructs a node, sets its prototype
* and invokes the scripted constructor function on it.
*/
public class NodeConstructor extends BuiltinFunctionObject {
FesiEngine engine;
String typename;
/**
* Creates a new NodeConstructor object.
*
* @param name ...
* @param fp ...
* @param engine ...
*/
public NodeConstructor(String name, FunctionPrototype fp, FesiEngine engine) {
super(fp, engine.getEvaluator(), name, 1);
typename = name;
this.engine = engine;
}
/**
*
*
* @param thisObject ...
* @param arguments ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
/**
*
*
* @param thisObject ...
* @param arguments ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESNode node = null;
Application app = engine.getApplication();
if ("Node".equals(typename) || "hopobject".equalsIgnoreCase(typename)) {
String nodeName = null;
if ((arguments.length > 0) && (arguments[0] != null)) {
nodeName = arguments[0].toString();
}
Node n = new Node(nodeName, (String) null, app.getWrappedNodeManager());
node = new ESNode(engine.getPrototype("hopobject"), this.evaluator, n, engine);
engine.putNodeWrapper(node.getNode(), node);
} else {
// 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
// is that we want to be able to use the specail features like subnode relations even for
// transient nodes.
ObjectPrototype op = engine.getPrototype(typename);
Node n = new Node(typename, typename, app.getWrappedNodeManager());
node = new ESNode(op, engine.getEvaluator(), n, engine);
node.setPrototype(typename);
node.getNode().setDbMapping(app.getDbMapping(typename));
try {
// first try calling "constructor", if that doesn't work, try calling a function
// with the name of the type.
// HACK: There is an incompatibility problem here, because the property
// constructor is defined as the constructor of the object by EcmaScript.
if (op.getProperty("constructor", "constructor".hashCode()) instanceof ConstructedFunctionObject) {
node.doIndirectCall(engine.getEvaluator(), node, "constructor",
arguments);
} else if (op.getProperty(typename, typename.hashCode()) instanceof ConstructedFunctionObject) {
node.doIndirectCall(engine.getEvaluator(), node, typename, arguments);
}
} catch (Exception x) {
throw new EcmaScriptException(x.toString());
}
}
return node;
}
/**
*
*
* @param propertyName ...
* @param previousScope ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope,
int hash) throws EcmaScriptException {
return super.getPropertyInScope(propertyName, previousScope, hash);
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
if ("prototype".equals(propertyName)) {
return engine.getPrototype(typename);
}
return super.getProperty(propertyName, hash);
}
/**
*
*
* @return ...
*/
public String[] getSpecialPropertyNames() {
String[] ns = { };
return ns;
}
}
// class NodeConstructor

View file

@ -1,32 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi;
import helma.scripting.ScriptingException;
/**
*
*/
public final class PhantomEngine extends FesiEngine {
/**
*
*/
public Object invoke(Object thisObject, String functionName, Object[] args,
boolean xmlrpc) throws ScriptingException {
return super.invoke(thisObject, functionName, args, xmlrpc);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,307 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Extensions.*;
import FESI.Interpreter.*;
import helma.framework.core.Application;
import helma.framework.core.RequestEvaluator;
import helma.objectmodel.INode;
import helma.objectmodel.db.Node;
import helma.objectmodel.dom.*;
import helma.scripting.fesi.ESNode;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
/**
*
*/
public class DomExtension extends Extension {
private transient Evaluator evaluator = null;
/**
* Creates a new DomExtension object.
*/
public DomExtension() {
super();
}
/**
*
*
* @param evaluator ...
*
* @throws EcmaScriptException ...
*/
public void initializeExtension(Evaluator evaluator)
throws EcmaScriptException {
this.evaluator = evaluator;
GlobalObject go = evaluator.getGlobalObject();
ObjectPrototype op = (ObjectPrototype) evaluator.getObjectPrototype();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
ESObject globalXml = new GlobalObjectXml("Xml", evaluator, fp);
globalXml.putHiddenProperty("length", new ESNumber(1));
globalXml.putHiddenProperty("read", new XmlRead("read", evaluator, fp, false));
globalXml.putHiddenProperty("readFromString",
new XmlRead("readFromString", evaluator, fp, true));
globalXml.putHiddenProperty("write", new XmlWrite("write", evaluator, fp));
globalXml.putHiddenProperty("writeToString",
new XmlWriteToString("writeToString", evaluator, fp));
globalXml.putHiddenProperty("get", new XmlGet("get", evaluator, fp));
globalXml.putHiddenProperty("getFromString",
new XmlGetFromString("getFromString", evaluator, fp));
go.putHiddenProperty("Xml", globalXml);
}
class GlobalObjectXml extends BuiltinFunctionObject {
GlobalObjectXml(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
throw new EcmaScriptException("Xml can't be instanced");
}
public String toString() {
try {
String parser = javax.xml.parsers.DocumentBuilderFactory.newInstance()
.getClass()
.getPackage()
.getName();
return "[Xml " + parser + "]";
} catch (NullPointerException zeero) {
return "[Xml - no parser available]";
}
}
}
class XmlWrite extends BuiltinFunctionObject {
XmlWrite(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
if ((arguments == null) || (arguments.length != 2)) {
throw new EcmaScriptException("Wrong number of arguments in Xml.write()");
}
INode node = null;
try {
node = ((ESNode) arguments[0]).getNode();
} catch (Exception e) {
// we definitly need a node
throw new EcmaScriptException("First argument in Xml.write() is not an hopobject");
}
try {
File tmpFile = new File(arguments[1].toString() + ".tmp." +
XmlWriter.generateID());
XmlWriter writer = new XmlWriter(tmpFile, "UTF-8");
writer.setDatabaseMode(false);
boolean result = writer.write(node);
writer.close();
File finalFile = new File(arguments[1].toString());
tmpFile.renameTo(finalFile);
this.evaluator.engine.getApplication().logEvent("wrote xml to " +
finalFile.getAbsolutePath());
} catch (IOException io) {
throw new EcmaScriptException(io.toString());
}
return ESBoolean.makeBoolean(true);
}
}
/**
* Xml.create() is used to get a string containing the xml-content.
* Useful if Xml-content should be made public through the web.
*/
class XmlWriteToString extends BuiltinFunctionObject {
XmlWriteToString(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
if ((arguments == null) || (arguments.length == 0)) {
throw new EcmaScriptException("Not enough arguments in Xml.writeToString()");
}
INode node = null;
try {
node = ((ESNode) arguments[0]).getNode();
} catch (Exception e) {
// we definitly need a node
throw new EcmaScriptException("argument is not an hopobject");
}
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XmlWriter writer = new XmlWriter(out, "UTF-8");
// in case we ever want to limit serialization depth...
// if (arguments.length > 1 && arguments[1] instanceof ESNumber)
// writer.setMaxLevels(arguments[1].toInt32());
writer.setDatabaseMode(false);
boolean result = writer.write(node);
writer.flush();
return new ESString(out.toString("UTF-8"));
} catch (IOException io) {
throw new EcmaScriptException(io.toString());
}
}
}
class XmlRead extends BuiltinFunctionObject {
boolean fromstring;
XmlRead(String name, Evaluator evaluator, FunctionPrototype fp, boolean fromstring) {
super(fp, evaluator, name, 1);
this.fromstring = fromstring;
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
if ((arguments == null) || (arguments.length == 0)) {
throw new EcmaScriptException("Missing arguments in Xml.read()");
}
INode node = null;
try {
node = ((ESNode) arguments[1]).getNode();
} catch (Exception e) { //classcast, arrayindex etc
// make sure we have a node, even if 2nd arg doesn't exist or is not a node
node = new Node((String) null, (String) null,
this.evaluator.engine.getApplication()
.getWrappedNodeManager());
}
try {
XmlReader reader = new XmlReader();
INode result = null;
if (fromstring) {
result = reader.read(new StringReader(arguments[0].toString()), node);
} else {
result = reader.read(new File(arguments[0].toString()), node);
}
return this.evaluator.engine.getNodeWrapper(result);
} catch (NoClassDefFoundError e) {
throw new EcmaScriptException("Can't load XML parser:" + e);
} catch (Exception f) {
throw new EcmaScriptException(f.toString());
}
}
}
class XmlGet extends BuiltinFunctionObject {
XmlGet(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
if ((arguments == null) || (arguments.length == 0)) {
throw new EcmaScriptException("Xml.get() needs a location as an argument");
}
try {
XmlConverter converter;
if (arguments.length > 1) {
converter = new XmlConverter(arguments[1].toString());
} else {
converter = new XmlConverter();
}
INode node = new helma.objectmodel.db.Node((String) null, (String) null,
this.evaluator.engine.getApplication()
.getWrappedNodeManager());
INode result = converter.convert(arguments[0].toString(), node);
return this.evaluator.engine.getNodeWrapper(result);
} catch (NoClassDefFoundError e) {
throw new EcmaScriptException("Can't load dom-capable xml parser.");
} catch (RuntimeException f) {
throw new EcmaScriptException(f.toString());
}
}
}
class XmlGetFromString extends BuiltinFunctionObject {
XmlGetFromString(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
if ((arguments == null) || (arguments.length == 0)) {
throw new EcmaScriptException("Xml.getFromString() needs an XML string as parameter");
}
try {
XmlConverter converter;
if (arguments.length > 1) {
converter = new XmlConverter(arguments[1].toString());
} else {
converter = new XmlConverter();
}
INode node = new helma.objectmodel.db.Node((String) null, (String) null,
this.evaluator.engine.getApplication()
.getWrappedNodeManager());
INode result = converter.convertFromString(arguments[0].toString(), node);
return this.evaluator.engine.getNodeWrapper(result);
} catch (NoClassDefFoundError e) {
throw new EcmaScriptException("Can't load dom-capable xml parser.");
} catch (RuntimeException f) {
throw new EcmaScriptException(f.toString());
}
}
}
}

View file

@ -1,353 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Interpreter.*;
import helma.util.*;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
/**
* A JavaScript wrapper around a JavaMail message class to send
* mail via SMTP from Helma
*/
public class ESMail extends ESObject implements Serializable {
public static final int OK = 0;
public static final int SUBJECT = 10;
public static final int TEXT = 11;
public static final int MIMEPART = 12;
public static final int TO = 20;
public static final int CC = 21;
public static final int BCC = 22;
public static final int FROM = 23;
public static final int REPLYTO = 24;
public static final int SEND = 30;
MailExtension mailx;
Properties mprops;
MimeMessage message;
Multipart multipart;
StringBuffer buffer;
int status;
/**
* Creates a new ESMail object.
*
* @param mailx ...
*/
public ESMail(MailExtension mailx) {
super(mailx.esMailPrototype, mailx.eval);
this.status = OK;
this.mailx = mailx;
this.mprops = mailx.mprops;
// create some properties and get the default Session
try {
Properties props = new Properties();
props.put("mail.smtp.host", mprops.getProperty("smtp", "mail"));
Session session = Session.getDefaultInstance(props, null);
message = new MimeMessage(session);
} catch (Throwable t) {
this.evaluator.engine.getApplication().logEvent("Error in mail constructor: " +
t);
}
}
/**
*
*
* @param status ...
*/
public void setStatus(int status) {
// Only register the first error that occurrs
if (this.status == 0) {
this.status = status;
}
}
/**
*
*
* @return ...
*/
public int getStatus() {
return status;
}
/**
*
*
* @param propertyName ...
* @param hash ...
*
* @return ...
*
* @throws EcmaScriptException ...
*/
public ESValue getProperty(String propertyName, int hash)
throws EcmaScriptException {
if ("status".equalsIgnoreCase(propertyName)) {
return new ESNumber(status);
}
return super.getProperty(propertyName, hash);
}
/**
*
*/
public void setText(ESValue val) throws Exception {
if (buffer == null) {
buffer = new StringBuffer();
}
if (val != null) {
buffer.append(val.toString());
}
}
/**
*
*
* @param val ...
*
* @throws Exception ...
* @throws IOException ...
*/
public void addPart(ESValue[] val) throws Exception {
if ((val == null) || (val.length == 0) || (val.length > 2)) {
throw new IOException("mail.addPart called with wrong number of arguments.");
}
if (multipart == null) {
multipart = new MimeMultipart();
}
MimeBodyPart part = new MimeBodyPart();
Object obj = val[0].toJavaObject();
if (obj instanceof String) {
part.setContent(obj.toString(), "text/plain");
} else if (obj instanceof File) {
FileDataSource source = new FileDataSource((File) obj);
part.setDataHandler(new DataHandler(source));
} else if (obj instanceof MimePart) {
MimePartDataSource source = new MimePartDataSource((MimePart) obj);
part.setDataHandler(new DataHandler(source));
}
// check if an explicit file name was given for this part
if (val.length == 2) {
try {
part.setFileName(val[1].toString());
} catch (Exception x) {
// FIXME: error setting file name ... should we ignore this or throw an exception?
}
}
multipart.addBodyPart(part);
}
/**
*
*
* @param val ...
*
* @throws Exception ...
*/
public void setSubject(ESValue val) throws Exception {
if (val == null) {
return;
}
message.setSubject(MimeUtility.encodeWord(val.toString()));
}
/**
*
*
* @param add ...
*
* @throws Exception ...
* @throws AddressException ...
*/
public void setReplyTo(ESValue add) throws Exception {
String addstring = add.toString();
if (addstring.indexOf("@") < 0) {
throw new AddressException();
}
Address[] replyTo = new Address[1];
replyTo[0] = new InternetAddress(addstring);
message.setReplyTo(replyTo);
}
/**
*
*
* @param add ...
*
* @throws Exception ...
* @throws AddressException ...
*/
public void setFrom(ESValue[] add) throws Exception {
String addstring = add[0].toString();
if (addstring.indexOf("@") < 0) {
throw new AddressException();
}
Address address = null;
if (add.length > 1) {
address = new InternetAddress(addstring,
MimeUtility.encodeWord(add[1].toString()));
} else {
address = new InternetAddress(addstring);
}
message.setFrom(address);
}
/**
*
*
* @param add ...
*
* @throws Exception ...
* @throws AddressException ...
*/
public void addTo(ESValue[] add) throws Exception {
String addstring = add[0].toString();
if (addstring.indexOf("@") < 0) {
throw new AddressException();
}
Address address = null;
if (add.length > 1) {
address = new InternetAddress(addstring,
MimeUtility.encodeWord(add[1].toString()));
} else {
address = new InternetAddress(addstring);
}
message.addRecipient(Message.RecipientType.TO, address);
}
/**
*
*
* @param add ...
*
* @throws Exception ...
* @throws AddressException ...
*/
public void addCC(ESValue[] add) throws Exception {
String addstring = add[0].toString();
if (addstring.indexOf("@") < 0) {
throw new AddressException();
}
Address address = null;
if (add.length > 1) {
address = new InternetAddress(addstring,
MimeUtility.encodeWord(add[1].toString()));
} else {
address = new InternetAddress(addstring);
}
message.addRecipient(Message.RecipientType.CC, address);
}
/**
*
*
* @param add ...
*
* @throws Exception ...
* @throws AddressException ...
*/
public void addBCC(ESValue[] add) throws Exception {
String addstring = add[0].toString();
if (addstring.indexOf("@") < 0) {
throw new AddressException();
}
Address address = null;
if (add.length > 1) {
address = new InternetAddress(addstring,
MimeUtility.encodeWord(add[1].toString()));
} else {
address = new InternetAddress(addstring);
}
message.addRecipient(Message.RecipientType.BCC, address);
}
/**
*
*
* @throws Exception ...
*/
public void send() throws Exception {
if (buffer != null) {
// if we also have a multipart body, add
// plain string as first part to it.
if (multipart != null) {
MimeBodyPart part = new MimeBodyPart();
part.setContent(buffer.toString(), "text/plain");
multipart.addBodyPart(part, 0);
message.setContent(multipart);
} else {
message.setText(buffer.toString());
}
} else if (multipart != null) {
message.setContent(multipart);
} else {
message.setText("");
}
Transport.send(message);
}
}

View file

@ -1,525 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.AST.*;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Extensions.*;
import FESI.Interpreter.*;
import FESI.Parser.*;
import com.oroinc.net.ftp.*;
import helma.objectmodel.*;
import java.io.*;
/**
* A FTP-client object that allows to do some FTP from HOP applications.
* FTP support is far from complete but can easily be extended if more
* functionality is needed.
* This uses the NetComponent classes from savarese.org (ex oroinc.com).
*/
class ESFtpClient extends ESObject {
private FTPClient ftpclient;
private String server;
private Exception lastError = null;
private File localDir = null;
/**
* Create a new FTP Client
*
* @param prototype The prototype object for the FTP object
* @param evaluator The current evaluator
*/
ESFtpClient(ESObject prototype, Evaluator evaluator, ESValue srvstr) {
super(prototype, evaluator);
this.server = srvstr.toString();
}
ESFtpClient(ESObject prototype, Evaluator evaluator) {
super(prototype, evaluator);
}
/**
*
*
* @return ...
*/
public String getESClassName() {
return "FtpClient";
}
/**
*
*
* @return ...
*/
public String toString() {
return "[FtpClient]";
}
/**
*
*
* @return ...
*/
public String toDetailString() {
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
this.toString() + "]";
}
ESValue getLastError() throws EcmaScriptException {
if (lastError == null) {
return ESNull.theNull;
} else {
return ESLoader.normalizeValue(lastError, evaluator);
}
}
/**
* Login to the FTP server
*
* @param arguments The argument list
* @return true if successful, false otherwise
*/
ESValue login(ESValue[] arguments) throws EcmaScriptException {
if (server == null) {
return ESBoolean.makeBoolean(false);
}
try {
ftpclient = new FTPClient();
ftpclient.connect(server);
boolean b = ftpclient.login(arguments[0].toString(), arguments[1].toString());
return ESBoolean.makeBoolean(b);
} catch (Exception x) {
return ESBoolean.makeBoolean(false);
} catch (NoClassDefFoundError x) {
return ESBoolean.makeBoolean(false);
}
}
ESValue cd(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESBoolean.makeBoolean(false);
}
try {
ftpclient.changeWorkingDirectory(arguments[0].toString());
return ESBoolean.makeBoolean(true);
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue mkdir(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESBoolean.makeBoolean(false);
}
try {
return ESBoolean.makeBoolean(ftpclient.makeDirectory(arguments[0].toString()));
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue lcd(ESValue[] arguments) throws EcmaScriptException {
try {
localDir = new File(arguments[0].toString());
if (!localDir.exists()) {
localDir.mkdirs();
}
return ESBoolean.makeBoolean(true);
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue putFile(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESBoolean.makeBoolean(false);
}
try {
String fn = arguments[0].toString();
File f = (localDir == null) ? new File(fn) : new File(localDir, fn);
InputStream fin = new BufferedInputStream(new FileInputStream(f));
ftpclient.storeFile(arguments[1].toString(), fin);
fin.close();
return ESBoolean.makeBoolean(true);
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue putString(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESBoolean.makeBoolean(false);
}
try {
byte[] bytes = null;
// check if this already is a byte array
if (arguments[0] instanceof ESArrayWrapper) {
Object o = ((ESArrayWrapper) arguments[0]).toJavaObject();
if (o instanceof byte[]) {
bytes = (byte[]) o;
}
}
if (bytes == null) {
bytes = arguments[0].toString().getBytes();
}
ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
ftpclient.storeFile(arguments[1].toString(), bin);
return ESBoolean.makeBoolean(true);
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue getFile(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESBoolean.makeBoolean(false);
}
try {
String fn = arguments[0].toString();
File f = (localDir == null) ? new File(fn) : new File(localDir, fn);
OutputStream out = new BufferedOutputStream(new FileOutputStream(f));
ftpclient.retrieveFile(arguments[0].toString(), out);
out.close();
return ESBoolean.makeBoolean(true);
} catch (Exception wrong) {
}
return ESBoolean.makeBoolean(false);
}
ESValue getString(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient == null) {
return ESNull.theNull;
}
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ftpclient.retrieveFile(arguments[0].toString(), bout);
return new ESString(bout.toString());
} catch (Exception wrong) {
}
return ESNull.theNull;
}
/**
* Disconnect from FTP server
*
* @param arguments The argument list
* @return true if successful, false otherwise
*/
ESValue logout(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient != null) {
try {
ftpclient.logout();
} catch (IOException ignore) {
}
try {
ftpclient.disconnect();
} catch (IOException ignore) {
}
}
return ESBoolean.makeBoolean(true);
}
ESValue binary(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient != null) {
try {
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
return ESBoolean.makeBoolean(true);
} catch (IOException ignore) {
}
}
return ESBoolean.makeBoolean(false);
}
ESValue ascii(ESValue[] arguments) throws EcmaScriptException {
if (ftpclient != null) {
try {
ftpclient.setFileType(FTP.ASCII_FILE_TYPE);
return ESBoolean.makeBoolean(true);
} catch (IOException ignore) {
}
}
return ESBoolean.makeBoolean(false);
}
}
/**
*
*/
public class FtpExtension extends Extension {
private transient Evaluator evaluator = null;
private ESObject esFtpPrototype = null;
/**
* Creates a new FtpExtension object.
*/
public FtpExtension() {
super();
}
/**
*
*
* @param evaluator ...
*
* @throws EcmaScriptException ...
*/
public void initializeExtension(Evaluator evaluator)
throws EcmaScriptException {
this.evaluator = evaluator;
GlobalObject go = evaluator.getGlobalObject();
ObjectPrototype op = (ObjectPrototype) evaluator.getObjectPrototype();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
esFtpPrototype = new ESFtpClient(op, evaluator);
ESObject globalFtpObject = new GlobalObjectFtpClient("FtpClient", evaluator, fp);
globalFtpObject.putHiddenProperty("prototype", esFtpPrototype);
globalFtpObject.putHiddenProperty("length", new ESNumber(1));
esFtpPrototype.putHiddenProperty("login",
new FtpClientLogin("login", evaluator, fp));
esFtpPrototype.putHiddenProperty("cd", new FtpClientCD("cd", evaluator, fp));
esFtpPrototype.putHiddenProperty("mkdir",
new FtpClientMKDIR("mkdir", evaluator, fp));
esFtpPrototype.putHiddenProperty("lcd", new FtpClientLCD("lcd", evaluator, fp));
esFtpPrototype.putHiddenProperty("putFile",
new FtpClientPutFile("putFile", evaluator, fp));
esFtpPrototype.putHiddenProperty("putString",
new FtpClientPutString("putString", evaluator, fp));
esFtpPrototype.putHiddenProperty("getFile",
new FtpClientGetFile("getFile", evaluator, fp));
esFtpPrototype.putHiddenProperty("getString",
new FtpClientGetString("getString", evaluator, fp));
esFtpPrototype.putHiddenProperty("logout",
new FtpClientLogout("logout", evaluator, fp));
esFtpPrototype.putHiddenProperty("binary",
new FtpClientBinary("binary", evaluator, fp));
esFtpPrototype.putHiddenProperty("ascii",
new FtpClientAscii("ascii", evaluator, fp));
go.putHiddenProperty("FtpClient", globalFtpObject);
}
class GlobalObjectFtpClient extends BuiltinFunctionObject {
GlobalObjectFtpClient(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = null;
if (arguments.length != 1) {
throw new EcmaScriptException("FtpClient requires 1 argument");
}
ftp = new ESFtpClient(esFtpPrototype, this.evaluator, arguments[0]);
return ftp;
}
}
class FtpClientLogin extends BuiltinFunctionObject {
FtpClientLogin(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.login(arguments);
}
}
class FtpClientCD extends BuiltinFunctionObject {
FtpClientCD(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.cd(arguments);
}
}
class FtpClientMKDIR extends BuiltinFunctionObject {
FtpClientMKDIR(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.mkdir(arguments);
}
}
class FtpClientLCD extends BuiltinFunctionObject {
FtpClientLCD(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.lcd(arguments);
}
}
class FtpClientPutFile extends BuiltinFunctionObject {
FtpClientPutFile(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.putFile(arguments);
}
}
class FtpClientPutString extends BuiltinFunctionObject {
FtpClientPutString(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.putString(arguments);
}
}
class FtpClientGetFile extends BuiltinFunctionObject {
FtpClientGetFile(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.getFile(arguments);
}
}
class FtpClientGetString extends BuiltinFunctionObject {
FtpClientGetString(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.getString(arguments);
}
}
class FtpClientLogout extends BuiltinFunctionObject {
FtpClientLogout(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.logout(arguments);
}
}
class FtpClientBinary extends BuiltinFunctionObject {
FtpClientBinary(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.binary(arguments);
}
}
class FtpClientAscii extends BuiltinFunctionObject {
FtpClientAscii(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESFtpClient ftp = (ESFtpClient) thisObject;
return ftp.ascii(arguments);
}
}
}

View file

@ -1,124 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Extensions.*;
import FESI.Interpreter.*;
import helma.image.*;
import helma.objectmodel.*;
import helma.util.*;
import java.awt.image.*;
import java.io.*;
import java.rmi.Naming;
import java.util.*;
/**
* Extension to do Image manipulation from HOP.
*/
public class ImageExtension extends Extension {
static ImageGenerator imggen;
protected Evaluator evaluator = null;
/**
* Creates a new ImageExtension object.
*/
public ImageExtension() {
super();
}
/**
* Called by the evaluator after the extension is loaded.
*/
public void initializeExtension(Evaluator evaluator)
throws EcmaScriptException {
this.evaluator = evaluator;
GlobalObject go = evaluator.getGlobalObject();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
ESObject image = new GlobalObjectImage("Image", evaluator, fp, this); // the Image constructor
go.putHiddenProperty("Image", image); // register the constructor for a Image object.
}
class GlobalObjectImage extends BuiltinFunctionObject {
ImageExtension imagex;
GlobalObjectImage(String name, Evaluator evaluator, FunctionPrototype fp,
ImageExtension imagex) {
super(fp, evaluator, name, 1);
this.imagex = imagex;
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
Object img = null;
try {
if (imggen == null) {
try {
imggen = new ImageGenerator();
} catch (UnsatisfiedLinkError noawt) {
System.err.println("Error creating Image: " + noawt);
}
}
if (arguments.length == 1) {
if (arguments[0] instanceof ESArrayWrapper) {
Object obj = ((ESArrayWrapper) arguments[0]).toJavaObject();
if (obj instanceof byte[]) {
img = imggen.createImage((byte[]) obj);
}
} else if (arguments[0] instanceof ESString) {
String imgurl = arguments[0].toString();
img = imggen.createPaintableImage(imgurl);
}
} else if (arguments.length == 2) {
if (arguments[0] instanceof ESWrapper &&
arguments[1] instanceof ESWrapper) {
// create a new image from an existing one and an image filter
Object image = arguments[0].toJavaObject();
Object filter = arguments[1].toJavaObject();
img = imggen.createPaintableImage((ImageWrapper) image,
(ImageFilter) filter);
} else if (arguments[0].isNumberValue() &&
arguments[1].isNumberValue()) {
img = imggen.createPaintableImage(arguments[0].toInt32(),
arguments[1].toInt32());
}
}
} catch (Exception error) {
System.err.println("Error creating Image: " + error);
}
if (img == null) {
throw new EcmaScriptException("Error creating image: Bad parameters or setup problem.");
}
return new ESWrapper(img, this.evaluator);
}
}
}

View file

@ -1,324 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Extensions.*;
import FESI.Interpreter.*;
import helma.util.*;
import java.io.*;
import java.util.*;
/**
* Extension to create and send mail messages via SMTP from HOP applications
*/
public class MailExtension extends Extension {
protected Evaluator eval = null;
protected ObjectPrototype esMailPrototype = null;
protected Properties mprops;
/**
* Creates a new MailExtension object.
*/
public MailExtension() {
super();
}
/**
*
*
* @param props ...
*/
public void setProperties(Properties props) {
this.mprops = props;
}
/**
* Called by the evaluator after the extension is loaded.
*/
public void initializeExtension(Evaluator evaluator)
throws EcmaScriptException {
this.eval = evaluator;
GlobalObject go = evaluator.getGlobalObject();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
ESObject op = evaluator.getObjectPrototype();
esMailPrototype = new ObjectPrototype(op, evaluator); // the Node prototype
ESObject mail = new GlobalObjectMail("Mail", evaluator, fp, this); // the Mail constructor
go.putHiddenProperty("Mail", mail); // register the constructor for a Mail object.
// methods for sending mail from JS...
ESObject p = new MailSetText("setText", evaluator, fp);
esMailPrototype.putHiddenProperty("setText", p);
esMailPrototype.putHiddenProperty("addText", p);
esMailPrototype.putHiddenProperty("addPart",
new MailAddPart("addPart", evaluator, fp));
esMailPrototype.putHiddenProperty("setSubject",
new MailSetSubject("setSubject", evaluator, fp));
esMailPrototype.putHiddenProperty("setReplyTo",
new MailSetReplyTo("setReplyTo", evaluator, fp));
esMailPrototype.putHiddenProperty("setFrom",
new MailSetFrom("setFrom", evaluator, fp));
p = new MailAddTo("addTo", evaluator, fp);
esMailPrototype.putHiddenProperty("addTo", p);
esMailPrototype.putHiddenProperty("setTo", p);
p = new MailAddCC("addCC", evaluator, fp);
esMailPrototype.putHiddenProperty("addCC", p);
esMailPrototype.putHiddenProperty("setCC", p);
p = new MailAddBCC("addBCC", evaluator, fp);
esMailPrototype.putHiddenProperty("addBCC", p);
esMailPrototype.putHiddenProperty("setBCC", p);
esMailPrototype.putHiddenProperty("send", new MailSend("send", evaluator, fp));
}
class GlobalObjectMail extends BuiltinFunctionObject {
MailExtension mailx;
GlobalObjectMail(String name, Evaluator evaluator, FunctionPrototype fp,
MailExtension mailx) {
super(fp, evaluator, name, 1);
this.mailx = mailx;
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = null;
if (arguments.length == 0) {
mail = new ESMail(mailx);
} else {
mail = new ESMail(mailx);
// should/could do something with extra arguments...
}
return mail;
}
}
class MailSetText extends BuiltinFunctionObject {
MailSetText(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
if (arguments.length == 1) {
try {
mail.setText(arguments[0]);
} catch (Exception x) {
mail.setStatus(ESMail.TEXT);
return ESBoolean.makeBoolean(false);
}
}
return ESBoolean.makeBoolean(true);
}
}
class MailAddPart extends BuiltinFunctionObject {
MailAddPart(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.addPart(arguments);
} catch (Exception x) {
mail.setStatus(ESMail.MIMEPART);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
class MailSetSubject extends BuiltinFunctionObject {
MailSetSubject(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
if (arguments.length == 1) {
try {
mail.setSubject(arguments[0]);
} catch (Exception x) {
mail.setStatus(ESMail.SUBJECT);
return ESBoolean.makeBoolean(false);
}
}
return ESBoolean.makeBoolean(true);
}
}
class MailSetReplyTo extends BuiltinFunctionObject {
MailSetReplyTo(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
if (arguments.length == 1) {
try {
mail.setReplyTo(arguments[0]);
} catch (Exception x) {
mail.setStatus(ESMail.REPLYTO);
return ESBoolean.makeBoolean(false);
}
}
return ESBoolean.makeBoolean(true);
}
}
class MailSetFrom extends BuiltinFunctionObject {
MailSetFrom(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.setFrom(arguments);
} catch (Exception x) {
mail.setStatus(ESMail.FROM);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
class MailAddTo extends BuiltinFunctionObject {
MailAddTo(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.addTo(arguments);
} catch (Exception x) {
mail.setStatus(ESMail.TO);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
class MailAddCC extends BuiltinFunctionObject {
MailAddCC(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.addCC(arguments);
} catch (Exception x) {
mail.setStatus(ESMail.CC);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
class MailAddBCC extends BuiltinFunctionObject {
MailAddBCC(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.addBCC(arguments);
} catch (Exception x) {
mail.setStatus(ESMail.BCC);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
class MailSend extends BuiltinFunctionObject {
MailSend(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESMail mail = (ESMail) thisObject;
try {
mail.send();
} catch (Exception x) {
evaluator.engine.getApplication().logEvent("Error sending mail: " + x);
mail.setStatus(ESMail.SEND);
return ESBoolean.makeBoolean(false);
}
return ESBoolean.makeBoolean(true);
}
}
}

View file

@ -1,182 +0,0 @@
/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2003 Helma Software. All Rights Reserved.
*
* $RCSfile$
* $Author$
* $Revision$
* $Date$
*/
package helma.scripting.fesi.extensions;
import FESI.Data.*;
import FESI.Exceptions.*;
import FESI.Extensions.*;
import FESI.Interpreter.*;
import helma.scripting.fesi.FesiEngine;
import org.apache.xmlrpc.*;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* An extension to transparently call and serve XML-RPC from the
* <a href=http://home.worldcom.ch/jmlugrin/fesi/>FESI EcmaScript</a> interpreter.
* The extension adds constructors for XML-RPC clients and servers to the Global Object.
* For more information on how to use this please look at the files <tt>server.es</tt> and
* <tt>client.es</tt> in the src/fesi directory of the distribution.
*
* All argument conversion is done automatically. Currently the following argument and return
* types are supported:
* <ul>
* <li> plain objects (with all properties returned by ESObject.getProperties ())
* <li> arrays
* <li> strings
* <li> date objects
* <li> booleans
* <li> integer and float numbers (long values are not supported!)
* </ul>
*
*/
public class XmlRpcExtension extends Extension {
Evaluator evaluator;
ESObject op;
/**
*
*
* @param evaluator ...
*
* @throws EcmaScriptException ...
*/
public void initializeExtension(Evaluator evaluator)
throws EcmaScriptException {
// XmlRpc.setDebug (true);
this.evaluator = evaluator;
GlobalObject go = evaluator.getGlobalObject();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
op = evaluator.getObjectPrototype();
go.putHiddenProperty("Remote", new GlobalObjectRemote("Remote", evaluator, fp)); // the Remote constructor
}
class GlobalObjectRemote extends BuiltinFunctionObject {
GlobalObjectRemote(String name, Evaluator evaluator, FunctionPrototype fp) {
super(fp, evaluator, name, 1);
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments)
throws EcmaScriptException {
ESObject remote = null;
String url = null;
String robj = null;
if (arguments.length >= 1) {
url = arguments[0].toString();
}
if (arguments.length >= 2) {
robj = arguments[1].toString();
}
try {
remote = new ESRemote(op, this.evaluator, url, robj);
} catch (MalformedURLException x) {
throw new EcmaScriptException(x.toString());
}
return remote;
}
}
class ESRemote extends ObjectPrototype {
URL url;
String remoteObject;
public ESRemote(ESObject prototype, Evaluator evaluator, String urlstring,
String robj) throws MalformedURLException {
super(prototype, evaluator);
this.url = new URL(urlstring);
remoteObject = robj;
}
public ESRemote(ESObject prototype, Evaluator evaluator, URL url, String robj) {
super(prototype, evaluator);
this.url = url;
remoteObject = robj;
}
public ESValue doIndirectCall(Evaluator evaluator, ESObject target,
String functionName, ESValue[] arguments)
throws EcmaScriptException, NoSuchMethodException {
// System.out.println ("doIndirectCall called with "+remoteObject+"."+functionName);
XmlRpcClient client = new XmlRpcClient(url);
// long now = System.currentTimeMillis ();
Object retval = null;
int l = arguments.length;
Vector v = new Vector();
for (int i = 0; i < l; i++) {
Object arg = FesiEngine.processXmlRpcResponse(arguments[i]);
// System.out.println ("converted to J: "+arg.getClass ());
v.addElement(arg);
}
// System.out.println ("spent "+(System.currentTimeMillis ()-now)+" millis in argument conversion");
ESObject esretval = ObjectObject.createObject(evaluator);
try {
String method = (remoteObject == null) ? functionName
: (remoteObject + "." +
functionName);
retval = client.execute(method, v);
esretval.putProperty("error", ESNull.theNull, "error".hashCode());
esretval.putProperty("result",
FesiEngine.processXmlRpcArgument(retval, evaluator),
"result".hashCode());
} catch (Exception x) {
String msg = x.getMessage();
if ((msg == null) || (msg.length() == 0)) {
msg = x.toString();
}
esretval.putProperty("error", new ESString(msg), "error".hashCode());
esretval.putProperty("result", ESNull.theNull, "result".hashCode());
}
return esretval;
}
public ESValue getProperty(String name, int hash)
throws EcmaScriptException {
ESValue sprop = super.getProperty(name, hash);
if ((sprop != ESUndefined.theUndefined) && (sprop != ESNull.theNull)) {
return sprop;
}
String newRemoteObject = (remoteObject == null) ? name
: (remoteObject + "." + name);
return new ESRemote(op, this.evaluator, url, newRemoteObject);
}
}
}