Skip to content
ManageFolder.java 1.52 KiB
Newer Older
xtof's avatar
xtof committed
package org.josast.databaseSync.config;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ManageFolder {

	private static Logger appLogger = Logger.getLogger("AmsatLogger");
	private String RepositoryPath = null;


	private String defaultrepository = "data";

	public ManageFolder() {
		RepositoryPath = System.getProperty("user.dir") + "\\" + defaultrepository;
	}

	public ManageFolder(String path) {

		if (path == null) {
			RepositoryPath = System.getProperty("user.dir") + "\\" + defaultrepository;

		} else if (path.length() == 0) {
			RepositoryPath = System.getProperty("user.dir") + "\\+defaultrepository";
		} else {
			RepositoryPath = System.getProperty("user.dir") + "\\" + path;
		}
	}
	
	/**
	 * @return the repositoryPath
	 */
	public String getRepositoryPath() {
		return RepositoryPath;
	}

	/**
	 * @param repositoryPath the repositoryPath to set
	 */
	public void setRepositoryPath(String repositoryPath) {
		RepositoryPath = repositoryPath;
	}

	public void createdDirectories() {

		Path path = Paths.get(RepositoryPath);
		// if directory exists?
		if (!Files.exists(path)) {
			try {
				Files.createDirectories(path);
				appLogger.info("directory created : " + RepositoryPath);
			} catch (IOException e) {
				appLogger.log(Level.SEVERE, "cannot create outpout directorie " + e.toString());
			}
		} else
		{
			appLogger.info("directory already exist : " + RepositoryPath);
		}

	}

}