Example usage for com.liferay.portal.kernel.scripting ScriptingException ScriptingException

List of usage examples for com.liferay.portal.kernel.scripting ScriptingException ScriptingException

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.scripting ScriptingException ScriptingException.

Prototype

public ScriptingException(String msg, Throwable cause) 

Source Link

Usage

From source file:au.com.permeance.liferay.clojure.ClojureScriptingExecutor.java

License:Open Source License

/**
 * This method calls the supplied {@link Callable}, wrapping any exception it may through with a
 * {@link ScriptingException} compatable with the {@link BaseScriptingExecutor} API.
 *
 * @param callable the callable to invoke.
 * @param <V>      the result type of method <tt>call</tt>
 *
 * @return computed result// w  ww  .ja  v a  2s.  c om
 *
 * @throws ScriptingException if {@link Callable#call()} throws an exception, it will be used as the cause of the
 *                            thrown {@link ScriptingException}.
 */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
protected final <V> V callAndWrapException(final Callable<V> callable) throws ScriptingException {
    try {
        return callable.call();
    }
    // CHECKSTYLE.OFF: IllegalCatch
    catch (final Exception e) {
        // CHECKSTYLE.ON: IllegalCatch
        LOG.error("Error executing clojure script", e);
        throw new ScriptingException("Error executing clojure script", e);
    }
}

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");
    }/*w ww.java  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

private int _getIntegerHint(String hintName, Map<String, String> hints, int defaultValue)
        throws ScriptingException {

    int hint;//from  www . j a v  a2s  . c  o  m

    if (hints.containsKey(hintName)) {
        try {
            hint = Integer.parseInt(hints.get(hintName));
        } catch (NumberFormatException nfe) {
            throw new ScriptingException("Value for " + hintName + " hint must be an integer", nfe);
        }
    } else {
        hint = defaultValue;
    }

    return hint;
}