List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:org.archive.wayback.webapp.RequestMapper.java
/** * @param configPath/*from www.j a v a 2 s .c om*/ * @param servletContext * @throws ConfigurationException */ @SuppressWarnings("unchecked") public RequestMapper(ServletContext servletContext) throws ConfigurationException { String configPath = servletContext.getInitParameter(CONFIG_PATH); if (configPath == null) { throw new ConfigurationException("Missing " + CONFIG_PATH + " parameter"); } String resolvedPath = servletContext.getRealPath(configPath); Resource resource = new FileSystemResource(resolvedPath); factory = new XmlBeanFactory(resource); Map map = factory.getBeansOfType(PropertyPlaceholderConfigurer.class); if (map != null) { Collection<PropertyPlaceholderConfigurer> macros = map.values(); for (PropertyPlaceholderConfigurer macro : macros) { macro.postProcessBeanFactory(factory); } } factory.preInstantiateSingletons(); }
From source file:de.ingrid.iplug.ckan.index.ScriptedDatabaseDocumentProducerTest.java
@Test public void mapCkanDocToElasticsearch() throws Exception { CkanRecordSetProducer p = new CkanRecordSetProducer(); p.setStatusProvider(statusProvider); ScriptedDocumentMapper m = new ScriptedDocumentMapper(); Resource[] mappingScripts = { new FileSystemResource("src/main/resources/mapping/ckan_to_lucene.js") }; m.setMappingScripts(mappingScripts); m.setCompile(false);/*w ww . j a va 2s . co m*/ List<IRecordMapper> mList = new ArrayList<IRecordMapper>(); mList.add(m); CkanDocumentProducer dp = new CkanDocumentProducer(); dp.setRecordSetProducer(p); dp.setRecordMapperList(mList); if (dp.hasNext()) { // only check first dataset if (dp.hasNext()) { Map<String, Object> doc = dp.next(); assertNotNull(doc); Collection<String> keys = Arrays.asList("id", "title", "notes", "tags"); assertTrue(doc.keySet().containsAll(keys)); } } else { fail("No document produced"); } }
From source file:org.cloudfoundry.identity.varz.BootstrapTests.java
private GenericXmlApplicationContext getServletContext(String... resources) { String profiles = null;/*www .j a v a 2 s .c o m*/ String[] resourcesToLoad = resources; if (!resources[0].endsWith(".xml")) { profiles = resources[0]; resourcesToLoad = new String[resources.length - 1]; System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length); } GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load(resourcesToLoad); if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } // Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources( new Resource[] { new FileSystemResource("./src/test/resources/test/config/varz.yml") }); context.getEnvironment().getPropertySources() .addLast(new PropertiesPropertySource("servletProperties", factory.getObject())); context.refresh(); return context; }
From source file:com.siberhus.tdfl.DflSimpleTest.java
@Test public void testLoadXlsFileToBeanManually() throws DataFileLoaderException { employeeDfl.setDataFileProcessor(employeeDfp); employeeDfl.setResource(new FileSystemResource(XLS_FILE_IN_NAME)); // employeeDfl.setDestination(new FileSystemResource(XLS_FILE_OUT_NAME)); employeeDfl.load();//from w w w . j av a2 s . co m }
From source file:com.consol.citrus.admin.service.spring.filter.GetSpringImportsFilter.java
@Override public short startElement(Element element) { if (DomUtils.nodeNameEquals(element, "import")) { String resourceLocation = element.getAttribute("resource"); if (StringUtils.hasText(resourceLocation)) { if (resourceLocation.startsWith("classpath:")) { resourceLocation = resourceLocation.substring("classpath:".length()); } else if (resourceLocation.startsWith("file:")) { resourceLocation = resourceLocation.substring("file:".length()); }//from w ww .j a v a2s . co m try { File importedFile = new FileSystemResource( parentConfigFile.getParentFile().getCanonicalPath() + File.separator + resourceLocation) .getFile(); if (importedFile.exists()) { importedFiles.add(importedFile); } } catch (IOException e) { log.warn("Unable to resolve imported file resource location", e); } } } return NodeFilter.FILTER_ACCEPT; }
From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTaskletTest.java
@Test public void testExecuteFileDoesNotExist() throws Exception { // setup// w w w. j a v a2s.c om tasklet = new GetLineCountTasklet(); tasklet.setResource(new FileSystemResource("foobar.txt")); // execute try { tasklet.execute(null, null); } catch (Exception e) { assertTrue(e instanceof FileNotFoundException); } }
From source file:architecture.ee.web.struts2.action.admin.ajax.SqlFinderAction.java
public Resource getTargetResource() { log.debug(path);/*from w ww.j a v a 2 s. c o m*/ log.debug(getSqlFileLocation().getAbsolutePath()); return new FileSystemResource(getSqlFileLocation().getAbsolutePath() + this.path); }
From source file:org.cloudfoundry.identity.login.BootstrapTests.java
private GenericXmlApplicationContext getServletContext(String... resources) { String profiles = null;// ww w .j av a 2 s. c o m String[] resourcesToLoad = resources; if (!resources[0].endsWith(".xml")) { profiles = resources[0]; resourcesToLoad = new String[resources.length - 1]; System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length); } GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load(resourcesToLoad); if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } // Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources( new Resource[] { new FileSystemResource("./src/test/resources/test/config/login.yml") }); context.getEnvironment().getPropertySources() .addLast(new PropertiesPropertySource("servletProperties", factory.getObject())); context.refresh(); return context; }
From source file:groovyx.osgi.test.LocalFileSystemIvyRepository.java
public Resource locateArtifact(String group, String id, String version, String type) { type = type != null ? type : DEFAULT_TYPE; // path is <baseDir>/<group>/<id>/<type>s/<id>-<version>.jar StringBuilder location = new StringBuilder(); if (group != null) { // group//from w w w . j a v a 2 s . com location.append(group); location.append(SLASH_CHAR); } // id location.append(id); location.append(SLASH_CHAR); // type is always in plural form location.append(type); location.append("s"); // id and version location.append(SLASH_CHAR); location.append(id); location.append("-"); location.append(version); location.append(".jar"); return new FileSystemResource(new File(repositoryDir, location.toString())); }
From source file:org.dawnsci.marketplace.controllers.FileController.java
@RequestMapping(value = "/{solution}/**", method = { RequestMethod.GET, RequestMethod.HEAD }) @ResponseBody/* w ww . j ava2 s . c o m*/ public ResponseEntity<FileSystemResource> getFile(@PathVariable("solution") String solution, HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); AntPathMatcher apm = new AntPathMatcher(); path = apm.extractPathWithinPattern(bestMatchPattern, path); File file = fileService.getFile(solution, path); if (file.exists() && file.isFile()) { try { String detect = tika.detect(file); MediaType mediaType = MediaType.parseMediaType(detect); return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType) .lastModified(file.lastModified()).body(new FileSystemResource(file)); } catch (IOException e) { e.printStackTrace(); } } else { throw new ResourceNotFoundException(); } return null; }