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:org.joy.generator.engine.FreeMarkerImpl.java

public void initConfiguration() {
    try {//from   www. j a  va 2s. c  o m
        config = new Configuration();

        ClassPathResource resource = new ClassPathResource("templates/freemarker");

        //            config.setDirectoryForTemplateLoading(new File(classPath + "templates/freemarker"));

        config.setDirectoryForTemplateLoading(resource.getFile());

        config.setObjectWrapper(new DefaultObjectWrapper());

        config.setSetting("classic_compatible", "true");
        config.setSetting("whitespace_stripping", "true");
        config.setSetting("template_update_delay", "1");
        config.setSetting("locale", "zh_CN");
        config.setSetting("default_encoding", DEFAULT_ENCODING);
        config.setSetting("url_escaping_charset", DEFAULT_ENCODING);
        config.setSetting("datetime_format", "yyyy-MM-dd hh:mm:ss");
        config.setSetting("date_format", "yyyy-MM-dd");
        config.setSetting("time_format", "HH:mm:ss");
        config.setSetting("number_format", "0.######;");
    } catch (Exception e) {
        LOGGER.info(e.getMessage(), e);
    }
}

From source file:mbg.test.ib2j2.conditional.AbstractConditionalJava2Test.java

public AbstractConditionalJava2Test() {
    factory = new GenericApplicationContext();
    Resource res = new ClassPathResource("/mbg/test/ib2j2/conditional/SpringBeans.xml");
    XmlBeanDefinitionReader r = new XmlBeanDefinitionReader(factory);
    r.loadBeanDefinitions(res);//from ww w .  j a  v  a  2 s.  com
}

From source file:$.ChangesController.java

@RequestMapping(value = CHANGES_URI, method = RequestMethod.GET)
    @ResponseBody/* w  ww. j a v a 2 s  .c  om*/
    public String getChangesContent() throws IOException {
        ClassPathResource resource = new ClassPathResource("changes.txt");

        // add end of lines
        String resStr = "";
        List<String> lines = IOUtils.readLines(resource.getInputStream(), "utf-8");
        for (String line : lines) {
            resStr += line;
            resStr += "<br/>${symbol_escape}n";
        }

        return resStr;
    }

From source file:com.consol.citrus.admin.service.FileBrowserServiceTest.java

@Test
public void testGetFolders() throws Exception {
    String[] folders = testling.getFolders(new ClassPathResource("projects").getFile());
    Assert.assertNotNull(folders);//from  w  w w.  ja v a 2  s. co  m
    Assert.assertEquals(folders.length, 4);
    Assert.assertEquals(folders[0], "ant");
    Assert.assertEquals(folders[1], "maven");
    Assert.assertEquals(folders[2], "maven_connector");
    Assert.assertEquals(folders[3], "sample");
}

From source file:com.oreilly.springdata.jpa.AbstractIntegrationTest.java

/**
 * Populates the configured {@link DataSource} with data from {@code data.sql}.
 * //from   w  w  w  .j  a  v a 2  s. c  om
 * @throws SQLException
 */
@Before
public void populateDatabase() throws SQLException {

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("data.sql"));

    Connection connection = null;

    try {
        connection = DataSourceUtils.getConnection(dataSource);
        populator.populate(connection);
    } finally {
        if (connection != null) {
            DataSourceUtils.releaseConnection(connection, dataSource);
        }
    }
}

From source file:com.backend.test.repository.AbstractIntegrationTest.java

/**
 * Populates the configured {@link DataSource} with data from {@code data.sql}.
 * //  ww  w.j  a v a 2  s . c  om
 * @throws SQLException
 */
@Before
public void populateDatabase() throws SQLException {

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("foodies.sql"));

    Connection connection = null;

    try {
        connection = DataSourceUtils.getConnection(dataSource);
        populator.populate(connection);
    } finally {
        if (connection != null) {
            DataSourceUtils.releaseConnection(connection, dataSource);
        }
    }
}

From source file:org.ngrinder.monitor.controller.MonitorControllerTest.java

@Test
public void testMonitorData() throws ParseException, IOException {
    ModelMap model = new ModelMap();
    String monitorIP = "127.0.0.1";
    long mockTestId = 1234567890;
    String mockPath = String.valueOf(mockTestId) + File.separator + "report";
    File mockTestReportFile = new ClassPathResource(mockPath).getFile();

    // set a mock home object to let it find the sample monitor file.
    Home realHome = config.getHome();//from w  ww  . j av a 2 s . c  o m
    Home mockHome = mock(Home.class);
    when(mockHome.getPerfTestReportDirectory(String.valueOf(mockTestId))).thenReturn(mockTestReportFile);
    ReflectionTestUtils.setField(config, "home", mockHome);

    String rtnStr = monitorController.getMonitorData(model, mockTestId, monitorIP, 700);
    LOG.debug("Monitor data for ip:{} is\n{}", "127.0.0.1", rtnStr);

    // reset the home object
    ReflectionTestUtils.setField(config, "home", realHome);
}

From source file:org.shept.util.JarResourceCopier.java

public void initializeResources(ServletContext context) {
    String destPath = StringUtils.cleanPath(context.getRealPath(getTargetPath()));
    if (files != null && files.length > 0) {
        for (int i = 0; i < files.length; i++) {
            String source = StringUtils.applyRelativePath(getSourcePath(), files[i]);
            // surprise surprise you can't use StringUtils.applyRelativePath here this will cut off the last part of destPath
            JarUtils.copyResourcesOnce(new ClassPathResource(source), destPath, destPath + "/" + files[i]);
        }//from   w ww  .  j a v  a2  s  .c  o m
    } else {
        JarUtils.copyResourcesOnce(new ClassPathResource(getSourcePath()), destPath);
    }
}

From source file:com.nominanuda.springsoy.SoySourceTest.java

@Before
public void setUp() {
    soySource = new SoySource();
    soySource.setCache(false);//  ww w  .  j av  a  2  s . c o m
    soySource.setTemplatesLocation(new ClassPathResource(getClass().getPackage().getName().replace('.', '/')));
}

From source file:org.impotch.calcul.impot.cantonal.ge.pp.avant2010.BaremeRevenuFamille2000Test.java

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    ChargeurFichierEconometre chargeur = new ChargeurFichierEconometre();
    chargeur.setFichier(new ClassPathResource("ge/BASEIMP.CSV"));
    return Arrays.asList(chargeur.charger(2000, true));
}