/* 
 * This file is part of the PDF Split And Merge source code
 * Created on 22 ott 2015
 * Copyright 2013-2014 by Andrea Vacondio (andrea.vacondio@gmail.com).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.pdfsam.community;

import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.pdfsam.support.RequireUtils.requireNotBlank;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.pdfsam.ConfigurableProperty;
import org.pdfsam.Pdfsam;

/**
 * @author Andrea Vacondio
 *
 */
public class PdfsamCommunity implements Pdfsam {
    private Properties properties = new Properties();
    private String name;
    private String shortName;

    public PdfsamCommunity(String name, String shortName) throws IOException {
        requireNotBlank(name, "Application name cannot be blank");
        requireNotBlank(shortName, "Application short name cannot be blank");
        this.name = name;
        this.shortName = shortName;
        try (InputStream stream = this.getClass().getResourceAsStream("/pdfsam.properties")) {
            properties.load(stream);
        }
    }

    @Override
    public String name() {
        return name;
    }

    @Override
    public String shortName() {
        return shortName;
    }

    @Override
    public String property(ConfigurableProperty prop, String defaultValue) {
        return properties.getProperty(prop.prop, defaultValue);
    }

    @Override
    public String property(ConfigurableProperty prop) {
        return properties.getProperty(prop.prop, EMPTY);
    }
}
