List of usage examples for javax.script ScriptEngineFactory getLanguageName
public String getLanguageName();
ScriptEngine
. 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);/*from w w w . j av a2 s. co 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.pentaho.reporting.ui.datasources.pmd.PmdDataSourceEditor.java
private String mapLanguageToSyntaxHighlighting(final ScriptEngineFactory script) { if (script == null) { return SyntaxConstants.SYNTAX_STYLE_NONE; }//from w w w .j a v a2 s .c o m final String language = script.getLanguageName(); if ("ECMAScript".equalsIgnoreCase(language) || "js".equalsIgnoreCase(language) || "rhino".equalsIgnoreCase(language) || "javascript".equalsIgnoreCase(language)) { return SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT; } if ("groovy".equalsIgnoreCase(language)) { return SyntaxConstants.SYNTAX_STYLE_GROOVY; } return SyntaxConstants.SYNTAX_STYLE_NONE; }
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//from ww w .j a v a2 s . 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; }
From source file:org.pentaho.reporting.ui.datasources.jdbc.ui.JdbcDataSourceDialog.java
private String getGlobalScriptingLanguage() { final ScriptEngineFactory selectedValue = (ScriptEngineFactory) globalLanguageField.getSelectedItem(); if (selectedValue == null) { return null; }//from ww w.ja v a 2s . c o m return selectedValue.getLanguageName(); }
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private String listScriptEngines() { StringBuilder sb = new StringBuilder(OStrings.getString("SCW_LIST_ENGINES") + "\n"); for (ScriptEngineFactory engine : ScriptRunner.MANAGER.getEngineFactories()) { sb.append(" - "); sb.append(engine.getEngineName()); sb.append(" "); sb.append(engine.getLanguageName()); sb.append(" v."); sb.append(engine.getLanguageVersion()); sb.append(" (").append(OStrings.getString("SCW_EXTENSIONS")).append(" "); boolean hasMore = false; for (String ext : engine.getExtensions()) { if (hasMore) { sb.append(", "); }/*from w ww. ja v a2 s. c om*/ sb.append(ext); hasMore = true; } sb.append(")"); sb.append("\n"); } return sb.toString(); }