Skip to content
Snippets Groups Projects
Commit 392e37c0 authored by ribeaudc's avatar ribeaudc
Browse files

[LMS-414] remove: - 'IFile.exists', 'IFile.isDirectory',...

[LMS-414] remove: - 'IFile.exists', 'IFile.isDirectory', 'IFile.canReadAndWrite' (replaced by 'IFile.check')
- TODO regarding processing directory
add: - 'tryGetDirectoryForAbsolutePaths' and 'tryGetDirectoryForRelativePaths' to 'PathPrefixPrepender'

SVN: 6059
parent a588a145
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,10 @@ import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; ...@@ -31,6 +31,10 @@ import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
*/ */
public final class PathPrefixPrepender public final class PathPrefixPrepender
{ {
private final File absolutePathsDirectoryOrNull;
private final File relativePathsDirectoryOrNull;
private final String prefixForAbsolutePaths; private final String prefixForAbsolutePaths;
private final String prefixForRelativePaths; private final String prefixForRelativePaths;
...@@ -42,15 +46,21 @@ public final class PathPrefixPrepender ...@@ -42,15 +46,21 @@ public final class PathPrefixPrepender
public PathPrefixPrepender(final String prefixForAbsolutePathsOrNull, public PathPrefixPrepender(final String prefixForAbsolutePathsOrNull,
final String prefixForRelativePathsOrNull) throws ConfigurationFailureException final String prefixForRelativePathsOrNull) throws ConfigurationFailureException
{ {
this.prefixForAbsolutePaths = StringUtils.defaultString(prefixForAbsolutePathsOrNull); this.prefixForAbsolutePaths = defaultString(prefixForAbsolutePathsOrNull);
assertValid(this.prefixForAbsolutePaths, "absolute"); absolutePathsDirectoryOrNull = tryCreateFile(this.prefixForAbsolutePaths, "absolute");
this.prefixForRelativePaths = preparePrefix(prefixForRelativePathsOrNull); this.prefixForRelativePaths = preparePrefix(defaultString(prefixForRelativePathsOrNull));
assertValid(this.prefixForRelativePaths, "relative"); relativePathsDirectoryOrNull = tryCreateFile(this.prefixForRelativePaths, "relative");
}
private final static String defaultString(final String path)
{
return StringUtils.defaultString(path).trim();
} }
private final static String preparePrefix(final String pathPrefix) private final static String preparePrefix(final String pathPrefix)
{ {
if (StringUtils.isEmpty(pathPrefix)) assert pathPrefix != null : "Unspecified path prefix.";
if (pathPrefix.length() == 0)
{ {
return ""; return "";
} }
...@@ -61,25 +71,44 @@ public final class PathPrefixPrepender ...@@ -61,25 +71,44 @@ public final class PathPrefixPrepender
return pathPrefix + "/"; return pathPrefix + "/";
} }
private void assertValid(final String prefix, final String type) private final static File tryCreateFile(final String prefix, final String type)
throws ConfigurationFailureException throws ConfigurationFailureException
{ {
if (prefix.length() != 0) assert prefix != null : "Unspecified path prefix.";
if (prefix.length() > 0)
{ {
final File file = new File(prefix); final File file = new File(prefix);
if (file.exists() == false) final String response =
FileUtilities.checkDirectoryFullyAccessible(file, type + " prefix path");
if (response != null)
{ {
throw ConfigurationFailureException.fromTemplate( throw new ConfigurationFailureException(response);
"Invalid prefix for %s paths: given file '%s' does not exist.", type, file
.getAbsolutePath());
} }
return file;
} }
return null;
}
/**
* Returns the directory for absolute paths.
*/
public final File tryGetDirectoryForAbsolutePaths()
{
return absolutePathsDirectoryOrNull;
}
/**
* Returns the directory for relative paths.
*/
public final File tryGetDirectoryForRelativePaths()
{
return relativePathsDirectoryOrNull;
} }
/** /**
* Returns the specified path with the appropriated prefix. * Returns the specified path with the appropriated prefix.
*/ */
public String addPrefixTo(final String path) public final String addPrefixTo(final String path)
{ {
assert path != null : "Undefined path."; assert path != null : "Undefined path.";
return (FilenameUtils.getPrefixLength(path) > 0 ? prefixForAbsolutePaths return (FilenameUtils.getPrefixLength(path) > 0 ? prefixForAbsolutePaths
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment