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.StringUtil;
018    
019    import java.util.Properties;
020    
021    /**
022     * @author Jorge Ferrer
023     * @author Iv??n Zaera
024     */
025    public class PropertiesSettings extends BaseSettings {
026    
027            public PropertiesSettings(
028                    LocationVariableResolver locationVariableResolver,
029                    Properties properties) {
030    
031                    this(locationVariableResolver, properties, null);
032            }
033    
034            public PropertiesSettings(
035                    LocationVariableResolver locationVariableResolver,
036                    Properties properties, Settings parentSettings) {
037    
038                    super(parentSettings);
039    
040                    _locationVariableResolver = locationVariableResolver;
041                    _properties = properties;
042            }
043    
044            @Override
045            protected String doGetValue(String key) {
046                    return readProperty(key);
047            }
048    
049            @Override
050            protected String[] doGetValues(String key) {
051                    return StringUtil.split(doGetValue(key));
052            }
053    
054            protected String getProperty(String key) {
055                    return readProperty(key);
056            }
057    
058            protected String readProperty(String key) {
059                    String value = _properties.getProperty(key);
060    
061                    if (_locationVariableResolver.isLocationVariable(value)) {
062                            return _locationVariableResolver.resolve(value);
063                    }
064    
065                    return value;
066            }
067    
068            private final LocationVariableResolver _locationVariableResolver;
069            private final Properties _properties;
070    
071    }