/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2005 L.Meckert - lmeckert@club-internet.fr
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.patches;

import fr.gouv.finances.cp.xemelios.updater.AbstractConfigurator;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

/**
 *
 * @author chm
 */
public class Core33013 extends AbstractConfigurator {
    public static final transient String TRANSFORMER_PROPERTY = "javax.xml.transform.TransformerFactory";
    public static final transient String SYS_TRANSFORMER_PROPERTY = "${"+TRANSFORMER_PROPERTY+"}";
    
    public Core33013() {
        super();
    }

    @Override
    public void run() throws Exception {
        String prop = props.replace(SYS_TRANSFORMER_PROPERTY);
        boolean propSet = SYS_TRANSFORMER_PROPERTY.equals(prop);
        if(!propSet) {
            Properties xemProps = new Properties();
            File xemPropsFile = new File(props.replace("${xemelios.prg}/root/xemelios.properties"));
            if(!xemPropsFile.exists()) {
            } else {
                xemProps.load(new FileInputStream(xemPropsFile));
                xemProps.setProperty(TRANSFORMER_PROPERTY, "net.sf.saxon.TransformerFactoryImpl");
                xemProps.store(new FileOutputStream(xemPropsFile),"");
            }
        }
        setPreviousConfigurator(new Core3200());
    }

}
