40,6 → 40,13 |
*/ |
public class RatesUpdater implements Runnable |
{ |
/* |
* XML markup attributes |
*/ |
private static final String ATTR_RATE = "rate"; //$NON-NLS-1$ |
private static final String ATTR_CURRENCY = "currency"; //$NON-NLS-1$ |
private static final String ATTR_TIME = "time"; //$NON-NLS-1$ |
|
private static final String URL_ECB = |
"http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; //$NON-NLS-1$ |
|
49,8 → 56,11 |
private final UpdateService service; |
|
/** |
* @param activityContext |
* The activityContext for this updater. |
* FIXME: Required only for database access |
* @param updateService |
* |
* The service that started this updater |
*/ |
public RatesUpdater(CurrenciesActivity activityContext, |
UpdateService updateService) |
69,6 → 79,7 |
|
/** |
* @param updateThread |
* the thread that this updater is running in |
*/ |
public void setUpdateThread(ConverterThread updateThread) |
{ |
133,12 → 144,13 |
|
try |
{ |
updated = df.parse(parentCube.getAttribute("time")); |
updated = |
df.parse(parentCube.getAttribute(RatesUpdater.ATTR_TIME)); |
} |
catch (ParseException e) |
{ |
Log.e(this.getClass().toString(), |
"Could not parse the `time' attribute into a Date", e); |
"Could not parse the `time' attribute into a Date", e); //$NON-NLS-1$ |
} |
|
expr = |
155,12 → 167,12 |
for (int i = 0; i < len; ++i) |
{ |
Element item = (Element) childCubes.item(i); |
String currency = item.getAttribute("currency"); |
String currency = item.getAttribute(RatesUpdater.ATTR_CURRENCY); |
|
try |
{ |
Double rate = |
Double.parseDouble(item.getAttribute("rate")); //$NON-NLS-1$ |
Double.parseDouble(item.getAttribute(RatesUpdater.ATTR_RATE)); |
conversionRates |
.put(currency, new ConversionData(rate, updated)); |
} |
171,28 → 183,27 |
} |
|
this.activityContext.getDatabase().writeConversionsToDatabase(null); |
this.activityContext.fillTableRates(); |
} |
catch (XPathExpressionException e) |
{ |
Log.e(this.getClass().toString(), "Error in XPath expression", e); |
Log.e(this.getClass().toString(), "Error in XPath expression", e); //$NON-NLS-1$ |
} |
} |
catch (SAXException e) |
{ |
Log.e(this.getClass().toString(), |
"Exception while parsing external XML resource", e); |
"Exception while parsing external XML resource", e); //$NON-NLS-1$ |
} |
catch (IOException e) |
{ |
Log.e(this.getClass().toString(), |
"I/O exception while parsing external XML resource", e); |
"I/O exception while parsing external XML resource", e); //$NON-NLS-1$ |
} |
} |
catch (ParserConfigurationException e) |
{ |
Log.e(this.getClass().toString(), |
"Document builder cannot be created", e); |
"Document builder cannot be created", e); //$NON-NLS-1$ |
} |
|
if (len > 0) |