Search in sources :

Example 66 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.

the class EPubParagraphExtractionHelperTest method testExtractParagraphsFromChapterFile_ENG_GDL_1855_ch4.

@Test
public void testExtractParagraphsFromChapterFile_ENG_GDL_1855_ch4() throws IOException {
    ResourceLoader resourceLoader = new ClassRelativeResourceLoader(EPubParagraphExtractionHelper.class);
    Resource resource = resourceLoader.getResource("eng-gdl-1855.epub_chapter-4.xhtml");
    File xhtmlFile = resource.getFile();
    logger.debug("xhtmlFile: " + xhtmlFile);
    List<String> storyBookParagraphs = EPubParagraphExtractionHelper.extractParagraphsFromChapterFile(xhtmlFile);
    assertThat(storyBookParagraphs.size(), is(2));
    assertThat(storyBookParagraphs.get(0), is("Some wild cats have spots."));
    assertThat(storyBookParagraphs.get(1), is("Like the leopard and the leopard cat!"));
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) Resource(org.springframework.core.io.Resource) File(java.io.File) Test(org.junit.Test)

Example 67 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.

the class EPubParagraphExtractionHelperTest method testExtractParagraphsFromChapterFile_ENG_GDL_1855.

@Test
public void testExtractParagraphsFromChapterFile_ENG_GDL_1855() throws IOException {
    ResourceLoader resourceLoader = new ClassRelativeResourceLoader(EPubParagraphExtractionHelper.class);
    Resource resource = resourceLoader.getResource("eng-gdl-1855.epub_chapter-2.xhtml");
    File xhtmlFile = resource.getFile();
    logger.debug("xhtmlFile: " + xhtmlFile);
    List<String> storyBookParagraphs = EPubParagraphExtractionHelper.extractParagraphsFromChapterFile(xhtmlFile);
    assertThat(storyBookParagraphs.size(), is(2));
    assertThat(storyBookParagraphs.get(0), is("Some wild cats have stripes."));
    assertThat(storyBookParagraphs.get(1), is("Like the tiger!"));
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) Resource(org.springframework.core.io.Resource) File(java.io.File) Test(org.junit.Test)

Example 68 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project jbehave-core by jbehave.

the class SpringApplicationContextFactory method createApplicationContext.

/**
 * Creates a configurable application context from the resources provided.
 * The context will be an instance of
 * {@link AnnotationConfigApplicationContext}, if the resources are
 * annotated class names, or {@link GenericApplicationContext} otherwise.
 *
 * @return A ConfigurableApplicationContext
 */
public ConfigurableApplicationContext createApplicationContext() {
    try {
        // first try to create annotation config application context
        Class<?>[] annotatedClasses = new Class<?>[resources.length];
        for (int i = 0; i < resources.length; i++) {
            annotatedClasses[i] = this.classLoader.loadClass(resources[i]);
        }
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(annotatedClasses);
        context.setParent(parent);
        context.setClassLoader(classLoader);
        return context;
    } catch (ClassNotFoundException e) {
        // create generic application context
        GenericApplicationContext context = new GenericApplicationContext(parent);
        context.setClassLoader(classLoader);
        ResourceLoader resourceLoader = new DefaultResourceLoader(classLoader);
        context.setResourceLoader(resourceLoader);
        BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
        for (String resource : resources) {
            reader.loadBeanDefinitions(resourceLoader.getResource(resource));
        }
        context.refresh();
        return context;
    }
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 69 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project syndesis by syndesisio.

the class DataManagerTest method setup.

@Before
public void setup() {
    cacheManager = new LRUCacheManager(100);
    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    // Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
    dataManager.init();
    dataManager.resetDeploymentData();
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Example 70 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project syndesis by syndesisio.

the class MetricsCollectorTest method before.

@Before
public void before() throws IOException, ParseException {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    DBI dbi = new DBI(ds);
    this.jsondb = new SqlJsonDB(dbi, null, Arrays.asList(new Index("/pair", "key")));
    try {
        this.jsondb.dropTables();
    } catch (Exception e) {
    }
    this.jsondb.createTables();
    jsondbRM = new JsonDBRawMetrics(jsondb);
    load();
    CacheManager cacheManager = new LRUCacheManager(100);
    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    // Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
    intMH = new IntegrationMetricsHandler(dataManager);
}
Also used : DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DBI(org.skife.jdbi.v2.DBI) Index(io.syndesis.server.jsondb.impl.Index) DataManager(io.syndesis.server.dao.manager.DataManager) ParseException(java.text.ParseException) IOException(java.io.IOException) SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) CacheManager(io.syndesis.common.util.cache.CacheManager) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Aggregations

ResourceLoader (org.springframework.core.io.ResourceLoader)90 Resource (org.springframework.core.io.Resource)51 Test (org.junit.Test)35 ClassRelativeResourceLoader (org.springframework.core.io.ClassRelativeResourceLoader)34 File (java.io.File)33 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)26 Test (org.junit.jupiter.api.Test)15 IOException (java.io.IOException)9 Environment (org.springframework.core.env.Environment)9 ByteArrayResource (org.springframework.core.io.ByteArrayResource)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 FileSystemResource (org.springframework.core.io.FileSystemResource)6 HashMap (java.util.HashMap)5 Configuration (freemarker.template.Configuration)4 Template (freemarker.template.Template)4 InputStream (java.io.InputStream)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 InputStreamReader (java.io.InputStreamReader)3 Properties (java.util.Properties)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3