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.pdfsam.configuration.PdfsamEnterpriseConfig.java

@Bean(name = "logo")
public Group logo() throws IOException {
    Resource resource = new ClassPathResource("/fxml/LogoEnterprise.fxml");
    return FXMLLoader.load(resource.getURL());
}

From source file:com.enonic.cms.itest.content.imports.ImportServiceImplTest_importJobThreadSafe.java

@Before
public void setUp() throws IOException {
    personContentTypeXml = resourceToString(
            new ClassPathResource("com/enonic/cms/itest/content/imports/personContentType.xml"));

    DomainFactory factory = fixture.getFactory();

    fixture.initSystemData();/*from  www .j  a va 2 s  . c  om*/

    fixture.createAndStoreNormalUserWithUserGroup("testuser", "Test user", "testuserstore");

    fixture.save(
            factory.createContentHandler("MyHandler", ContentHandlerName.CUSTOM.getHandlerClassShortName()));
    fixture.save(factory.createContentType("PersonCty", ContentHandlerName.CUSTOM.getHandlerClassShortName(),
            XMLDocumentFactory.create(personContentTypeXml).getAsJDOMDocument()));
    fixture.save(factory.createUnit("MyUnit"));
    fixture.save(factory.createCategory("Persons", null, "PersonCty", "MyUnit", "testuser", "testuser"));
    fixture.save(factory.createCategoryAccessForUser("Persons", "testuser", "read, create, approve"));

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);

    PortalSecurityHolder.setAnonUser(fixture.findUserByName(User.ANONYMOUS_UID).getKey());
    PortalSecurityHolder.setLoggedInUser(fixture.findUserByName("testuser").getKey());
    PortalSecurityHolder.setImpersonatedUser(fixture.findUserByName("testuser").getKey());

    ImportJobFactory.setExecuteInOneTransaction(true);
}

From source file:org.web4thejob.test.AbstractWebApplicationContextTest.java

@Before
public void initializeData() {
    if (initialized) {
        return;/*from   ww w .  j a  va  2 s.co  m*/
    }

    Properties datasource = new Properties();
    try {
        datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    JobletInstaller jobletInstaller;
    jobletInstaller = ContextUtil.getBean(JobletInstaller.class);
    jobletInstaller.setConnectionInfo(datasource);
    List<Exception> errors = jobletInstaller.installAll();
    if (errors.isEmpty()) {
        ContextUtil.addActiveProfile("installed");
        ContextUtil.refresh();
    } else {
        throw new RuntimeException("Test Context initialization failed.");
    }

    initialized = true;
}

From source file:ru.anr.cmdline.base.plugins.CustomBannerProvider.java

/**
 * {@inheritDoc}// w ww .j  a v a 2 s  .c om
 */
@Override
public String getBanner() {

    StringBuilder sb = new StringBuilder();

    try {

        InputStreamSource iss = new ClassPathResource("welcome.text.txt");
        sb.append(FileUtils.readBanner(new InputStreamReader(iss.getInputStream())));

    } catch (IOException ex) {
        logger.info("File 'welcome.text.txt' not found in classpath");
    }

    sb.append(OsUtils.LINE_SEPARATOR);
    return sb.toString();
}

From source file:org.wso2.carbon.metrics.jdbc.reporter.JdbcReporterTest.java

@BeforeSuite
private static void init() throws Exception {
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
    template = new JdbcTemplate(dataSource);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
    populator.populate(dataSource.getConnection());
    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
    transactionTemplate = new TransactionTemplate(dataSourceTransactionManager);
}

From source file:org.cloudfoundry.identity.uaa.db.InitialPreDatabaseVersioningSchemaCreator.java

@Override
public void migrate(Connection connection) throws Exception {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(// ww w .  j  a  va2  s .  co  m
            new ClassPathResource("org/cloudfoundry/identity/uaa/db/" + type + "/V1_5_2__initial_db.sql"));
    populator.setContinueOnError(true);
    populator.setIgnoreFailedDrops(true);
    populator.populate(connection);
}

From source file:org.jtheque.persistence.impl.DaoNotes.java

/**
 * Construct a new DaoNotes.//w w  w.j av a 2 s.co  m
 *
 * @param imageService    The resources.
 * @param languageService The language service.
 */
public DaoNotes(ImageService imageService, LanguageService languageService) {
    super();

    this.languageService = languageService;

    stars = new BufferedImage[7];

    for (int i = 0; i < 7; ++i) {
        String starName = "Star" + (i + 1);

        imageService.registerResource(starName,
                new ClassPathResource("org/jtheque/persistence/" + starName + ".png"));

        stars[i] = imageService.getImage(starName);
    }
}

From source file:com.github.gabrielruiu.spring.yahoo.sample.config.InMemoryDatabaseConfig.java

private DatabasePopulator databasePopulator() {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("YahooJdbcUsersConnectionRepository.sql"));
    return populator;
}

From source file:com.jeffrodriguez.webtools.spring.ns.UrlBeanDefinitionParserTest.java

@Test
public void test() {
    ApplicationContext ac = new GenericXmlApplicationContext(
            new ClassPathResource("com/jeffrodriguez/webtools/spring/ns/url.xml"));

    UrlBuilder url = ac.getBean(UrlBuilder.class);
    assertNotNull(url);/*from  w w  w .  j a v a 2 s  . co m*/
    assertEquals("http://www.example.com/?foo=bar&foo=baz&qux=quux", url.toString());
}

From source file:example.users.UserInitializer.java

public void init() throws Exception {

    List<User> users = readUsers(new ClassPathResource("randomuser.me.csv"));

    repository.deleteAll();/*ww  w  .j  ava  2s. co  m*/
    repository.save(users);
}