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.kernel.portlet.configuration.icon;
016    
017    import com.liferay.portal.kernel.util.ListUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.registry.ServiceReference;
021    import com.liferay.registry.collections.ServiceReferenceMapper;
022    import com.liferay.registry.util.StringPlus;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * @author Eudaldo Alonso
029     */
030    public class PortletConfigurationIconServiceReferenceMapper
031            implements ServiceReferenceMapper<String, PortletConfigurationIconFactory> {
032    
033            @Override
034            public void map(
035                    ServiceReference<PortletConfigurationIconFactory> serviceReference,
036                    Emitter<String> emitter) {
037    
038                    String portletId = (String)serviceReference.getProperty(
039                            "javax.portlet.name");
040    
041                    if (Validator.isNull(portletId)) {
042                            portletId = StringPool.STAR;
043                    }
044    
045                    List<String> paths = StringPlus.asList(
046                            serviceReference.getProperty("path"));
047    
048                    if (ListUtil.isEmpty(paths)) {
049                            paths = new ArrayList<>();
050    
051                            paths.add(StringPool.DASH);
052                    }
053    
054                    for (String path : paths) {
055                            emitter.emit(getKey(portletId, path));
056                    }
057            }
058    
059            protected String getKey(String portletId, String path) {
060                    return portletId + StringPool.COLON + path;
061            }
062    
063    }