use of com.sun.xml.dtdparser.DTDParser in project jaxb-ri by eclipse-ee4j.
the class TDTDReader method parse.
/**
* Parses DTD grammar and a binding information into BGM.
*
* <p>
* This method is just a utility method that covers 80% of the use
* cases.
*
* @param bindingInfo
* binding information file, if any. Can be null.
*/
public static Model parse(InputSource dtd, InputSource bindingInfo, ErrorReceiver errorReceiver, Options opts) {
try {
// set up a ring
final Ring old = Ring.begin();
try {
ErrorReceiverFilter ef = new ErrorReceiverFilter(errorReceiver);
JCodeModel cm = new JCodeModel();
Model model = new Model(opts, cm, NameConverter.standard, opts.classNameAllocator, null);
Ring.add(cm);
Ring.add(model);
Ring.add(ErrorReceiver.class, ef);
TDTDReader reader = new TDTDReader(ef, opts, bindingInfo);
DTDParser parser = new DTDParser();
parser.setDtdHandler(reader);
if (opts.entityResolver != null)
parser.setEntityResolver(opts.entityResolver);
try {
parser.parse(dtd);
} catch (SAXParseException e) {
// this error was already handled by GrammarReaderController
return null;
}
Ring.get(ModelChecker.class).check();
if (ef.hadError())
return null;
else
return model;
} finally {
Ring.end(old);
}
} catch (IOException | SAXException e) {
errorReceiver.error(new SAXParseException2(e.getMessage(), null, e));
return null;
} catch (AbortException e) {
// parsing was aborted but the error was already reported
return null;
}
}
Aggregations