/** * Loads the configuration from the location represented by the String. * @param config The configuration location. * @param loader The default ClassLoader to use. * @return The InputSource to use to read the configuration. */ protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) { try { final URL url = new URL(config); return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI())); } catch (final Exception ex) { final ConfigurationSource source = ConfigurationSource.fromResource(config, loader); if (source == null) { try { final File file = new File(config); return new ConfigurationSource(new FileInputStream(file), file); } catch (final FileNotFoundException fnfe) { // Ignore the exception LOGGER.catching(Level.DEBUG, fnfe); } } return source; } }
final ClassLoader loader = LoaderUtil.getThreadContextClassLoader(); final String path = ConfigurationFactory.extractClassLoaderUriPath(configLocation); final ConfigurationSource source = fromResource(path, loader); if (source != null) { return source;
private Configuration getConfiguration(final LoggerContext loggerContext, final boolean isTest, final String name) { final boolean named = Strings.isNotEmpty(name); final ClassLoader loader = LoaderUtil.getThreadContextClassLoader(); for (final ConfigurationFactory factory : getFactories()) { String configName; final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX; final String [] types = factory.getSupportedTypes(); if (types == null) { continue; } for (final String suffix : types) { if (suffix.equals(ALL_TYPES)) { continue; } configName = named ? prefix + name + suffix : prefix + suffix; final ConfigurationSource source = ConfigurationSource.fromResource(configName, loader); if (source != null) { if (!factory.isActive()) { LOGGER.warn("Found configuration file {} for inactive ConfigurationFactory {}", configName, factory.getClass().getName()); } return factory.getConfiguration(loggerContext, source); } } } return null; }
/** * Returns the Configuration obtained using a given ClassLoader. * @param loggerContext The logger context * @param name The configuration name. * @param configLocation A URI representing the location of the configuration. * @param loader The default ClassLoader to use. If this is {@code null}, then the * {@linkplain LoaderUtil#getThreadContextClassLoader() default ClassLoader} will be used. * * @return The Configuration. */ public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation, final ClassLoader loader) { if (!isActive()) { return null; } if (loader == null) { return getConfiguration(loggerContext, name, configLocation); } if (isClassLoaderUri(configLocation)) { final String path = extractClassLoaderUriPath(configLocation); final ConfigurationSource source = ConfigurationSource.fromResource(path, loader); if (source != null) { final Configuration configuration = getConfiguration(loggerContext, source); if (configuration != null) { return configuration; } } } return getConfiguration(loggerContext, name, configLocation); }