1 package cz.cuni.amis.pogamut.base.utils.configuration;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.util.Properties;
8
9 import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
10 import cz.cuni.amis.utils.configuration.PropertyProvider;
11 import cz.cuni.amis.utils.exception.PogamutException;
12
13
14
15
16
17 public class CustomPropertiesProvider extends PropertyProvider {
18
19 LogCategory log = new LogCategory("CustomPropertiesProvider");
20
21 static final String resource = "PogamutPlatformCustom.properties";
22 Properties properties = new Properties();
23 File propFile;
24
25 public CustomPropertiesProvider() {
26 log.addConsoleHandler();
27 try {
28 propFile = new File(resource);
29 properties.load(new FileInputStream(propFile));
30 } catch (FileNotFoundException e) {
31
32 log.warning("Custom property file not found in " + propFile.getAbsolutePath() + ".");
33 } catch (IOException ex) {
34 throw new PogamutException("I/O exception while reading the custom Pogamut platform property file 'PogamutPlatformCustom.properties', absolute location '" + propFile.getAbsolutePath() + "'.", ex, log, this);
35 }
36 }
37
38 @Override
39 public String getProperty(String key) {
40 return properties.getProperty(key);
41 }
42
43 @Override
44 public int getPriority() {
45 return 1000;
46 }
47
48 @Override
49 public String toString() {
50 return "CustomPropertiesProvider[source='" + propFile.getAbsolutePath() + "']";
51 }
52 }