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.settings;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    
019    import java.util.Map;
020    
021    /**
022     * @author Ivan Zaera
023     */
024    public class ParameterMapSettingsLocator implements SettingsLocator {
025    
026            public ParameterMapSettingsLocator(
027                    Map<String, String[]> parameterMap, SettingsLocator settingsLocator) {
028    
029                    this(parameterMap, null, settingsLocator);
030            }
031    
032            public ParameterMapSettingsLocator(
033                    Map<String, String[]> parameterMap, String parameterNamePrefix,
034                    SettingsLocator settingsLocator) {
035    
036                    _parameterMap = parameterMap;
037                    _parameterNamePrefix = parameterNamePrefix;
038                    _settingsLocator = settingsLocator;
039            }
040    
041            @Override
042            public Settings getSettings() throws SettingsException {
043                    Settings settings = _settingsLocator.getSettings();
044    
045                    ParameterMapSettings parameterMapSettings = new ParameterMapSettings(
046                            _parameterMap, settings);
047    
048                    if (Validator.isNotNull(_parameterNamePrefix)) {
049                            parameterMapSettings.setParameterNamePrefix(_parameterNamePrefix);
050                    }
051    
052                    return parameterMapSettings;
053            }
054    
055            @Override
056            public String getSettingsId() {
057                    return _settingsLocator.getSettingsId();
058            }
059    
060            private final Map<String, String[]> _parameterMap;
061            private final String _parameterNamePrefix;
062            private final SettingsLocator _settingsLocator;
063    
064    }