Introduction

This toolkit aims to provide a simple facade to validate xml based configuration files. It caches and manages the Schemas and is capable of scanning ClassLoaders for potential schema definitions.

Using ResolverFactory

ResolverFactory is a utility class in ConfigKit that makes it easy to manage the set of XML entitys that can be loaded from a jar file. The XML entitys should be declared in a file named META-INF/spice/catalog.xml . The format is simple and a sample is;

      
<catalog version="1.0">
  <entity publicId="-//PHOENIX/Assembly DTD Version 1.0//EN"
          resource="org/apache/avalon/phoenix/tools/assembly.dtd"/>
  <entity systemId="http://jakarta.apache.org/phoenix/assembly_1_0.dtd"
          resource="org/apache/avalon/phoenix/tools/assembly.dtd"/>
  <entity
     publicId="-//PHOENIX/BlockInfo DTD Version 1.0//EN"
     systemId="http://jakarta.apache.org/phoenix/blockinfo_1_0.dtd"
     resource="org/apache/avalon/phoenix/tools/blockinfo.dtd"/>
</catalog>
 
    

The developer can then create an EntityResolver that will resolve the entitys declared in the descriptor via the following. Assuming that the "classloader" is the ClassLoader in which the descriptor is stored.

      
final EntityResolver resolver = ResolverFactory.createResolver( classloader );
            
    

Using ConfigValidator

ConfigValidator is a utility class used to perform validation of configuration files. Each ConfigValidator is bound to a particular schema. The schema can either be loaded from catalog (as described above) or by passing in a InputStream or InputSource object to the ConfigValidatorFactory. Example Usage;

      
final InputStream mySchemaInputStream = ...;
final InputStream myConfigInputStream = ...;
final ConfigValidator validator =
    ConfigValidatorFactory.create( "http://relaxng.org/ns/structure/1.0",
                                   mySchemaInputStream );
try
{
    validator.validate( myConfigInputStream, null );
}
catch( final ValidateException ve )
{
   //validation failed...
}
            
    

or loading the schema from the catalog

      
final InputStream myConfigInputStream = ...;
final ConfigValidator validator =
    ConfigValidatorFactory.create( "http://relaxng.org/ns/structure/1.0",
                                   "-//PHOENIX/BlockInfo DTD Version 1.0//EN",
                                   null,
                                   classloader );
try
{
    validator.validate( myConfigInputStream, null );
}
catch( final ValidateException ve )
{
    //validation failed...
}