001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.scripting;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.util.ProxyFactory;
019    
020    import java.util.Map;
021    import java.util.Set;
022    
023    /**
024     * @author Alberto Montero
025     * @author Brian Wing Shun Chan
026     * @author Shuyang Zhou
027     */
028    public class ScriptingUtil {
029    
030            public static void clearCache(String language) throws ScriptingException {
031                    getScripting().clearCache(language);
032            }
033    
034            public static ScriptingExecutor createScriptingExecutor(
035                    String language, boolean executeInSeparateThread) {
036    
037                    return getScripting().createScriptingExecutor(
038                            language, executeInSeparateThread);
039            }
040    
041            public static Map<String, Object> eval(
042                            Set<String> allowedClasses, Map<String, Object> inputObjects,
043                            Set<String> outputNames, String language, String script)
044                    throws ScriptingException {
045    
046                    return getScripting().eval(
047                            allowedClasses, inputObjects, outputNames, language, script);
048            }
049    
050            /**
051             * @deprecated As of 7.0.0, replaced by {@link #eval(Set, Map, Set, String,
052             *             String)}
053             */
054            @Deprecated
055            public static Map<String, Object> eval(
056                            Set<String> allowedClasses, Map<String, Object> inputObjects,
057                            Set<String> outputNames, String language, String script,
058                            String... servletContextNames)
059                    throws ScriptingException {
060    
061                    return getScripting().eval(
062                            allowedClasses, inputObjects, outputNames, language, script,
063                            servletContextNames);
064            }
065    
066            public static void exec(
067                            Set<String> allowedClasses, Map<String, Object> inputObjects,
068                            String language, String script)
069                    throws ScriptingException {
070    
071                    getScripting().exec(allowedClasses, inputObjects, language, script);
072            }
073    
074            /**
075             * @deprecated As of 7.0.0, replaced by {@link #exec(Set, Map, String,
076             *             String)}
077             */
078            @Deprecated
079            public static void exec(
080                            Set<String> allowedClasses, Map<String, Object> inputObjects,
081                            String language, String script, String... servletContextNames)
082                    throws ScriptingException {
083    
084                    getScripting().exec(
085                            allowedClasses, inputObjects, language, script,
086                            servletContextNames);
087            }
088    
089            public static Scripting getScripting() {
090                    PortalRuntimePermission.checkGetBeanProperty(ScriptingUtil.class);
091    
092                    return _scripting;
093            }
094    
095            public static Set<String> getSupportedLanguages() {
096                    return getScripting().getSupportedLanguages();
097            }
098    
099            private static final Scripting _scripting =
100                    ProxyFactory.newServiceTrackedInstance(Scripting.class);
101    
102    }