private void resolveSchemaGrammar( String loc, String uri) throws Exception {
SchemaGrammar grammar = (SchemaGrammar) fGrammarResolver.getGrammar(uri);
if (grammar == null) {
DOMParser parser = new DOMParser();
parser.setEntityResolver( new Resolver(fEntityHandler) );
parser.setErrorHandler( new ErrorHandler() );
try {
parser.setFeature("http://xml.org/sax/features/validation", false);
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
} catch ( org.xml.sax.SAXNotRecognizedException e ) {
e.printStackTrace();
} catch ( org.xml.sax.SAXNotSupportedException e ) {
e.printStackTrace();
}
// expand it before passing it to the parser
InputSource source = null;
EntityResolver currentER = parser.getEntityResolver();
if (currentER != null) {
source = currentER.resolveEntity("", loc);
}
if (source == null) {
loc = fEntityHandler.expandSystemId(loc);
source = new InputSource(loc);
}
try {
parser.parse( source );
} catch ( IOException e ) {
e.printStackTrace();
} catch ( SAXException e ) {
//System.out.println("loc = "+loc);
//e.printStackTrace();
reportRecoverableXMLError( XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR, e.getMessage() );
}
Document document = parser.getDocument(); //Our Grammar
TraverseSchema tst = null;
try {
if (DEBUG_SCHEMA_VALIDATION) {
System.out.println("I am geting the Schema Document");