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.EditorOptions;
018    import com.liferay.portal.kernel.editor.configuration.EditorOptionsContributor;
019    import com.liferay.portal.kernel.util.ListUtil;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.RequestBackedPortletURLFactory;
022    import com.liferay.registry.collections.ServiceReferenceMapper;
023    import com.liferay.registry.collections.ServiceTrackerCollections;
024    import com.liferay.registry.collections.ServiceTrackerMap;
025    
026    import java.util.Iterator;
027    import java.util.List;
028    import java.util.Map;
029    
030    /**
031     * @author Sergio Gonz??lez
032     */
033    public class EditorOptionsProvider
034            extends BaseEditorConfigurationProvider<EditorOptionsContributor> {
035    
036            public EditorOptions getEditorOptions(
037                    String portletName, String editorConfigKey, String editorName,
038                    Map<String, Object> inputEditorTaglibAttributes,
039                    ThemeDisplay themeDisplay,
040                    RequestBackedPortletURLFactory requestBackedPortletURLFactory) {
041    
042                    EditorOptions editorOptions = new EditorOptions();
043    
044                    Iterator<EditorOptionsContributor> iterator = ListUtil.reverseIterator(
045                            getContributors(portletName, editorConfigKey, editorName));
046    
047                    while (iterator.hasNext()) {
048                            EditorOptionsContributor editorOptionsContributor = iterator.next();
049    
050                            editorOptionsContributor.populateEditorOptions(
051                                    editorOptions, inputEditorTaglibAttributes, themeDisplay,
052                                    requestBackedPortletURLFactory);
053                    }
054    
055                    return editorOptions;
056            }
057    
058            @Override
059            protected ServiceTrackerMap<String, List<EditorOptionsContributor>>
060                    getServiceTrackerMap() {
061    
062                    return _serviceTrackerMap;
063            }
064    
065            private static final ServiceReferenceMapper
066                    <String, EditorOptionsContributor>
067                            _serviceReferenceMapper = new EditorServiceReferenceMapper<>();
068            private static final ServiceTrackerMap
069                    <String, List<EditorOptionsContributor>> _serviceTrackerMap =
070                            ServiceTrackerCollections.openMultiValueMap(
071                                    EditorOptionsContributor.class,
072                                    "(|(editor.config.key=*)(editor.name=*)(javax.portlet.name=*)" +
073                                            "(objectClass=" + EditorOptionsContributor.class.getName() +
074                                                    "))",
075                                    _serviceReferenceMapper);
076    
077    }