Project

General

Profile

Download (1.58 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.util;
10

    
11
import java.io.File;
12
import java.io.FileInputStream;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15
import java.util.Properties;
16

    
17
import eu.etaxonomy.cdm.common.CdmUtils;
18

    
19
/**
20
 * @author a.kohlbecker
21
 * @since May 8, 2017
22
 *
23
 */
24
public class ConfigFileUtils extends CdmUtils {
25

    
26
    private static final String CDM_VAADIN_CONFIG_FOLDER = "cdm-vaadin";
27

    
28
    //TODO better store in VaadinSession?
29
    static Properties uiprops = null;
30

    
31
    public static File getPropertiesFile(String instanceName, String propertiesSet) {
32

    
33
        File vaadinConfigFolder = getCdmSubDir(CDM_VAADIN_CONFIG_FOLDER);
34
        return new File(vaadinConfigFolder, instanceName + (propertiesSet == null? "" : "-" + propertiesSet) + ".properties");
35

    
36
    }
37

    
38
    public static Properties getApplicationProperties(String instanceName) throws IOException {
39
        if(uiprops == null){
40
            uiprops = new Properties();
41
            File uiPropertiesFile = getPropertiesFile(instanceName, "app");
42
            if(uiPropertiesFile.exists()){
43
                try {
44
                    uiprops.load(new FileInputStream(uiPropertiesFile));
45
                } catch (FileNotFoundException e) {
46
                    // must not happen since we checked before
47
                }
48
            }
49
        }
50
        return uiprops;
51
    }
52
}
(8-8/11)