当前位置: 首页>>代码示例>>Java>>正文


Java ScriptEngineManager.getEngineByExtension方法代码示例

本文整理汇总了Java中javax.script.ScriptEngineManager.getEngineByExtension方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptEngineManager.getEngineByExtension方法的具体用法?Java ScriptEngineManager.getEngineByExtension怎么用?Java ScriptEngineManager.getEngineByExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.script.ScriptEngineManager的用法示例。


在下文中一共展示了ScriptEngineManager.getEngineByExtension方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test6

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
@Test
    public void test6() throws Exception {
        Document document = Jsoup.parse(FileUtils.readFileToString(new File("/Users/eddy/Desktop/content")));
        Elements elements = document.getElementsByTag("script");
//        String result = elements.stream().filter(e -> e.data().contains("globalRepeatSubmitToken") && e.childNodes().size() > 0)
//                .findFirst().map(e -> e.childNode(0).outerHtml()).orElse(StringUtils.EMPTY);

        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");
//        engine.eval(result);
//        Object o = engine.get("globalRepeatSubmitToken");
//        System.out.println(o);

//        ticketInfoForPassengerForm
        String ticketInfo = elements.stream().filter(e -> e.data().contains("ticketInfoForPassengerForm") && e.childNodes().size() > 0)
                .findFirst().map(e -> e.childNode(0).outerHtml()).orElse(StringUtils.EMPTY);
        ticketInfo = ticketInfo.substring(0, ticketInfo.lastIndexOf("var"));
        engine.eval(ticketInfo);
        ScriptObjectMirror o2 = (ScriptObjectMirror) engine.get("ticketInfoForPassengerForm");
        System.out.println(o2.get("purpose_codes"));

    }
 
开发者ID:justice-code,项目名称:Thrush,代码行数:23,代码来源:LoginTest.java

示例2: DefaultJavaScriptEngine

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public DefaultJavaScriptEngine(Console console, WebService webService) {
    this.console = console;
    this.webService = webService;
    ScriptEngineManager engineManager = new ScriptEngineManager();
    engine = engineManager.getEngineByExtension("js");
    if (engine == null) {
        LOGGER.warn("No JavaScript engine available!");
        scriptContext = null;
        references = null;
    } else {
        scriptContext = new ScriptCtx(console);
        engine.setContext(scriptContext);
        try {
            engine.eval(INIT_JS);
        } catch (ScriptException e) {
            throw new IllegalStateException("Could not run initialization js: " + INIT_JS, e);
        }
        references = new HashMap<>();
        references.put("console", new JavaScriptConsole());
        references.put("webService", new JavaScriptWebService());
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:23,代码来源:DefaultJavaScriptEngine.java

示例3: getToken

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public static String getToken(String html) throws ScriptException {
    Document document = Jsoup.parse(html);

    Elements elements = document.getElementsByTag("script");
    String jsContent = elements.stream().filter(e -> e.data().contains("globalRepeatSubmitToken") && e.childNodes().size() > 0)
            .findFirst().map(e -> e.childNode(0).outerHtml()).orElse(StringUtils.EMPTY);

    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");
    engine.eval(jsContent);
    return (String) engine.get("globalRepeatSubmitToken");
}
 
开发者ID:justice-code,项目名称:Thrush,代码行数:13,代码来源:TokenUtil.java

示例4: getTicketInfoForPassengerForm

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
private static String getTicketInfoForPassengerForm(String html, String key) throws ScriptException {
    Document document = Jsoup.parse(html);

    Elements elements = document.getElementsByTag("script");
    String jsContent = elements.stream().filter(e -> e.data().contains("ticketInfoForPassengerForm") && e.childNodes().size() > 0)
            .findFirst().map(e -> e.childNode(0).outerHtml()).orElse(StringUtils.EMPTY);
    jsContent = jsContent.substring(0, jsContent.lastIndexOf("var"));

    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");
    engine.eval(jsContent);
    ScriptObjectMirror objectMirror = (ScriptObjectMirror) engine.get("ticketInfoForPassengerForm");
    return (String) objectMirror.get(key);
}
 
开发者ID:justice-code,项目名称:Thrush,代码行数:15,代码来源:TokenUtil.java

示例5: createScriptEngine

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
/**
 * Create a {@link ScriptEngine} according to extension of script specified in
 * {@link getScriptFile()}
 * @param manager
 * @return Correct script engine for script file.
 */
@Override
protected ScriptEngine createScriptEngine(ScriptEngineManager manager) {
    String scriptExtension = getExt(getScriptFile());

    return manager.getEngineByExtension(scriptExtension);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:13,代码来源:FileScriptLogic.java

示例6: execute

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
private void execute(final String scriptFileName, final String engineName)
		throws ScriptException, FileNotFoundException {
	final ScriptEngineManager factory = new ScriptEngineManager();
	final ScriptEngine engine;
	if (engineName != null && engineName.length() > 0) {
		engine = factory.getEngineByName(engineName);
	} else {
		engine = factory
				.getEngineByExtension(getExtensionFrom(scriptFileName));
	}
	Reader scriptFileReade = new FileReader(new File(scriptFileName));
	engine.eval(scriptFileReade);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-By-Example,代码行数:14,代码来源:Processor.java

示例7: LessCSSLoader

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public LessCSSLoader() {
    ScriptEngineManager mgr = new ScriptEngineManager();
    engine = mgr.getEngineByExtension("js");

    try {
        engine.eval(createParserScript());
    } catch (ScriptException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:11,代码来源:LessCSSLoader.java

示例8: scriptingSafe

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public static void scriptingSafe() throws ScriptException {

        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine scriptEngine = scriptEngineManager.getEngineByExtension("js");

        String code = "var test=3;test=test*2;";
        Object result = scriptEngine.eval(code);
    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:9,代码来源:ScriptEngineSample.java

示例9: scripting

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public static void scripting(String userInput) throws ScriptException {

        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine scriptEngine = scriptEngineManager.getEngineByExtension("js");

        Object result = scriptEngine.eval("test=1;" + userInput);

    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:9,代码来源:ScriptEngineSample.java

示例10: main

import javax.script.ScriptEngineManager; //导入方法依赖的package包/类
public static void main(String ... args) throws ScriptException {
    ScriptEngineManager manager = new ScriptEngineManager();

    for (ScriptEngineFactory f : manager.getEngineFactories()) {
        System.out.println(f.getEngineName() + " -> " + f.getLanguageName() + " (" + String.join(", ", f.getExtensions()) + ")");
    }

    System.out.println("");

    ScriptEngine python_engine;
    ScriptEngine javascript_engine;
    ScriptEngine lua_engine;

    long start_time;
    long end_time;

    System.out.println("Testing Python interpreter...");

    python_engine = manager.getEngineByExtension("py");
    start_time = System.currentTimeMillis();

    python_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");

    System.out.println("Testing JavaScript interpreter...");

    javascript_engine = manager.getEngineByExtension("js");
    start_time = System.currentTimeMillis();

    javascript_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");

    System.out.println("Testing Lua interpreter...");

    lua_engine = manager.getEngineByExtension("lua");
    start_time = System.currentTimeMillis();

    lua_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");
}
 
开发者ID:ScriptyMod,项目名称:Scripty,代码行数:47,代码来源:ScriptTest.java


注:本文中的javax.script.ScriptEngineManager.getEngineByExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。