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.editor.configuration;
016    
017    import com.liferay.portal.kernel.editor.configuration.EditorConfigTransformer;
018    import com.liferay.portal.kernel.editor.configuration.EditorConfiguration;
019    import com.liferay.portal.kernel.editor.configuration.EditorConfigurationFactory;
020    import com.liferay.portal.kernel.editor.configuration.EditorOptions;
021    import com.liferay.portal.kernel.json.JSONObject;
022    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
023    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.registry.collections.ServiceTrackerCollections;
026    import com.liferay.registry.collections.ServiceTrackerMap;
027    
028    import java.util.Map;
029    
030    /**
031     * @author Sergio Gonz??lez
032     */
033    public class EditorConfigurationFactoryImpl
034            implements EditorConfigurationFactory {
035    
036            @Override
037            public EditorConfiguration getEditorConfiguration(
038                    String portletName, String editorConfigKey, String editorName,
039                    Map<String, Object> inputEditorTaglibAttributes,
040                    ThemeDisplay themeDisplay,
041                    LiferayPortletResponse liferayPortletResponse) {
042    
043                    JSONObject configJSONObject = _editorConfigProvider.getConfigJSONObject(
044                            portletName, editorConfigKey, editorName,
045                            inputEditorTaglibAttributes, themeDisplay, liferayPortletResponse);
046    
047                    EditorOptions editorOptions = _editorOptionsProvider.getEditorOptions(
048                            portletName, editorConfigKey, editorName,
049                            inputEditorTaglibAttributes, themeDisplay, liferayPortletResponse);
050    
051                    EditorConfigTransformer editorConfigTransformer =
052                            _editorConfigTransformerServiceTrackerMap.getService(editorName);
053    
054                    if (editorConfigTransformer != null) {
055                            editorConfigTransformer.transform(
056                                    editorOptions, inputEditorTaglibAttributes, themeDisplay,
057                                    liferayPortletResponse, configJSONObject);
058                    }
059    
060                    return new EditorConfigurationImpl(configJSONObject, editorOptions);
061            }
062    
063            public void setEditorConfigProvider(
064                    EditorConfigProvider editorConfigProvider) {
065    
066                    PortalRuntimePermission.checkSetBeanProperty(getClass());
067    
068                    _editorConfigProvider = editorConfigProvider;
069            }
070    
071            public void setEditorOptionsProvider(
072                    EditorOptionsProvider editorOptionsProvider) {
073    
074                    PortalRuntimePermission.checkSetBeanProperty(getClass());
075    
076                    _editorOptionsProvider = editorOptionsProvider;
077            }
078    
079            private static EditorConfigProvider _editorConfigProvider;
080            private static final ServiceTrackerMap<String, EditorConfigTransformer>
081                    _editorConfigTransformerServiceTrackerMap =
082                            ServiceTrackerCollections.singleValueMap(
083                                    EditorConfigTransformer.class, "editor.name");
084            private static EditorOptionsProvider _editorOptionsProvider;
085    
086            static {
087                    _editorConfigTransformerServiceTrackerMap.open();
088            }
089    
090    }