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    /**
018     * @author Iv??n Zaera
019     */
020    public class FallbackSettings extends BaseSettings {
021    
022            public FallbackSettings(
023                    Settings parentSettings, FallbackKeys fallbackKeys) {
024    
025                    super(parentSettings);
026    
027                    _fallbackKeys = fallbackKeys;
028            }
029    
030            @Override
031            protected String doGetValue(String key) {
032                    String value = parentSettings.getValue(key, null);
033    
034                    if (value != null) {
035                            return value;
036                    }
037    
038                    String[] fallbackKeysArray = _fallbackKeys.get(key);
039    
040                    for (String fallbackKey : fallbackKeysArray) {
041                            value = parentSettings.getValue(fallbackKey, null);
042    
043                            if (value != null) {
044                                    return value;
045                            }
046                    }
047    
048                    return null;
049            }
050    
051            @Override
052            protected String[] doGetValues(String key) {
053                    String[] values = parentSettings.getValues(key, null);
054    
055                    if (values != null) {
056                            return values;
057                    }
058    
059                    String[] fallbackKeysArray = _fallbackKeys.get(key);
060    
061                    for (String fallbackKey : fallbackKeysArray) {
062                            values = parentSettings.getValues(fallbackKey, null);
063    
064                            if (values != null) {
065                                    return values;
066                            }
067                    }
068    
069                    return null;
070            }
071    
072            private final FallbackKeys _fallbackKeys;
073    
074    }