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


Java Function类代码示例

本文整理汇总了Java中org.mozilla.javascript.Function的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: decryptSignature

import org.mozilla.javascript.Function; //导入依赖的package包/类
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
    Context context = Context.enter();
    context.setOptimizationLevel(-1);
    Object result;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        throw new DecryptException("could not get decrypt signature", e);
    } finally {
        Context.exit();
    }
    return result == null ? "" : result.toString();
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:17,代码来源:YoutubeStreamExtractor.java

示例2: read_file

import org.mozilla.javascript.Function; //导入依赖的package包/类
public SheetJSFile read_file(String filename) throws IOException, ObjectNotFoundException {
	/* open file */
	String d = JSHelper.read_file(filename);

	/* options argument */
	NativeObject q = (NativeObject)this.cx.evaluateString(this.scope, "q = {'type':'binary'};", "<cmd>", 2, null);

	/* set up function arguments */
	Object functionArgs[] = {d, q};

	/* call read -> wb workbook */
	Function readfunc = (Function)JSHelper.get_object("XLSX.read",this.scope);
	NativeObject wb = (NativeObject)readfunc.call(this.cx, this.scope, this.nXLSX, functionArgs);

	return new SheetJSFile(wb, this);
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:17,代码来源:SheetJS.java

示例3: confirm

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * Wraps the 'confirm' method of the Window interface.
 */
public static Object confirm(Context cx,
                              Scriptable thisObj,
                              Object[] args,
                              Function funObj) {
    int len = args.length;
    WindowWrapper ww = (WindowWrapper)thisObj;
    Window window = ww.window;
    if (len >= 1) {
        String message =
            (String)Context.jsToJava(args[0], String.class);
        if (window.confirm(message))
            return Context.toObject(Boolean.TRUE, thisObj);
        else
            return Context.toObject(Boolean.FALSE, thisObj);
    }
    return Context.toObject(Boolean.FALSE, thisObj);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:21,代码来源:WindowWrapper.java

示例4: call

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * Calls JavaScript native function.
 * 
 * @param function Function to be called.
 * @param args Call arguments.
 */
public static void call(final Function function, final Object... args) {
	Scriptable scope = function.getParentScope();
	ObjectTopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope);
	if (topLevel != null) {
		Context cx = topLevel.getBrowserScriptEngine().enterContext();
		try {
			function.call(cx, scope, scope, args);
		} catch (Exception ex) {
			try {
				JavaScriptEngine.throwWrappedScriptException(ex);
			} catch (ScriptException e) {
				throw new WrappedException(e);
			}
		} finally {
			Context.exit();
		}
	}
}
 
开发者ID:jutils,项目名称:jsen-js,代码行数:25,代码来源:HostedJavaMethod.java

示例5: executeSimpleHandlerCore

import org.mozilla.javascript.Function; //导入依赖的package包/类
protected void executeSimpleHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
	handlerName = "on" + handlerType;

	Engine.logBeans.trace("(Transaction) Searching the " + handlerType + " handler (" + handlerName + ")");
	Object object = scope.get(handlerName, scope);
	Engine.logBeans.trace("(Transaction) Rhino returned: [" + object.getClass().getName() + "] " + object.toString());
       
	if (!(object instanceof Function)) {
		Engine.logBeans.debug("(Transaction) No " + handlerType + " handler (" + handlerName + ") found");
		return;
	}
	else {
		Engine.logBeans.debug("(Transaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
	}

	function = (Function) object;

	Object returnedValue = function.call(myJavascriptContext, scope, scope, null);
	if (returnedValue instanceof org.mozilla.javascript.Undefined) {
		handlerResult = "";
	}
	else {
		handlerResult = returnedValue.toString();
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:26,代码来源:Transaction.java

示例6: runScript

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例7: load

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * load
 * @param response
 */
public void load( WebResponse response ) {
		Function onLoadEvent=null;
    try {
        Context context = Context.enter();
        context.initStandardObjects( null );

        HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument();
        if (!(htmlDocument instanceof HTMLDocumentImpl)) return;

        HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody();
        if (body == null) return;
        onLoadEvent = body.getOnloadEvent();
        if (onLoadEvent == null) return;
        onLoadEvent.call( context, body, body, new Object[0] );
    } catch (JavaScriptException e) {
    	ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString());
    	// HttpUnitUtils.handleException(e);
    } catch (EcmaError ee) {
    	//throw ee;
    	ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString());        	
    } finally {
        Context.exit();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:DomBasedScriptingEngineFactory.java

示例8: parseToHtml

import org.mozilla.javascript.Function; //导入依赖的package包/类
@JSStaticFunction
public static void parseToHtml(final String url, final String option, final Function func) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Document document = null;
            try {
                document = Jsoup.connect(url).get();
                Elements element = document.select(option);

                func.call(context, scope, scope, new Object[] { element.html(), null });
            } catch (IOException e) {
                try {
                    func.call(context, scope, scope, new Object[] { null, e});
                } catch (Exception err) {}
            }
        }
    }).start();
}
 
开发者ID:Su-Yong,项目名称:NewKakaoBot,代码行数:20,代码来源:ScriptUtil.java

示例9: parseToText

import org.mozilla.javascript.Function; //导入依赖的package包/类
@JSStaticFunction
public static void parseToText(final String url, final String option, final Function func) throws IOException {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Document document = null;
            try {
                document = Jsoup.connect(url).get();
                Elements element = document.select(option);

                func.call(context, scope, scope, new Object[] { element.text(), null });
            } catch (IOException e) {
                try {
                    func.call(context, scope, scope, new Object[] { null, e });
                } catch (Exception err) {}
            }
        }
    }).start();
}
 
开发者ID:Su-Yong,项目名称:NewKakaoBot,代码行数:20,代码来源:ScriptUtil.java

示例10: invokeFunction

import org.mozilla.javascript.Function; //导入依赖的package包/类
public void invokeFunction(String name, Object... parameters) {
    Function func = (Function) globalScope.get(name, globalScope);

    if(func != null) {
        Context.enter();
        try {
            func.call(context, globalScope, globalScope, parameters);
        } catch (EcmaError err) {
            KakaoManager.getInstance().receiveError(err);
        }
        String params = "";
        int i = 0;
        for(Object p : parameters) {
            i++;
            params += " -> " + String.valueOf(p);
            if(i != parameters.length) {
                params += "\n";
            }
        }

        Logger.Log log = new Logger.Log();
        log.type = Logger.Type.APP;
        log.title = "call \"" + name + "\"";
        log.index = "parameters\n" + params;

        Logger.getInstance().add(log);
    }
}
 
开发者ID:Su-Yong,项目名称:NewKakaoBot,代码行数:29,代码来源:ScriptEngine.java

示例11: testFunctionWithContinuations

import org.mozilla.javascript.Function; //导入依赖的package包/类
public void testFunctionWithContinuations() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { return myObject.f(a); }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        Object applicationState = pending.getApplicationState();
        assertEquals(7, ((Number)applicationState).intValue());
        int saved = (Integer) applicationState;
        Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:22,代码来源:ContinuationsApiTest.java

示例12: test0

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * ECMA 11.4.3 says that typeof on host object is Implementation-dependent
 */
public void test0() throws Exception
{
       final Function f = new BaseFunction()
       {
       	@Override
       	public Object call(Context _cx, Scriptable _scope, Scriptable _thisObj,
       			Object[] _args)
       	{
       		return _args[0].getClass().getName();
       	}
       };
	final ContextAction action = new ContextAction()
	{
		public Object run(final Context context)
		{
			final Scriptable scope = context.initStandardObjects();
			scope.put("myObj", scope, f);
			return context.evaluateString(scope, "typeof myObj", "test script", 1, null);
		}
	};
	doTest("function", action);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:26,代码来源:TypeOfTest.java

示例13: callJsFunction

import org.mozilla.javascript.Function; //导入依赖的package包/类
public void callJsFunction(String name, Object... params) {
    Object obj = getJsFunction(name);
    if (obj instanceof Function) {
        Function function = (Function) obj;
        // NativeObject result = (NativeObject)
        function.call(rhino, scope, scope, params);
        processResult(RESULT_OK, "");
    }
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:10,代码来源:AppRunnerInterpreter.java

示例14: decipherKey

import org.mozilla.javascript.Function; //导入依赖的package包/类
/**
 * After finding the decrypted code in the js html5 player code
 * run the code passing the encryptedSig parameter
 *
 * @param encryptedSig
 * @param html5player
 * @return
 * @throws Exception
 */
private static String decipherKey(String encryptedSig, String html5player)
        throws Exception {
    String decipherFunc = loadFunction(html5player);
    Context context = Context.enter();
    // Rhino interpreted mode
    context.setOptimizationLevel(-1);
    Object result = null;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decipherFunc, "decipherFunc", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Context.exit();
    }
    if (result == null) {
        return "";
    } else {
        return result.toString();
    }
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:33,代码来源:YoutubeLinkRetriever.java

示例15: evaluate

import org.mozilla.javascript.Function; //导入依赖的package包/类
@Override
public String evaluate(Script script, String func, Object[] args) {
	String resultStr = "";

	try {
		rhino.evaluateString(scope, script.getSourceCode(), script.getHumanName(), 1, null);
		
		Function function = (Function) scope.get(func, scope);
		Object result = function.call(rhino, scope, scope, args);

		if (result != null) {
			resultStr = result.toString();
		}

	} catch (Exception e) {
		e(e);
	}

	return resultStr;
}
 
开发者ID:nmud,项目名称:nmud-demo,代码行数:21,代码来源:JSEnvironment.java


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