SchemaValidate (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs.optional, class: SchemaValidate

# 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`

public class SchemaValidate extends XMLValidateTask
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 Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SchemaValidate.SchemaLocation`
  representation of a schema location.

  ### Nested classes/interfaces inherited from class XMLValidateTask

  `XMLValidateTask.Attribute, XMLValidateTask.Property, XMLValidateTask.ValidatorErrorHandler`
  Modifier and Type
  Class
  Description
  `static class`
  `XMLValidateTask.Attribute`
  The class to create to set a feature of the parser.
  `static final class`
  `XMLValidateTask.Property`
  A Parser property.
  `protected class`
  `XMLValidateTask.ValidatorErrorHandler`
  ValidatorErrorHandler role : log SAX parse exceptions, remember if an error occurred

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `ERROR_DUPLICATE_SCHEMA`
  Duplicate declaration of schema
  `static final String`
  `ERROR_NO_XSD_SUPPORT`
  schema features not supported
  `static final String`
  `ERROR_PARSER_CREATION_FAILURE`
  unable to create parser
  `static final String`
  `ERROR_SAX_1`
  SAX1 not supported
  `static final String`
  `ERROR_TOO_MANY_DEFAULT_SCHEMAS`
  too many default schemas
  `static final String`
  `MESSAGE_ADDING_SCHEMA`
  adding schema

  ### Fields inherited from class XMLValidateTask

  `classpath, errorHandler, failOnError, file, filesets, INIT_FAILED_MSG, lenient, MESSAGE_FILES_VALIDATED, readerClassName, warn, xmlReader`
  Modifier and Type
  Field
  Description
  `protected Path`
  `classpath`
  `protected XMLValidateTask.ValidatorErrorHandler`
  `errorHandler`
  `protected boolean`
  `failOnError`
  `protected File`
  `file`
  file to be validated
  `protected Vector<FileSet>`
  `filesets`
  sets of file to be validated
  `protected static final String`
  `INIT_FAILED_MSG`
  `protected boolean`
  `lenient`
  `static final String`
  `MESSAGE_FILES_VALIDATED`
  Message for successful validation
  `protected String`
  `readerClassName`
  `protected boolean`
  `warn`
  `protected XMLReader`
  `xmlReader`
  the parser is viewed as a SAX2 XMLReader.

  ### Fields inherited from class Task

  `target, taskName, taskType, wrapper`
  Modifier and Type
  Field
  Description
  `protected Target`
  `target`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskName`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskType`
  Deprecated.
  since 1.6.x.
  `protected RuntimeConfigurable`
  `wrapper`
  Deprecated.
  since 1.6.x.

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SchemaValidate()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addConfiguredSchema(SchemaValidate.SchemaLocation location)`
  add the schema
  `protected void`
  `addSchemaLocations()`
  build a string list of all schema locations, then set the relevant property.
  `protected void`
  `createAnonymousSchema()`
  create a schema location to hold the anonymous schema
  `protected XMLReader`
  `createDefaultReader()`
  Create a reader if the use of the class did not specify another one.
  `boolean`
  `enableJAXP12SchemaValidation()`
  Set schema attributes in a JAXP 1.2 engine.
  `boolean`
  `enableXercesSchemaValidation()`
  Turn on XSD support in Xerces.
  `protected String`
  `getNoNamespaceSchemaURL()`
  get the URL of the no namespace schema
  `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 void`
  `onSuccessfulValidation(int fileProcessed)`
  handler called on successful file validation.
  `void`
  `setDisableDTD(boolean disableDTD)`
  flag to disable DTD support.
  `protected void`
  `setFeatureIfSupported(String feature, boolean value)`
  set a feature if it is supported, log at verbose level if not
  `void`
  `setFullChecking(boolean fullChecking)`
  enable full schema checking.
  `void`
  `setNoNamespaceFile(File defaultSchemaFile)`
  identify a file containing the default schema
  `void`
  `setNoNamespaceURL(String defaultSchemaURL)`
  identify the URL of the default schema

  ### Methods 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, setWarn`
  Modifier and Type
  Method
  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()`
  `DTDLocation`
  `createDTD()`
  Create a DTD location record; optional.
  `XMLValidateTask.Property`
  `createProperty()`
  Creates a property.
  `protected XMLReader`
  `createXmlReader()`
  create the XML reader.
  `protected boolean`
  `doValidate(File afile)`
  parse the file
  `void`
  `execute()`
  execute the task
  `protected EntityResolver`
  `getEntityResolver()`
  accessor to the xmlCatalog used in the task
  `protected XMLReader`
  `getXmlReader()`
  get the XML reader.
  `protected boolean`
  `isSax1Parser()`
  test that returns true if we are using a SAX1 parser.
  `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.

  ### 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, setTaskType`
  Modifier and Type
  Method
  Description
  `final void`
  `bindToOwner(Task owner)`
  Bind a task to another; use this when configuring a newly created task to do work on behalf of another.
  `Target`
  `getOwningTarget()`
  Returns the container target of this task.
  `RuntimeConfigurable`
  `getRuntimeConfigurableWrapper()`
  Returns the wrapper used for runtime configuration.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `String`
  `getTaskType()`
  Return the type of task.
  `protected RuntimeConfigurable`
  `getWrapper()`
  Return the runtime configurable structure for this task.
  `protected void`
  `handleErrorFlush(String output)`
  Handles an error line by logging it with the WARN priority.
  `protected void`
  `handleErrorOutput(String output)`
  Handles an error output by logging it with the WARN priority.
  `protected void`
  `handleFlush(String output)`
  Handles output by logging it with the INFO priority.
  `protected int`
  `handleInput(byte[] buffer, int offset, int length)`
  Handle an input request by this task.
  `protected void`
  `handleOutput(String output)`
  Handles output by logging it with the INFO priority.
  `protected final boolean`
  `isInvalid()`
  Has this task been marked invalid?
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(String msg, Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `maybeConfigure()`
  Configures this task - if it hasn't been done already.
  `final void`
  `perform()`
  Performs this task if it's still valid, or gets a replacement version and performs that otherwise.
  `void`
  `reconfigure()`
  Force the task to be reconfigured from its RuntimeConfigurable.
  `void`
  `setOwningTarget(Target target)`
  Sets the target container of this task.
  `void`
  `setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)`
  Sets the wrapper to be used for runtime configuration.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.
  `void`
  `setTaskType(String type)`
  Sets the name with which the task has been invoked.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ERROR_SAX_1

    public static final String ERROR_SAX_1
    SAX1 not supported
    See Also:
      - Constant Field Values

  - ### ERROR_NO_XSD_SUPPORT

    public static final String ERROR_NO_XSD_SUPPORT
    schema features not supported
    See Also:
      - Constant Field Values

  - ### ERROR_TOO_MANY_DEFAULT_SCHEMAS

    public static final String ERROR_TOO_MANY_DEFAULT_SCHEMAS
    too many default schemas
    See Also:
      - Constant Field Values

  - ### ERROR_PARSER_CREATION_FAILURE

    public static final String ERROR_PARSER_CREATION_FAILURE
    unable to create parser
    See Also:
      - Constant Field Values

  - ### MESSAGE_ADDING_SCHEMA

    public static final String MESSAGE_ADDING_SCHEMA
    adding schema
    See Also:
      - Constant Field Values

  - ### ERROR_DUPLICATE_SCHEMA

    public static final String ERROR_DUPLICATE_SCHEMA
    Duplicate declaration of schema
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### SchemaValidate

    public SchemaValidate()

- ## Method Details

  - ### init

    public void init() throws BuildException
    Called by the project to let the task initialize properly. The default implementation is a no-op.
    Overrides:
      `init` in class `XMLValidateTask`
    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:
      - JAXP 1.2 Approved CHANGES

  - ### addConfiguredSchema

    public void addConfiguredSchema(SchemaValidate.SchemaLocation location)
    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` - a `boolean` value.

  - ### createAnonymousSchema

    protected void createAnonymousSchema()
    create a schema location to hold the anonymous schema

  - ### setNoNamespaceURL

    public void setNoNamespaceURL(String defaultSchemaURL)
    identify the URL of the default schema
    Parameters:
      `defaultSchemaURL` - the URL of the default schema.

  - ### setNoNamespaceFile

    public void setNoNamespaceFile(File defaultSchemaFile)
    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` - a `boolean` value.

  - ### 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:
      `initValidator` in class `XMLValidateTask`
    Throws:
      `BuildException` - if something went wrong

  - ### createDefaultReader

    protected XMLReader createDefaultReader()
    Create a reader if the use of the class did not specify another one. The reason to not use `JAXPUtils.getXMLReader()` was to create our own factory with our own options.
    Overrides:
      `createDefaultReader` in class `XMLValidateTask`
    Returns:
      a default XML parser

  - ### addSchemaLocations

    protected void addSchemaLocations()
    build a string list of all schema locations, then set the relevant property.

  - ### getNoNamespaceSchemaURL

    protected String getNoNamespaceSchemaURL()
    get the URL of the no namespace schema
    Returns:
      the schema URL

  - ### setFeatureIfSupported

    protected void setFeatureIfSupported(String feature, boolean value)
    set a feature if it is supported, log at verbose level if not
    Parameters:
      `feature` - the feature.
      `value` - a `boolean` value.

  - ### onSuccessfulValidation

    protected void onSuccessfulValidation(int fileProcessed)
    handler called on successful file validation.
    Overrides:
      `onSuccessfulValidation` in class `XMLValidateTask`
    Parameters:
      `fileProcessed` - number of files processed.