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


Java ScriptEngineFactory.getExtensions方法代码示例

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


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

示例1: findScriptEngineCandidates

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private Map<ScriptEngine, Integer> findScriptEngineCandidates(boolean findByName) {
    Map<ScriptEngine, Integer> matchPositionPerScriptEngineCandidate = new HashMap<>();
    int matchPosition;
    List<String> lookupCriteria;

    for (ScriptEngineFactory factory : new ScriptEngineManager().getEngineFactories()) {
        matchPosition = 0;
        if (findByName) {
            lookupCriteria = factory.getNames();
        } else {
            lookupCriteria = factory.getExtensions();
        }

        for (String criteria : lookupCriteria) {
            if (criteria.equalsIgnoreCase(scriptEngineLookupName)) {
                matchPositionPerScriptEngineCandidate.put(factory.getScriptEngine(), matchPosition);
            }
            matchPosition++;
        }
    }

    return matchPositionPerScriptEngineCandidate;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:24,代码来源:Script.java

示例2: list

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Test
public void list() {
	ScriptEngineManager manager = new ScriptEngineManager();
	List<ScriptEngineFactory> factories = manager.getEngineFactories();
	for (ScriptEngineFactory factory : factories) {
		System.out.println(String.format("Engine: %s v%s; %s v%s",
				factory.getEngineName(),
				factory.getEngineVersion(),
				factory.getLanguageName(),
				factory.getLanguageVersion()));
		List<String> extensions = factory.getExtensions();
		System.out.println("Extensions:");
		print(extensions);

		List<String> names = factory.getNames();
		System.out.println("Names:");
		print(names);

		List<String> mimeTypes = factory.getMimeTypes();
		System.out.println("MIME Types:");
		print(mimeTypes);
	}
}
 
开发者ID:RockManJoe64,项目名称:fixprotocol-test-suite,代码行数:24,代码来源:ListAllEngines.java

示例3: loadModules

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Override
public void loadModules() {

    super.loadModules();

    List<ScriptEngineFactory> factories = getModules();

    for (ScriptEngineFactory factory : factories) {
        _engineManager.registerEngineName(factory.getEngineName(), factory);

        List<String> extensions = factory.getExtensions();
        for (String ext : extensions) {
            _engineManager.registerEngineExtension(ext, factory);
        }

        List<String> mimes = factory.getMimeTypes();
        for (String mime : mimes) {
            _engineManager.registerEngineExtension(mime, factory);
        }

        NucMsg.info("Loaded script engine: {0}", factory.getEngineName());
    }
}
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:24,代码来源:InternalScriptEngineLoader.java

示例4: L2ScriptEngineManager

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private L2ScriptEngineManager()
{
	ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
	List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories();
	if (USE_COMPILED_CACHE)
		_cache = this.loadCompiledScriptCache();
	else
		_cache = null;
	_log.info("Initializing Script Engine Manager");
	for (ScriptEngineFactory factory : factories)
		try
		{
			ScriptEngine engine = factory.getScriptEngine();
			boolean reg = false;
			for (String name : factory.getNames())
			{
				ScriptEngine existentEngine = _nameEngines.get(name);
				if (existentEngine != null)
				{
					double engineVer = Double.parseDouble(factory.getEngineVersion());
					double existentEngVer = Double.parseDouble(existentEngine.getFactory().getEngineVersion());
					if (engineVer <= existentEngVer)
						continue;
				}
				reg = true;
				_nameEngines.put(name, engine);
			}
			if (reg)
				_log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " - Language Version: " + factory.getLanguageVersion());
			for (String ext : factory.getExtensions())
				if (!ext.equals("java") || factory.getLanguageName().equals("java"))
					_extEngines.put(ext, engine);
		}
		catch (Exception e)
		{
			_log.warning("Failed initializing factory. ");
			e.printStackTrace();
		}
	this.preConfigure();
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:41,代码来源:L2ScriptEngineManager.java

示例5: actionPerformed

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    ScriptEngine scriptEngine = getScriptManager().getEngine();
    ScriptEngineFactory engineFactory = scriptEngine.getFactory();
    List<String> extensions = engineFactory.getExtensions();
    JFileChooser fileChooser = OpenAction.createFileChooser(engineFactory);
    while (true) {
        int i = fileChooser.showSaveDialog(getScriptConsoleTopComponent());
        if (i != JFileChooser.APPROVE_OPTION || fileChooser.getSelectedFile() == null) {
            return;
        }

        File file = fileChooser.getSelectedFile();
        if (extensions.size() > 0) {
            file = ensureFileNameWithExtension(file, extensions);
        }
        if (!file.exists()) {
            getScriptConsoleTopComponent().saveScriptAs(file);
            return;
        } else {
            String msg = MessageFormat.format("File ''{0}'' already exists.\n" +
                    "Do you want to overwrite it?", file.getName());
            int ret = JOptionPane.showConfirmDialog(getScriptConsoleTopComponent(),
                                                    msg,
                                                    "Save Script",
                                                    JOptionPane.YES_NO_CANCEL_OPTION);
            if (ret == JOptionPane.YES_OPTION) {
                getScriptConsoleTopComponent().saveScriptAs(file);
                return;
            } else if (ret == JOptionPane.CANCEL_OPTION) {
                return;
            }
        }
    }
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:36,代码来源:SaveAsAction.java

示例6: showEngineDetails

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private void showEngineDetails(JComponent parent, ScriptEngineFactory scriptEngineFactory) {
    StringBuilder out = new StringBuilder();

    out.append(String.format("Engine name: %s\n", scriptEngineFactory.getEngineName()));
    out.append(String.format("Engine version: %s\n", scriptEngineFactory.getEngineVersion()));
    out.append(String.format("Language name: %s\n", scriptEngineFactory.getLanguageName()));
    out.append(String.format("Language version: %s\n", scriptEngineFactory.getLanguageVersion()));

    out.append("File name extension(s):");
    final List<String> extensions = scriptEngineFactory.getExtensions();
    for (String extension : extensions) {
        out.append(" ");
        out.append(extension);
    }
    out.append("\n");

    out.append("File content type(s):");
    final List<String> mimeTypes = scriptEngineFactory.getMimeTypes();
    for (String mimeType : mimeTypes) {
        out.append(" ");
        out.append(mimeType);
    }
    out.append("\n");

    out.append("Engine factory name(s): ");
    final List<String> names = scriptEngineFactory.getNames();
    for (String name : names) {
        out.append(" ");
        out.append(name);
    }
    out.append("\n");

    JOptionPane.showMessageDialog(parent, out.toString(), "Script Engine Details", JOptionPane.INFORMATION_MESSAGE);
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:35,代码来源:NewAction.java

示例7: factoryTests

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:ScriptEngineTest.java

示例8: testScriptEngineFactory

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
/**
 * Tests the Lua script engine factory.
 */
@Test
public void testScriptEngineFactory() {
	// Get factory
	ScriptEngineFactory factory = scriptEngine.getFactory();

	// getEngineName()
	assertEquals("JNLua", factory.getEngineName());

	// getEngineVersion()
	assertEquals("1.0", factory.getEngineVersion());

	// getNames()
	List<String> names = factory.getNames();
	assertTrue(names.contains("lua"));
	assertTrue(names.contains("Lua"));
	assertTrue(names.contains("jnlua"));
	assertTrue(names.contains("JNLua"));

	// getLanguageName()
	assertEquals("Lua", factory.getLanguageName());

	// getLanguageVersion()
	assertEquals("5.2", factory.getLanguageVersion());

	// getExtensions()
	List<String> extensions = factory.getExtensions();
	assertTrue(extensions.contains("lua"));

	// getMimeTypes()
	List<String> mimeTypes = factory.getMimeTypes();
	assertTrue(mimeTypes.contains("application/x-lua"));
	assertTrue(mimeTypes.contains("text/x-lua"));

	// getParameter()
	assertEquals(factory.getEngineName(), factory
			.getParameter(ScriptEngine.ENGINE));
	assertEquals(factory.getEngineVersion(), factory
			.getParameter(ScriptEngine.ENGINE_VERSION));
	assertTrue(factory.getNames().contains(
			factory.getParameter(ScriptEngine.NAME)));
	assertEquals(factory.getLanguageName(), factory
			.getParameter(ScriptEngine.LANGUAGE));
	assertEquals(factory.getLanguageVersion(), factory
			.getParameter(ScriptEngine.LANGUAGE_VERSION));

	// getScriptEngine()
	assertNotNull(factory.getScriptEngine());

	// getMethodCallSyntax()
	assertEquals("process:execute(a, b)", factory.getMethodCallSyntax(
			"process", "execute", "a", "b"));

	// getOutputStatement()
	assertEquals("print(\"test\")", factory.getOutputStatement("test"));
	assertEquals("print(\"\\\"quoted\\\"\")", factory
			.getOutputStatement("\"quoted\""));

	// getProgram()
	assertEquals("a = 1\nreturn b\n", factory.getProgram("a = 1",
			"return b"));
}
 
开发者ID:airminer,项目名称:jnlua,代码行数:65,代码来源:LuaScriptEngineTest.java

示例9: factoryTests

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:56,代码来源:ScriptEngineTest.java

示例10: createFileFilter

import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public static FileNameExtensionFilter createFileFilter(ScriptEngineFactory scriptEngineFactory) {
    List<String> extensionList = scriptEngineFactory.getExtensions();
    String[] extensions = extensionList.toArray(new String[extensionList.size()]);
    String description = String.format("%s files", scriptEngineFactory.getLanguageName());
    return new FileNameExtensionFilter(description, extensions);
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:7,代码来源:OpenAction.java


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