/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001, 2002,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <p> This class provides an easy way for a user to preparse grammars
* of various types. By default, it knows how to preparse external
* DTD's and schemas; it provides an easy way for user applications to
* register classes that know how to parse additional grammar types.
* By default, it does no grammar caching; but it provides ways for
* user applications to do so.
*
* @author Neil Graham, IBM
*
* @version $Id: XMLGrammarPreparser.java,v 1.7 2010-11-01 04:40:10 joehw Exp $
*/
public class XMLGrammarPreparser {
//
// Constants
//
// feature: continue-after-fatal-error
/** Property identifier: symbol table. */
/** Property identifier: error reporter. */
/** Property identifier: error handler. */
/** Property identifier: entity resolver. */
/** Property identifier: grammar pool . */
// the "built-in" grammar loaders
static {
"com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader");
"com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDLoader");
}
/** Recognized properties. */
};
// Data
// Hashtable holding our loaders
//
// Constructors
//
/** Default constructor. */
public XMLGrammarPreparser() {
this(new SymbolTable());
} // <init>()
/**
* Constructs a preparser using the specified symbol table.
*
* @param symbolTable The symbol table to use.
*/
fErrorReporter = new XMLErrorReporter();
fEntityResolver = new XMLEntityManager();
// those are all the basic properties...
} // <init>(SymbolTable)
//
// Public methods
//
/*
* Register a type of grammar to make it preparsable. If
* the second parameter is null, the parser will use its built-in
* facilities for that grammar type.
* This should be called by the application immediately
* after creating this object and before initializing any properties/features.
* @param type URI identifying the type of the grammar
* @param loader an object capable of preparsing that type; null if the ppreparser should use built-in knowledge.
* @return true if successful; false if no built-in knowledge of
* the type or if unable to instantiate the string we know about
*/
// got one; just instantiate it...
try {
} catch (Exception e) {
return false;
}
return true;
}
return false;
}
// were given one
return true;
} // registerPreparser(String, XMLGrammarLoader): boolean
/**
* Parse a grammar from a location identified by an
* XMLInputSource.
* This method also adds this grammar to the XMLGrammarPool
*
* @param type The type of the grammar to be constructed
* @param is The XMLInputSource containing this grammar's
* information
* <strong>If a URI is included in the systemId field, the parser will not expand this URI or make it
* available to the EntityResolver</strong>
* @return The newly created <code>Grammar</code>.
* @exception XNIException thrown on an error in grammar
* construction
* @exception IOException thrown if an error is encountered
* in reading the file
*/
// make sure gl's been set up with all the "basic" properties:
// potentially, not all will support this one...
if(fGrammarPool != null) {
try {
} catch(Exception e) {
// too bad...
}
}
}
return null;
} // preparseGrammar(String, XMLInputSource): Grammar
/**
* Set the locale to use for messages.
*
* @param locale The locale object to use for localization of messages.
*
* @exception XNIException Thrown if the parser does not support the
* specified locale.
*/
} // setLocale(Locale)
/** Return the Locale the XMLGrammarLoader is using. */
return fLocale;
} // getLocale(): Locale
/**
* Sets the error handler.
*
* @param errorHandler The error handler.
*/
} // setErrorHandler(XMLErrorHandler)
/** Returns the registered error handler. */
return fErrorReporter.getErrorHandler();
} // getErrorHandler(): XMLErrorHandler
/**
* Sets the entity resolver.
*
* @param entityResolver The new entity resolver.
*/
} // setEntityResolver(XMLEntityResolver)
/** Returns the registered entity resolver. */
return fEntityResolver;
} // getEntityResolver(): XMLEntityResolver
/**
* Sets the grammar pool.
*
* @param grammarPool The new grammar pool.
*/
} // setGrammarPool(XMLGrammarPool)
/** Returns the registered grammar pool. */
return fGrammarPool;
} // getGrammarPool(): XMLGrammarPool
// it's possible the application may want access to a certain loader to do
// some custom work.
} // getLoader(String): XMLGrammarLoader
// set a feature. This method tries to set it on all
// registered loaders; it eats any resulting exceptions. If
// an app needs to know if a particular feature is supported
// by a grammar loader of a particular type, it will have
// to retrieve that loader and use the loader's setFeature method.
while(loaders.hasMoreElements()){
try {
} catch(Exception e) {
// eat it up...
}
}
// since our error reporter is a property we set later,
// make sure features it understands are also set.
}
} //setFeature(String, boolean)
// set a property. This method tries to set it on all
// registered loaders; it eats any resulting exceptions. If
// an app needs to know if a particular property is supported
// by a grammar loader of a particular type, it will have
// to retrieve that loader and use the loader's setProperty method.
// <p> <strong>An application should use the explicit method
// in this class to set "standard" properties like error handler etc.</strong>
while(loaders.hasMoreElements()){
try {
} catch(Exception e) {
// eat it up...
}
}
} //setProperty(String, Object)
// get status of feature in a particular loader. This
// catches no exceptions--including NPE's--so the application had
// better make sure the loader exists and knows about this feature.
// @param type type of grammar to look for the feature in.
// @param featureId the feature string to query.
// @return the value of the feature.
} // getFeature (String, String): boolean
// get status of property in a particular loader. This
// catches no exceptions--including NPE's--so the application had
// better make sure the loader exists and knows about this property.
// <strong>For standard properties--that will be supported
// by all loaders--the specific methods should be queried!</strong>
// @param type type of grammar to look for the property in.
// @param propertyId the property string to query.
// @return the value of the property.
} // getProperty(String, String): Object
} // class XMLGrammarPreparser