1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.rugged.errors;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.net.URL;
23 import java.net.URLConnection;
24 import java.nio.charset.StandardCharsets;
25 import java.util.Locale;
26 import java.util.MissingResourceException;
27 import java.util.PropertyResourceBundle;
28 import java.util.ResourceBundle;
29
30 import org.hipparchus.exception.Localizable;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public enum RuggedMessages implements Localizable {
52
53
54
55 INTERNAL_ERROR("internal error, please notify development team by creating an issue at {0}"),
56
57 OUT_OF_TILE_INDICES("no data at indices [{0}, {1}], tile only covers from [0, 0] to [{2}, {3}] (inclusive)"),
58
59 OUT_OF_TILE_ANGLES("no data at latitude {0} and longitude {1}, tile covers only latitudes {2} to {3} and longitudes {4} to {5}"),
60
61 NO_DEM_DATA("no Digital Elevation Model data at latitude {0} and longitude {1}"),
62
63 TILE_WITHOUT_REQUIRED_NEIGHBORS_SELECTED("the tile selected for latitude {0} and longitude {1} does not contain required point neighborhood"),
64
65 OUT_OF_TIME_RANGE("date {0} is out of time span [{1}, {2}] (UTC)"),
66
67 UNINITIALIZED_CONTEXT("general context has not been initialized (missing call to {0})"),
68
69 EMPTY_TILE("tile is empty: {0} ⨉ {1}"),
70
71 UNKNOWN_SENSOR("unknown sensor {0}"),
72
73 LINE_OF_SIGHT_DOES_NOT_REACH_GROUND("line-of-sight does not reach ground"),
74
75 LINE_OF_SIGHT_NEVER_CROSSES_LATITUDE("line-of-sight never crosses latitude {0}"),
76
77 LINE_OF_SIGHT_NEVER_CROSSES_LONGITUDE("line-of-sight never crosses longitude {0}"),
78
79 LINE_OF_SIGHT_NEVER_CROSSES_ALTITUDE("line-of-sight never crosses altitude {0}"),
80
81 DEM_ENTRY_POINT_IS_BEHIND_SPACECRAFT("line-of-sight enters the Digital Elevation Model behind spacecraft!"),
82
83 FRAMES_MISMATCH_WITH_INTERPOLATOR_DUMP("frame {0} does not match frame {1} from interpolator dump"),
84
85 NOT_INTERPOLATOR_DUMP_DATA("data is not an interpolator dump"),
86
87 DEBUG_DUMP_ALREADY_ACTIVE("debug dump is already active for this thread"),
88
89 DEBUG_DUMP_ACTIVATION_ERROR("unable to active debug dump with file {0}: {1}"),
90
91 DEBUG_DUMP_NOT_ACTIVE("debug dump is not active for this thread"),
92
93 CANNOT_PARSE_LINE("cannot parse line {0}, file {1}: {2}"),
94
95 LIGHT_TIME_CORRECTION_REDEFINED("light time correction redefined, line {0}, file {1}: {2}"),
96
97 ABERRATION_OF_LIGHT_CORRECTION_REDEFINED("aberration of light correction redefined, line {0}, file {1}: {2}"),
98
99 ATMOSPHERIC_REFRACTION_REDEFINED("atmospheric refraction correction redefined, line {0}, file {1}: {2}"),
100
101 TILE_ALREADY_DEFINED("tile {0} already defined, line {1}, file {2}: {3}"),
102
103 UNKNOWN_TILE("unknown tile {0}, line {1}, file {2}: {3}"),
104
105 NO_PARAMETERS_SELECTED("no parameters have been selected for estimation"),
106
107 NO_REFERENCE_MAPPINGS("no reference mappings for parameters estimation"),
108
109 DUPLICATED_PARAMETER_NAME("a different parameter with name {0} already exists"),
110
111 INVALID_RUGGED_NAME("invalid rugged name"),
112
113 UNSUPPORTED_REFINING_CONTEXT("refining using {0} rugged instance is not handled"),
114
115 NO_LAYER_DATA("no atmospheric layer data at altitude {0} (lowest altitude: {1})"),
116
117 INVALID_STEP("step {0} is not valid : {1}"),
118
119 INVALID_RANGE_FOR_LINES("range between min line {0} and max line {1} is invalid {2}"),
120
121 SENSOR_PIXEL_NOT_FOUND_IN_RANGE_LINES("impossible to find sensor pixel in given range lines (with atmospheric refraction) between lines {0} and {1}"),
122
123 SENSOR_PIXEL_NOT_FOUND_IN_PIXELS_LINE("impossible to find sensor pixel: pixel {0} outside interval [ {1} , {2} [ (with atmospheric refraction margin = {3})");
124
125
126 private static final String RESOURCE_BASE_NAME = "assets/org/orekit/rugged/RuggedMessages";
127
128
129 private final String sourceFormat;
130
131
132
133
134
135 RuggedMessages(final String sourceFormat) {
136 this.sourceFormat = sourceFormat;
137 }
138
139
140 @Override
141 public String getSourceString() {
142 return sourceFormat;
143 }
144
145
146 @Override
147 public String getLocalizedString(final Locale locale) {
148 try {
149 final ResourceBundle bundle =
150 ResourceBundle.getBundle(RESOURCE_BASE_NAME, locale, new UTF8Control());
151 if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
152 final String translated = bundle.getString(name());
153 if (translated.length() > 0 &&
154 !translated.toLowerCase(locale).contains("missing translation")) {
155
156 return translated;
157 }
158 }
159
160 } catch (MissingResourceException mre) {
161
162 }
163
164
165
166 return sourceFormat;
167
168 }
169
170
171
172
173
174
175
176
177 public static class UTF8Control extends ResourceBundle.Control {
178
179
180 @Override
181 public ResourceBundle newBundle(final String baseName, final Locale locale, final String format,
182 final ClassLoader loader, final boolean reload) throws IOException {
183
184 final String bundleName = toBundleName(baseName, locale);
185 final String resourceName = toResourceName(bundleName, "utf8");
186 ResourceBundle bundle = null;
187 InputStream stream = null;
188 if (reload) {
189 final URL url = loader.getResource(resourceName);
190 if (url != null) {
191 final URLConnection connection = url.openConnection();
192 if (connection != null) {
193 connection.setUseCaches(false);
194 stream = connection.getInputStream();
195 }
196 }
197 } else {
198 stream = loader.getResourceAsStream(resourceName);
199 }
200 if (stream != null) {
201 try (InputStreamReader inputStreamReader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
202
203 bundle = new PropertyResourceBundle(inputStreamReader);
204 }
205 }
206 return bundle;
207 }
208
209 }
210
211 }