Example usage for javax.script ScriptException getColumnNumber

List of usage examples for javax.script ScriptException getColumnNumber

Introduction

In this page you can find the example usage for javax.script ScriptException getColumnNumber.

Prototype

public int getColumnNumber() 

Source Link

Document

Get the column number on which an error occurred.

Usage

From source file:com.espertech.esper.epl.script.jsr223.JSR223Helper.java

public static String getScriptCompileMsg(ScriptException ex) {
    if (ex.getLineNumber() != 1 && ex.getColumnNumber() != -1) {
        return "At line " + ex.getLineNumber() + " column " + ex.getColumnNumber() + ": " + ex.getMessage();
    } else {//from  w w w  . jav  a  2s.c o m
        return ex.getMessage();
    }
}

From source file:com.intuit.tank.tools.script.ScriptRunner.java

/**
 * //ww  w  .  ja v  a2 s  .  c o m
 * @param scriptName
 * @param script
 * @param engine
 * @param inputs
 * @param output
 * @return
 * @throws ScriptException
 */
public ScriptIOBean runScript(@Nullable String scriptName, @Nonnull String script, @Nonnull ScriptEngine engine,
        @Nonnull Map<String, Object> inputs, OutputLogger output) throws ScriptException {
    Reader reader = null;
    ScriptIOBean ioBean = null;
    try {
        reader = new StringReader(script);
        ioBean = new ScriptIOBean(inputs, output);
        engine.put("ioBean", ioBean);
        ioBean.println("Starting test...");
        engine.eval(reader, engine.getContext());
        ioBean.println("Finished test...");
    } catch (ScriptException e) {
        throw new ScriptException(e.getMessage(), scriptName, e.getLineNumber(), e.getColumnNumber());
    } finally {
        IOUtils.closeQuietly(reader);
    }
    return ioBean;
}

From source file:com.aionemu.commons.scripting.AionScriptEngineManager.java

public void reportScriptFileError(File script, ScriptException e) {
    log.warn("Failed executing script: " + script.getPath() + ".");

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.println("Error on: " + script.getAbsolutePath());
    pw.println("Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber());
    pw.println();//from   w ww  .  j a v a 2s  .  c o  m
    e.printStackTrace(pw);
    pw.close();

    final String report = sw.toString();

    FileOutputStream fos = null;
    try {
        String fileName = script.getName() + ".error.log";

        fos = new FileOutputStream(new File(script.getParent(), fileName));
        fos.write(report.getBytes());

        log.warn("See " + fileName + " for details.");
    } catch (IOException ioe) {
        log.warn("Additionally failed when trying to write an error report on script directory.", ioe);
        log.info(report);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.l2jfree.gameserver.scripting.L2ScriptEngineManager.java

public void reportScriptFileError(File script, ScriptException e) {
    _log.warn("Failed executing script: " + script.getPath() + ".");

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    pw.println("Error on: " + script.getAbsolutePath());
    pw.println("Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber());
    pw.println();/*  w  w w  .j av a 2 s .  c  o  m*/
    e.printStackTrace(pw);
    pw.close();

    final String report = sw.toString();

    FileOutputStream fos = null;
    try {
        String fileName = script.getName() + ".error.log";

        fos = new FileOutputStream(new File(script.getParent(), fileName));
        fos.write(report.getBytes());

        _log.warn("See " + fileName + " for details.");
    } catch (IOException ioe) {
        _log.warn("Additionally failed when trying to write an error report on script directory.", ioe);
        _log.info(report);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:org.fit.cssbox.scriptbox.dom.Html5DocumentImpl.java

/**
 * Reports document's script error.//from  w w  w.  j av a  2  s  .c om
 * 
 * @see <a href=http://www.w3.org/html/wg/drafts/html/CR/webappapis.html#runtime-script-errors-in-documents">Runtime script errors in documents</a>
 */
public void reportScriptError(Script<?, ?, ?> script) {
    if (errorReportingMode) {
        return;
    }
    ScriptException scriptException = script.getException();
    Throwable rootException = ExceptionUtils.getRootCause(scriptException);

    if (scriptException == null) {
        return;
    }

    errorReportingMode = true;

    int lineno = scriptException.getLineNumber();
    int colno = scriptException.getColumnNumber();
    ;
    String message = rootException.getMessage();
    String location = _address.toExternalForm();
    Object errorObject = rootException; // TODO: Here should be an Error object

    if (script.hasMutedErros()) {
        message = "Script error.";
    }

    ErrorEvent errorEvent = new ErrorEvent();

    errorEvent.initEvent("error", false, true, message, location, lineno, colno, errorObject);

    errorReportingMode = false;

    _window.dispatchEvent(errorEvent);
}

From source file:org.openadaptor.auxil.processor.script.ScriptProcessor.java

/**
 * Process a data item.//from w w  w  .  ja v a2  s.  c o m
 * It will bind the data using the configured databinding, to
 * make it available to the script.
 * 
 * The bound object will be returned in a single Element Object[]
 * <br>
 * Note: If compilation is not possible, and the script is contained in a 
 * file, then the file will be read each time a datum is being processed. This
 * should be avoided for obvious reasons :-)
 */
protected Object[] doProcess(Object data) {
    if (data == null) { //conform to IDataProcessor contract.
        throw new NullRecordException("Null record not permitted");
    }
    //Clone it if possible.
    //data=ReflectionUtils.clone(data);
    data = cloner.clone(data);
    try {
        scriptEngine.put(metadataBinding, metadata);
        scriptEngine.put(dataBinding, data);
        if (compiledScript != null) {
            lastResult = compiledScript.eval();
        } else {
            if (script != null) {
                lastResult = scriptEngine.eval(script);
            } else {
                lastResult = scriptEngine.eval(new FileReader(scriptFilename));
            }
        }
        data = scriptEngine.get(dataBinding);
        if (data == null) {
            data = new Object[] {};
        } else {
            if (boxReturnedArrays || (!(data instanceof Object[]))) {
                data = new Object[] { data }; //Wrap it in an Object array.
            }
        }
        return (Object[]) data;
    } catch (ScriptException e) {
        log.debug("Script cause: " + e.getCause());

        throw new ProcessingException("failed to execute script, " + e.getMessage() + " line "
                + e.getLineNumber() + " col " + e.getColumnNumber(), e, this);
    } catch (FileNotFoundException e) {
        throw new ConnectionException("failed to load script file, " + e.getMessage() + scriptFilename, e,
                this);
    }
}

From source file:org.openadaptor.auxil.processor.script.ScriptProcessor.java

/**
 * Initialise the script engine./* w w w . java2s  . c  o m*/
 * <br>
 * This will create a script engine, and compile the supplied
 * script is compilation is possible, and enabled.
 * @throws ValidationException
 */
private void initialise() throws ValidationException {
    log.info("Initialising script engine for language: " + language);
    log.debug("Compile flag: " + compile);
    scriptEngine = createScriptEngine();
    if (compile && scriptEngine instanceof Compilable) {
        Compilable compilableScriptEngine = (Compilable) scriptEngine;
        try {
            if (script != null) {
                log.debug("Compiling script: " + script);
                compiledScript = compilableScriptEngine.compile(script);
            } else {
                log.debug("Compiling script from file: " + scriptFilename);
                compiledScript = compilableScriptEngine.compile(new FileReader(scriptFilename));
            }
            log.info("Script compiled successfully");
        } catch (ScriptException e) {
            String failMsg = "Failed to compile script, " + e.getMessage() + " line " + e.getLineNumber()
                    + " col " + e.getColumnNumber();
            log.warn(failMsg);
            throw new ValidationException(failMsg, e, this);
        } catch (FileNotFoundException e) {
            String failMsg = "Failed to compile script, " + e.getMessage();
            log.warn(failMsg);
            throw new ValidationException(failMsg, e, this);
        }
    }
    //Apply binding to allow scripts to access logging
    scriptEngine.put(logBinding, log);
    //Apply extra bindings, if any.
    applyBindings(scriptEngine, additionalBindings);
}

From source file:org.quackbot.hooks.loaders.JSHookLoader.java

protected Object invokeFunction(ScriptEngine jsEngine, Map<String, String> sourceMap, String functionName,
        Object... args) throws JSHookException {
    try {/*w ww  .  j a  va2s  . c  o m*/
        return ((Invocable) jsEngine).invokeFunction(functionName, args);
    } catch (ScriptException ex) {
        //Calculate where the exception occured at
        int lastLine = 0;
        for (Map.Entry<String, String> curEntry : sourceMap.entrySet()) {
            int fileLen = curEntry.getValue().split(System.getProperty("line.separator")).length;
            if (lastLine <= ex.getLineNumber() && ex.getLineNumber() >= fileLen)
                throw new JSHookException("Exception encountered when invoking function " + functionName,
                        curEntry.getKey(), ex.getLineNumber() - lastLine, ex.getColumnNumber(), ex);
            else
                lastLine += fileLen;
        }
        throw new JSHookException("Exception encountered when invoking function " + functionName, "unknown",
                ex.getLineNumber(), ex.getColumnNumber(), ex);
    } catch (NoSuchMethodException ex) {
        throw new JSHookException("Can't find function " + functionName + " in file(s) "
                + StringUtils.join(sourceMap.keySet().toArray()), ex);
    }
}