Search in sources :

Example 1 with ParseException

use of bsh.ParseException in project adempiere by adempiere.

the class BeanShellEditor method actionValidate.

//  actionProcess
/**
	 *  Validate Script
	 */
private void actionValidate() {
    /** Example:
		import org.compiere.util.DB;
		import java.sql.*;
		PreparedStatement pstmt =DB.prepareStatement("select Name, Password from AD_User where Name like 'Super%'");
		ResultSet rs = pstmt.executeQuery();
		if (rs.next())
		{
		result = rs.getString("Name") + "; password= " + rs.getString("Password");
		}
		**/
    MUser user = MUser.get(Env.getCtx());
    if (!user.isAdministrator()) {
        fResult.setText("Not Administrator");
        return;
    }
    //
    m_script.setScript(editor.getText());
    Exception e = null;
    try {
        m_script.validate();
    } catch (ParseException e1) {
        e = e1;
    }
    if (e != null) {
        ADialog.error(m_WindowNo, this, "ScriptError", e.toString());
        fResult.setText("Syntax errors detected.");
    } else
        fResult.setText("No syntax errors detected.");
}
Also used : ParseException(bsh.ParseException) MUser(org.compiere.model.MUser) ParseException(bsh.ParseException)

Example 2 with ParseException

use of bsh.ParseException in project jPOS by jpos.

the class BSHMethodTest method testExecuteThrowsParseException1.

@Test
public void testExecuteThrowsParseException1() throws Throwable {
    Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
    e.addContent("XXXXXXX XXXXXXXXX XXXX");
    e.setAttributes(new ArrayList());
    try {
        BSHMethod.createBshMethod(e).execute(arguments, "testBSHMethodResultName");
        fail("Expected ParseException to be thrown");
    } catch (ParseException ex) {
        assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
    }
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ParseException(bsh.ParseException) Test(org.junit.Test)

Example 3 with ParseException

use of bsh.ParseException in project jPOS by jpos.

the class BSHMethodTest method testExecuteThrowsParseException.

@Test
public void testExecuteThrowsParseException() throws Throwable {
    Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
    e.addContent("XXXXXXX XXXXXXXXX XXXX");
    e.setAttributes(new ArrayList());
    Map<Integer, ?> arguments = new HashMap();
    Collection<?> returnNames = new ArrayList();
    try {
        BSHMethod.createBshMethod(e).execute(arguments, returnNames);
        fail("Expected ParseException to be thrown");
    } catch (ParseException ex) {
        assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
    }
}
Also used : HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ParseException(bsh.ParseException) Test(org.junit.Test)

Example 4 with ParseException

use of bsh.ParseException in project jPOS by jpos.

the class BSHTransactionParticipantTest method testExecuteMethodThrowsParseException.

@Test
public void testExecuteMethodThrowsParseException() throws Throwable {
    BSHTransactionParticipant bSHTransactionParticipant = new BSHTransactionParticipant();
    try {
        bSHTransactionParticipant.executeMethod(new BSHMethod("\u000E\u0019\u0003/\u0008Tz<|p", false), 100L, new CharConversionException(), new LogEvent("testBSHTransactionParticipantTag", new Object()), "testBSHTransactionParticipantResultName");
        fail("Expected ParseException to be thrown");
    } catch (ParseException ex) {
        assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 4")));
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ParseException(bsh.ParseException) CharConversionException(java.io.CharConversionException) Test(org.junit.Test)

Example 5 with ParseException

use of bsh.ParseException in project symmetric-ds by JumpMind.

the class BshDatabaseWriterFilter method executeScripts.

@Override
protected void executeScripts(DataContext context, String key, Set<String> scripts, boolean isFailOnError) {
    Interpreter interpreter = getInterpreter(context);
    String currentScript = null;
    try {
        bind(interpreter, context, null, null, null);
        if (scripts != null) {
            for (String script : scripts) {
                currentScript = script;
                interpreter.eval(script);
            }
        }
    } catch (EvalError e) {
        if (e instanceof ParseException) {
            String errorMsg = String.format("Evaluation error while parsing the following beanshell script:\n\n%s\n\nThe error was on line %d and the error message was: %s", currentScript, e.getErrorLineNumber(), e.getMessage());
            log.error(errorMsg, e);
            if (isFailOnError) {
                throw new SymmetricException(errorMsg);
            }
        } else if (e instanceof TargetError) {
            Throwable target = ((TargetError) e).getTarget();
            String errorMsg = String.format("Evaluation error occured in the following beanshell script:\n\n%s\n\nThe error was on line %d", currentScript, e.getErrorLineNumber());
            log.error(errorMsg, target);
            if (isFailOnError) {
                if (target instanceof RuntimeException) {
                    throw (RuntimeException) target;
                } else {
                    throw new SymmetricException(target);
                }
            } else {
                log.error("Failed while evaluating script", target);
            }
        }
    }
}
Also used : Interpreter(bsh.Interpreter) SymmetricException(org.jumpmind.symmetric.SymmetricException) EvalError(bsh.EvalError) ParseException(bsh.ParseException) TargetError(bsh.TargetError)

Aggregations

ParseException (bsh.ParseException)5 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Element (org.jdom2.Element)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 TargetError (bsh.TargetError)1 CharConversionException (java.io.CharConversionException)1 HashMap (java.util.HashMap)1 MUser (org.compiere.model.MUser)1 LogEvent (org.jpos.util.LogEvent)1 SymmetricException (org.jumpmind.symmetric.SymmetricException)1