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.StringPool;
018    
019    import java.util.Map;
020    
021    /**
022     * @author Iv??n Zaera
023     */
024    public class ParameterMapSettings extends BaseSettings {
025    
026            public static final String PREFERENCES_PREFIX = "preferences--";
027    
028            public static final String SETTINGS_PREFIX = "settings--";
029    
030            public ParameterMapSettings(
031                    Map<String, String[]> parameterMap, Settings parentSettings) {
032    
033                    super(parentSettings);
034    
035                    _parameterMap = parameterMap;
036            }
037    
038            @Override
039            protected String doGetValue(String key) {
040                    String[] values = doGetValues(key);
041    
042                    if (values == null) {
043                            return null;
044                    }
045    
046                    return values[0];
047            }
048    
049            @Override
050            protected String[] doGetValues(String key) {
051                    String[] values = _parameterMap.get(key);
052    
053                    if (values == null) {
054                            values = _parameterMap.get(
055                                    PREFERENCES_PREFIX + key + StringPool.DOUBLE_DASH);
056                    }
057    
058                    if (values == null) {
059                            values = _parameterMap.get(
060                                    SETTINGS_PREFIX + key + StringPool.DOUBLE_DASH);
061                    }
062    
063                    return values;
064            }
065    
066            private final Map<String, String[]> _parameterMap;
067    
068    }