net.dpml.cli.validation
Class FileValidator
java.lang.Objectnet.dpml.cli.validation.FileValidator
- Validator
The
FileValidator validates the string argument
values are files. If the value is a file, the string value in
the
java.util.List of values is replaced with the
java.io.File instance.
The following attributes can also be specified using the
appropriate settors:
- existing
- is a file
- is a directory
The following example shows how to limit the valid values
for the config attribute to files that exist.
...
ArgumentBuilder builder = new ArgumentBuilder();
FileValidator validator = FileValidator.getExistingFileInstance();
Argument age =
builder.withName("config");
.withValidator(validator);
static FileValidator | getExistingDirectoryInstance()- Returns a
FileValidator for existing directories.
|
static FileValidator | getExistingFileInstance()- Returns a
FileValidator for existing files.
|
static FileValidator | getExistingInstance()- Returns a
FileValidator for existing files/directories.
|
boolean | isDirectory()- Returns whether the argument values must represent directories.
|
boolean | isExisting()- Returns whether the argument values must represent existing
files/directories.
|
boolean | isFile()- Returns whether the argument values must represent directories.
|
void | setDirectory(boolean directory)- Specifies whether the argument values must represent directories.
|
void | setExisting(boolean existing)- Specifies whether the argument values must represent existing
files/directories.
|
void | setFile(boolean file)- Specifies whether the argument values must represent files.
|
void | validate(List values)- Validate the list of values against the list of permitted values.
|
getExistingInstance
public static FileValidator getExistingInstance()
Returns a FileValidator for existing files/directories.
- a
FileValidator for existing files/directories.
isDirectory
public boolean isDirectory()
Returns whether the argument values must represent directories.
- whether the argument values must represent directories.
isExisting
public boolean isExisting()
Returns whether the argument values must represent existing
files/directories.
- whether the argument values must represent existing
files/directories.
isFile
public boolean isFile()
Returns whether the argument values must represent directories.
- whether the argument values must represent directories.
setDirectory
public void setDirectory(boolean directory)
Specifies whether the argument values must represent directories.
directory - specifies whether the argument values must
represent directories.
setExisting
public void setExisting(boolean existing)
Specifies whether the argument values must represent existing
files/directories.
existing - specifies whether the argument values must
represent existing files/directories.
setFile
public void setFile(boolean file)
Specifies whether the argument values must represent files.
file - specifies whether the argument values must
represent files.
validate
public void validate(List values)
throws InvalidArgumentException Validate the list of values against the list of permitted values.
If a value is valid, replace the string in the values
java.util.List with the java.io.File instance.
- validate in interface Validator
values - the list of values to validate
net.dpml.cli.validation.Validator.validate(java.util.List)