List of usage examples for com.liferay.portal.kernel.scripting ExecutionException ExecutionException
public ExecutionException(Throwable cause)
From source file:au.com.permeance.liferay.clojure.ClojureScriptingExecutor.java
License:Open Source License
/** * Evaluates the supplied script under the clojure runtime. * * @param allowedClasses a set of class names filtering which objects can be accessed. Note: restricting class * access is not supported by this executor, so this parameter must be null or empty. * @param inputObjects a map of input object names and values to expose to the script during execution. * @param outputNames a set of output names to exopse to the script during execution. Note: is expected that the * script is aware of these names and returns a map accordingly containing all relevant entries. * @param script the script to execute. * * @return the result of executing the supplied script and extracting the map entries specified by outputNames from * its result./* w ww. j a v a 2 s . c om*/ * * @throws ScriptingException if an error occurs while executing the supplied script. */ @Override public final Map<String, Object> eval(final Set<String> allowedClasses, final Map<String, Object> inputObjects, final Set<String> outputNames, final String script) throws ScriptingException { if (allowedClasses != null && !allowedClasses.isEmpty()) { throw new ExecutionException("Constrained execution not supported for Clojure"); } final Callable<Map<String, Object>> callable = createCallableForScript(inputObjects, outputNames, script); return callAndWrapException(callable); }
From source file:com.liferay.rtl.scripting.ruby.RubyExecutor.java
License:Open Source License
protected Map<String, Object> doEval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, File scriptFile, String script, ClassLoader... classLoaders) throws ScriptingException { if (allowedClasses != null) { throw new ExecutionException("Constrained execution not supported for Ruby"); }//ww w .jav a 2 s . com try { LocalContextProvider localContextProvider = _scriptingContainer.getProvider(); RubyInstanceConfig rubyInstanceConfig = localContextProvider.getRubyInstanceConfig(); rubyInstanceConfig.setCurrentDirectory(_basePath); if (ArrayUtil.isNotEmpty(classLoaders)) { ClassLoader aggregateClassLoader = AggregateClassLoader .getAggregateClassLoader(PortalClassLoaderUtil.getClassLoader(), classLoaders); rubyInstanceConfig.setLoader(aggregateClassLoader); } rubyInstanceConfig.setLoadPaths(_loadPaths); for (Map.Entry<String, Object> entry : inputObjects.entrySet()) { String inputName = entry.getKey(); Object inputObject = entry.getValue(); if (!inputName.startsWith(StringPool.DOLLAR)) { inputName = StringPool.DOLLAR + inputName; } _scriptingContainer.put(inputName, inputObject); } if (scriptFile != null) { _scriptingContainer.runScriptlet(new FileInputStream(scriptFile), scriptFile.toString()); } else { _scriptingContainer.runScriptlet(script); } if (outputNames == null) { return null; } Map<String, Object> outputObjects = new HashMap<String, Object>(); for (String outputName : outputNames) { outputObjects.put(outputName, _scriptingContainer.get(outputName)); } return outputObjects; } catch (RaiseException re) { throw new ScriptingException(re.getException().message.asJavaString() + "\n\n", re); } catch (FileNotFoundException fnfe) { throw new ScriptingException(fnfe); } finally { try { _globalRuntimeField.set(null, null); } catch (Exception e) { _log.error(e, 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 w ww. j a v a 2s .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
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"); }//w ww .ja v a 2 s . 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; }