Class SchemaValidate
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.optional.XMLValidateTask
org.apache.tools.ant.taskdefs.optional.SchemaValidate
- All Implemented Interfaces:
Cloneable
Validate XML Schema documents.
This task validates XML schema documents. It requires an XML parser
that handles the relevant SAX, Xerces or JAXP options.
To resolve remote references, Ant may need its proxy set up, using the
setproxy task.
Hands off most of the work to its parent,
XMLValidateTask- Since:
- Ant1.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classrepresentation of a schema location.Nested classes/interfaces inherited from class XMLValidateTask
XMLValidateTask.Attribute, XMLValidateTask.Property, XMLValidateTask.ValidatorErrorHandlerModifier and TypeClassDescriptionstatic classThe class to create to set a feature of the parser.static final classA Parser property.protected classValidatorErrorHandler role : log SAX parse exceptions, remember if an error occurred -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDuplicate declaration of schemastatic final Stringschema features not supportedstatic final Stringunable to create parserstatic final StringSAX1 not supportedstatic final Stringtoo many default schemasstatic final Stringadding schemaFields inherited from class XMLValidateTask
classpath, errorHandler, failOnError, file, filesets, INIT_FAILED_MSG, lenient, MESSAGE_FILES_VALIDATED, readerClassName, warn, xmlReaderModifier and TypeFieldDescriptionprotected Pathprotected XMLValidateTask.ValidatorErrorHandlerprotected booleanprotected Filefile to be validatedsets of file to be validatedprotected static final Stringprotected booleanstatic final StringMessage for successful validationprotected Stringprotected booleanprotected XMLReaderthe parser is viewed as a SAX2 XMLReader.Fields inherited from class ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd the schemaprotected voidbuild a string list of all schema locations, then set the relevant property.protected voidcreate a schema location to hold the anonymous schemaprotected XMLReaderCreate a reader if the use of the class did not specify another one.booleanSet schema attributes in a JAXP 1.2 engine.booleanTurn on XSD support in Xerces.protected Stringget the URL of the no namespace schemavoidinit()Called by the project to let the task initialize properly.protected voidinit the parser : load the parser class, and set features if necessary It is only after this that the reader is validprotected voidonSuccessfulValidation(int fileProcessed) handler called on successful file validation.voidsetDisableDTD(boolean disableDTD) flag to disable DTD support.protected voidsetFeatureIfSupported(String feature, boolean value) set a feature if it is supported, log at verbose level if notvoidsetFullChecking(boolean fullChecking) enable full schema checking.voidsetNoNamespaceFile(File defaultSchemaFile) identify a file containing the default schemavoidsetNoNamespaceURL(String defaultSchemaURL) identify the URL of the default schemaMethods inherited from class XMLValidateTask
addConfiguredXMLCatalog, addFileset, cleanup, createAttribute, createClasspath, createDTD, createProperty, createXmlReader, doValidate, execute, getEntityResolver, getXmlReader, isSax1Parser, setClassName, setClasspath, setClasspathRef, setFailOnError, setFeature, setFile, setLenient, setProperty, setWarnModifier and TypeMethodDescriptionvoidaddConfiguredXMLCatalog(XMLCatalog catalog) add an XMLCatalog as a nested element; optional.voidaddFileset(FileSet set) specify a set of file to be checkedprotected voidcleanup()Cleans up resources.Add an attribute nested element.Create a DTD location record; optional.Creates a property.protected XMLReadercreate the XML reader.protected booleandoValidate(File afile) parse the filevoidexecute()execute the taskprotected EntityResolveraccessor to the xmlCatalog used in the taskprotected XMLReaderget the XML reader.protected booleantest that returns true if we are using a SAX1 parser.voidsetClassName(String className) Specify the class name of the SAX parser to be used.voidsetClasspath(Path classpath) Specify the classpath to be searched to load the parser (optional)voidWhere to find the parser class; optional.voidsetFailOnError(boolean fail) Specify how parser error are to be handled.protected voidsetFeature(String feature, boolean value) Set a feature on the parser.voidspecify the file to be checked; optional.voidsetLenient(boolean bool) Specify whether the parser should be validating.protected voidsetProperty(String name, String value) Sets a property.voidsetWarn(boolean bool) Specify how parser error are to be handled.Methods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProjectModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.voidsetProject(Project project) Sets the project object of this component.
-
Field Details
-
ERROR_SAX_1
-
ERROR_NO_XSD_SUPPORT
-
ERROR_TOO_MANY_DEFAULT_SCHEMAS
-
ERROR_PARSER_CREATION_FAILURE
-
MESSAGE_ADDING_SCHEMA
-
ERROR_DUPLICATE_SCHEMA
-
-
Constructor Details
-
SchemaValidate
public SchemaValidate()
-
-
Method Details
-
init
Called by the project to let the task initialize properly. The default implementation is a no-op.- Overrides:
initin classXMLValidateTask- Throws:
BuildException- if something goes wrong with the build
-
enableXercesSchemaValidation
public boolean enableXercesSchemaValidation()Turn on XSD support in Xerces.- Returns:
- true on success, false on failure
-
enableJAXP12SchemaValidation
public boolean enableJAXP12SchemaValidation()Set schema attributes in a JAXP 1.2 engine.- Returns:
- true on success, false on failure
- See Also:
-
addConfiguredSchema
add the schema- Parameters:
location- the schema location.- Throws:
BuildException- if there is no namespace, or if there already is a declaration of this schema with a different value
-
setFullChecking
public void setFullChecking(boolean fullChecking) enable full schema checking. Slower but better.- Parameters:
fullChecking- abooleanvalue.
-
createAnonymousSchema
protected void createAnonymousSchema()create a schema location to hold the anonymous schema -
setNoNamespaceURL
identify the URL of the default schema- Parameters:
defaultSchemaURL- the URL of the default schema.
-
setNoNamespaceFile
identify a file containing the default schema- Parameters:
defaultSchemaFile- the location of the default schema.
-
setDisableDTD
public void setDisableDTD(boolean disableDTD) flag to disable DTD support.- Parameters:
disableDTD- abooleanvalue.
-
initValidator
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- Overrides:
initValidatorin classXMLValidateTask- Throws:
BuildException- if something went wrong
-
createDefaultReader
Create a reader if the use of the class did not specify another one. The reason to not useJAXPUtils.getXMLReader()was to create our own factory with our own options.- Overrides:
createDefaultReaderin classXMLValidateTask- Returns:
- a default XML parser
-
addSchemaLocations
protected void addSchemaLocations()build a string list of all schema locations, then set the relevant property. -
getNoNamespaceSchemaURL
get the URL of the no namespace schema- Returns:
- the schema URL
-
setFeatureIfSupported
set a feature if it is supported, log at verbose level if not- Parameters:
feature- the feature.value- abooleanvalue.
-
onSuccessfulValidation
protected void onSuccessfulValidation(int fileProcessed) handler called on successful file validation.- Overrides:
onSuccessfulValidationin classXMLValidateTask- Parameters:
fileProcessed- number of files processed.
-