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


Java EvaluatorException类代码示例

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


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

示例1: compressJs

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
private void compressJs(String sourceName, InputStream in, OutputStream out) throws IOException
{
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    SourceFile input = SourceFile.fromInputStream(sourceName, in, Charset.forName("UTF-8"));

    com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
    compiler.compile(Collections.EMPTY_LIST, Collections.singletonList(input), options);

    if (compiler.hasErrors())
    {
        throw new EvaluatorException(compiler.getErrors()[0].description);
    }

    String compressed = compiler.toSource();
    IOUtils.copy(new StringReader(compressed), out);
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:19,代码来源:ResourcesManagerImpl.java

示例2: setFilter

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public void setFilter(String filter) throws ServiceException {
	if (filter == null) {
		filter = "";
	}
	if (!this.filter.equals(filter)) {
		this.filter = filter;
		if (filter.length() != 0) {
			Context js_context = Context.enter();
			try {
				js_and.reset(filter);
				js_or.reset(js_and.replaceAll(" && "));
				filter = js_or.replaceAll(" || ");
				js_filter = js_context.compileString(filter, "filter", 0, null);
			} catch (EvaluatorException e) {
				throw new ServiceException("Failed to compile JS filter : " + e.getMessage(), e);
			} finally {
				Context.exit();
			}
		} else {
			js_filter = null;
		}
		bContinue = false;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:LogManager.java

示例3: executeSimpleHandlerCore

import org.mozilla.javascript.EvaluatorException; //导入依赖的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

示例4: runtimeError

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
@Override
public EvaluatorException runtimeError(String msg, String scriptName, int lineNum, String line, int linePos)
{
	StringBuilder summary = new StringBuilder();
	summary.append(r.getString("error.preamble", scriptName) + "\n");
	summary.append(msg + "\n");

	for( String error : errors )
	{
		summary.append(r.getString("label.error") + ": " + error + "\n");
	}
	for( String warning : warnings )
	{
		summary.append(r.getString("label.warning") + ": " + warning + "\n");
	}
	return new EvaluatorException(summary.toString());
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:ScriptingServiceImpl.java

示例5: receiveError

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public void receiveError(final EvaluatorException err) {
    if(isForeground) {
        MainActivity.UIThread(new Runnable() {
            @Override
            public void run() {
                MainActivity.settingPower.setChecked(false);
                Toast.makeText(ctx, "Error: EvaluatorException (" + err.lineNumber() + ", " + err.columnNumber() + ")\n" + err.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    Logger.Log log = new Logger.Log();
    log.type = Logger.Type.ERROR;
    log.title = "Error: EvaluatorException";
    log.index = "at (" + err.lineNumber() + ", " + err.columnNumber() + ")\n" + err.toString();

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

示例6: loadScriptFromSource

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public static Script loadScriptFromSource(Context cx, String scriptSource,
                                          String path, int lineno,
                                          Object securityDomain)
{
    try {
        return cx.compileString(scriptSource, path, lineno,
                                securityDomain);
    } catch (EvaluatorException ee) {
        // Already printed message.
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
            cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
            "msg.uncaughtJSException", ex.toString());
        exitCode = EXITCODE_RUNTIME_ERROR;
        Context.reportError(msg);
    }
    return null;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:25,代码来源:Main.java

示例7: evaluateExpression

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public Object evaluateExpression(Script expression)
{
	ensureContext();
	
	Object value = expression.exec(context, scope);
	
	Object javaValue;
	// not converting Number objects because the generic conversion call below
	// always converts to Double
	if (value == null || value instanceof Number)
	{
		javaValue = value;
	}
	else
	{
		try
		{
			javaValue = Context.jsToJava(value, Object.class);
		}
		catch (EvaluatorException e)
		{
			throw new JRRuntimeException(e);
		}
	}
	return javaValue;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:27,代码来源:JavaScriptEvaluatorScope.java

示例8: addError

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public void addError(EvaluatorException error)
{
	++errorCount;
	
	errors.append(errorCount);
	errors.append(". ");
	String message = error.getMessage();
	errors.append(message);
	errors.append(" at column ");
	errors.append(error.columnNumber());
	String lineSource = error.lineSource();
	if (lineSource != null)
	{
		errors.append(" in line\n");
		errors.append(lineSource);
	}
	errors.append("\n");
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:19,代码来源:JavaScriptCompilerBase.java

示例9: evaluate

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JavaScript expression: {1}", expression);
    try {
        final Context ctx = ContextFactory.getGlobal().enterContext();
        Script script = scriptCache.get(expression);
        if (script == null) {
            ctx.setOptimizationLevel(9);
            script = ctx.compileString(expression, "<cmd>", 1, null);
            scriptCache.put(expression, script);
        }
        final Scriptable scope = ctx.newObject(parentScope);
        scope.setPrototype(parentScope);
        scope.setParentScope(null);
        for (final Entry<String, ?> entry : values.entrySet()) {
            scope.put(entry.getKey(), scope, Context.javaToJS(entry.getValue(), scope));
        }
        return script.exec(ctx, scope);
    } catch (final EvaluatorException ex) {
        throw new ExpressionEvaluationException("Evaluating JavaScript expression failed: " + expression, ex);
    } finally {
        Context.exit();
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:24,代码来源:ExpressionLanguageJavaScriptImpl.java

示例10: jsonToSdp

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
static String jsonToSdp(JSONObject json) throws InvalidDescriptionException {
    synchronized (SdpProcessor.class) {
        if (sInstance == null) {
            sInstance = new SdpProcessor();
        }
    }
    Context context = Context.enter();
    context.setOptimizationLevel(-1);
    context.setLanguageVersion(Context.VERSION_1_8);
    try {
        ScriptableObject scope = sInstance.getScope();
        Object result = sInstance.getJsonToSdpFunction().call(context, scope, scope, new Object[]{json.toString()});
        return "" + result;
    } catch (EvaluatorException e) {
        throw new InvalidDescriptionException("failed to parse sdp: " + e.getMessage(), e);
    } finally {
        Context.exit();
    }
}
 
开发者ID:EricssonResearch,项目名称:openwebrtc-android-sdk,代码行数:20,代码来源:SdpProcessor.java

示例11: compileJavascriptAssertions

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
private Object compileJavascriptAssertions(AssertionsJavascriptWrapper assertionsJavascriptWrapper) throws Exception {

		String javascriptText = assertionsJavascriptWrapper.getJavascriptText();	
		HashMap<String, Object> referencedObjects = assertionsJavascriptWrapper.getReferencedObjects();
		
		Object compiledJavascriptObject = null;
		Context rhinoContext = Context.enter();

		try {
			ScriptableObject scope = rhinoContext.initStandardObjects();
			
			for (String key : referencedObjects.keySet()) {
				Object referencedObject = referencedObjects.get(key);
				
				Object wrappedObject = Context.javaToJS(referencedObject, scope);
				ScriptableObject.putProperty(scope, key,
						wrappedObject);
			}

			Scriptable that = rhinoContext.newObject(scope);
			Function fct = rhinoContext.compileFunction(scope,
					javascriptText, "script", 1, null);
			Object result = fct
					.call(rhinoContext, scope, that, new Object[] {});
			compiledJavascriptObject = result == Context.getUndefinedValue() ? null : Context
					.jsToJava(result, Object.class);
		} catch (EvaluatorException ee) {
			ee.printStackTrace();
		} finally {
			Context.exit();
		}
		
		return compiledJavascriptObject;
		
	}
 
开发者ID:marcotabago,项目名称:hl7-mapping-validator,代码行数:36,代码来源:AssertionsJavascriptCompiler.java

示例12: getVariableNames

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
private Set<String> getVariableNames(String expression) {
	if (CommonUtils.isNullOrEmpty(expression)) {
		return Collections.emptySet();
	}
	Set<String> set = parameterReferencesByExpression.get(expression);
	if (set == null) {
		set = new HashSet<String>();
		parameterReferencesByExpression.put(expression, set);
		try {
			set.addAll(FormulaInfo.getVariableNames(expression));
		} catch (EvaluatorException e) {
			try {
				// Sometimes the 'expression' is a duration, so that is okay
				DurationFormat.parseFormattedDuration(expression);
				set = new HashSet<String>();
			} catch (Exception x) {
				trace.error("couldn't parse expression: " + expression, e);
			}
		}
	}
	return set;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:23,代码来源:DependencyMaintenanceSystem.java

示例13: get

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
@Override
public Object get(int index, Scriptable start) {
	PropertyInfo pinfo = this.classWrapper.getIntegerIndexer();
	if (pinfo == null) {
		return super.get(index, start);
	} else {
		try {
			Method getter = pinfo.getGetter();
			if (getter == null) {
				throw new EvaluatorException("Indexer is write-only");
			}
			// Cannot retain delegate with a strong reference.
			Object javaObject = this.getJavaObject();
			if (javaObject == null) {
				throw new IllegalStateException("Java object (class=" + this.classWrapper + ") is null.");
			}
			Object raw = getter.invoke(javaObject, new Object[] { Integer.valueOf(index) });
			if (raw != null) {
				return JavaScript.getInstance().getJavascriptObject(raw, this.getParentScope());
			}
		} catch (Exception err) {
			err.getCause();
		}
	}
	return Scriptable.NOT_FOUND;
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:27,代码来源:JavaObjectWrapper.java

示例14: put

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
@Override
public void put(int index, Scriptable start, Object value) {
	PropertyInfo pinfo = this.classWrapper.getIntegerIndexer();
	if (pinfo == null) {
		super.put(index, start, value);
	} else {
		try {
			Method setter = pinfo.getSetter();
			if (setter == null) {
				throw new EvaluatorException("Indexer is read-only");
			}
			Object actualValue;
			actualValue = JavaScript.getInstance().getJavaObject(value, pinfo.getPropertyType());
			setter.invoke(this.getJavaObject(), new Object[] { Integer.valueOf(index), actualValue });
		} catch (Exception err) {
			err.getCause();
		}
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:20,代码来源:JavaObjectWrapper.java

示例15: runtimeError

import org.mozilla.javascript.EvaluatorException; //导入依赖的package包/类
/**
 * Creates an EvaluatorException that may be thrown.
 * runtimeErrors, unlike errors, will always terminate the
 * current script.
 *
 * @param message a String describing the error
 * @param sourceName a String describing the JavaScript source
 *     where the error occured; typically a filename or URL
 * @param line the line number associated with the error
 * @param lineSource the text of the line (may be null)
 * @param lineOffset the offset into lineSource where problem was detected
 * @return an EvaluatorException that will be thrown.
 */
public EvaluatorException runtimeError(String message,
                                       String sourceName,
                                       int line,
                                       String lineSource,
                                       int lineOffset) {
    String msg =
        formatMessage(message, sourceName, line, lineSource, lineOffset);

    if(upstreamReporter != null)
        upstreamReporter.errorReport(msg, null);
    else
        System.out.println("ECMA.RuntimeError: " + msg);

    return new EvaluatorException(msg);
}
 
开发者ID:Norkart,项目名称:NK-VirtualGlobe,代码行数:29,代码来源:ReportAdapter.java


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