All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jopendocument.dom.template.engine.RhinoTemplateScriptEngine Maven / Gradle / Ivy

Go to download

jOpenDocument is a free library for developers looking to use Open Document files without OpenOffice.org.

The newest version!
package org.jopendocument.dom.template.engine;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class RhinoTemplateScriptEngine extends DataModel {
    private Context cx;
    private Scriptable scope;

    public RhinoTemplateScriptEngine() {
        cx = ContextFactory.getGlobal().enterContext();
        scope = cx.initStandardObjects();
    }

    @Override
    protected Object _eval(String script) {
        return Context.jsToJava(cx.evaluateString(scope, script, "", 1, null), Object.class);
    }

    @Override
    public void put(String key, Object value) {
        Object jsObj = Context.javaToJS(value, scope);
        ScriptableObject.putProperty(scope, key, jsObj);
    }

    @Override
    public DataModel copy() {
        throw new UnsupportedOperationException();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy