001package uk.ac.ebi.pride.jmztab2.utils;
002
003import java.io.IOException;
004import java.util.Properties;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007import static uk.ac.ebi.pride.jmztab2.model.MZTabConstants.NEW_LINE;
008import uk.ac.ebi.pride.jmztab2.utils.errors.LogicalErrorType;
009import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorType;
010
011/**
012 * This class will load the properties used by the mzTab-M library for message formatting during validation.
013 *
014 * @author qingwei
015 * @author nilshoffmann
016 * @since 29/01/13
017 *
018 */
019public final class MZTabProperties {
020
021    private static Logger LOGGER = LoggerFactory.
022        getLogger(MZTabProperties.class);
023
024    private MZTabProperties() {
025
026    }
027
028    private static final Properties properties = new Properties();
029
030    static {
031        loadProperties("/conf1_1/mztab.properties");
032        loadProperties("/conf1_1/mztab_format_error.properties");
033        loadProperties("/conf1_1/mztab_logical_error.properties");
034        loadProperties("/conf1_1/mztab_crosscheck_error.properties");
035    }
036
037    private static void loadProperties(String path) {
038        try {
039            properties.load(MZTabProperties.class.getResourceAsStream(path));
040        } catch (IOException e) {
041            LOGGER.error(
042                "Could not load properties from classpath location: " + path, e.
043                    getMessage());
044        }
045    }
046
047    /**
048     * <p>
049     * getProperty.</p>
050     *
051     * @param key a {@link java.lang.String} object.
052     * @return a {@link java.lang.String} object.
053     */
054    public static String getProperty(String key) {
055        return properties.getProperty(key);
056    }
057
058    /**
059     * Constant
060     * <code>MZTAB_EXCEPTION_MESSAGE="There exist errors in the metadata sect"{trunked}</code>
061     */
062    public static final String MZTAB_EXCEPTION_MESSAGE = "There exist errors in the metadata section or "
063        + "protein/peptide/small_molecule/small_molecule_feature/small_molecule_evidence header section! Validation will stop, and ignore data table check!" + NEW_LINE;
064    /**
065     * Constant
066     * <code>MZTAB_ERROR_OVERFLOW_EXCEPTION_MESSAGE="System error queue overflow! + NEW_LINE"</code>
067     */
068    public static final String MZTAB_ERROR_OVERFLOW_EXCEPTION_MESSAGE = "System error queue overflow!" + NEW_LINE;
069
070    /**
071     * Constant <code>ENCODE="getProperty(mztab.encode)"</code>
072     */
073    public static final String ENCODE = getProperty("mztab.encode");
074    /**
075     * Constant
076     * <code>MAX_ERROR_COUNT=Integer.parseInt(getProperty("mztab.max_error_count"))</code>
077     */
078    public static final int MAX_ERROR_COUNT = Integer.parseInt(getProperty(
079        "mztab.max_error_count"));
080    /**
081     * Constant <code>LEVEL</code>
082     */
083    public static final LogicalErrorType.Level LEVEL = MZTabErrorType.findLevel(
084        getProperty("mztab.level"));
085
086}