001    /**
002     * Copyright (c) 2000-2012 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    
019    import java.util.Map;
020    import java.util.Set;
021    
022    import javax.portlet.PortletConfig;
023    import javax.portlet.PortletContext;
024    import javax.portlet.PortletRequest;
025    import javax.portlet.PortletResponse;
026    
027    /**
028     * @author Alberto Montero
029     * @author Brian Wing Shun Chan
030     */
031    public class ScriptingUtil {
032    
033            public static void addScriptingExecutor(
034                    String language, ScriptingExecutor scriptingExecutor) {
035    
036                    getScripting().addScriptingExecutor(language, scriptingExecutor);
037            }
038    
039            public static void clearCache(String language) throws ScriptingException {
040                    getScripting().clearCache(language);
041            }
042    
043            public static Map<String, Object> eval(
044                            Set<String> allowedClasses, Map<String, Object> inputObjects,
045                            Set<String> outputNames, String language, String script,
046                            ClassLoader... classLoaders)
047                    throws ScriptingException {
048    
049                    return getScripting().eval(
050                            allowedClasses, inputObjects, outputNames, language, script,
051                            classLoaders);
052            }
053    
054            public static void exec(
055                            Set<String> allowedClasses, Map<String, Object> inputObjects,
056                            String language, String script, ClassLoader... classLoaders)
057                    throws ScriptingException {
058    
059                    getScripting().exec(
060                            allowedClasses, inputObjects, language, script, classLoaders);
061            }
062    
063            public static Map<String, Object> getPortletObjects(
064                    PortletConfig portletConfig, PortletContext portletContext,
065                    PortletRequest portletRequest, PortletResponse portletResponse) {
066    
067                    return getScripting().getPortletObjects(
068                            portletConfig, portletContext, portletRequest, portletResponse);
069            }
070    
071            public static Scripting getScripting() {
072                    PortalRuntimePermission.checkGetBeanProperty(ScriptingUtil.class);
073    
074                    return _scripting;
075            }
076    
077            public static Set<String> getSupportedLanguages() {
078                    return getScripting().getSupportedLanguages();
079            }
080    
081            public void setScripting(Scripting scripting) {
082                    PortalRuntimePermission.checkSetBeanProperty(getClass());
083    
084                    _scripting = scripting;
085            }
086    
087            private static Scripting _scripting;
088    
089    }