public class DefaultXmlFileValidator extends DefaultFileValidator
null
. DefaultFileValidator
,
ErrorHandler
,
XMLUtils.loadXmlFromFile(File)
,
Serialized FormALL
Constructor and Description |
---|
DefaultXmlFileValidator()
Default constructor, where the parameters are:
mustExists =
true
readable = true
writable = false
acceptFileType = AcceptFileType.FILE
|
DefaultXmlFileValidator(boolean writable)
Constructor, where the parameters are:
mustExists =
true
readable = true
acceptFileType = AcceptFileType.FILE
|
DefaultXmlFileValidator(File schemaFile)
Creates a DefaultXmlFileValidator where the XML file will be validated against a schema file.
|
DefaultXmlFileValidator(String resourceName)
Constructor where the file is load through "
Class.class.getResource(resourceName); ". |
DefaultXmlFileValidator(URL schemaUrl)
Creates a DefaultXmlFileValidator where the XML file will be validated against a schema url.
|
Modifier and Type | Method and Description |
---|---|
Document |
getDocument(File file)
Loads a XML file as an DOM Document and validates it against the defined schema.
|
org.apache.commons.logging.Log |
getLogger()
Gets the logger
|
List<String> |
getRestrictions()
Gets a detailed description of the FileValidator with any constraints that might influence the validation.
|
URL |
getSchemaUrl()
Gets the schema URL,
|
String |
getType()
A short string defining the type of "file" the FileValidator is validating.
|
void |
setSchemaUrl(URL schemaUrl)
Sets the schema URL
|
void |
validate(String sourceType,
String sourceName,
String intialValue,
File file)
Method to implement for validation a
File . |
void |
validateFile(File file)
Validates a XML file using the SchemaURL.
|
getAcceptFileType, isMustExists, isReadable, isWriteable
public DefaultXmlFileValidator()
true
true
false
AcceptFileType.FILE
public DefaultXmlFileValidator(File schemaFile) throws PropertyException
schemaFile
- the schema file, ignored if null
.PropertyException
- if the schemaFile cannot be converted to a URL representation.public DefaultXmlFileValidator(URL schemaUrl)
schemaUrl
- the schema url, ignored if null
.public DefaultXmlFileValidator(String resourceName)
Class.class.getResource(resourceName);
". resourceName
- the path/name of the desired resourcepublic DefaultXmlFileValidator(boolean writable)
true
true
AcceptFileType.FILE
writable
- if true
test that the file/directory must be writable otherwise an exception is thrown when validating.public URL getSchemaUrl()
null
is returned.public void setSchemaUrl(URL schemaUrl)
schemaUrl
- the schema url.public void validate(String sourceType, String sourceName, String intialValue, File file) throws PropertyException
FileValidator
File
.validate
in interface FileValidator
validate
in class DefaultFileValidator
sourceType
- the type from where the FileValidator is called, this is used to make sensible exception messages.sourceName
- the sourceName of from where the FileValidator is called, this is used to make sensible exception messages.intialValue
- the initial value which the File has been initialized.file
- the file instance.PropertyException
- thrown if fails validation. The intention of the message build is sourceType [sourceName with value [intialValue] <the error message
> [file.getAbsolutePath()].public Document getDocument(File file) throws PropertyIOException
file
- thePropertyIOException
- if loading or validation failed.XMLUtils.loadXmlFromFile(File, URL)
public void validateFile(File file) throws PropertyIOException
file
- the filePropertyIOException
- if the file wasnt found or the XML did not validate.getSchemaUrl()
,
XMLUtils.validateXmlFile(File, URL)
public List<String> getRestrictions()
FileValidator
getRestrictions
in interface FileValidator
getRestrictions
in class DefaultFileValidator
public String getType()
FileValidator
getType
in interface FileValidator
getType
in class DefaultFileValidator
public org.apache.commons.logging.Log getLogger()
FileValidator
getLogger
in interface FileValidator
getLogger
in class DefaultFileValidator