com.calitha.xml
Class XMLGrammarPoolBuilder

java.lang.Object
  extended by com.calitha.xml.XMLGrammarPoolBuilder

public class XMLGrammarPoolBuilder
extends Object

The XMLGrammarPoolBuilder represents a builder class for making XML grammar pools.

Grammar pools can be loaded with grammars (DTD's and XML Schema'a) and set in parser configurations or parsers.

The grammar pool pre-parses all the grammars, so that this won't have to happen again each time a parser starts validating an XML file.

Author:
Robert van Loenhout

Field Summary
static String GRAMMAR_POOL
           
 
Constructor Summary
XMLGrammarPoolBuilder()
          Creates a new grammar pool builder.
 
Method Summary
 void addDTDGrammar(String resourceName)
          Adds a DTD grammar to the pool.
 void addDTDGrammar(String publicId, String systemId, InputStream input)
          Adds a DTD grammar to the pool.
 void addDTDGrammar(org.apache.xerces.xni.parser.XMLInputSource source)
          Adds a DTD to the grammar pool.
 void addSchemaGrammar(InputStream input)
          Adds an XML Schema to the grammar pool.
 void addSchemaGrammar(String resourceName)
          Adds an XML Schema to the grammar pool.
 void addSchemaGrammar(String publicId, String systemId, InputStream input)
          Adds an XML Schema to the grammar pool.
 void addSchemaGrammar(org.apache.xerces.xni.parser.XMLInputSource source)
          Adds an XML Schem to the grammar pool.
 org.apache.xerces.xni.grammars.XMLGrammarPool getGrammarPool()
          Gets the grammar pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRAMMAR_POOL

public static final String GRAMMAR_POOL
See Also:
Constant Field Values
Constructor Detail

XMLGrammarPoolBuilder

public XMLGrammarPoolBuilder()
Creates a new grammar pool builder.

Method Detail

addDTDGrammar

public void addDTDGrammar(org.apache.xerces.xni.parser.XMLInputSource source)
                   throws IOException
Adds a DTD to the grammar pool.

Parameters:
source - DTD
Throws:
IOException - if an I/O errors occurs

addDTDGrammar

public void addDTDGrammar(String publicId,
                          String systemId,
                          InputStream input)
                   throws IOException
Adds a DTD grammar to the pool.

You can set the publicId to null, but the systemId must match the name used in the XML file for the DTD.

Parameters:
publicId - public id
systemId - system id
input - DTD
Throws:
IOException - if an I/O error occurs

addDTDGrammar

public void addDTDGrammar(String resourceName)
                   throws IOException
Adds a DTD grammar to the pool.

The DTD is added by getting the resource using the specified name, and setting the last part of the resource name as the system id, so that this DTD can be found later when validating XML files. This system id must match the system id in the XML file.

Parameters:
resourceName - name of the DTD resource
Throws:
IOException - if an I/O error occurs

addSchemaGrammar

public void addSchemaGrammar(org.apache.xerces.xni.parser.XMLInputSource source)
                      throws IOException
Adds an XML Schem to the grammar pool.

The schema is later used when the namespace matches one in a XML file

Parameters:
source - schema
Throws:
IOException - if an I/O errors occurs

addSchemaGrammar

public void addSchemaGrammar(String publicId,
                             String systemId,
                             InputStream input)
                      throws IOException
Adds an XML Schema to the grammar pool.

The schema is later used when the namespace matches one in a XML file The public id and system id can both be null.

Parameters:
publicId - public id
systemId - system id
input - schema
Throws:
IOException - if an I/O error occurs

addSchemaGrammar

public void addSchemaGrammar(InputStream input)
                      throws IOException
Adds an XML Schema to the grammar pool.

The schema is later used when the namespace matches one in a XML file

Parameters:
input - schema
Throws:
IOException - if an I/O error occurs

addSchemaGrammar

public void addSchemaGrammar(String resourceName)
                      throws IOException
Adds an XML Schema to the grammar pool.

The schema is later used when the namespace matches one in a XML file

Parameters:
resourceName - name of the schema resource
Throws:
IOException - if an I/O error occurs

getGrammarPool

public org.apache.xerces.xni.grammars.XMLGrammarPool getGrammarPool()
Gets the grammar pool.

It might be a good idea to lock the grammar pool after finishing with this builder.

Returns:
pool