Search in sources :

Example 1 with DTDParser

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;
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) IOException(java.io.IOException) JCodeModel(com.sun.codemodel.JCodeModel) SAXException(org.xml.sax.SAXException) ModelChecker(com.sun.tools.xjc.reader.ModelChecker) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) Ring(com.sun.tools.xjc.reader.Ring) SAXParseException(org.xml.sax.SAXParseException) Model(com.sun.tools.xjc.model.Model) JCodeModel(com.sun.codemodel.JCodeModel) DTDParser(com.sun.xml.dtdparser.DTDParser) AbortException(com.sun.tools.xjc.AbortException)

Aggregations

JCodeModel (com.sun.codemodel.JCodeModel)1 SAXParseException2 (com.sun.istack.SAXParseException2)1 AbortException (com.sun.tools.xjc.AbortException)1 Model (com.sun.tools.xjc.model.Model)1 ModelChecker (com.sun.tools.xjc.reader.ModelChecker)1 Ring (com.sun.tools.xjc.reader.Ring)1 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)1 DTDParser (com.sun.xml.dtdparser.DTDParser)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1