/*
 * Copyright
 *   2008 axYus - www.axyus.com
 *   2008 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


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

import fr.gouv.finances.dgfip.utils.Amount;
import fr.gouv.finances.dgfip.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!=null ? 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);
   }
    
}
