JSF

JSF Dersleri-Döviz Kuru Çekme Uygulaması

Merhaba arkadaşlar. Bu yazımızda başka bir siteden veri çekmeyi öğreneceğiz. Bu yazıyı hazırlamamda yazrdımcı olan Alper Özaslan‘a buradan teşekkürlerimi iletiyorum.

Verilerini çekeceğimiz sayfa Merkez Bankası’nın kurlarını gösteren sayfa. Eclipse geliştirme ortamında yazdığım projeyi buraya tıklayarak indirebilirsiniz. Özaslan tarafından yazılmış Swing uygulamasını indirmek isteyenler de buraya tıklayarak indirebilir. Uygulamada DOM-Document Object Model (Belge Nesne Modeli) kullanıldı. Şimdi uygulamamızın nasıl çalıştığını, ne yaptığını inceleyelim.

Xml kodlarını düzenlemek için buradaki sayfayı kullanabilirsiniz. Ben merkez bankasınız Xml kodlarını düzenlediğimde şöyle bir sonuç çıktı:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="isokur.xsl"?>
<Tarih_Date Tarih="10.09.2014" Date="09/10/2014">
    <Currency Kod="USD" CurrencyCode="USD">
        <Unit>1</Unit>
        <Isim>ABD DOLARI</Isim>
        <CurrencyName>US DOLLAR</CurrencyName>
        <ForexBuying>2.2022</ForexBuying>
        <ForexSelling>2.2062</ForexSelling>
        <BanknoteBuying>2.2007</BanknoteBuying>
        <BanknoteSelling>2.2095</BanknoteSelling>
        <CrossRateUSD>1</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="CAD" CurrencyCode="CAD">
        <Unit>1</Unit>
        <Isim>KANADA DOLARI</Isim>
        <CurrencyName>CANADIAN DOLLAR</CurrencyName>
        <ForexBuying>2.0007</ForexBuying>
        <ForexSelling>2.0097</ForexSelling>
        <BanknoteBuying>1.9933</BanknoteBuying>
        <BanknoteSelling>2.0173</BanknoteSelling>
        <CrossRateUSD>1.0992</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="XDR" CurrencyCode="XDR">
        <Unit>1</Unit>
        <Isim>�ZEL �EKME HAKKI</Isim>
        <CurrencyName>SPECIAL D.RIGHT</CurrencyName>
        <ForexBuying>3.3054</ForexBuying>
        <ForexSelling />
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD />
        <CrossRateOther>1.49961</CrossRateOther>
    </Currency>
    <Currency Kod="DKK" CurrencyCode="DKK">
        <Unit>1</Unit>
        <Isim>DAN�MARKA KRONU</Isim>
        <CurrencyName>DANISH KRONE</CurrencyName>
        <ForexBuying>0.38215</ForexBuying>
        <ForexSelling>0.38402</ForexSelling>
        <BanknoteBuying>0.38188</BanknoteBuying>
        <BanknoteSelling>0.3849</BanknoteSelling>
        <CrossRateUSD>5.7537</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="SEK" CurrencyCode="SEK">
        <Unit>1</Unit>
        <Isim>�SVE� KRONU</Isim>
        <CurrencyName>SWEDISH KRONA</CurrencyName>
        <ForexBuying>0.30871</ForexBuying>
        <ForexSelling>0.3119</ForexSelling>
        <BanknoteBuying>0.30849</BanknoteBuying>
        <BanknoteSelling>0.31262</BanknoteSelling>
        <CrossRateUSD>7.1032</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="CHF" CurrencyCode="CHF">
        <Unit>1</Unit>
        <Isim>�SV��RE FRANGI</Isim>
        <CurrencyName>SWISS FRANK</CurrencyName>
        <ForexBuying>2.3539</ForexBuying>
        <ForexSelling>2.369</ForexSelling>
        <BanknoteBuying>2.3504</BanknoteBuying>
        <BanknoteSelling>2.3726</BanknoteSelling>
        <CrossRateUSD>0.9334</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="NOK" CurrencyCode="NOK">
        <Unit>1</Unit>
        <Isim>NORVE� KRONU</Isim>
        <CurrencyName>NORWEGIAN KRONE</CurrencyName>
        <ForexBuying>0.34631</ForexBuying>
        <ForexSelling>0.34864</ForexSelling>
        <BanknoteBuying>0.34607</BanknoteBuying>
        <BanknoteSelling>0.34944</BanknoteSelling>
        <CrossRateUSD>6.3434</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="JPY" CurrencyCode="JPY">
        <Unit>100</Unit>
        <Isim>JAPON YEN�</Isim>
        <CurrencyName>YEN</CurrencyName>
        <ForexBuying>2.06</ForexBuying>
        <ForexSelling>2.0736</ForexSelling>
        <BanknoteBuying>2.0524</BanknoteBuying>
        <BanknoteSelling>2.0815</BanknoteSelling>
        <CrossRateUSD>106.65</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="SAR" CurrencyCode="SAR">
        <Unit>1</Unit>
        <Isim>SUUD� ARAB. R�YAL�</Isim>
        <CurrencyName>SAUDI RIYAL</CurrencyName>
        <ForexBuying>0.58717</ForexBuying>
        <ForexSelling>0.58823</ForexSelling>
        <BanknoteBuying>0.58277</BanknoteBuying>
        <BanknoteSelling>0.59264</BanknoteSelling>
        <CrossRateUSD>3.7505</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="KWD" CurrencyCode="KWD">
        <Unit>1</Unit>
        <Isim>KUVEYT D�NARI</Isim>
        <CurrencyName>KUWAITI DINAR</CurrencyName>
        <ForexBuying>7.6374</ForexBuying>
        <ForexSelling>7.7373</ForexSelling>
        <BanknoteBuying>7.5228</BanknoteBuying>
        <BanknoteSelling>7.8534</BanknoteSelling>
        <CrossRateUSD />
        <CrossRateOther>3.4876</CrossRateOther>
    </Currency>
    <Currency Kod="AUD" CurrencyCode="AUD">
        <Unit>1</Unit>
        <Isim>AVUSTRALYA DOLARI</Isim>
        <CurrencyName>AUSTRALIAN DOLL</CurrencyName>
        <ForexBuying>2.0075</ForexBuying>
        <ForexSelling>2.0205</ForexSelling>
        <BanknoteBuying>1.9983</BanknoteBuying>
        <BanknoteSelling>2.0326</BanknoteSelling>
        <CrossRateUSD>1.0944</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="EUR" CurrencyCode="EUR">
        <Unit>1</Unit>
        <Isim>EURO</Isim>
        <CurrencyName>EURO</CurrencyName>
        <ForexBuying>2.8492</ForexBuying>
        <ForexSelling>2.8543</ForexSelling>
        <BanknoteBuying>2.8472</BanknoteBuying>
        <BanknoteSelling>2.8586</BanknoteSelling>
        <CrossRateUSD />
        <CrossRateOther>1.2938</CrossRateOther>
    </Currency>
    <Currency Kod="GBP" CurrencyCode="GBP">
        <Unit>1</Unit>
        <Isim>�NG�L�Z STERL�N�</Isim>
        <CurrencyName>POUND STERLING</CurrencyName>
        <ForexBuying>3.5428</ForexBuying>
        <ForexSelling>3.5612</ForexSelling>
        <BanknoteBuying>3.5403</BanknoteBuying>
        <BanknoteSelling>3.5665</BanknoteSelling>
        <CrossRateUSD />
        <CrossRateOther>1.6115</CrossRateOther>
    </Currency>
    <Currency Kod="RUB" CurrencyCode="RUB">
        <Unit>1</Unit>
        <Isim>RUS RUBLES�</Isim>
        <CurrencyName>RUSSIAN ROUBLE</CurrencyName>
        <ForexBuying>0.0588</ForexBuying>
        <ForexSelling>0.05957</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>37.24</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="RON" CurrencyCode="RON">
        <Unit>1</Unit>
        <Isim>RUMEN LEY�</Isim>
        <CurrencyName>NEW LEU</CurrencyName>
        <ForexBuying>0.63988</ForexBuying>
        <ForexSelling>0.64825</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>3.4223</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="PKR" CurrencyCode="PKR">
        <Unit>1</Unit>
        <Isim>PAK�STAN RUP�S�</Isim>
        <CurrencyName>RUPEE</CurrencyName>
        <ForexBuying>0.02147</ForexBuying>
        <ForexSelling>0.02175</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>102</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="IRR" CurrencyCode="IRR">
        <Unit>100</Unit>
        <Isim>�RAN R�YAL�</Isim>
        <CurrencyName>RIAL</CurrencyName>
        <ForexBuying>0.00822</ForexBuying>
        <ForexSelling>0.00833</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>26627</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="CNY" CurrencyCode="CNY">
        <Unit>1</Unit>
        <Isim>��N YUANI</Isim>
        <CurrencyName>YUAN RENMINBI</CurrencyName>
        <ForexBuying>0.35727</ForexBuying>
        <ForexSelling>0.36195</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>6.1293</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="BGN" CurrencyCode="BGN">
        <Unit>1</Unit>
        <Isim>BULGAR LEVASI</Isim>
        <CurrencyName>BULGARIAN LEV</CurrencyName>
        <ForexBuying>1.4485</ForexBuying>
        <ForexSelling>1.4675</ForexSelling>
        <BanknoteBuying />
        <BanknoteSelling />
        <CrossRateUSD>1.5118</CrossRateUSD>
        <CrossRateOther />
    </Currency>
    <Currency Kod="DEM" CurrencyCode="DEM">
        <Isim>ALMAN MARKI</Isim>
        <CurrencyName>DEUTSCHE MARK</CurrencyName>
        <CrossRateEuro>1.95583</CrossRateEuro>
    </Currency>
    <Currency Kod="BEF" CurrencyCode="BEF">
        <Isim>BEL��KA FRANGI</Isim>
        <CurrencyName>BEL��KA FRANGI</CurrencyName>
        <CrossRateEuro>40.3399</CrossRateEuro>
    </Currency>
    <Currency Kod="LUF" CurrencyCode="LUF">
        <Isim>L�KSEMBURG FRANGI</Isim>
        <CurrencyName>L�KSEMBURG FRANGI</CurrencyName>
        <CrossRateEuro>40.3399</CrossRateEuro>
    </Currency>
    <Currency Kod="ESP" CurrencyCode="ESP">
        <Isim>�SPANYOL PEZETASI</Isim>
        <CurrencyName>�SPANYOL PEZETASI</CurrencyName>
        <CrossRateEuro>166.386</CrossRateEuro>
    </Currency>
    <Currency Kod="FRF" CurrencyCode="FRF">
        <Isim>FRANSIZ FRANGI</Isim>
        <CurrencyName>FRANSIZ FRANGI</CurrencyName>
        <CrossRateEuro>6.55957</CrossRateEuro>
    </Currency>
    <Currency Kod="IEP" CurrencyCode="IEP">
        <Isim>�RLANDA L�RASI</Isim>
        <CurrencyName>�RLANDA L�RASI</CurrencyName>
        <CrossRateEuro>0.787564</CrossRateEuro>
    </Currency>
    <Currency Kod="ITL" CurrencyCode="ITL">
        <Isim>�TALYAN L�RET�</Isim>
        <CurrencyName>�TALYAN L�RET�</CurrencyName>
        <CrossRateEuro>1936.27</CrossRateEuro>
    </Currency>
    <Currency Kod="NLG" CurrencyCode="NLG">
        <Isim>HOLLANDA FLOR�N�</Isim>
        <CurrencyName>HOLLANDA FLOR�N�</CurrencyName>
        <CrossRateEuro>2.20371</CrossRateEuro>
    </Currency>
    <Currency Kod="ATS" CurrencyCode="ATS">
        <Isim>AVUSTURYA ��L�N�</Isim>
        <CurrencyName>AVUSTURYA ��L�N�</CurrencyName>
        <CrossRateEuro>13.7603</CrossRateEuro>
    </Currency>
    <Currency Kod="PTE" CurrencyCode="PTE">
        <Isim>PORTEK�Z ESK�DOSU</Isim>
        <CurrencyName>PORTEK�Z ESK�DOSU</CurrencyName>
        <CrossRateEuro>200.482</CrossRateEuro>
    </Currency>
    <Currency Kod="FIM" CurrencyCode="FIM">
        <Isim>F�N MARKKASI</Isim>
        <CurrencyName>F�N MARKKASI</CurrencyName>
        <CrossRateEuro>5.94573</CrossRateEuro>
    </Currency>
    <Currency Kod="GRD" CurrencyCode="GRD">
        <Isim>YUNAN DRAHM�S�</Isim>
        <CurrencyName>YUNAN DRAHM�S�</CurrencyName>
        <CrossRateEuro>340.750</CrossRateEuro>
    </Currency>
</Tarih_Date>

Bu işlemi neden yaptık diye sorarsanız Java’da yazacağımız kod ile değerleri çekeceğiz. Orada hangi isimler ile çekeceğimizi bilmek için Xml kodunu düzenleyip anlamamız gerekiyordu. Bu Xml kodunda her bir döviz Currency etiketi ile oluşturulmuş. Etiketin içinde de CurrencyName,Isim gibi başka etiketler var. Bu değerleri çekeceğiz.

Şimdi verileri çeken Java kodunu inceleyelim. Bu uygulamada asıl işlemi yapan kod TCMBReader sınıfı içindeki getCurrencies metodudur. Bu metot içinde xhtml sayfasında kullanacağımız listeyi oluşturduk ve metot sonunda return ettik. Daha sonra indireceğimiz Xml dosyasını parse ederken kullanacağımız builder nesnesini oluşturduk. Builder nesnesinin hangi URL’den indirip parse edeceğini bilmesi için de bir URL nesnesi oluşturup URL’i verdik. Ardından belgenin belleğe alınma işlemini tamamlamak için bir Document nesnesi oluşturduk ve verdiğimiz URL ile openStream yaparak akışı tamamladık.

Belgeyi belleğe aldıktan sonra Currency etiketli alanları tek tek topluyoruz ve bunu bir NodeList nesnesine aktarıyoruz. Akabinde bir for döngüsü ile tüm Currency etiketli alanlar içindeki ebilgileri çekiyoruz. Ana etiketli (Kod, CurrencyCode) bilgileri çekerken Element nesnesi işimize yarıyor. Alt etiketli (Isim, CurrencyName vb.) bilgiler içinse getCharacterDataFromElement, getFloat, getElementValue metotları ile bilgileri çekiyoruz.

Diğer Java sınıfımızda ise kullandığımız nesneler ve  get ve set metotları yer almakta. Xhtml sayfasında da dataTable kullandık. Ekran çıktısına ve merkez bankasının şu anki verilerine bakıp karşılaştırma yapalım. Resmi net görmek için üstüne tıklayın.

Adsız

 

 

 

 

 

 

 

 

 

Bu yazıda da bu kadar arkadaşlar. Başka bir yazıda görüşmek üzere hoşçakalın.

 

Yorum Yap