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

org.zodiac.script.engine.js.JavaScriptEngine Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.script.engine.js;

import org.zodiac.commons.crypto.Md5;
import org.zodiac.commons.util.Strings;
import org.zodiac.script.engine.common.CommonScriptEngine;

import javax.script.CompiledScript;

public class JavaScriptEngine extends CommonScriptEngine {

    @Override
    public String getScriptName() {
        return "javascript";
    }

    @Override
    public boolean compile(String id, String code) throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("compile {} {} : {}", getScriptName(), id, code);
        }
        if (compilable == null)
            init();
        CompiledScript compiledScript = compilable.compile(Strings.concat("(function(){", code, "\n})();"));
        CommonScriptContext scriptContext = new CommonScriptContext(id, Md5.md5Hex(code), compiledScript);
        scriptBase.put(id, scriptContext);
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy