Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package il.ac.hit
- import java.io._
- import java.net.URL
- import java.text.SimpleDateFormat
- import java.util.StringTokenizer
- import scala.io.Source
- import scala.xml.XML
- import java.util.Date
- // the Model
- object XMLreader extends XMLReaderInterface{
- def connectToUrl (): Int = {
- val url = new URL("http://www.abelski.com/currencies.xml")
- //val url = new URL("http://www.boi.org.il/currency.xml")
- val connection = url.openConnection()
- val document = XML.load(connection.getInputStream)
- var countCurrencies : Int = 0
- val writer = new PrintWriter(new File("CurrenicesData.txt"))
- try{
- writer.write( ((document\\"CURRENCIES")\\"LAST_UPDATE").text )
- writer.write(System.lineSeparator())
- for ( currentData <- (document\\"CURRENCY") ){
- countCurrencies = countCurrencies + 1
- writer.write( (currentData\\"CURRENCYCODE").text + " " + (currentData\\"RATE").text )
- writer.write(System.lineSeparator())
- }
- }
- finally writer.close()
- countCurrencies
- }
- def updateData(currenciesNamesArray: Array[String], currenciesRatesArray: Array[Double]): java.util.Date ={
- connectToUrl()
- var ob = Source.fromFile("CurrenicesData.txt");
- var i_local = 0
- for( line <- ob.getLines.drop(1) ) // to not contain the first line of the file
- {
- var st = new StringTokenizer(line," ", false)
- var currencyName = st.nextToken()
- var currencyRate = st.nextToken().toDouble
- currenciesNamesArray(i_local) = currencyName
- currenciesRatesArray(i_local) = currencyRate
- i_local = i_local + 1
- }
- ob = Source.fromFile("CurrenicesData.txt");
- val iterator = ob.getLines()
- val stringDate = iterator.next()
- val simpleDateFormat:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- val date = simpleDateFormat.parse(stringDate);
- date
- } // end of method
- }// end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement