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.security.pacl.permission.PortalRuntimePermission;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portlet.RequestBackedPortletURLFactory;
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                    RequestBackedPortletURLFactory requestBackedPortletURLFactory) {
042    
043                    JSONObject configJSONObject = _editorConfigProvider.getConfigJSONObject(
044                            portletName, editorConfigKey, editorName,
045                            inputEditorTaglibAttributes, themeDisplay,
046                            requestBackedPortletURLFactory);
047    
048                    EditorOptions editorOptions = _editorOptionsProvider.getEditorOptions(
049                            portletName, editorConfigKey, editorName,
050                            inputEditorTaglibAttributes, themeDisplay,
051                            requestBackedPortletURLFactory);
052    
053                    EditorConfigTransformer editorConfigTransformer =
054                            _editorConfigTransformerServiceTrackerMap.getService(editorName);
055    
056                    if (editorConfigTransformer != null) {
057                            editorConfigTransformer.transform(
058                                    editorOptions, inputEditorTaglibAttributes, configJSONObject,
059                                    themeDisplay, requestBackedPortletURLFactory);
060                    }
061    
062                    return new EditorConfigurationImpl(configJSONObject, editorOptions);
063            }
064    
065            public void setEditorConfigProvider(
066                    EditorConfigProvider editorConfigProvider) {
067    
068                    PortalRuntimePermission.checkSetBeanProperty(getClass());
069    
070                    _editorConfigProvider = editorConfigProvider;
071            }
072    
073            public void setEditorOptionsProvider(
074                    EditorOptionsProvider editorOptionsProvider) {
075    
076                    PortalRuntimePermission.checkSetBeanProperty(getClass());
077    
078                    _editorOptionsProvider = editorOptionsProvider;
079            }
080    
081            private static EditorConfigProvider _editorConfigProvider;
082            private static final ServiceTrackerMap<String, EditorConfigTransformer>
083                    _editorConfigTransformerServiceTrackerMap =
084                            ServiceTrackerCollections.openSingleValueMap(
085                                    EditorConfigTransformer.class, "editor.name");
086            private static EditorOptionsProvider _editorOptionsProvider;
087    
088    }