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();
}
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;
}
}
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;
}
Aggregations