Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional

public Class SchemaValidate

extends XMLValidateTask
Class Inheritance
Imports
java.io.File, java.net.MalformedURLException, java.util.HashMap, .Map, java.util.stream.Collectors, javax.xml.parsers.ParserConfigurationException, .SAXParser, .SAXParserFactory, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.util.FileUtils, .XmlConstants, org.xml.sax.SAXException, .SAXNotRecognizedException, .SAXNotSupportedException, .XMLReader

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
SchemaValidate.SchemaLocation

representation of a schema location.

Field Summary

Modifier and TypeField and Description
private SchemaValidate.SchemaLocation
anonymousSchema

default URL for nonamespace schemas

private boolean
disableDTD

flag to disable DTD support.

public static final String
ERROR_DUPLICATE_SCHEMA

Duplicate declaration of schema

public static final String
ERROR_NO_XSD_SUPPORT

schema features not supported

public static final String
ERROR_PARSER_CREATION_FAILURE

unable to create parser

public static final String
ERROR_SAX_1

SAX1 not supported

public static final String
ERROR_TOO_MANY_DEFAULT_SCHEMAS

too many default schemas

private boolean
fullChecking

full checking of a schema

public static final String
MESSAGE_ADDING_SCHEMA

adding schema

private Map<String, SchemaValidate.SchemaLocation>
schemaLocations

map of all declared schemas; we catch and complain about redefinitions

Inherited from org.apache.tools.ant.taskdefs.optional.XMLValidateTask:
classpatherrorHandlerfailOnErrorfilefilesetsINIT_FAILED_MSGlenientMESSAGE_FILES_VALIDATEDreaderClassNamewarnxmlReader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addConfiguredSchema(SchemaValidate.SchemaLocation
the schema location.
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

Returns:

a default XML parser
createDefaultReader
()

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.createDefaultReader.

Create a reader if the use of the class did not specify another one.
public boolean

Returns:

true on success, false on failure
enableJAXP12SchemaValidation
()

Set schema attributes in a JAXP 1.2 engine.

public boolean

Returns:

true on success, false on failure
enableXercesSchemaValidation
()

Turn on XSD support in Xerces.

protected String

Returns:

the schema URL
getNoNamespaceSchemaURL
()

get the URL of the no namespace schema

public void
init()

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.init.

Called by the project to let the task initialize properly.
protected void
initValidator()

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.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
number of files processed.
fileProcessed
)

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.onSuccessfulValidation.

handler called on successful file validation.
public void
setDisableDTD(boolean
a boolean value.
disableDTD
)

flag to disable DTD support.

protected void
setFeatureIfSupported(String
the feature.
feature
,
boolean
a boolean value.
value
)

set a feature if it is supported, log at verbose level if not

public void
setFullChecking(boolean
a boolean value.
fullChecking
)

enable full schema checking.

public void
setNoNamespaceFile(File
the location of the default schema.
defaultSchemaFile
)

identify a file containing the default schema

private void
setNoNamespaceSchemaProperty(String
name of the property to set
property
)

set nonamespace handling up for xerces or other parsers

public void
setNoNamespaceURL(String
the URL of the default schema.
defaultSchemaURL
)

identify the URL of the default schema

Inherited from org.apache.tools.ant.taskdefs.optional.XMLValidateTask:
addConfiguredXMLCatalogaddFilesetcleanupcreateAttributecreateClasspathcreateDTDcreatePropertycreateXmlReaderdoValidateexecutegetEntityResolvergetXmlReaderisSax1ParsersetClassNamesetClasspathsetClasspathRefsetFailOnErrorsetFeaturesetFilesetLenientsetPropertysetWarn

Field Detail

anonymousSchemaback to summary
private SchemaValidate.SchemaLocation anonymousSchema

default URL for nonamespace schemas

disableDTDback to summary
private boolean disableDTD

flag to disable DTD support. Best left enabled.

ERROR_DUPLICATE_SCHEMAback to summary
public static final String ERROR_DUPLICATE_SCHEMA

Duplicate declaration of schema

ERROR_NO_XSD_SUPPORTback to summary
public static final String ERROR_NO_XSD_SUPPORT

schema features not supported

ERROR_PARSER_CREATION_FAILUREback to summary
public static final String ERROR_PARSER_CREATION_FAILURE

unable to create parser

ERROR_SAX_1back to summary
public static final String ERROR_SAX_1

SAX1 not supported

ERROR_TOO_MANY_DEFAULT_SCHEMASback to summary
public static final String ERROR_TOO_MANY_DEFAULT_SCHEMAS

too many default schemas

fullCheckingback to summary
private boolean fullChecking

full checking of a schema

MESSAGE_ADDING_SCHEMAback to summary
public static final String MESSAGE_ADDING_SCHEMA

adding schema

schemaLocationsback to summary
private Map<String, SchemaValidate.SchemaLocation> schemaLocations

map of all declared schemas; we catch and complain about redefinitions

Constructor Detail

SchemaValidateback to summary
public SchemaValidate()

Method Detail

addConfiguredSchemaback to summary
public void addConfiguredSchema(SchemaValidate.SchemaLocation location)

add the schema

Parameters
location:SchemaValidate.SchemaLocation

the schema location.

Exceptions
BuildException:
if there is no namespace, or if there already is a declaration of this schema with a different value
addSchemaLocationsback to summary
protected void addSchemaLocations()

build a string list of all schema locations, then set the relevant property.

createAnonymousSchemaback to summary
protected void createAnonymousSchema()

create a schema location to hold the anonymous schema

createDefaultReaderback to summary
protected XMLReader createDefaultReader()

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.createDefaultReader.

Create a reader if the use of the class did not specify another one. The reason to not use org.apache.tools.ant.util.JAXPUtils#getXMLReader() was to create our own factory with our own options.

Returns:XMLReader

a default XML parser

Annotations
@Override
enableJAXP12SchemaValidationback to summary
public boolean enableJAXP12SchemaValidation()

Set schema attributes in a JAXP 1.2 engine.

Returns:boolean

true on success, false on failure

See Also
JAXP 1.2 Approved CHANGES
enableXercesSchemaValidationback to summary
public boolean enableXercesSchemaValidation()

Turn on XSD support in Xerces.

Returns:boolean

true on success, false on failure

getNoNamespaceSchemaURLback to summary
protected String getNoNamespaceSchemaURL()

get the URL of the no namespace schema

Returns:String

the schema URL

initback to summary
public void init() throws BuildException

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.init.

Called by the project to let the task initialize properly. The default implementation is a no-op.

Annotations
@Override
Exceptions
BuildException:
if something goes wrong with the build
initValidatorback to summary
protected void initValidator()

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.initValidator.

init the parser : load the parser class, and set features if necessary It is only after this that the reader is valid

Annotations
@Override
Exceptions
BuildException:
if something went wrong
onSuccessfulValidationback to summary
protected void onSuccessfulValidation(int fileProcessed)

Overrides org.apache.tools.ant.taskdefs.optional.XMLValidateTask.onSuccessfulValidation.

handler called on successful file validation.

Parameters
fileProcessed:int

number of files processed.

Annotations
@Override
setDisableDTDback to summary
public void setDisableDTD(boolean disableDTD)

flag to disable DTD support.

Parameters
disableDTD:boolean

a boolean value.

setFeatureIfSupportedback to summary
protected void setFeatureIfSupported(String feature, boolean value)

set a feature if it is supported, log at verbose level if not

Parameters
feature:String

the feature.

value:boolean

a boolean value.

setFullCheckingback to summary
public void setFullChecking(boolean fullChecking)

enable full schema checking. Slower but better.

Parameters
fullChecking:boolean

a boolean value.

setNoNamespaceFileback to summary
public void setNoNamespaceFile(File defaultSchemaFile)

identify a file containing the default schema

Parameters
defaultSchemaFile:File

the location of the default schema.

setNoNamespaceSchemaPropertyback to summary
private void setNoNamespaceSchemaProperty(String property)

set nonamespace handling up for xerces or other parsers

Parameters
property:String

name of the property to set

setNoNamespaceURLback to summary
public void setNoNamespaceURL(String defaultSchemaURL)

identify the URL of the default schema

Parameters
defaultSchemaURL:String

the URL of the default schema.

org.apache.tools.ant.taskdefs.optional back to summary

public Class SchemaValidate.SchemaLocation

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.tools.ant.taskdefs.optional.SchemaValidate.SchemaLocation

representation of a schema location. This is a URI plus either a file or a url

Field Summary

Modifier and TypeField and Description
public static final String
ERROR_NO_FILE

File not found

public static final String
ERROR_NO_LOCATION

No location provided

public static final String
ERROR_NO_URI

No namespace URI

public static final String
public static final String
ERROR_TWO_LOCATIONS

Both URL and File were given for schema

private File
private String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true iff the objects are considered equal in value
equals
(Object
object to compare against
o
)

Overrides java.lang.Object.equals.

equality test checks namespace, location and filename.
public File

Returns:

the file containing the schema.
getFile
()

Get the file.

public String

Returns:

the namespace.
getNamespace
()

Get the namespace.

public String

Returns:

a URL to the schema
getSchemaLocationURL
()

get the URL of the schema

public String

Returns:

string of uri and location
getURIandLocation
()

validate the fields then create a "uri location" string

public String

Returns:

the URL string.
getUrl
()

The URL containing the schema.

public int

Returns:

the hashcode.
hashCode
()

Overrides java.lang.Object.hashCode.

Generate a hashcode depending on the namespace, url and file name.
private boolean

Returns:

true if it is not null or empty
isSet
(String
string to check
property
)

check that a property is set

public void
setFile(File
the file contains the schema.
file
)

identify a file that contains this namespace's schema.

public void
setNamespace(String
the namespace to use.
namespace
)

set the namespace of this schema.

public void
setUrl(String
the URL string.
url
)

identify a URL that hosts the schema.

public String

Returns:

a string representation of the object.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object for error messages and the like
public void
validateNamespace()

assert that a namespace is valid

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ERROR_NO_FILEback to summary
public static final String ERROR_NO_FILE

File not found

ERROR_NO_LOCATIONback to summary
public static final String ERROR_NO_LOCATION

No location provided

ERROR_NO_URIback to summary
public static final String ERROR_NO_URI

No namespace URI

ERROR_NO_URL_REPRESENTATIONback to summary
public static final String ERROR_NO_URL_REPRESENTATION

Cannot make URL

ERROR_TWO_LOCATIONSback to summary
public static final String ERROR_TWO_LOCATIONS

Both URL and File were given for schema

fileback to summary
private File file
namespaceback to summary
private String namespace
urlback to summary
private String url

Constructor Detail

SchemaLocationback to summary
public SchemaLocation()

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

equality test checks namespace, location and filename. All must match,

Parameters
o:Object

object to compare against

Returns:boolean

true iff the objects are considered equal in value

Annotations
@Override
getFileback to summary
public File getFile()

Get the file.

Returns:File

the file containing the schema.

getNamespaceback to summary
public String getNamespace()

Get the namespace.

Returns:String

the namespace.

getSchemaLocationURLback to summary
public String getSchemaLocationURL()

get the URL of the schema

Returns:String

a URL to the schema

Exceptions
BuildException:
if not
getURIandLocationback to summary
public String getURIandLocation() throws BuildException

validate the fields then create a "uri location" string

Returns:String

string of uri and location

Exceptions
BuildException:
if there is an error.
getUrlback to summary
public String getUrl()

The URL containing the schema.

Returns:String

the URL string.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Generate a hashcode depending on the namespace, url and file name.

Returns:int

the hashcode.

Annotations
@Override
isSetback to summary
private boolean isSet(String property)

check that a property is set

Parameters
property:String

string to check

Returns:boolean

true if it is not null or empty

setFileback to summary
public void setFile(File file)

identify a file that contains this namespace's schema. The file must exist.

Parameters
file:File

the file contains the schema.

setNamespaceback to summary
public void setNamespace(String namespace)

set the namespace of this schema. Any URI

Parameters
namespace:String

the namespace to use.

setUrlback to summary
public void setUrl(String url)

identify a URL that hosts the schema.

Parameters
url:String

the URL string.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object for error messages and the like

Returns:String

a string representation of the object.

Annotations
@Override
validateNamespaceback to summary
public void validateNamespace()

assert that a namespace is valid

Exceptions
BuildException:
if not