List of usage examples for javax.script ScriptEngineFactory getEngineName
public String getEngineName();
ScriptEngine
. From source file:ca.hedlund.jiss.preprocessor.LangPreprocessor.java
private void printLangs(JissModel model, StringBuffer cmd) { final ScriptEngineManager manager = new ScriptEngineManager(JissModel.class.getClassLoader()); final List<String> cmds = new ArrayList<String>(); for (ScriptEngineFactory factory : manager.getEngineFactories()) { final String engineInfo = factory.getLanguageName() + " " + factory.getLanguageVersion() + ":" + factory.getEngineName() + " " + factory.getEngineVersion(); cmds.add(createPrintCmd(model, engineInfo)); }//ww w.j a v a2 s . c om final ScriptEngineFactory factory = model.getScriptEngine().getFactory(); final String prog = StringEscapeUtils.unescapeJava(factory.getProgram(cmds.toArray(new String[0]))); cmd.append(prog); }
From source file:ca.hedlund.jiss.preprocessor.LangPreprocessor.java
private void printCurrentLang(JissModel model, StringBuffer cmd) { final List<String> cmds = new ArrayList<String>(); final ScriptEngineFactory factory = model.getScriptEngine().getFactory(); final String engineInfo = factory.getLanguageName() + " " + factory.getLanguageVersion() + ":" + factory.getEngineName() + " " + factory.getEngineVersion(); cmds.add(createPrintCmd(model, engineInfo)); final String prog = StringEscapeUtils.unescapeJava(factory.getProgram(cmds.toArray(new String[0]))); cmd.append(prog);/*from ww w. ja va2 s .c o m*/ }
From source file:org.pentaho.platform.plugin.condition.scriptable.ScriptableCondition.java
public void setListAvailableEngines(final boolean value) { this.listAvailableEngines = value; if (value) {// w w w. j a v a 2 s . c o m System.out.println("*** DEBUG - Display Script Engine List ***"); ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : factories) { System.out.println(String.format("Engine %s, Version %s, Language %s, Registered Names: %s", factory.getEngineName(), factory.getEngineVersion(), factory.getLanguageName(), factory.getNames().toString())); } } }
From source file:org.apache.accumulo.core.util.shell.commands.ScriptCommand.java
private void listJSREngineInfo(ScriptEngineManager mgr, Shell shellState) throws IOException { List<ScriptEngineFactory> factories = mgr.getEngineFactories(); Set<String> lines = new TreeSet<String>(); for (ScriptEngineFactory factory : factories) { lines.add("ScriptEngineFactory Info"); String engName = factory.getEngineName(); String engVersion = factory.getEngineVersion(); String langName = factory.getLanguageName(); String langVersion = factory.getLanguageVersion(); lines.add("\tScript Engine: " + engName + " (" + engVersion + ")"); List<String> engNames = factory.getNames(); for (String name : engNames) { lines.add("\tEngine Alias: " + name); }/* w w w. j ava 2 s . co m*/ lines.add("\tLanguage: " + langName + " (" + langVersion + ")"); } shellState.printLines(lines.iterator(), true); }
From source file:org.apache.felix.webconsole.plugins.scriptconsole.internal.ScriptEngineManager.java
private Collection<?> registerFactory(final EngineManagerState mgr, final ScriptEngineFactory factory, final Map<Object, Object> props) { log.log(LogService.LOG_INFO,/* w w w . ja v a 2s. c o m*/ String.format("Adding ScriptEngine %s, %s for language %s, %s", factory.getEngineName(), factory.getEngineVersion(), factory.getLanguageName(), factory.getLanguageVersion())); mgr.factories.add(factory); mgr.factoryProperties.put(factory, props); for (Object ext : factory.getExtensions()) { mgr.extensionAssociations.put((String) ext, factory); } return factory.getExtensions(); }
From source file:ca.hedlund.jiss.preprocessor.InfoPreprocessor.java
@Override public boolean preprocessCommand(JissModel jissModel, String orig, StringBuffer cmd) { final String c = cmd.toString(); if (c.equals(INFO_CMD)) { // clear string cmd.setLength(0);/*w ww . j a v a2s . c o m*/ final ScriptEngine se = jissModel.getScriptEngine(); final ScriptEngineFactory seFactory = se.getFactory(); final boolean incnl = !seFactory.getOutputStatement("").startsWith("println"); final String infoCmd = seFactory.getOutputStatement(INFO_TXT + (incnl ? "\\n" : "")); final String langCmd = seFactory.getOutputStatement("Language:" + seFactory.getLanguageName() + " " + seFactory.getLanguageVersion() + (incnl ? "\\n" : "")); final String engineCmd = seFactory.getOutputStatement("Engine:" + seFactory.getEngineName() + " " + seFactory.getEngineVersion() + (incnl ? "\\n" : "")); final String program = seFactory.getProgram(infoCmd, langCmd, engineCmd); cmd.append(StringEscapeUtils.unescapeJava(program)); } // we want the scripting engine to handle the replaced command return false; }
From source file:com.aionemu.commons.scripting.AionScriptEngineManager.java
private AionScriptEngineManager() { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); if (USE_COMPILED_CACHE) { _cache = loadCompiledScriptCache(); } else {// w w w .j a v a 2 s.com _cache = null; } log.info("Initializing Script Engine Manager"); for (ScriptEngineFactory factory : factories) { try { log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " " + factory.getLanguageVersion()); ScriptEngine engine = factory.getScriptEngine(); for (String name : factory.getNames()) { if (_nameEngines.containsKey(name)) throw new IllegalStateException("Multiple script engines for the same name!"); _nameEngines.put(name, engine); } for (String ext : factory.getExtensions()) { if (_extEngines.containsKey(ext)) throw new IllegalStateException("Multiple script engines for the same extension!"); _extEngines.put(ext, engine); } } catch (Exception e) { log.warn("Failed initializing factory.", e); } } }
From source file:com.l2jfree.gameserver.scripting.L2ScriptEngineManager.java
private L2ScriptEngineManager() { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); if (USE_COMPILED_CACHE) { _cache = loadCompiledScriptCache(); } else {//from w w w .jav a2 s . c o m _cache = null; } _log.info("Initializing Script Engine Manager"); for (ScriptEngineFactory factory : factories) { try { _log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " " + factory.getLanguageVersion()); ScriptEngine engine = factory.getScriptEngine(); for (String name : factory.getNames()) { if (_nameEngines.containsKey(name)) throw new IllegalStateException("Multiple script engines for the same name!"); _nameEngines.put(name, engine); } for (String ext : factory.getExtensions()) { if (_extEngines.containsKey(ext)) throw new IllegalStateException("Multiple script engines for the same extension!"); _extEngines.put(ext, engine); } } catch (Exception e) { _log.warn("Failed initializing factory.", e); } } preConfigure(); }
From source file:sample.fa.ScriptRunnerApplication.java
void createGUI() { Box buttonBox = Box.createHorizontalBox(); JButton loadButton = new JButton("Load"); loadButton.addActionListener(this::loadScript); buttonBox.add(loadButton);// w w w.j a v a2 s . c o m JButton saveButton = new JButton("Save"); saveButton.addActionListener(this::saveScript); buttonBox.add(saveButton); JButton executeButton = new JButton("Execute"); executeButton.addActionListener(this::executeScript); buttonBox.add(executeButton); languagesModel = new DefaultComboBoxModel(); ScriptEngineManager sem = new ScriptEngineManager(); for (ScriptEngineFactory sef : sem.getEngineFactories()) { languagesModel.addElement(sef.getScriptEngine()); } JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel); JLabel languageLabel = new JLabel(); languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index, boolean isSelected, boolean cellHasFocus) -> { ScriptEngineFactory sef = se.getFactory(); languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*." + String.join(", *.", sef.getExtensions()) + ")"); return languageLabel; }); buttonBox.add(Box.createHorizontalGlue()); buttonBox.add(languagesCombo); scriptContents = new JTextArea(); scriptContents.setRows(8); scriptContents.setColumns(40); scriptResults = new JTextArea(); scriptResults.setEditable(false); scriptResults.setRows(8); scriptResults.setColumns(40); JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults); JFrame frame = new JFrame("Script Runner"); frame.add(buttonBox, BorderLayout.NORTH); frame.add(jsp, BorderLayout.CENTER); frame.pack(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); }
From source file:org.jahia.utils.ScriptEngineUtils.java
/** * Determines whether the specified {@link ScriptEngineFactory} supports at least one of the script names * declared by the given OSGi headers assuming they provide a value for the * {@link BundleScriptingConfigurationConstants#JAHIA_MODULE_SCRIPTING_VIEWS} header. * * @param scriptFactory the ScriptEngineFactory whose support for views defined in the specified bundle is to be * determined/* www . j ava 2s . c o m*/ * @param headers the OSGi headers to be checked if declared view technologies defined by the {@link * BundleScriptingConfigurationConstants#JAHIA_MODULE_SCRIPTING_VIEWS} OSGI header are * supported by the specified ScriptEngineFactory * @return {@code true} if the specified ScriptEngineFactory can handle at least one of the specified script names, * {@code false} otherwise. Note that if the headers contain the {@link BundleScriptingConfigurationConstants#JAHIA_MODULE_HAS_VIEWS} * header with a "{@code no}" value, we won't look at other headers since the module has indicated that it shouldn't * contain any views so the factory shouldn't attempt to process any it might find. */ public static boolean canFactoryProcessViews(ScriptEngineFactory scriptFactory, Dictionary<String, String> headers) { if (scriptFactory == null) { throw new IllegalArgumentException("ScriptEngineFactory is null"); } if (headers != null) { final String hasViews = headers.get(BundleScriptingConfigurationConstants.JAHIA_MODULE_HAS_VIEWS); if ("no".equalsIgnoreCase(StringUtils.trim(hasViews))) { // if the bundle indicated that it doesn't provide views, the factory shouldn't process it regardless // of other configuration return false; } else { final String commaSeparatedScriptNames = headers .get(BundleScriptingConfigurationConstants.JAHIA_MODULE_SCRIPTING_VIEWS); // check if the bundle provided a list of of comma-separated scripting language names for the views it provides // the bundle should only be scanned if it defined the header and the header contains the name or language of the factory associated with the extension final String[] split = StringUtils.split(commaSeparatedScriptNames, ','); if (split != null) { // check extensions final List<String> extensions = scriptFactory.getExtensions(); List<String> scriptNames = new ArrayList<>(split.length); for (String scriptName : split) { String script = scriptName.trim().toLowerCase(); scriptNames.add(script); if (extensions.contains(script)) { return true; } } return scriptNames.contains(scriptFactory.getEngineName().trim().toLowerCase()) || scriptNames.contains(scriptFactory.getLanguageName().trim().toLowerCase()); } } } return false; }