package dynamic.sitebackup;

import dynamic.WebBackup;
import dynamic.common.FilePutter;

import java.io.File;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: John
 * Date: 25/04/12
 * Time: 12:54
 * To change this template use File | Settings | File Templates.
 */
public class PageSaver {


    public static void savePage(String directory, String url, String contents) {

        File root = new File(directory);
        if(!root.exists())
            root.mkdir();

        String target_directory_string = url.substring(WebBackup.BASE_URL.length() +1);

        File target_file = new File(directory + "/" + target_directory_string + ".html");
        target_file.getParentFile().mkdirs();

        try {
            FilePutter.PutInFile(target_file.getAbsolutePath(),contents);
        } catch (IOException e) {
            WebBackup.flagError("*** error saving to " + target_file.getAbsolutePath());
        }

    }


}
