use of javax.script.ScriptEngineManager in project opennms by OpenNMS.
the class OSGiScriptEngineManager method getEngineByMimeType.
public ScriptEngine getEngineByMimeType(String mimeType) {
// TODO this is a hack to deal with context class loader issues
ScriptEngine engine = null;
for (ScriptEngineManager manager : classLoaders.keySet()) {
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
engine = manager.getEngineByMimeType(mimeType);
Thread.currentThread().setContextClassLoader(old);
if (engine != null)
break;
}
return engine;
}
use of javax.script.ScriptEngineManager in project jgnash by ccavanaugh.
the class ExecuteJavaScriptAction method showAndWait.
public static void showAndWait() {
final ResourceBundle resources = ResourceUtils.getBundle();
final FileChooser fileChooser = configureFileChooser();
fileChooser.setTitle(resources.getString("Title.SelFile"));
final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
if (file != null) {
Preferences pref = Preferences.userNodeForPackage(ExecuteJavaScriptAction.class);
pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
Platform.runLater(() -> {
try (final Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
new ScriptEngineManager().getEngineByName("nashorn").eval(reader);
} catch (IOException | ScriptException ex) {
Logger.getLogger(ExecuteJavaScriptAction.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
});
}
}
use of javax.script.ScriptEngineManager in project jgnash by ccavanaugh.
the class RunJavaScriptAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final Preferences pref = Preferences.userNodeForPackage(RunJavaScriptAction.class);
JFileChooser chooser = new JFileChooser(pref.get(JAVASCRIPT_DIR, null));
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
pref.put(JAVASCRIPT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
final Path path = chooser.getSelectedFile().toPath();
EventQueue.invokeLater(() -> {
try (final Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
new ScriptEngineManager().getEngineByName("nashorn").eval(reader);
} catch (IOException | ScriptException ex) {
Logger.getLogger(RunJavaScriptAction.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
});
}
}
use of javax.script.ScriptEngineManager in project hazelcast by hazelcast.
the class OSGiScriptEngineManager method createScriptEngineManagerInfo.
private ScriptEngineManagerInfo createScriptEngineManagerInfo(String factoryName, ClassLoader factoryLoader) {
try {
ScriptEngineManager manager = new ScriptEngineManager(factoryLoader);
manager.setBindings(bindings);
return new ScriptEngineManagerInfo(manager, factoryLoader);
} catch (Exception e) {
// May fail if script implementation is not in environment
logger.warning("Found ScriptEngineFactory candidate for " + factoryName + ", but could not load ScripEngineManager! -> " + e);
if (logger.isFinestEnabled()) {
logger.finest(e);
}
return null;
}
}
use of javax.script.ScriptEngineManager in project cryptomator by cryptomator.
the class ExitUtil method showTrayNotification.
private void showTrayNotification(TrayIcon trayIcon) {
int remainingTrayNotification = settings.numTrayNotifications().get();
if (remainingTrayNotification <= 0) {
return;
} else {
settings.numTrayNotifications().set(remainingTrayNotification - 1);
}
final Runnable notificationCmd;
if (SystemUtils.IS_OS_MAC_OSX) {
final String title = localization.getString("tray.infoMsg.title");
final String msg = localization.getString("tray.infoMsg.msg.osx");
final String notificationCenterAppleScript = String.format("display notification \"%s\" with title \"%s\"", msg, title);
notificationCmd = () -> {
try {
final ScriptEngineManager mgr = new ScriptEngineManager();
final ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine");
if (engine != null) {
engine.eval(notificationCenterAppleScript);
} else {
Runtime.getRuntime().exec(new String[] { "/usr/bin/osascript", "-e", notificationCenterAppleScript });
}
} catch (ScriptException | IOException e) {
// ignore, user will notice the tray icon anyway.
}
};
} else {
final String title = localization.getString("tray.infoMsg.title");
final String msg = localization.getString("tray.infoMsg.msg");
notificationCmd = () -> {
trayIcon.displayMessage(title, msg, MessageType.INFO);
};
}
SwingUtilities.invokeLater(() -> {
notificationCmd.run();
});
}
Aggregations