use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.
the class ConfigurationDigester method getDigester.
private Digester getDigester(Configuration configuration) throws ConfigurationException, ParserConfigurationException, SAXException {
XMLReader reader = XmlUtils.getXMLReader(configuration);
Digester digester = new Digester(reader) {
// override Digester.createSAXException() implementations to obtain a clear unduplicated message and a properly nested stacktrace on IBM JDK
@Override
public SAXException createSAXException(String message, Exception e) {
return SaxException.createSaxException(message, getDocumentLocator(), e);
}
@Override
public SAXException createSAXException(Exception e) {
return SaxException.createSaxException(null, getDocumentLocator(), e);
}
};
digester.setUseContextClassLoader(true);
digester.push(configuration);
Resource digesterRulesResource = Resource.getResource(configuration, getDigesterRules());
loadDigesterRules(digester, digesterRulesResource);
if (validation) {
digester.setValidating(true);
digester.setNamespaceAware(true);
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
URL xsdUrl = ClassUtils.getResourceURL(CONFIGURATION_VALIDATION_SCHEMA);
if (xsdUrl == null) {
throw new ConfigurationException("cannot get URL from [" + CONFIGURATION_VALIDATION_SCHEMA + "]");
}
digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdUrl.toExternalForm());
XmlErrorHandler xeh = new XmlErrorHandler(CONFIGURATION_VALIDATION_SCHEMA);
digester.setErrorHandler(xeh);
}
return digester;
}
use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.
the class ConfigurationDigester method digestConfiguration.
private void digestConfiguration(Configuration configuration) throws ConfigurationException {
String configurationFile = ConfigurationUtils.getConfigurationFile(configuration.getClassLoader(), configuration.getName());
Digester digester = null;
Resource configurationResource = Resource.getResource(configuration, configurationFile);
if (configurationResource == null) {
throw new ConfigurationException("Configuration file [" + configurationFile + "] not found in ClassLoader [" + configuration.getClassLoader() + "]");
}
try {
digester = getDigester(configuration);
if (log.isDebugEnabled())
log.debug("digesting configuration [" + configuration.getName() + "] configurationFile [" + configurationFile + "]");
AppConstants appConstants = AppConstants.getInstance(configuration.getClassLoader());
parseAndResolveEntitiesAndProperties(digester, configuration, configurationResource, appConstants);
configLogger.info(configuration.getLoadedConfiguration());
} catch (Throwable t) {
// wrap exception to be sure it gets rendered via the IbisException-renderer
String currentElementName = null;
if (digester != null) {
currentElementName = digester.getCurrentElementName();
}
throw new ConfigurationException("error during unmarshalling configuration from file [" + configurationFile + "] with digester-rules-file [" + getDigesterRules() + "] in element [" + currentElementName + "]", t);
}
}
use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.
the class ClassLoaderEntityResolver method resolveEntity.
/**
* @see org.xml.sax.EntityResolver#resolveEntity(String, String)
*/
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (log.isDebugEnabled())
log.debug("Resolving publicId [" + publicId + "] systemId [" + systemId + "] in scope [" + scopeProvider + "]");
Resource resource = Resource.getResource(scopeProvider, systemId);
if (resource != null) {
return resource.asInputSource();
}
// If nothing found, return a SAXException. If NULL is returned it can trigger default (fallback) behaviour using the internal EntityResolver.
String message = "Cannot get resource for publicId [" + publicId + "] with systemId [" + systemId + "] in scope [" + scopeProvider + "]";
throw new SAXException(message);
}
use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.
the class FlowDiagramManager method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
Resource xsltSourceConfig = Resource.getResource(ADAPTER2DOT_XSLT);
transformerPoolAdapter = TransformerPool.getInstance(xsltSourceConfig, 2);
Resource xsltSourceIbis = Resource.getResource(CONFIGURATION2DOT_XSLT);
transformerPoolConfig = TransformerPool.getInstance(xsltSourceIbis, 2);
IFlowGenerator generator = getFlowGenerator();
if (generator == null) {
log.warn("no IFlowGenerator found. Unable to generate flow diagrams");
} else {
if (log.isDebugEnabled())
log.debug("using IFlowGenerator [" + generator + "]");
fileExtension = generator.getFileExtension();
}
noImageAvailable = ClassUtils.getResourceURL(NO_IMAGE_AVAILABLE);
if (noImageAvailable == null) {
throw new IllegalStateException("image [" + NO_IMAGE_AVAILABLE + "] not found");
}
}
use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.
the class FrankDigesterRulesTest method parseDigesterRulesXml.
@Test
public void parseDigesterRulesXml() {
DummyDigesterRulesParser handler = new DummyDigesterRulesParser();
Resource digesterRules = Resource.getResource("digester-rules.xml");
try {
XmlUtils.parseXml(digesterRules.asInputSource(), handler);
} catch (IOException e) {
throw new IllegalStateException("unable to open digesterRules file", e);
} catch (SAXException e) {
throw new IllegalStateException("unable to parse digesterRules file", e);
}
assertTrue("must at least have 33 patterns", handler.size() >= 33);
}
Aggregations