List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource
public ClassPathResource(String path)
From source file:com.glaf.core.context.ApplicationContext.java
public static String getAppPath() { if (appPath == null) { try {/*from ww w .j a v a 2 s . co m*/ Resource resource = new ClassPathResource("/glaf.properties"); appPath = resource.getFile().getParentFile().getParentFile().getParentFile().getAbsolutePath(); logger.info("app path:" + appPath); } catch (Exception ex) { ex.printStackTrace(); } } return appPath; }
From source file:org.apache.servicemix.http.HttpEndpointLoadWsdlTest.java
public void testLoadWsdl() throws Exception { MyHttpEndpoint endpoint = new MyHttpEndpoint(); endpoint.setWsdlResource(new ClassPathResource("org/apache/servicemix/http/wsdl/relative.wsdl")); endpoint.setTargetEndpoint("TestPort"); endpoint.setTargetService(new QName("http://test.namespace/wsdl", "TestService")); endpoint.setLocationURI("http://0.0.0.0:1234/services/service1/"); endpoint.setSoap(true);/*from w w w. j av a 2 s. c o m*/ endpoint.setService(new QName("http://test.namespace/wsdl", "Service")); endpoint.loadWsdl(); assertFalse(endpoint.getWsdls().isEmpty()); assertEquals(1, endpoint.getWsdls().size()); assertTrue(endpoint.getWsdls().containsKey("Service1/Requests.xsd")); assertTrue(endpoint.getWsdls().containsKey("Service1/subschema/SubSchema.xsd")); assertTrue(endpoint.getWsdls().containsKey("common/DataType.xsd")); assertTrue(endpoint.getWsdls().containsKey("common/TestEnum.xsd")); assertTrue(endpoint.getWsdls().containsKey("Service1/Responses.xsd")); assertTrue(endpoint.getWsdls().containsKey("common/Fault.xsd")); assertTrue(endpoint.getWsdls().containsKey("main.wsdl")); }
From source file:com.xyxy.platform.modules.core.security.utils.DigestsTest.java
@Test public void digestFile() throws IOException { Resource resource = new ClassPathResource("/logback.xml"); byte[] md5result = Digests.md5(resource.getInputStream()); byte[] sha1result = Digests.sha1(resource.getInputStream()); System.out.println("md5: " + Encodes.encodeHex(md5result)); System.out.println("sha1:" + Encodes.encodeHex(sha1result)); }
From source file:com.acme.legacy.app.repository.JsonUserRepository.java
@PostConstruct @SuppressWarnings("unchecked") public void init() throws Exception { Resource resource = new ClassPathResource("users.json"); ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().build(); List<User> userList = mapper.readValue(resource.getInputStream(), new TypeReference<List<User>>() { });/*from w ww. j a v a 2s . co m*/ Map<String, User> userMap = new TreeMap<>(); for (User user : userList) userMap.put(user.getEmail(), user); this.users = Collections.unmodifiableMap(userMap); }
From source file:org.ng200.openolympus.MvcConfig.java
@Bean public static PropertySourcesPlaceholderConfigurer properties() { final PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer(); final Resource[] resources = new ClassPathResource[] { new ClassPathResource("spring.properties") }; propertySources.setLocations(resources); propertySources.setIgnoreUnresolvablePlaceholders(true); return propertySources; }
From source file:com.octo.captcha.engine.bufferedengine.buffer.DatabaseCaptchaBufferTest.java
public CaptchaBuffer getBuffer() { //just get initialize the database and create //get the datasource from spring conf this.datasource = (DataSource) (new XmlBeanFactory(new ClassPathResource("testDatabaseCaptchaBuffer.xml"))) .getBean("dataSource"); //drop and recreate the table Connection con = null;//from w w w . java2 s . c o m Statement ps = null; ResultSet rs = null; try { con = datasource.getConnection(); ps = con.createStatement(); try { ps.execute(CREATE); } catch (SQLException e) { } ps = con.createStatement(); ps.execute(EMPTY); } catch (SQLException e) { if (rs != null) { try { rs.close(); } catch (SQLException ex) { } throw new RuntimeException(e); } } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } if (con != null) { try { con.close(); } catch (SQLException e) { } } } DatabaseCaptchaBuffer buffer = new DatabaseCaptchaBuffer(datasource); return buffer; }
From source file:example.springdata.rest.stores.StoreInitializer.java
/** * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to * persisted./*from w w w. j a v a2 s . co m*/ * * @return * @throws Exception */ public static List<Store> readStores() throws Exception { ClassPathResource resource = new ClassPathResource("starbucks.csv"); Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close(); FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>(); itemReader.setResource(resource); // DelimitedLineTokenizer defaults to comma as its delimiter DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>(); lineMapper.setFieldSetMapper(fields -> { Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude")); Address address = new Address(fields.readString("Street Address"), fields.readString("City"), fields.readString("Zip"), location); return new Store(fields.readString("Name"), address); }); lineMapper.setLineTokenizer(tokenizer); itemReader.setLineMapper(lineMapper); itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); itemReader.setLinesToSkip(1); itemReader.open(new ExecutionContext()); List<Store> stores = new ArrayList<>(); Store store = null; do { store = itemReader.read(); if (store != null) { stores.add(store); } } while (store != null); return stores; }
From source file:org.synyx.hades.domain.auditing.support.AuditingBeanFactoryPostProcessorUnitTest.java
@Before public void setUp() { beanFactory = new XmlBeanFactory(new ClassPathResource(getConfigFile())); processor = new AuditingBeanFactoryPostProcessor(); }
From source file:com.wavemaker.commons.util.SpringUtils.java
private static GenericApplicationContext initSpringConfig(boolean refresh) { GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("config.xml")); if (refresh) { ctx.refresh();/* w ww. j a va 2s. c o m*/ } return ctx; }
From source file:org.alfresco.textgen.TextGenerator.java
public TextGenerator(String configPath) { ClassPathResource cpr = new ClassPathResource(configPath); if (!cpr.exists()) { throw new RuntimeException("No resource found: " + configPath); }/*from w w w . j a v a 2 s.com*/ InputStream is = null; InputStreamReader r = null; BufferedReader br = null; try { int lineNumber = 0; is = cpr.getInputStream(); r = new InputStreamReader(is, "UTF-8"); br = new BufferedReader(r); String line; while ((line = br.readLine()) != null) { lineNumber++; if (lineNumber == 1) { // skip header continue; } String[] split = line.split("\t"); if (split.length != 7) { //System.out.println("Skipping "+lineNumber); continue; } String word = split[1].replaceAll("\\*", ""); String mode = split[3].replaceAll("\\*", ""); long frequency = Long.parseLong(split[4].replaceAll("#", "").trim()); // Single varient if (mode.equals(":")) { if (!ignore(word)) { wordGenerator.addWord(splitAlternates(word), frequency == 0 ? 1 : frequency); } } else { if (word.equals("@")) { // varient if (!ignore(mode)) { wordGenerator.addWord(splitAlternates(mode), frequency == 0 ? 1 : frequency); } } else { //System.out.println("Skipping totla and using varients for " + word + " @ " + lineNumber); } } } } catch (IOException e) { throw new RuntimeException("Failed to load resource " + configPath); } finally { if (br != null) { try { br.close(); } catch (Exception e) { } } if (r != null) { try { r.close(); } catch (Exception e) { } } if (is != null) { try { is.close(); } catch (Exception e) { } } } }