本文整理汇总了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"));
}
示例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());
}
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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");
}