List of usage examples for com.liferay.portal.kernel.scripting ScriptingException ScriptingException
public ScriptingException(Throwable cause)
From source file:com.liferay.rtl.scripting.ruby.RubyExecutor.java
License:Open Source License
protected Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, File scriptFile, String script, ClassLoader... classLoaders) throws ScriptingException { if (!_executeInSeparateThread) { return doEval(allowedClasses, inputObjects, outputNames, scriptFile, script, classLoaders); }/*w ww . ja v a 2s . co m*/ EvalCallable evalCallable = new EvalCallable(allowedClasses, inputObjects, outputNames, scriptFile, script, classLoaders); FutureTask<Map<String, Object>> futureTask = new FutureTask<Map<String, Object>>(evalCallable); Thread oneTimeExecutorThread = _threadFactory.newThread(futureTask); oneTimeExecutorThread.start(); try { oneTimeExecutorThread.join(); return futureTask.get(); } catch (Exception e) { futureTask.cancel(true); oneTimeExecutorThread.interrupt(); throw new ScriptingException(e); } }
From source file:com.slemarchand.portal.scripting.sql.internal.SQLExecutor.java
License:Open Source License
@Override public Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, String script) throws ScriptingException { if (allowedClasses != null) { throw new ExecutionException("Constrained execution not supported for database queries"); }//from ww w . ja v a 2s . com UnsyncPrintWriter out = (UnsyncPrintWriter) inputObjects.get("out"); Map<String, String> hints = _getHints(script); boolean emptyScript = script.replace("--help", "").trim().length() == 0; boolean help = _getHint("help", hints, null) != null; if (help || emptyScript) { _displayHelp(out); } else { out.append( "To learn more about execution parameters, add \"--help\" line in your script or execute empty script\n\n"); } if (!emptyScript) { int maxRows = _getIntegerHint("maxRows", hints, 50); List<String> columnLabels = new LinkedList<String>(); List<List<Object>> rows = null; try { rows = _execQuery(script, maxRows, columnLabels); } catch (SQLException e) { throw new ScriptingException(e); } String format = _getHint("format", hints, "html"); if ("html".equalsIgnoreCase(format)) { _formatHTML(columnLabels, rows, out); } else if ("csv".equalsIgnoreCase(format)) { _formatCSV(columnLabels, rows, out); } else { throw new ScriptingException("Unknown value '" + format + "' for hint 'format'"); } } Map<String, Object> outputObjects; if (outputNames != null) { // Output objects not supported outputObjects = new HashMap<String, Object>(); } else { outputObjects = null; } return outputObjects; }
From source file:com.slemarchand.portal.scripting.sql.internal.SQLExecutor.java
License:Open Source License
private Map _getHints(String sqlQuery) throws ScriptingException { Properties props = new Properties(); try {/* w w w . j av a 2s . co m*/ String[] lines = sqlQuery.split("[\\n\\r]"); StringBuilder hintsStr = new StringBuilder(); for (String l : lines) { l = l.trim(); if (l.startsWith("--")) { hintsStr.append(l.substring(2).trim() + _LINE_SEPARATOR); } } props.load(new StringReader(hintsStr.toString())); } catch (IOException e) { throw new ScriptingException(e); } return props; }
From source file:com.slemarchand.sqlqueryscripting.hook.events.AppStartupAction.java
License:Open Source License
private void addScriptingExecutor(Scripting scripting, String language, ScriptingExecutor scriptingExecutor) throws ScriptingException { Method method;/* w w w . ja va 2 s . c o m*/ try { method = scripting.getClass().getMethod("addScriptingExecutor", String.class, ScriptingExecutor.class); } catch (SecurityException e) { throw new ScriptingException(e); } catch (NoSuchMethodException e) { throw new ScriptingException(e); } try { method.invoke(scripting, language, scriptingExecutor); } catch (IllegalArgumentException e) { throw new ScriptingException(e); } catch (IllegalAccessException e) { throw new ScriptingException(e); } catch (InvocationTargetException e) { throw new ScriptingException(e); } }
From source file:com.slemarchand.sqlqueryscripting.scripting.sqlquery.SQLQueryExecutor.java
License:Open Source License
public Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, File script, ClassLoader... classLoaders) throws ScriptingException { try {//from w w w . j a va2 s. c om return eval(allowedClasses, inputObjects, outputNames, FileUtil.read(script)); } catch (IOException e) { throw new ScriptingException(e); } }
From source file:com.slemarchand.sqlqueryscripting.scripting.sqlquery.SQLQueryExecutor.java
License:Open Source License
public Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, String script, ClassLoader... classLoaders) throws ScriptingException { if (allowedClasses != null) { throw new ExecutionException("Constrained execution not supported for database queries"); }//www .j a v a2 s. c o m UnsyncPrintWriter out = (UnsyncPrintWriter) inputObjects.get("out"); Map<String, String> hints = _getHints(script); boolean emptyScript = script.replace("--help", "").trim().length() == 0; boolean help = _getHint("help", hints, null) != null; if (help || emptyScript) { _displayHelp(out); } else { out.append( "To learn more about execution parameters, add \"--help\" line in your script or execute empty script\n\n"); } if (!emptyScript) { int maxRows = _getIntegerHint("maxRows", hints, 50); List<String> columnLabels = new LinkedList<String>(); List<List<Object>> rows = null; try { rows = _execQuery(script, maxRows, columnLabels); } catch (SQLException e) { throw new ScriptingException(e); } String format = _getHint("format", hints, "html"); if ("html".equalsIgnoreCase(format)) { _formatHTML(columnLabels, rows, out); } else if ("csv".equalsIgnoreCase(format)) { _formatCSV(columnLabels, rows, out); } else { throw new ScriptingException("Unknown value '" + format + "' for hint 'format'"); } } Map<String, Object> outputObjects; if (outputNames != null) { // Output objects not supported outputObjects = new HashMap<String, Object>(); } else { outputObjects = null; } return outputObjects; }
From source file:com.slemarchand.sqlqueryscripting.scripting.sqlquery.SQLQueryExecutor.java
License:Open Source License
private Map _getHints(String sqlQuery) throws ScriptingException { Properties props = new Properties(); try {/*from w w w . j a v a2 s .c o m*/ List<String> lines = IOUtils.readLines(new StringReader(sqlQuery)); StringBuilder hintsStr = new StringBuilder(); for (String l : lines) { l = l.trim(); if (l.startsWith("--")) { hintsStr.append(l.substring(2).trim() + LINE_SEPARATOR); } } props.load(new StringReader(hintsStr.toString())); } catch (IOException e) { throw new ScriptingException(e); } return props; }