Skip to content

Commit f005f06

Browse files
committed
Updated ECB parser
1 parent ec5b3b6 commit f005f06

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/ECBAbstractRateProvider.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.InputStream;
1919
import java.math.MathContext;
20+
import java.nio.charset.StandardCharsets;
2021
import java.time.LocalDate;
2122
import java.time.format.DateTimeFormatter;
2223
import java.util.Comparator;
@@ -46,6 +47,8 @@
4647
import org.javamoney.moneta.spi.DefaultNumberValue;
4748
import org.javamoney.moneta.spi.loader.LoaderService;
4849
import org.javamoney.moneta.spi.loader.LoaderService.LoaderListener;
50+
import org.xml.sax.InputSource;
51+
import org.xml.sax.XMLReader;
4952

5053
/**
5154
* Base to all Europe Central Bank implementation.
@@ -97,8 +100,18 @@ abstract class ECBAbstractRateProvider extends AbstractRateProvider implements
97100
public void newDataLoaded(String resourceId, InputStream is) {
98101
final int oldSize = this.rates.size();
99102
try {
100-
SAXParser parser = saxParserFactory.newSAXParser();
101-
parser.parse(is, new ECBRateReadingHandler(rates, getContext()));
103+
final SAXParser parser = saxParserFactory.newSAXParser();
104+
//parser.parse(is, new ECBRateReadingHandler(rates, getContext()));
105+
106+
XMLReader xmlReader = parser.getXMLReader();
107+
xmlReader.setContentHandler(new ECBRateReadingHandler(rates, getContext()));
108+
109+
final InputSource source = new InputSource(is);
110+
111+
// different encoding
112+
source.setEncoding(StandardCharsets.UTF_8.displayName());
113+
xmlReader.parse(source);
114+
102115
int newSize = this.rates.size();
103116
loadState = "Loaded " + resourceId + " exchange rates for days:" + (newSize - oldSize);
104117
LOG.config(loadState);

moneta-core/src/main/java/org/javamoney/moneta/spi/DefaultConfigProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ private void updateConfig(Properties props) {
9797
priorities.put(key, prio);
9898
config.put(key, value);
9999
} else if (existingPrio == prio) {
100-
throw new IllegalStateException(
101-
"AmbiguousConfiguration detected for '" + key + "'.");
100+
// throw new IllegalStateException(
101+
// "AmbiguousConfiguration detected for '" + key + "'.");
102+
LOG.warning("AmbiguousConfiguration detected for '" + key + "'.");
102103
}
103104
// else ignore entry with lower prio!
104105
}

moneta-core/src/main/java/org/javamoney/moneta/spi/LazyBoundCurrencyConversion.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
2+
Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
33
44
Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
use this file except in compliance with the License. You may obtain a copy of
@@ -31,6 +31,8 @@
3131
* target timestamp.
3232
*
3333
* @author Anatole Tresch
34+
* @author Werner Keil
35+
* @author otaviojava
3436
*/
3537
public class LazyBoundCurrencyConversion extends AbstractCurrencyConversion implements CurrencyConversion {
3638

@@ -89,5 +91,4 @@ public String toString() {
8991
return "CurrencyConversion [MonetaryAmount -> MonetaryAmount; provider=" + rateProvider + ", context=" +
9092
getContext() + ", termCurrency=" + getCurrency() + ']';
9193
}
92-
9394
}

0 commit comments

Comments
 (0)