Example usage for org.springframework.core.io ResourceLoader getResource

List of usage examples for org.springframework.core.io ResourceLoader getResource

Introduction

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

Prototype

Resource getResource(String location);

Source Link

Document

Return a Resource handle for the specified resource location.

Usage

From source file:org.springextensions.db4o.io.ResourceStorageTest.java

@Test
public void testExistsNot() {
    String uri = "resource";

    Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(false);

    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource(uri)).thenReturn(resource);

    ResourceStorage resourceStorage = new ResourceStorage();
    resourceStorage.setResourceLoader(resourceLoader);

    Assert.assertFalse(resourceStorage.exists(uri));
}

From source file:org.springextensions.db4o.io.ResourceStorageTest.java

@Test
public void testOpen() {
    String uri = "resource";
    BinConfiguration binConfiguration = new BinConfiguration(uri, false, 0, false);

    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
    Resource resource = new ByteArrayResource(bytes);

    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource(uri)).thenReturn(resource);

    ResourceStorage resourceStorage = new ResourceStorage();
    resourceStorage.setResourceLoader(resourceLoader);

    Bin bin = resourceStorage.open(binConfiguration);

    Assert.assertEquals(bin.length(), bytes.length);
}

From source file:com.epam.ta.reportportal.core.jasper.JasperReportRender.java

@Autowired
public JasperReportRender(ResourceLoader resourceLoader) throws JRException, IOException {
    Resource reportTemplate = resourceLoader.getResource(REPORT_JRXML_TEMPLATE);
    com.google.common.base.Preconditions.checkArgument(reportTemplate.exists());
    InputStream inputStream = reportTemplate.getInputStream();
    JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
    this.jasperReport = JasperCompileManager.compileReport(jasperDesign);

}

From source file:com.bstek.dorado.web.servlet.DefaultDoradoAppContextImporter.java

protected void importBeanDefinitionResource(String location, Element element, ParserContext parserContext)
        throws Exception {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    try {//from   w  w w  .ja  v a  2 s. c  om
        ResourceLoader resourceLoader = readerContext.getResourceLoader();
        Resource relativeResource = resourceLoader.getResource(location);

        int importCount = readerContext.getReader().loadBeanDefinitions(relativeResource);
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Imported " + importCount + " bean definitions from dorado-context [" + location + "]");
        }
    } catch (Exception ex) {
        readerContext.error("Invalid dorado-context [" + location + "] to import bean definitions from",
                element, null, ex);
    }

    readerContext.fireImportProcessed(location, readerContext.extractSource(element));
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetrieverTest.java

@Test
public void testZeroNoAttributes() throws Exception {
    final PortletXmlMappableAttributesRetriever portletXmlMappableAttributesRetriever = new PortletXmlMappableAttributesRetriever();

    final ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource("/WEB-INF/portlet.xml")).thenReturn(new ClassPathResource(
            "/org/jasig/springframework/security/portlet/authentication/portlet_0_no_attributes.xml"));
    portletXmlMappableAttributesRetriever.setResourceLoader(resourceLoader);

    portletXmlMappableAttributesRetriever.afterPropertiesSet();

    final Set<String> mappableAttributes = portletXmlMappableAttributesRetriever.getMappableAttributes();

    assertEquals(Collections.emptySet(), mappableAttributes);
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetrieverTest.java

@Test
public void testOneNoAttributes() throws Exception {
    final PortletXmlMappableAttributesRetriever portletXmlMappableAttributesRetriever = new PortletXmlMappableAttributesRetriever();

    final ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource("/WEB-INF/portlet.xml")).thenReturn(new ClassPathResource(
            "/org/jasig/springframework/security/portlet/authentication/portlet_1_no_attributes.xml"));
    portletXmlMappableAttributesRetriever.setResourceLoader(resourceLoader);

    portletXmlMappableAttributesRetriever.afterPropertiesSet();

    final Set<String> mappableAttributes = portletXmlMappableAttributesRetriever.getMappableAttributes();

    assertEquals(Collections.emptySet(), mappableAttributes);
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetrieverTest.java

@Test
public void testTwoWithAttributes() throws Exception {
    final PortletXmlMappableAttributesRetriever portletXmlMappableAttributesRetriever = new PortletXmlMappableAttributesRetriever();

    final ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource("/WEB-INF/portlet.xml")).thenReturn(new ClassPathResource(
            "/org/jasig/springframework/security/portlet/authentication/portlet_2_with_attributes.xml"));
    portletXmlMappableAttributesRetriever.setResourceLoader(resourceLoader);

    portletXmlMappableAttributesRetriever.afterPropertiesSet();

    final Set<String> mappableAttributes = portletXmlMappableAttributesRetriever.getMappableAttributes();

    final Set<String> expected = ImmutableSet.of("name1", "name2", "name3");
    assertEquals(expected, mappableAttributes);
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetrieverTest.java

@Test
public void testTwoWithAttributesSpecificPortlet() throws Exception {
    final PortletXmlMappableAttributesRetriever portletXmlMappableAttributesRetriever = new PortletXmlMappableAttributesRetriever();

    final PortletConfig portletConfig = mock(PortletConfig.class);
    when(portletConfig.getPortletName()).thenReturn("ContextTestPortlet");
    portletXmlMappableAttributesRetriever.setPortletConfig(portletConfig);

    final ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource("/WEB-INF/portlet.xml")).thenReturn(new ClassPathResource(
            "/org/jasig/springframework/security/portlet/authentication/portlet_2_with_attributes.xml"));
    portletXmlMappableAttributesRetriever.setResourceLoader(resourceLoader);

    portletXmlMappableAttributesRetriever.afterPropertiesSet();

    final Set<String> mappableAttributes = portletXmlMappableAttributesRetriever.getMappableAttributes();

    final Set<String> expected = ImmutableSet.of("name1", "name2");
    assertEquals(expected, mappableAttributes);
}

From source file:org.kuali.maven.plugins.graph.processor.StyleProcessor.java

protected Properties getProperties() {
    String location = "classpath:dot.properties";
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource(location);
    InputStream in = null;//w  w w .j  a  v  a  2 s  .c o  m
    try {
        Properties properties = new Properties();
        in = resource.getInputStream();
        properties.load(in);
        return properties;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.lightadmin.core.config.management.rmi.DataManipulationServiceImpl.java

private ResourceDatabasePopulator databasePopulator(final String location) {
    final ResourceLoader resourceLoader = new DefaultResourceLoader();
    final ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.addScript(resourceLoader.getResource(location));
    return databasePopulator;
}