public class XMLValidateTask extends Task
Type | Property and Description |
---|---|
XMLValidateTask.Property |
create
Creates a property.
|
Modifier and Type | Class and Description |
---|---|
static class |
XMLValidateTask.Attribute
The class to create to set a feature of the parser.
|
static class |
XMLValidateTask.Property
A Parser property.
|
protected class |
XMLValidateTask.ValidatorErrorHandler
ValidatorErrorHandler role :
log SAX parse exceptions,
remember if an error occurred
|
Modifier and Type | Field and Description |
---|---|
protected Path |
classpath |
protected XMLValidateTask.ValidatorErrorHandler |
errorHandler |
protected boolean |
failOnError |
protected File |
file
file to be validated
|
protected Vector |
filesets
sets of file to be validated
|
protected static String |
INIT_FAILED_MSG |
protected boolean |
lenient |
static String |
MESSAGE_FILES_VALIDATED
Message for successful validation
|
protected String |
readerClassName |
protected boolean |
warn |
protected org.xml.sax.XMLReader |
xmlReader
the parser is viewed as a SAX2 XMLReader.
|
Constructor and Description |
---|
XMLValidateTask() |
Modifier and Type | Method and Description |
---|---|
void |
addConfiguredXMLCatalog(XMLCatalog catalog)
add an XMLCatalog as a nested element; optional.
|
void |
addFileset(FileSet set)
specify a set of file to be checked
|
protected void |
cleanup()
Cleans up resources.
|
XMLValidateTask.Attribute |
createAttribute()
Add an attribute nested element.
|
Path |
createClasspath() |
protected org.xml.sax.XMLReader |
createDefaultReader()
Create a reader if the use of the class did not specify another one.
|
DTDLocation |
createDTD()
Create a DTD location record; optional.
|
XMLValidateTask.Property |
createProperty()
Creates a property.
|
protected org.xml.sax.XMLReader |
createXmlReader()
create the XML reader.
|
protected boolean |
doValidate(File afile)
parse the file
|
void |
execute()
execute the task
|
protected org.xml.sax.EntityResolver |
getEntityResolver()
accessor to the xmlCatalog used in the task
|
protected org.xml.sax.XMLReader |
getXmlReader()
get the XML reader.
|
void |
init()
Called by the project to let the task initialize properly.
|
protected void |
initValidator()
init the parser :
load the parser class, and set features if necessary
It is only after this that the reader is valid
|
protected boolean |
isSax1Parser()
test that returns true if we are using a SAX1 parser.
|
protected void |
onSuccessfulValidation(int fileProcessed)
handler called on successful file validation.
|
void |
setClassName(String className)
Specify the class name of the SAX parser to be used.
|
void |
setClasspath(Path classpath)
Specify the classpath to be searched to load the parser (optional)
|
void |
setClasspathRef(Reference r)
Where to find the parser class; optional.
|
void |
setFailOnError(boolean fail)
Specify how parser error are to be handled.
|
protected void |
setFeature(String feature,
boolean value)
Set a feature on the parser.
|
void |
setFile(File file)
specify the file to be checked; optional.
|
void |
setLenient(boolean bool)
Specify whether the parser should be validating.
|
protected void |
setProperty(String name,
String value)
Sets a property.
|
void |
setWarn(boolean bool)
Specify how parser error are to be handled.
|
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
public XMLValidateTask.Property createProperty
protected Path classpath
protected XMLValidateTask.ValidatorErrorHandler errorHandler
protected boolean failOnError
protected File file
protected Vector filesets
protected static final String INIT_FAILED_MSG
protected boolean lenient
public static final String MESSAGE_FILES_VALIDATED
protected String readerClassName
protected boolean warn
protected org.xml.sax.XMLReader xmlReader
public void addConfiguredXMLCatalog(XMLCatalog catalog)
catalog
- XMLCatalog to usepublic void addFileset(FileSet set)
set
- the fileset to checkprotected void cleanup()
public XMLValidateTask.Attribute createAttribute()
public Path createClasspath()
setClasspath(org.apache.tools.ant.types.Path)
protected org.xml.sax.XMLReader createDefaultReader()
BuildException
- if something went wrongpublic DTDLocation createDTD()
public XMLValidateTask.Property createProperty()
protected org.xml.sax.XMLReader createXmlReader()
readerClassName
,
falling back to a default reader if not.
If the returned reader is an instance of ParserAdapter
then
we have created and wrapped a SAX1 parser.protected boolean doValidate(File afile)
afile
- the file to validate.public void execute() throws BuildException
execute
in class Task
BuildException
- if failonerror
is true and an error happensprotected org.xml.sax.EntityResolver getEntityResolver()
protected org.xml.sax.XMLReader getXmlReader()
initValidator()
.
If the reader is an instance of ParserAdapter
then
the parser is a SAX1 parser, and you cannot call
setFeature(String, boolean)
or setProperty(String, String)
on it.public void init() throws BuildException
init
in class Task
BuildException
- if something goes wrong with the buildprotected void initValidator()
BuildException
- if something went wrongprotected boolean isSax1Parser()
protected void onSuccessfulValidation(int fileProcessed)
fileProcessed
- number of files processed.public void setClassName(String className)
className
- should be an implementation of SAX2
org.xml.sax.XMLReader
or SAX2 org.xml.sax.Parser
.
if className is an implementation of
org.xml.sax.Parser
, setLenient(boolean)
,
will be ignored.
if not set, the default will be used.
XMLReader
,
Parser
public void setClasspath(Path classpath)
classpath
- the classpath to load the parserpublic void setClasspathRef(Reference r)
r
- reference to a classpath defined elsewheresetClasspath(org.apache.tools.ant.types.Path)
public void setFailOnError(boolean fail)
true
.
If set to true
(default), throw a buildException if the
parser yields an error.
fail
- if set to false
do not fail on errorprotected void setFeature(String feature, boolean value) throws BuildException
feature
- the name of the feature to setvalue
- the value of the featureBuildException
- if the feature was not supportedpublic void setFile(File file)
file
- the file to be checkedpublic void setLenient(boolean bool)
true
.
If set to false, the validation will fail only if the parsed document is not well formed XML.
this option is ignored if the specified class
with setClassName(String)
is not a SAX2 XMLReader.
bool
- if set to false
only fail on malformed XMLprotected void setProperty(String name, String value) throws BuildException
name
- a property namevalue
- a property value.BuildException
- if an error occurs.BuildException
- if the property was not supportedpublic void setWarn(boolean bool)
If set to true
(default), log a warn message for each SAX warn event.
bool
- if set to false
do not send warnings