/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2007 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.dropUsers;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.JOptionPane;

import fr.gouv.finances.cp.utils.PropertiesExpansion;
import fr.gouv.finances.dgfip.xemelios.common.Scramble;

public class ResetHim {
    public static final transient String PROP_CONFIG_FILE_NAME = "xemelios.mysql.config.filename";
    
    /**
     * @param args
     */
    public ResetHim() {
        String configFileName = System.getProperty(PROP_CONFIG_FILE_NAME);
        PropertiesExpansion props = new PropertiesExpansion();
        for(Object key:System.getProperties().keySet()) {
            props.put(key,System.getProperty((String)key));
        }
        try {
            props.load(new FileInputStream(configFileName));
            Class.forName(props.getProperty("driver.class"));
            String cryptedPass = props.getProperty("password");
            String clearPass = Scramble.unScramblePassword(cryptedPass);
            props.setProperty("password",clearPass);
            Connection con = DriverManager.getConnection(props.getProperty("database.url"),props);
            DlgResetAdminPassword dlg = new DlgResetAdminPassword(con);
            dlg.setVisible(true);
            con.close();
        } catch(Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
        System.exit(0);
    }
    
    public static void main(String args[]) {
        new ResetHim();
    }
    
}