Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java @ 9178:2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
author | gernotbelger |
---|---|
date | Tue, 26 Jun 2018 19:48:35 +0200 |
parents | |
children | dace17e26d33 |
comparison
equal
deleted
inserted
replaced
9177:37db8c4c44b7 | 9178:2f5052835b76 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.uinfo.inundationduration; | |
11 | |
12 import java.util.HashMap; | |
13 import java.util.LinkedHashMap; | |
14 import java.util.Map; | |
15 import java.util.Properties; | |
16 | |
17 import org.apache.commons.lang.text.StrSubstitutor; | |
18 import org.dive4elements.artifacts.CallMeta; | |
19 import org.dive4elements.artifacts.common.utils.Config; | |
20 import org.dive4elements.river.artifacts.resources.Resources; | |
21 | |
22 /** | |
23 * @author Domenico Nardi Tironi | |
24 * | |
25 */ | |
26 public class UedauernPropertiesHelper { | |
27 | |
28 private static UedauernPropertiesHelper instance; | |
29 private final String CONFIG_FILE; | |
30 private final String rivername; | |
31 private Integer[] mittelStartEnde = null; | |
32 private String[] einzeljahre = null; | |
33 private String mittelUrl = null; | |
34 private Properties properties = null; | |
35 | |
36 public UedauernPropertiesHelper(final String rivername) { | |
37 this.rivername = rivername; | |
38 this.CONFIG_FILE = makeFileName(rivername); | |
39 } | |
40 | |
41 public static synchronized UedauernPropertiesHelper getInstance(final String rivername) { | |
42 if (UedauernPropertiesHelper.instance == null || !UedauernPropertiesHelper.instance.getRivername().equals(rivername)) { | |
43 | |
44 UedauernPropertiesHelper.instance = new UedauernPropertiesHelper(rivername); | |
45 } | |
46 return UedauernPropertiesHelper.instance; | |
47 } | |
48 | |
49 private String getRivername() { | |
50 return this.rivername; | |
51 } | |
52 | |
53 private static final String makeFileName(final String river) { | |
54 return "uinfo_uedauern_aue_" + river + ".properties"; | |
55 } | |
56 | |
57 public LinkedHashMap<String, String> getExtraLayers(final CallMeta meta) { | |
58 final LinkedHashMap<String, String> entries = new LinkedHashMap<>(); | |
59 | |
60 final Integer[] totalEpoch = getMittelStartEnd(); | |
61 final Object[] args = new Object[] { String.valueOf(totalEpoch[0]), String.valueOf(totalEpoch[1]) }; | |
62 | |
63 // final ResourceBundle rb = ResourceBundle.getBundle("Name"); | |
64 entries.put("state.uinfo.totalepoch", Resources.getMsg(meta, "state.uinfo.totalepoch", args)); // | |
65 // String.valueOf: avoid formatting | |
66 // (3.333,00 | |
67 | |
68 return entries; | |
69 } | |
70 | |
71 private Properties getProperties() { | |
72 if (this.properties == null) { | |
73 this.properties = Config.loadProperties(this.CONFIG_FILE); | |
74 } | |
75 return this.properties; | |
76 } | |
77 | |
78 private final Integer[] getMittelStartEnd() { | |
79 if (this.mittelStartEnde == null) { | |
80 final Integer mittel_start = Integer.valueOf(getProperties().get("mittel_start").toString()); | |
81 final Integer mittel_ende = Integer.valueOf(getProperties().get("mittel_ende").toString()); | |
82 this.mittelStartEnde = new Integer[] { mittel_start, mittel_ende }; // lazy | |
83 | |
84 } | |
85 return this.mittelStartEnde; | |
86 } | |
87 | |
88 public String[] getEinzeljahre() { | |
89 if (this.einzeljahre == null) { // lazy | |
90 final Object years = getProperties().get("jahre"); | |
91 if (years != null) { | |
92 this.einzeljahre = years.toString().split(","); | |
93 } | |
94 } | |
95 return this.einzeljahre; | |
96 } | |
97 | |
98 public final String getMittelUrl() { | |
99 if (this.mittelUrl == null) { // lazy | |
100 this.mittelUrl = getProperties().get("mittel_url").toString(); | |
101 } | |
102 return this.mittelUrl; | |
103 } | |
104 | |
105 public final String urlFromYear(final int year) { | |
106 // besser kein lazy-loading, da der user nochmal zurück gehen und das Jahr ändern könnte... | |
107 final String templateUrl = getProperties().get("url").toString(); | |
108 final Map<String, String> tokens = new HashMap<>(); | |
109 tokens.put("jahr", String.valueOf(year)); | |
110 final StrSubstitutor subst = new StrSubstitutor(tokens); | |
111 final String yearUrl = subst.replace(templateUrl); | |
112 return yearUrl; | |
113 } | |
114 | |
115 public static boolean fileExistsForRiver(final String river) { | |
116 final Properties properties = Config.loadProperties(makeFileName(river)); | |
117 if (properties.size() == 0) { | |
118 return false; | |
119 } | |
120 return true; | |
121 } | |
122 } |