| Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.utils; |
| 2 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 3 | import de.ids_mannheim.korap.config.BeanInjectable; |
| 4 | |
| Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 5 | import java.io.File; |
| 6 | import java.io.FileInputStream; |
| 7 | import java.io.IOException; |
| 8 | import java.util.HashMap; |
| 9 | import java.util.Map; |
| 10 | import java.util.Properties; |
| 11 | |
| 12 | /** |
| 13 | * @author hanl |
| 14 | * @date 27/09/2014 |
| 15 | */ |
| 16 | public abstract class PropertyReader { |
| 17 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 18 | protected Map<String, Properties> read (String path) throws IOException { |
| Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 19 | Map<String, Properties> res = new HashMap<>(); |
| 20 | Properties s = new Properties(); |
| 21 | s.load(new FileInputStream(new File(path))); |
| 22 | for (Map.Entry<Object, Object> e : s.entrySet()) { |
| 23 | String key = e.getKey().toString().split("\\.")[0]; |
| 24 | Properties in = res.get(key); |
| 25 | if (in == null) { |
| 26 | in = new Properties(); |
| 27 | res.put(key, in); |
| 28 | } |
| 29 | in.setProperty(e.getKey().toString(), e.getValue().toString()); |
| 30 | } |
| 31 | return res; |
| 32 | } |
| 33 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 34 | |
| 35 | public abstract void load (); |
| Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 36 | |
| 37 | } |