Java Script executeScript(String script)

Here you can find the source of executeScript(String script)

Description

execute Script

License

Open Source License

Declaration

public static Object executeScript(String script) throws ScriptException 

Method Source Code

//package com.java2s;
/**/*from  w ww.j a  v a 2 s  . co  m*/
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {
    private static ScriptEngine _appleScriptEngine;
    private static ScriptEngineManager _scriptEngineManager;

    public static Object executeScript(String script) throws ScriptException {
        if (_appleScriptEngine == null) {
            _scriptEngineManager = new ScriptEngineManager();

            _appleScriptEngine = _scriptEngineManager.getEngineByName("AppleScriptEngine");

            if (_appleScriptEngine == null) {
                _appleScriptEngine = _scriptEngineManager.getEngineByName("AppleScript");

                if (_appleScriptEngine == null) {
                    throw new ScriptException("AppleScriptEngine not available");
                }
            }
        }

        return _appleScriptEngine.eval(script, _appleScriptEngine.getContext());
    }
}

Related

  1. eval(String name, Map params)
  2. eval(String script)
  3. evaluateExpression(String expr)
  4. evaluateExpression(String s)
  5. executeAppleScript(String script)
  6. executeScript(String strScript)
  7. fillStringCollection(ScriptObjectMirror som, Collection collection)
  8. generateToken(String val)
  9. getBallerinaFromJsonModel(String jsonModel)