Project

General

Profile

« Previous | Next » 

Revision 22fc2a78

Added by Andreas Kohlbecker almost 7 years ago

ref #6628 moving the ConfigFileUtils into cdmlib

View differences:

src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
29 29
import com.vaadin.spring.server.SpringVaadinServlet;
30 30
import com.vaadin.ui.UI;
31 31

  
32
import eu.etaxonomy.cdm.common.ConfigFileUtil;
32 33
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer;
33 34
import eu.etaxonomy.cdm.vaadin.security.annotation.EnableAnnotationBasedAccessControl;
34 35
import eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI;
......
36 37
import eu.etaxonomy.cdm.vaadin.ui.InactiveUIException;
37 38
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUI;
38 39
import eu.etaxonomy.cdm.vaadin.ui.StatusEditorUI;
39
import eu.etaxonomy.cdm.vaadin.util.ConfigFileUtils;
40 40
import eu.etaxonomy.vaadin.ui.annotation.EnableVaadinSpringNavigation;
41 41

  
42 42
/**
......
158 158
    }
159 159

  
160 160

  
161

  
162
    static final String PROPERTIES_NAME = "vaadin-apps";
163

  
164
    private Properties appProps = null;
165

  
166
    //@formatter:off
167
    private static final String APP_FILE_CONTENT=
168
            "########################################################\n"+
169
            "#                                                       \n"+
170
            "# Vaadin application specific configurations            \n"+
171
            "#                                                       \n"+
172
            "########################################################\n"+
173
            "                                                        \n"+
174
            "# Enablement of vaadin uis.                             \n"+
175
            "#                                                       \n"+
176
            "# Multiple uis can be defined as comma separated list.  \n"+
177
            "# Whitespace before and after the comma will be ignored.\n"+
178
            "# Valid values are the path properties of the @SpringUI \n"+
179
            "# annotation which is used for UI classes.              \n"+
180
            "cdm-vaadin.ui.activated=concept,distribution,editstatus \n";
181
    //@formatter:on
182

  
161 183
    /**
162 184
     * Checks if the ui class supplied is activated by listing it in the properties by its {@link SpringUI#path()} value.
163 185
     *
......
166 188
     * @throws InactiveUIException
167 189
     */
168 190
    private boolean isUIEnabled(Class<? extends UI>uiClass) throws InactiveUIException {
169
        String path = uiClass.getAnnotation(SpringUI.class).path();
191
        String path = uiClass.getAnnotation(SpringUI.class).path().trim();
170 192

  
171 193
        try {
172
            Properties appProps = ConfigFileUtils.getApplicationProperties(dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId());
194
            if(appProps == null){
195
                String currentDataSourceId = dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId();
196
                appProps = new ConfigFileUtil()
197
                        .setDefaultContent(APP_FILE_CONTENT)
198
                        .getProperties(currentDataSourceId, PROPERTIES_NAME);
199
            }
173 200
            if(appProps.get(CDM_VAADIN_UI_ACTIVATED) != null){
174 201
                String[] uiPaths = appProps.get(CDM_VAADIN_UI_ACTIVATED).toString().split("\\s*,\\s*");
175
                return Arrays.asList(uiPaths).stream().anyMatch(p -> p.equals(path));
202
                if(Arrays.asList(uiPaths).stream().anyMatch(p -> p.trim().equals(path))){
203
                    return true;
204
                }
176 205
            }
177 206
            throw new InactiveUIException(path);
178 207
        } catch (IOException e) {
src/main/java/eu/etaxonomy/cdm/vaadin/util/ConfigFileUtils.java
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
    //TODO better store in VaadinSession?
27
    static Properties uiprops = null;
28

  
29
    public static File getPropertiesFile(String instanceName, String propertiesSet) {
30

  
31
        File configFolder = getCdmHomeSubDir(CdmUtils.SUBFOLDER_WEBAPP);
32
        return new File(configFolder, instanceName + (propertiesSet == null? "" : "-" + propertiesSet) + ".properties");
33

  
34
    }
35

  
36
    public static Properties getApplicationProperties(String instanceName) throws IOException {
37
        if(uiprops == null){
38
            uiprops = new Properties();
39
            File uiPropertiesFile = getPropertiesFile(instanceName, "app");
40
            if(uiPropertiesFile.exists()){
41
                try {
42
                    uiprops.load(new FileInputStream(uiPropertiesFile));
43
                } catch (FileNotFoundException e) {
44
                    // must not happen since we checked before
45
                }
46
            }
47
        }
48
        return uiprops;
49
    }
50
}
src/main/java/eu/etaxonomy/cdm/vaadin/util/VaadinConfigFileUtils.java
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 eu.etaxonomy.cdm.common.ConfigFileUtil;
12

  
13
/**
14
 * Extends ConfigFileUtils to add Vaadin application specific default content
15
 *
16
 * @author a.kohlbecker
17
 * @since May 9, 2017
18
 *
19
 */
20
public class VaadinConfigFileUtils extends ConfigFileUtil {
21

  
22

  
23

  
24

  
25

  
26
}

Also available in: Unified diff