Search in sources :

Example 1 with ForkContentHandler

use of com.sun.tools.xjc.util.ForkContentHandler in project jaxb-ri by eclipse-ee4j.

the class BindInfo method parse.

/**
 * Parses an InputSource into dom4j Document.
 * Returns null in case of an exception.
 */
private static Document parse(Model model, InputSource is, ErrorReceiver receiver) throws AbortException {
    try {
        ValidatorHandler validator = bindingFileSchema.newValidator();
        // set up the pipe line as :
        // /-> extensionChecker -> validator
        // parser-> -<
        // \-> DOM builder
        SAXParserFactory pf = XmlFactory.createParserFactory(model.options.disableXmlSecurity);
        DocumentBuilderFactory domFactory = XmlFactory.createDocumentBuilderFactory(model.options.disableXmlSecurity);
        DOMBuilder builder = new DOMBuilder(domFactory);
        ErrorReceiverFilter controller = new ErrorReceiverFilter(receiver);
        validator.setErrorHandler(controller);
        XMLReader reader = pf.newSAXParser().getXMLReader();
        reader.setErrorHandler(controller);
        DTDExtensionBindingChecker checker = new DTDExtensionBindingChecker("", model.options, controller);
        checker.setContentHandler(validator);
        reader.setContentHandler(new ForkContentHandler(checker, builder));
        reader.parse(is);
        if (controller.hadError())
            throw new AbortException();
        return (Document) builder.getDOM();
    } catch (IOException | SAXException | ParserConfigurationException e) {
        receiver.error(new SAXParseException2(e.getMessage(), null, e));
    }
    throw new AbortException();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ValidatorHandler(javax.xml.validation.ValidatorHandler) SAXParseException2(com.sun.istack.SAXParseException2) ForkContentHandler(com.sun.tools.xjc.util.ForkContentHandler) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) AbortException(com.sun.tools.xjc.AbortException)

Example 2 with ForkContentHandler

use of com.sun.tools.xjc.util.ForkContentHandler in project jaxb-ri by eclipse-ee4j.

the class SCDBasedBindingSet method apply.

/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if (topLevel != null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v, unmarshaller);
        topLevel.applyAll(schema.getSchemas());
        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) ForkContentHandler(com.sun.tools.xjc.util.ForkContentHandler) Unmarshaller(jakarta.xml.bind.Unmarshaller)

Example 3 with ForkContentHandler

use of com.sun.tools.xjc.util.ForkContentHandler in project jaxb-ri by eclipse-ee4j.

the class ConfigReader method parseAndGetConfig.

/**
 * Parses an xml config file and returns a Config object.
 *
 * @param xmlFile
 *        The xml config file which is passed by the user to annotation processing
 * @return
 *        A non null Config object
 */
private Config parseAndGetConfig(File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
    XMLReader reader;
    try {
        SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
        reader = factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
        // in practice this will never happen
        throw new Error(e);
    }
    NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
    // set up validator
    ValidatorHandler validator = configSchema.newValidator();
    validator.setErrorHandler(errorHandler);
    // the validator will receive events first, then the parser.
    reader.setContentHandler(new ForkContentHandler(validator, runtime));
    reader.setErrorHandler(errorHandler);
    Config config = new Config(runtime);
    runtime.setRootHandler(config);
    reader.parse(new InputSource(xmlFile.toURI().toURL().toExternalForm()));
    runtime.reset();
    return config;
}
Also used : InputSource(org.xml.sax.InputSource) ValidatorHandler(javax.xml.validation.ValidatorHandler) Config(com.sun.tools.jxc.gen.config.Config) ForkContentHandler(com.sun.tools.xjc.util.ForkContentHandler) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

ForkContentHandler (com.sun.tools.xjc.util.ForkContentHandler)3 ValidatorHandler (javax.xml.validation.ValidatorHandler)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 XMLReader (org.xml.sax.XMLReader)2 SAXParseException2 (com.sun.istack.SAXParseException2)1 Config (com.sun.tools.jxc.gen.config.Config)1 AbortException (com.sun.tools.xjc.AbortException)1 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)1 Unmarshaller (jakarta.xml.bind.Unmarshaller)1 IOException (java.io.IOException)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1