Skip to content

Commit d498f37

Browse files
committed
added reader config
1 parent 3c198c2 commit d498f37

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

core/src/main/java/com/bc/fiduceo/core/SystemConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static SystemConfig load(InputStream inputStream) {
5656
final Document document = saxBuilder.build(inputStream);
5757
return new SystemConfig(document);
5858
} catch (JDOMException | IOException | RuntimeException e) {
59-
throw new RuntimeException("Unable to initialize use case configuration: " + e.getMessage(), e);
59+
throw new RuntimeException("Unable to initialize system configuration: " + e.getMessage(), e);
6060
}
6161
}
6262

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.bc.fiduceo.reader.slstr;
2+
3+
import com.bc.fiduceo.util.JDomUtils;
4+
import org.jdom.Document;
5+
import org.jdom.Element;
6+
import org.jdom.JDOMException;
7+
import org.jdom.input.SAXBuilder;
8+
9+
import java.io.IOException;
10+
import java.io.InputStream;
11+
12+
class SlstrReaderConfig {
13+
14+
private boolean usePixelGeoCoding;
15+
16+
SlstrReaderConfig(Document document) {
17+
this();
18+
19+
final Element rootElement = JDomUtils.getMandatoryRootElement("slstr-reader-config", document);
20+
final Element usePixelGeoCodingElement = rootElement.getChild("use-pixel-geocoding");
21+
if (usePixelGeoCodingElement != null) {
22+
usePixelGeoCoding = Boolean.parseBoolean(usePixelGeoCodingElement.getTextTrim());
23+
}
24+
}
25+
26+
SlstrReaderConfig() {
27+
usePixelGeoCoding = false;
28+
}
29+
30+
static SlstrReaderConfig load(InputStream inputStream) {
31+
final SAXBuilder saxBuilder = new SAXBuilder();
32+
try {
33+
final Document document = saxBuilder.build(inputStream);
34+
return new SlstrReaderConfig(document);
35+
} catch (JDOMException | IOException | RuntimeException e) {
36+
throw new RuntimeException("Unable to initialize reader configuration: " + e.getMessage(), e);
37+
}
38+
}
39+
40+
boolean usePixelGeoCoding() {
41+
return usePixelGeoCoding;
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.bc.fiduceo.reader.slstr;
2+
3+
import org.junit.Test;
4+
5+
import java.io.ByteArrayInputStream;
6+
7+
import static org.junit.Assert.assertFalse;
8+
import static org.junit.Assert.assertTrue;
9+
10+
public class SlstrReaderConfigTest {
11+
12+
@Test
13+
public void testConstruction() {
14+
final SlstrReaderConfig config = new SlstrReaderConfig();
15+
16+
assertFalse(config.usePixelGeoCoding());
17+
}
18+
19+
@Test
20+
public void testLoadAndGet_usePixelGeoCoding() {
21+
final String useCaseXml = "<slstr-reader-config>" +
22+
" <use-pixel-geocoding>true</use-pixel-geocoding>" +
23+
"</slstr-reader-config>";
24+
final ByteArrayInputStream inputStream = new ByteArrayInputStream(useCaseXml.getBytes());
25+
26+
final SlstrReaderConfig config = SlstrReaderConfig.load(inputStream);
27+
28+
assertTrue(config.usePixelGeoCoding());
29+
}
30+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<slstr-reader-config>
2+
<use-pixel-geocoding>false</use-pixel-geocoding>
3+
</slstr-reader-config>

0 commit comments

Comments
 (0)