Search in sources :

Example 1 with DelegatingEntityResolver

use of org.springframework.beans.factory.xml.DelegatingEntityResolver in project mule by mulesoft.

the class XmlConfigurationDocumentLoader method loadDocument.

/**
 * Creates a {@link Document} from an {@link InputStream} with the required configuration of a mule configuration file parsing.
 *
 * @param extensions if the current {@code inputStream} relies in other schemas pending to be loaded from an
 *        {@link ExtensionModel}, it will be picked up from {@code extensions} set
 * @param filename name of the file to display a better error messages (if there are any). Non null.
 * @param inputStream the input stream with the XML configuration content.
 * @return a new {@link Document} object with the provided content.
 * @throws MuleRuntimeException if an error occurs in {@link org.springframework.beans.factory.xml.DocumentLoader} factory, or
 *         if the current {@code filename} contains 1 or more errors.
 * @see {@link DefaultXmlLoggerErrorHandler#getErrors()}
 */
public Document loadDocument(Set<ExtensionModel> extensions, String filename, InputStream inputStream) {
    final XmlGathererErrorHandler errorHandler = createXmlGathererErrorHandler();
    Document document;
    try {
        document = new MuleDocumentLoader().loadDocument(new InputSource(inputStream), validationMode == VALIDATION_XSD ? new ModuleDelegatingEntityResolver(extensions) : new DelegatingEntityResolver(currentThread().getContextClassLoader()), errorHandler == null ? new DefaultHandler() : errorHandler, validationMode, true);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage(format("Error loading: %s, %s", filename, e.getMessage())), e);
    }
    if (validationMode == VALIDATION_XSD) {
        throwExceptionIfErrorsWereFound(errorHandler, filename);
    }
    return document;
}
Also used : InputSource(org.xml.sax.InputSource) DelegatingEntityResolver(org.springframework.beans.factory.xml.DelegatingEntityResolver) ModuleDelegatingEntityResolver(org.mule.runtime.config.internal.ModuleDelegatingEntityResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ModuleDelegatingEntityResolver(org.mule.runtime.config.internal.ModuleDelegatingEntityResolver) Document(org.w3c.dom.Document) MuleDocumentLoader(org.mule.runtime.config.internal.MuleDocumentLoader) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) SAXParseException(org.xml.sax.SAXParseException) DefaultHandler(org.xml.sax.helpers.DefaultHandler)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ModuleDelegatingEntityResolver (org.mule.runtime.config.internal.ModuleDelegatingEntityResolver)1 MuleDocumentLoader (org.mule.runtime.config.internal.MuleDocumentLoader)1 DelegatingEntityResolver (org.springframework.beans.factory.xml.DelegatingEntityResolver)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1 SAXParseException (org.xml.sax.SAXParseException)1 DefaultHandler (org.xml.sax.helpers.DefaultHandler)1