Package com.scratchdisk.script

Examples of com.scratchdisk.script.ScriptEngine


   * Loads and executes a set of JavaScript source files in the current scope.
   */
  public static void include(Context cx, Scriptable thisObj, Object[] args,
      Function funObj) throws Exception {
    File baseDir = getDirectory(thisObj);
    ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
    for (int i = 0; i < args.length; i++) {
      File file = new File(baseDir, Context.toString(args[i]));
      executeScript(engine.compile(file), engine.getScope(thisObj));
    }
  }
View Full Code Here


   * scope.
   */
  public static void execute(Context cx, Scriptable thisObj, Object[] args,
      Function funObj) throws Exception {
    File baseDir = getDirectory(thisObj);
    ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
    for (int i = 0; i < args.length; i++) {
      File file = new File(baseDir, Context.toString(args[i]));
      executeScript(engine.compile(file), engine.createScope());
    }
  }
View Full Code Here

   * obj.eval("print(this);");
   * </code>
   */
  public static void evaluate(Context cx, Scriptable thisObj, Object[] args,
      Function funObj) {
    ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
    engine.evaluate(Context.toString(args[0]), "evaluate",
        engine.getScope(thisObj));
  }
View Full Code Here

        // types and pass the result to a Java Json engine. The conversion
        // could be enforced through various conversion methods with different
        // argument types. But this will do for now, at least as long as there
        // are no other engines.
        try {
          ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
          Context cx = Context.getCurrentContext();
          Object json = NativeJSON.parse(cx,
              ((RhinoScope) engine.getGlobalScope()).getScope(),
              value.toString());
          if (json != null)
            return json;
        } catch (Exception e) {
        }
View Full Code Here

    } else if (value instanceof Double || value instanceof Float) {
      prefs.putDouble(keyStr, ((Number) value).doubleValue());
    } else if (value instanceof Number) {
      prefs.putLong(keyStr, ((Number) value).longValue());
    } else if (value instanceof Scriptable) {
      ScriptEngine engine = ScriptEngine.getEngineByName("JavaScript");
      Context cx = Context.getCurrentContext();
      Object json = NativeJSON.stringify(cx,
          ((RhinoScope) engine.getGlobalScope()).getScope(), value,
          null, null);
      prefs.put(keyStr, json  != null ? json.toString() : "null");
    } else if (value instanceof String) {
      prefs.put(keyStr, value.toString());
    }
View Full Code Here

        if (file.isDirectory() && !name.startsWith(".")
            && !name.equals("CVS")) {
          compileInitScripts(file);
        } else if (name.startsWith("__init__")) {
          try {
            ScriptEngine engine =
                ScriptEngine.getEngineByFile(file);
            if (engine == null)
              throw new ScriptException(
                  "Unable to find script engine for " + file);
            execute(file, engine.createScope());
          } catch (Exception e) {
            reportError(e);
          }
        }
      }
View Full Code Here

        if (file.isDirectory() && !name.startsWith(".")
            && !name.equals("CVS")) {
          loadLibraries(file);
        } else {
          try {
            ScriptEngine engine =
                ScriptEngine.getEngineByFile(file);
            if (engine != null)
              execute(file, engine.getGlobalScope());
          } catch (Exception e) {
            reportError(e);
          }
        }
      }
View Full Code Here

   * @throws ScriptException
   * @throws IOException
   */
  public static com.scratchdisk.script.Script compile(File file)
      throws ScriptException, IOException {
    ScriptEngine engine = ScriptEngine.getEngineByFile(file);
    if (engine == null)
      throw new ScriptException("Unable to find script engine for " + file);
    com.scratchdisk.script.Script script = engine.compile(file);
    if (script == null)
      throw new ScriptException("Unable to compile script " + file);
    return script;
  }
View Full Code Here

TOP

Related Classes of com.scratchdisk.script.ScriptEngine

Copyright © 2018 www.massapicom. 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.