/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package fr.gouv.finances.cp.xemelios.export;

import fr.gouv.finances.cp.utils.Amount;
import fr.gouv.finances.cp.xemelios.utils.HtmlTableWriter;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

/**
 *
 * @author chm
 */
public class HtmlTableExporterXls97SR1 extends HtmlTableExporter {
    private static DecimalFormat decF = new DecimalFormat("0.00");
    static {
        DecimalFormatSymbols dfs = decF.getDecimalFormatSymbols();
        dfs.setDecimalSeparator(',');
        decF.setDecimalFormatSymbols(dfs);
        decF.setGroupingUsed(false);
    }

    public HtmlTableExporterXls97SR1(Exporter exporter) {
        super(exporter);
    }

    @Override
    protected String getModelFileName() {
        return "/modeleExportXemelios-97SR1.xls";
    }
   /**
    * Formatage de l'objet a ecrire
    */
    @Override
   protected String formatted(Object o, Integer line) {

      // Reconnaitre seleon me type
      String rawStr;
      Integer styleId;
      Integer level = 3;
      if (o instanceof java.lang.Integer) {
         rawStr = ((Integer) o).toString();
         styleId = HtmlTableWriter.INTEGER_CELLFORMAT;
      } else if (o instanceof java.lang.Float) {
         //rawStr = ((Float) o).toString();
          rawStr = decF.format(((Float)o).floatValue());
         styleId = HtmlTableWriter.FLOAT_CELLFORMAT;
      } else if (o instanceof java.util.Date) {
         rawStr = df.format(o);
         styleId = HtmlTableWriter.DATE_CELLFORMAT;
      } else if (o instanceof Amount) {
//         Double d = new Double(((Amount) o).doubleValue());
         rawStr = decF.format(((Amount)o).doubleValue());
         styleId = HtmlTableWriter.FLOAT_CELLFORMAT;
      } else if (o instanceof java.lang.String) {
         rawStr = (String) o;
         styleId = HtmlTableWriter.TEXT_CELLFORMAT;
      } else {
         rawStr = o.toString();
         styleId = -1;
      }

      // mettre en gras les titres
      if (line == 0) {
         level = 1;
      }
      if (line == 1) {
         level = 2;
      }
      return HtmlTableWriter.buildCell(rawStr, styleId, level);
   }
    
}
