Example usage for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader

List of usage examples for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader

Introduction

In this page you can find the example usage for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader.

Prototype

public DefaultResourceLoader(@Nullable ClassLoader classLoader) 

Source Link

Document

Create a new DefaultResourceLoader.

Usage

From source file:com.mitre.cockpits.cmscockpit.CmsCockpitConfigurationTest.java

@BeforeClass
public static void testsSetup() {
    Registry.setCurrentTenantByID("junit");
    final GenericApplicationContext context = new GenericApplicationContext();
    context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader()));
    context.setClassLoader(Registry.class.getClassLoader());
    context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader());
    context.setParent(Registry.getGlobalApplicationContext());
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.setBeanClassLoader(Registry.class.getClassLoader());
    xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class);
    xmlReader.loadBeanDefinitions(getSpringConfigurationLocations());
    context.refresh();//w  w  w .  j ava 2 s .c  om
    applicationContext = context;
}

From source file:org.constretto.spring.internal.converter.SpringResourceValueConverter.java

public Resource fromString(String value) throws ConstrettoConversionException {
    return new DefaultResourceLoader(this.getClass().getClassLoader()).getResource(value);
}

From source file:org.sakaiproject.entitybroker.util.spring.EntityPropertiesServiceSpringImpl.java

@Override
public List<String> registerLocaleMessages(String prefix, String baseName, Locale locale,
        ClassLoader classLoader) {
    SpringMessageBundle messageBundle = new SpringMessageBundle();
    messageBundle.setResourceLoader(new DefaultResourceLoader(classLoader));
    messageBundle.setBasename(baseName);
    messageBundle.setDefaultEncoding("UTF-8");
    List<String> keys = messageBundle.getPropertyKeys(locale);
    registerPrefixMessageBundle(prefix, messageBundle);
    return keys;/*from   ww  w .  j  av a 2  s  .  c  o  m*/
}

From source file:com.agileapes.couteau.maven.resource.ClassPathScanningClassProvider.java

public void setClassLoader(ClassLoader classLoader) {
    this.classLoader = classLoader;
    this.setResourceLoader(new DefaultResourceLoader(classLoader));
}

From source file:ch.algotrader.config.ConfigLocator.java

private static ConfigLocator standaloneInit() throws Exception {

    DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ConfigLocator.class.getClassLoader());
    return standaloneInit(ConfigLoader.load(resourceLoader));
}

From source file:hm.binkley.util.XPropsConverter.java

public XPropsConverter() {
    register("address", value -> {
        final HostAndPort parsed = HostAndPort.fromString(value).requireBracketsForIPv6();
        return createUnresolved(parsed.getHostText(), parsed.getPort());
    });/*from w  w w .j a  v a2s  .co  m*/
    register("bundle", ResourceBundle::getBundle);
    register("byte", Byte::valueOf);
    register("class", Class::forName);
    register("date", LocalDate::parse);
    register("decimal", BigDecimal::new);
    register("double", Double::valueOf);
    register("duration", Duration::parse);
    register("file", File::new);
    register("float", Float::valueOf);
    register("inet", InetAddress::getByName);
    register("int", Integer::valueOf);
    register("integer", BigInteger::new);
    register("long", Long::valueOf);
    register("path", Paths::get);
    register("period", Period::parse);
    register("regex", Pattern::compile);
    register("resource",
            value -> new DefaultResourceLoader(currentThread().getContextClassLoader()).getResource(value));
    register("resource*",
            value -> asList(new PathMatchingResourcePatternResolver(currentThread().getContextClassLoader())
                    .getResources(value)));
    register("short", Short::valueOf);
    register("time", LocalDateTime::parse);
    register("timestamp", Instant::parse);
    register("tz", TimeZone::getTimeZone);
    register("uri", URI::create);
    register("url", URL::new);
}

From source file:gov.va.vinci.leo.cr.ExternalCollectionReader.java

/**
 * Load a resource object from the path to the CollectionReader descriptor then use the framework to initialize the reader.
 *
 * @param collectionReaderDescriptor Path to the CollectionReader descriptor.
 * @throws ResourceInitializationException if there is an error reading the descriptor.
 * @throws IOException if there is an error in the XML of the descriptor.
 * @throws InvalidXMLException if the CollectionReader cannot be initialized by the framework.
 *///  www.  j av a  2  s  . com
private void setCollectionReader(String collectionReaderDescriptor)
        throws IOException, InvalidXMLException, ResourceInitializationException {
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    DefaultResourceLoader loader = new DefaultResourceLoader(cl);
    Resource resource = loader.getResource(collectionReaderDescriptor);
    setCollectionReader(resource.getFile());
}

From source file:org.sahli.asciidoc.confluence.publisher.maven.plugin.AsciidocConfluencePublisherMojo.java

private List<Resource> templateResources() throws IOException {
    Artifact artifact = this.pluginArtifactMap
            .get("org.sahli.asciidoc.confluence.publisher:asciidoc-confluence-publisher-converter");
    URLClassLoader templateClassLoader = new URLClassLoader(new URL[] { artifact.getFile().toURI().toURL() });
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(
            new DefaultResourceLoader(templateClassLoader));

    return asList(pathMatchingResourcePatternResolver.getResources(TEMPLATES_CLASSPATH_PATTERN));
}

From source file:com.vilt.minium.script.test.impl.MiniumRhinoTestsSupport.java

protected Resource getResource(MiniumRhinoTestContextManager contextManager, JsVariable jsVariable) {
    String resourcePath = jsVariable.resource();
    Resource resource = null;//from w ww  .  ja va 2s  . c o  m
    if (StringUtils.isNotEmpty(resourcePath)) {
        resource = new DefaultResourceLoader(classLoader).getResource(resourcePath);
    } else if (StringUtils.isNotEmpty(jsVariable.resourceBean())) {
        resource = contextManager.getContext().getBean(jsVariable.resourceBean(), Resource.class);
    }
    if (resource == null)
        return null;

    checkState(resource.exists() && resource.isReadable());
    return resource;
}

From source file:com.rsmart.kuali.kfs.sys.context.PropertyLoadingFactoryBean.java

private static void loadProperties(Properties props, String propertyFileName) {
    entering();//from w w  w .j a v  a  2 s  .c  o  m
    debug("Loading %s", propertyFileName);
    InputStream propertyFileInputStream = null;
    try {
        try {
            propertyFileInputStream = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader())
                    .getResource(propertyFileName).getInputStream();
            props.load(propertyFileInputStream);
        } finally {
            if (propertyFileInputStream != null) {
                propertyFileInputStream.close();
            }
        }
    } catch (FileNotFoundException fnfe) {
        try {
            try {
                propertyFileInputStream = new FileInputStream(propertyFileName);
                props.load(propertyFileInputStream);
            } finally {
                if (propertyFileInputStream != null) {
                    propertyFileInputStream.close();
                }
            }
        } catch (Exception e) {
            warn("Could not load property file %s", propertyFileName);
            throwing(e);
        }

    } catch (IOException e) {
        warn("PropertyLoadingFactoryBean unable to load property file: %s", propertyFileName);
    } finally {
        exiting();
    }
}