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

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

Introduction

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

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:br.eb.ime.labprog3.tam.DefaultController.java

@RequestMapping(value = "index")
public String index(ModelMap map) {

    String fileName = "../../resources/xml/aeroportos.xml";
    Resource resource = null;/*from   w  w w  . java  2  s . c om*/

    resource = new ClassPathResource(fileName);

    AeroportoDAO dao = null;
    try {
        dao = new AeroportoDAO(resource.getFile());
    } catch (IOException ex) {
        Logger.getLogger(DefaultController.class.getName()).log(Level.SEVERE, null, ex);
    }

    List<Aeroporto> listaDeAeroportos = null;

    if (dao != null) {
        listaDeAeroportos = dao.listarAeroportos();
        map.addAttribute("listaDeAeroportos", listaDeAeroportos);

    }

    return "index";
}

From source file:no.difi.sdp.client.ObjectMother.java

public static Noekkelpar noekkelpar() {
    try {//w w w  . j a  va  2s.  co  m
        KeyStore keyStore = KeyStore.getInstance("jks");
        keyStore.load(new ClassPathResource("/selfsigned-keystore.jks").getInputStream(),
                "password1234".toCharArray());
        return Noekkelpar.fraKeyStore(keyStore, "avsender", "password1234");
    } catch (Exception e) {
        throw new RuntimeException("Kunne ikke laste keystore", e);
    }
}

From source file:net.groupbuy.service.impl.LogConfigServiceImpl.java

@SuppressWarnings("unchecked")
@Cacheable("logConfig")
public List<LogConfig> getAll() {
    try {//from   ww  w .j a v a 2s.co  m
        File shopxxXmlFile = new ClassPathResource(CommonAttributes.SHOPXX_XML_PATH).getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<org.dom4j.Element> elements = document.selectNodes("/shopxx/logConfig");
        List<LogConfig> logConfigs = new ArrayList<LogConfig>();
        for (org.dom4j.Element element : elements) {
            String operation = element.attributeValue("operation");
            String urlPattern = element.attributeValue("urlPattern");
            LogConfig logConfig = new LogConfig();
            logConfig.setOperation(operation);
            logConfig.setUrlPattern(urlPattern);
            logConfigs.add(logConfig);
        }
        return logConfigs;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.ligoj.app.plugin.prov.aws.in.CsvForBeanEc2Test.java

@Test
public void readTooFewData() throws IOException {
    final BufferedReader reader = new BufferedReader(new InputStreamReader(
            new ClassPathResource("mock-server/aws/index-small-too-few.csv").getInputStream()));
    Assertions.assertNull(new CsvForBeanEc2(reader).read());
}

From source file:com.eventattend.portal.Factory.UserFactory.java

public static UserController updateUserProfilePic() throws Exception {
    ClassPathResource resource = new ClassPathResource("BusinessObjectFactory.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    return (UserController) factory.getBean("User");
}

From source file:com.example.PathTests.java

@Test
public void test() throws Exception {
    ClassPathResource classPath = new ClassPathResource("");
    System.err.println(classPath.getURL().toString());
    System.err.println(Paths.get(new FileSystemResource(new FileSystemResource("src/main/resources").getURL()
            .toURI().toString().substring("file:".length())).getFile().toURI()).isAbsolute());
}

From source file:com.octo.captcha.engine.bufferedengine.SimpleBufferedEngineContainerTest.java

public void testExecute() throws Exception {
    Resource ressource = new ClassPathResource("testSimpleBufferedEngine.xml");
    ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
    BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");

    Thread.sleep(8000);//from  w w  w  . j  a va 2s .c o  m
    for (int i = 0; i < 30; i++) {
        assertNotNull(container.getNextCaptcha(Locale.US));

    }

    Thread.sleep(4000);

    ((SimpleBufferedEngineContainer) container).stopDaemon();
}

From source file:io.gravitee.repository.jdbc.config.JdbcRepositoryConfigurationTest.java

@Bean
public static Properties graviteeProperties() {
    final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    final Resource yamlResource = new ClassPathResource("gravitee.yml");
    yaml.setResources(yamlResource);//from www .j  av  a2  s .c  o m
    return yaml.getObject();
}

From source file:edu.northwestern.bioinformatics.studycalendar.restlets.ClasspathResourceRepresentation.java

@Override
public InputStream getStream() throws IOException {
    ClassPathResource res = new ClassPathResource(resourceName);
    if (!res.exists()) {
        throw new FileNotFoundException("Could not find " + resourceName);
    }//from w  ww .  j a v a 2s . c  o m
    return res.getInputStream();
}

From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyDbContextFactory.java

public static ApplicationContext makeNcbiTaxonomyDbContext() //String dbName)
        throws IOException

{
    /*//from  ww  w  . j  a  v  a 2s .  co  m
    File propsFile = PropertiesUtils
    .findPropertiesFile("NCBI_TAXONOMY_PROPERTIES", ".ncbitaxonomy", "ncbi_taxonomy.properties");
    EnvironmentUtils.init(propsFile);
            
    logger.debug("Using properties file: " + propsFile);
    Properties p = new Properties();
    FileInputStream is = null;
    try
       {
       is = new FileInputStream(propsFile);
       p.load(is);
       }
    finally
       {
       is.close();
       }
    //String dbName = (String) p.get("default");
            
    Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p);
            
    */
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    //         xmlReader.loadBeanDefinitions(new ClassPathResource("springjpautils.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomy.xml"));

    //PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    //cfg.setProperties(databases.get(dbName));
    //ctx.addBeanFactoryPostProcessor(cfg);

    ctx.refresh();

    // add a shutdown hook for the above context...
    ctx.registerShutdownHook();

    return ctx;
}