| | |
| | | import org.opends.quicksetup.i18n.ResourceProvider; |
| | | |
| | | import java.io.*; |
| | | import java.util.logging.Logger; |
| | | import java.util.logging.Level; |
| | | |
| | | /** |
| | | * Utility class for use by applications containing methods for managing |
| | |
| | | */ |
| | | public class FileManager { |
| | | |
| | | static private final Logger LOG = |
| | | Logger.getLogger(FileManager.class.getName()); |
| | | |
| | | private Application application = null; |
| | | |
| | | /** |
| | | * Creates a new file manager. |
| | | * @param app Application managing files. |
| | | */ |
| | | public FileManager() { |
| | | // do nothing; |
| | | } |
| | | |
| | | /** |
| | | * Creates a new file manager. |
| | | * @param app Application managing files to which progress notifications |
| | | * will be sent |
| | | */ |
| | | public FileManager(Application app) { |
| | | this.application = app; |
| | |
| | | } else { |
| | | // Just tell that the file/directory does not exist. |
| | | String[] arg = {file.toString()}; |
| | | application.notifyListeners(application.getFormattedWarning( |
| | | getMsg("file-does-not-exist", arg))); |
| | | |
| | | |
| | | if (application != null) { |
| | | application.notifyListeners(application.getFormattedWarning( |
| | | getMsg("file-does-not-exist", arg))); |
| | | } |
| | | LOG.log(Level.INFO, "file '" + file.toString() + "' does not exist"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (!destination.exists()) { |
| | | if (Utils.insureParentsExist(destination)) { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-copying-file", args))); |
| | | |
| | | if (application != null) { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-copying-file", args))); |
| | | } |
| | | LOG.log(Level.INFO, "copying file '" + |
| | | objectFile.getAbsolutePath() + "' to '" + |
| | | destination.getAbsolutePath() + "'"); |
| | | try { |
| | | FileInputStream fis = new FileInputStream(objectFile); |
| | | FileOutputStream fos = new FileOutputStream(destination); |
| | |
| | | } |
| | | } |
| | | |
| | | application.notifyListeners(application.getFormattedDone() + |
| | | application.getLineBreak()); |
| | | if (application != null) { |
| | | application.notifyListeners(application.getFormattedDone() + |
| | | application.getLineBreak()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | String errMsg = getMsg("error-copying-file", args); |
| | |
| | | ApplicationException.Type.FILE_SYSTEM_ERROR, errMsg, null); |
| | | } |
| | | } else { |
| | | application.notifyListeners(getMsg("info-ignoring-file", args) + |
| | | application.getLineBreak()); |
| | | LOG.log(Level.INFO, "Ignoring file '" + |
| | | objectFile.getAbsolutePath() + "' since '" + |
| | | destination.getAbsolutePath() + "' already exists"); |
| | | if (application != null) { |
| | | application.notifyListeners(getMsg("info-ignoring-file", args) + |
| | | application.getLineBreak()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | String[] arg = {file.getAbsolutePath()}; |
| | | boolean isFile = file.isFile(); |
| | | |
| | | if (isFile) { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-deleting-file", arg))); |
| | | } else { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-deleting-directory", arg))); |
| | | if (application != null) { |
| | | if (isFile) { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-deleting-file", arg))); |
| | | } else { |
| | | application.notifyListeners(application.getFormattedWithPoints( |
| | | getMsg("progress-deleting-directory", arg))); |
| | | } |
| | | } |
| | | LOG.log(Level.INFO, "deleting " + |
| | | (isFile ? " file " : " directory ") + |
| | | file.getAbsolutePath()); |
| | | |
| | | boolean delete = false; |
| | | /* |
| | |
| | | ApplicationException.Type.FILE_SYSTEM_ERROR, errMsg, null); |
| | | } |
| | | |
| | | application.notifyListeners(application.getFormattedDone() + |
| | | application.getLineBreak()); |
| | | if (application != null) { |
| | | application.notifyListeners(application.getFormattedDone() + |
| | | application.getLineBreak()); |
| | | } |
| | | } |
| | | } |
| | | |