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 clearCache(String language) throws ScriptingException {
034                    getScripting().clearCache(language);
035            }
036    
037            public static Map<String, Object> eval(
038                            Set<String> allowedClasses, Map<String, Object> inputObjects,
039                            Set<String> outputNames, String language, String script,
040                            ClassLoader... classLoaders)
041                    throws ScriptingException {
042    
043                    return getScripting().eval(
044                            allowedClasses, inputObjects, outputNames, language, script,
045                            classLoaders);
046            }
047    
048            public static void exec(
049                            Set<String> allowedClasses, Map<String, Object> inputObjects,
050                            String language, String script, ClassLoader... classLoaders)
051                    throws ScriptingException {
052    
053                    getScripting().exec(
054                            allowedClasses, inputObjects, language, script, classLoaders);
055            }
056    
057            public static Map<String, Object> getPortletObjects(
058                    PortletConfig portletConfig, PortletContext portletContext,
059                    PortletRequest portletRequest, PortletResponse portletResponse) {
060    
061                    return getScripting().getPortletObjects(
062                            portletConfig, portletContext, portletRequest, portletResponse);
063            }
064    
065            public static Scripting getScripting() {
066                    PortalRuntimePermission.checkGetBeanProperty(ScriptingUtil.class);
067    
068                    return _scripting;
069            }
070    
071            public static Set<String> getSupportedLanguages() {
072                    return getScripting().getSupportedLanguages();
073            }
074    
075            public void setScripting(Scripting scripting) {
076                    PortalRuntimePermission.checkSetBeanProperty(getClass());
077    
078                    _scripting = scripting;
079            }
080    
081            private static Scripting _scripting;
082    
083    }