01: package freemarker.ext.rhino;
02:
03: import org.mozilla.javascript.Scriptable;
04: import org.mozilla.javascript.Undefined;
05: import org.mozilla.javascript.UniqueTag;
06:
07: import freemarker.ext.beans.BeansWrapper;
08: import freemarker.template.TemplateModel;
09: import freemarker.template.TemplateModelException;
10:
11: /**
12: * <p><font color="red">Experimental: no backward compatibility guarantees</font>;
13: * any feedback is highly welcome!</p>
14: *
15: * @author Attila Szegedi
16: * @version $Id: RhinoWrapper.java,v 1.2.2.1 2006/07/31 11:34:52 szegedia Exp $
17: */
18: public class RhinoWrapper extends BeansWrapper {
19:
20: public TemplateModel wrap(Object obj) throws TemplateModelException {
21: if (obj instanceof Scriptable) {
22: return getInstance(obj, RhinoScriptableModel.FACTORY);
23: }
24: // So our existence builtins work as expected.
25: if (obj == Undefined.instance || obj == UniqueTag.NOT_FOUND
26: || obj == UniqueTag.NULL_VALUE) {
27: return null;
28: }
29: return super.wrap(obj);
30: }
31: }
|