org.apache.tools.ant.taskdefs.optional

Class XMLValidateTask


public class XMLValidateTask
extends Task

Checks XML files are valid (or only well formed). The task uses the SAX2 parser implementation provided by JAXP by default (probably the one that is used by Ant itself), but one can specify any SAX1/2 parser if needed.

Nested Class Summary

class
XMLValidateTask.Attribute
The class to create to set a feature of the parser.
class
XMLValidateTask.Property
A Parser property.
protected class
XMLValidateTask.ValidatorErrorHandler
ValidatorErrorHandler role :
  • log SAX parse exceptions,
  • remember if an error occurred

Field Summary

protected static String
INIT_FAILED_MSG
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 boolean
lenient
protected String
readerClassName
protected boolean
warn
protected XMLReader
xmlReader
the parser is viewed as a SAX2 XMLReader.

Fields inherited from class org.apache.tools.ant.Task

description, location, target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

project

Method Summary

void
addConfiguredXMLCatalog(XMLCatalog catalog)
add an XMLCatalog as a nested element; optional.
void
addFileset(FileSet set)
specify a set of file to be checked
XMLValidateTask.Attribute
createAttribute()
Add an attribute nested element.
Path
createClasspath()
DTDLocation
createDTD()
Create a DTD location record; optional.
XMLValidateTask.Property
createProperty()
Creates a property.
void
execute()
execute the task
protected EntityResolver
getEntityResolver()
accessor to the xmlCatalog used in the task
void
init()
Called by the project to let the task initialize properly.
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.
void
setFile(File file)
specify the file to be checked; optional.
void
setLenient(boolean bool)
Specify whether the parser should be validating.
void
setWarn(boolean bool)
Specify how parser error are to be handled.

Methods inherited from class org.apache.tools.ant.Task

execute, getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

getProject, log, log, setProject

Field Details

INIT_FAILED_MSG

protected static final String INIT_FAILED_MSG

classpath

protected Path classpath

errorHandler

protected XMLValidateTask.ValidatorErrorHandler errorHandler

failOnError

protected boolean failOnError

file

protected File file
file to be validated

filesets

protected Vector filesets
sets of file to be validated

lenient

protected boolean lenient

readerClassName

protected String readerClassName

warn

protected boolean warn

xmlReader

protected XMLReader xmlReader
the parser is viewed as a SAX2 XMLReader. If a SAX1 parser is specified, it's wrapped in an adapter that make it behave as a XMLReader. a more 'standard' way of doing this would be to use the JAXP1.1 SAXParser interface.

Method Details

addConfiguredXMLCatalog

public void addConfiguredXMLCatalog(XMLCatalog catalog)
add an XMLCatalog as a nested element; optional.
Parameters:
catalog - XMLCatalog to use

addFileset

public void addFileset(FileSet set)
specify a set of file to be checked
Parameters:
set - the fileset to check

createAttribute

public XMLValidateTask.Attribute createAttribute()
Add an attribute nested element. This is used for setting arbitrary features of the SAX parser. Valid attributes include
Returns:
attribute created
Since:
ant1.6

createClasspath

public Path createClasspath()
Returns:
the classpath created

createDTD

public DTDLocation createDTD()
Create a DTD location record; optional. This stores the location of a DTD. The DTD is identified by its public Id.
Returns:
created DTD location

createProperty

public XMLValidateTask.Property createProperty()
Creates a property.
Returns:
a property.
Since:
ant 1.6.2

execute

public void execute()
            throws BuildException
execute the task
Overrides:
execute in interface Task
Throws:
BuildException - if failonerror is true and an error happens

getEntityResolver

protected EntityResolver getEntityResolver()
accessor to the xmlCatalog used in the task
Returns:
xmlCatalog reference

init

public void init()
            throws BuildException
Called by the project to let the task initialize properly.
Overrides:
init in interface Task
Throws:
BuildException - if something goes wrong with the build

setClassName

public void setClassName(String className)
Specify the class name of the SAX parser to be used. (optional)
See Also:
org.xml.sax.XMLReader, org.xml.sax.Parser

setClasspath

public void setClasspath(Path classpath)
Specify the classpath to be searched to load the parser (optional)
Parameters:
classpath - the classpath to load the parser

setClasspathRef

public void setClasspathRef(Reference r)
Where to find the parser class; optional.
Parameters:
r - reference to a classpath defined elsewhere

setFailOnError

public void setFailOnError(boolean fail)
Specify how parser error are to be handled. Optional, default is true.

If set to true (default), throw a buildException if the parser yields an error.

Parameters:
fail - if set to false do not fail on error

setFile

public void setFile(File file)
specify the file to be checked; optional.
Parameters:
file - the file to be checked

setLenient

public void setLenient(boolean bool)
Parameters:
bool - if set to false only fail on malformed XML

setWarn

public void setWarn(boolean bool)
Specify how parser error are to be handled.

If set to true (default), log a warn message for each SAX warn event.

Parameters:
bool - if set to false do not send warnings

Copyright B) 2000-2006 Apache Software Foundation. All Rights Reserved.