package e4s.tutorial;

import java.text.SimpleDateFormat;

import e4s.application.CurrencyCode;
import e4s.application.CurrencyCode.CURRENCY;
import e4s.html.*;
import e4s.servlet.E4ModuleImplementation;


/**
 * Usage of CurrencyCodes. Currency codes are defined within E4S and there is a mechanism implemented which 
 * reads the current exchange rates automatically from the European Central Bank (ECB). 
 *
 * {@tutorial Example_CurrencyCode}
 * 
 * @see e4s.application.CurrencyCode
 */
public class Example_CurrencyCode extends E4ModuleImplementation
{
   public static E4Method start = null;
   
   public void start( HTML html )
   {
      BODY body = html.BODY();
      body.Message(E4Message.CAPTION,"Currency Codes");
      
      body.P();
      
      TABLE table = body.TABLE(TABLE.E4S_DEFAULT_TABLE());
      
      CURRENCY[] currencies = CurrencyCode.getCurrencies();
      
      for( int i = 0; i < currencies.length; i++ )
      {
         TR tr = table.TR();
         
         float rate = currencies[i].getRate();
         
         tr.TD().print(currencies[i].getCode());
         tr.TD().print(currencies[i].getName());
         tr.TD().print(null2nbsp(currencies[i].getSymbol()));

         // get the rate from EZB
         if (Float.isNaN(rate))
            tr.TD().print(NBSP);
         else
            tr.TD(Align.RIGHT).print(rate);
      }
      
      SimpleDateFormat df_date = getDateFormat();
      SimpleDateFormat df_time = getTimeFormat();
      
      FONT f = body.FONT(FONT.ARIAL_smaller);
      CurrencyCode.addLegend(f, getApplObj());
   }
}