Package org.scotlandyard.engine.json

Source Code of org.scotlandyard.engine.json.JavaScriptEngine

package org.scotlandyard.engine.json;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
/**
* <p>java script engine ,used to evaluate javascript as if it is in the browser</p>
* @author Hussain Al-Mutawa
* @version 2.0
* @since Sun Sep 23, 2011
*/
public class JavaScriptEngine {
  /**
   * evaluates a javascript string
   *
   * @param jscript the script to be evaluated
   * @return the return type made by javascript
   * @throws ScriptException if the script is not valid javascript text
   */
  public static Object eval(String jscript) throws ScriptException{
    final ScriptEngineManager manager = new ScriptEngineManager();
      final ScriptEngine engine = manager.getEngineByName("js");
      return engine.eval(jscript);
  }
}
TOP

Related Classes of org.scotlandyard.engine.json.JavaScriptEngine

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.