List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:edu.illinois.ncsa.springdata.SpringData.java
/** * Create the applicationContext anyway you want, in your * applicationContext.xml file add the following bean to your context.xml: * //from ww w.j a v a 2 s .c om * <pre> * <bean id="applicationContextProvider" class="edu.illinois.ncsa.springdata.SpringData" /> * </pre> * * * @deprecated */ @Deprecated public static void loadXMLContext(File file) { SpringData.context = new GenericXmlApplicationContext(new FileSystemResource(file)); }
From source file:org.globus.security.provider.TestPEMFileBasedKeyStore.java
@Test public void testProxyCerts() throws Exception { PEMKeyStore store = new PEMKeyStore(); // Parameters in properties file Properties properties = new Properties(); properties.setProperty(PEMKeyStore.PROXY_FILENAME, "file:" + this.proxyFile1.getAbsoluteFilename()); InputStream ins = null;//from www. j a v a 2s. co m try { ins = getProperties(properties); store.engineLoad(ins, null); } finally { if (ins != null) { ins.close(); } } Enumeration aliases = store.engineAliases(); assert (aliases.hasMoreElements()); // proxy file 1 String proxyId1 = new FileSystemResource(this.proxyFile1.getTempFile()).getURL().toExternalForm(); assertTrue(store.engineIsKeyEntry(proxyId1)); Key key = store.engineGetKey(proxyId1, null); assertNotNull(key != null); assertTrue(key instanceof PrivateKey); Certificate[] certificates = store.engineGetCertificateChain(this.proxyFile1.getURL().toExternalForm()); assertNotNull(certificates != null); assertTrue(certificates instanceof X509Certificate[]); key = null; // assert (this.proxyCertificates.get(this.proxyFile1.getAbsoluteFilename()).equals(certificates[0])); properties.setProperty(PEMKeyStore.PROXY_FILENAME, "file:" + this.proxyFile2.getAbsoluteFilename()); ins = null; try { ins = getProperties(properties); store.engineLoad(ins, null); } finally { if (ins != null) { ins.close(); } } // proxy file 2 String proxyId2 = new FileSystemResource(this.proxyFile2.getTempFile()).getURL().toExternalForm(); key = store.engineGetKey(proxyId2, null); assertTrue(store.engineIsKeyEntry(proxyId2)); assertNotNull(key); assertTrue(key instanceof PrivateKey); certificates = store.engineGetCertificateChain(proxyId1); assertNotNull(certificates != null); assertTrue(certificates instanceof X509Certificate[]); // assert (this.proxyCertificates.get(this.proxyFile2.getTempFilename()).equals(certificates[0])); // test delete store.engineDeleteEntry(proxyId1); certificates = store.engineGetCertificateChain(proxyId1); assertEquals(0, certificates.length); assertFalse(this.proxyFile1.getTempFile().exists()); assertFalse(store.engineIsKeyEntry(proxyId1)); }
From source file:com.sinosoft.one.mvc.scanning.MvcScanner.java
/** * ???jar?//from www . j a va 2 s . c o m * @return * @throws IOException */ public List<ResourceRef> getJarResources() throws IOException { if (jarResources == null) { if (logger.isInfoEnabled()) { logger.info("[jarFile] start to found available jar files for mvc to scanning..."); } List<ResourceRef> jarResources = new LinkedList<ResourceRef>(); Resource[] metaInfResources = resourcePatternResolver.getResources("classpath*:/META-INF/"); for (Resource metaInfResource : metaInfResources) { URL urlObject = metaInfResource.getURL(); if (ResourceUtils.isJarURL(urlObject)) { try { String path = URLDecoder.decode(urlObject.getPath(), "UTF-8"); // fix 20% if (path.startsWith("file:")) { path = path.substring("file:".length(), path.lastIndexOf('!')); } else { path = path.substring(0, path.lastIndexOf('!')); } Resource resource = new FileSystemResource(path); if (jarResources.contains(resource)) { if (logger.isDebugEnabled()) { logger.debug("[jarFile] skip replicated jar resource: " + path);// linux ???,fix it! } } else { ResourceRef ref = ResourceRef.toResourceRef(resource); if (ref.getModifiers() != null) { jarResources.add(ref); if (logger.isInfoEnabled()) { logger.info("[jarFile] add jar resource: " + ref); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not mvc jar resource: " + path); } } } } catch (Exception e) { logger.error(urlObject, e); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not mvc type(not a jar) " + urlObject); } } } this.jarResources = jarResources; if (logger.isInfoEnabled()) { logger.info("[jarFile] found " + jarResources.size() + " jar files: " + jarResources); } } else { if (logger.isInfoEnabled()) { logger.info("[jarFile] found cached " + jarResources.size() + " jar files: " + jarResources); } } return Collections.unmodifiableList(jarResources); }
From source file:com.clican.pluto.dataprocess.engine.impl.ProcessorContainerImpl.java
/** * Springinit-method???/*www . j ava 2 s . c o m*/ */ @SuppressWarnings("unchecked") public void start() { if (log.isInfoEnabled()) { log.info("Begin to start Process Data Container"); } for (String scan : scanList) { scan = scan.trim(); try { String pattern1; String pattern2; if (scan.startsWith("file")) { pattern1 = scan + "/**/*.xml"; pattern2 = scan + "/**/*.properties"; } else { pattern1 = ClassUtils.convertClassNameToResourcePath(scan) + "/**/*.xml"; pattern2 = ClassUtils.convertClassNameToResourcePath(scan) + "/**/*.properties"; } Resource[] resources1 = resourcePatternResolver.getResources(pattern1); Resource[] resources2 = resourcePatternResolver.getResources(pattern2); Map<String, Resource> map1 = new HashMap<String, Resource>(); Map<String, Resource> map2 = new HashMap<String, Resource>(); Set<String> usingPropertyResource = new HashSet<String>(); for (Resource resource : resources1) { map1.put(resource.getFilename().split("\\.")[0], resource); } for (Resource resource : resources2) { String fileName = resource.getFilename().split("\\.")[0]; String[] fn = fileName.split("\\_"); if (fn.length == 2 && map1.containsKey(fn[0])) { usingPropertyResource.add(fn[0]); } else { throw new RuntimeException("properties[" + fileName + "]???"); } map2.put(resource.getFilename().split("\\.")[0], resource); } for (Resource resource1 : resources1) { final Resource xmlRes = resource1; String fileName1 = resource1.getFilename().split("\\.")[0]; if (usingPropertyResource.contains(fileName1)) { for (Resource resource2 : resources2) { AbstractXmlApplicationContext subContext = new AbstractXmlApplicationContext( this.applicationContext) { protected Resource[] getConfigResources() { return new Resource[] { xmlRes }; } }; String fileName2 = resource2.getFilename().split("\\.")[0]; String[] fn = fileName2.split("\\_"); if (fn[0].equals(fileName1)) { com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer parentConf = (com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer) applicationContext .getBean("propertyConfigurer"); Resource[] resources = new Resource[1 + parentConf.getLocations().length]; for (int i = 0; i < parentConf.getLocations().length; i++) { resources[i] = parentConf.getLocations()[i]; } resources[resources.length - 1] = resource2; com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer subContainerConf = new com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer(); subContainerConf.setFileEncoding("utf-8"); subContainerConf.setLocations(resources); subContext.addBeanFactoryPostProcessor(subContainerConf); subContext.refresh(); processorGroupSpringMap.put(fn[1], subContext); Collection<String> coll = (Collection<String>) subContext .getBeansOfType(BaseDataProcessor.class).keySet(); for (String beanName : coll) { BaseDataProcessor bean = (BaseDataProcessor) subContext.getBean(beanName); if (bean.isStartProcessor()) { startProcessorNameMap.put(fn[1], beanName); break; } } if (!startProcessorNameMap.containsKey(fn[1])) { throw new RuntimeException( "?Process Container," + fn[1] + "?"); } } } } else { AbstractXmlApplicationContext subContext = new AbstractXmlApplicationContext( this.applicationContext) { protected Resource[] getConfigResources() { return new Resource[] { xmlRes }; } }; subContext.addBeanFactoryPostProcessor( (BeanFactoryPostProcessor) applicationContext.getBean("propertyConfigurer")); subContext.refresh(); processorGroupSpringMap.put(fileName1, subContext); Collection<String> coll = (Collection<String>) subContext .getBeansOfType(BaseDataProcessor.class).keySet(); for (String beanName : coll) { BaseDataProcessor bean = (BaseDataProcessor) subContext.getBean(beanName); if (bean.isStartProcessor()) { startProcessorNameMap.put(fileName1, beanName); break; } } if (!startProcessorNameMap.containsKey(fileName1)) { throw new RuntimeException( "?Process Container," + fileName1 + "?"); } } } } catch (Exception e) { throw new RuntimeException(e); } } for (Deploy deploy : deployList) { try { ClassPathXmlApplicationContext subContext = new ClassPathXmlApplicationContext( new String[] { deploy.getUrl() }, this.applicationContext); if (StringUtils.isNotEmpty(deploy.getPropertyResources())) { com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer parentConf = (com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer) applicationContext .getBean("propertyConfigurer"); String[] propertyResources = deploy.getPropertyResources().split(","); Resource[] resources = new Resource[propertyResources.length + parentConf.getLocations().length]; for (int i = 0; i < parentConf.getLocations().length; i++) { resources[i] = parentConf.getLocations()[i]; } for (int i = parentConf.getLocations().length; i < resources.length; i++) { String propertyResource = propertyResources[i - parentConf.getLocations().length]; if (propertyResource.startsWith("classpath")) { resources[i] = new ClassPathResource( propertyResource.substring(propertyResource.indexOf(":") + 1)); } else { resources[i] = new FileSystemResource( propertyResource.substring(propertyResource.indexOf(":") + 1)); } } com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer subContainerConf = new com.clican.pluto.common.support.spring.PropertyPlaceholderConfigurer(); subContainerConf.setFileEncoding("utf-8"); subContainerConf.setLocations(resources); subContext.addBeanFactoryPostProcessor(subContainerConf); } else { subContext.addBeanFactoryPostProcessor( (BeanFactoryPostProcessor) applicationContext.getBean("propertyConfigurer")); } subContext.refresh(); processorGroupSpringMap.put(deploy.getName(), subContext); Collection<String> coll = (Collection<String>) subContext.getBeansOfType(BaseDataProcessor.class) .keySet(); for (String beanName : coll) { BaseDataProcessor bean = (BaseDataProcessor) subContext.getBean(beanName); if (bean.isStartProcessor()) { startProcessorNameMap.put(deploy.getName(), beanName); break; } } if (!startProcessorNameMap.containsKey(deploy.getName())) { throw new RuntimeException( "?Process Container," + deploy.getName() + "?"); } } catch (Exception e) { log.error("Depoly [" + deploy.getName() + "] failure", e); throw new RuntimeException(e); } } log.info("The Process Data Container has been started successfully."); }
From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java
/** * Initialize the application context, adding the properties configuration file depending on the * specified path./*from ww w. j a v a 2 s . co m*/ * * @param propertiesPath the path to the file. * @return the resource loaded from the properties file. * @throws IOException error opening the properties file. */ private static Properties initApplicationContextAndProperties(String propertiesPath) throws IOException { Resource resource = new ClassPathResource(propertiesPath); if (!resource.exists()) { resource = new FileSystemResource(propertiesPath); } DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource); Properties properties = PropertiesLoaderUtils.loadProperties(resource); String dbType = (String) properties.get(AW_REPORT_MODEL_DB_TYPE); if (dbType != null && dbType.equals(DataBaseType.MONGODB.name())) { appCtx = new ClassPathXmlApplicationContext("classpath:kratubackend-mongodb-beans.xml"); } else { appCtx = new ClassPathXmlApplicationContext("classpath:kratubackend-sql-beans.xml"); } return properties; }
From source file:gr.abiss.calipso.config.CalipsoConfigurer.java
private void configureCalipso(ConfigurableListableBeanFactory beanFactory) throws Exception { String calipsoHome = null;/*from w w w . j a va 2 s.co m*/ InputStream is = this.getClass().getResourceAsStream("/calipso-init.properties"); Properties props = loadProps(is); logger.info("found 'calipso-init.properties' on classpath, processing..."); calipsoHome = props.getProperty("calipso.home"); if (calipsoHome.equals("${calipso.home}")) { calipsoHome = null; } if (StringUtils.isBlank(calipsoHome)) { logger.info( "valid 'calipso.home' property not available in 'calipso-init.properties', trying system properties."); calipsoHome = System.getProperty("calipso.home"); if (StringUtils.isNotBlank(calipsoHome)) { logger.info("'calipso.home' property initialized from system properties as '" + calipsoHome + "'"); } } if (StringUtils.isBlank(calipsoHome)) { logger.info( "valid 'calipso.home' property not available in system properties, trying servlet init paramters."); calipsoHome = servletContext.getInitParameter("calipso.home"); if (StringUtils.isNotBlank(calipsoHome)) { logger.info("Servlet init parameter 'calipso.home' exists: '" + calipsoHome + "'"); } } if (StringUtils.isBlank(calipsoHome)) { calipsoHome = System.getProperty("user.home") + "/.calipso"; logger.warn("Servlet init paramter 'calipso.home' does not exist. Will use 'user.home' directory '" + calipsoHome + "'"); } if (StringUtils.isNotBlank(calipsoHome) && !calipsoHome.equals("${calipso.home}")) { logger.info( "'calipso.home' property initialized from 'calipso-init.properties' as '" + calipsoHome + "'"); } //====================================================================== FilenameFilter ff = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith("messages_") && name.endsWith(".properties"); } }; //File[] messagePropsFiles = jtracInitResource.getFile().getParentFile().listFiles(ff); String locales = props.getProperty("calipso.locales", "en,el,ja"); // for(File f : messagePropsFiles) { // int endIndex = f.getName().indexOf('.'); // String localeCode = f.getName().substring(9, endIndex); // locales += "," + localeCode; // } logger.info("locales available configured are '" + locales + "'"); props.setProperty("calipso.locales", locales); //====================================================================== //====================================================================== File calipsoHomeDir = new File(calipsoHome); createIfNotExisting(calipsoHomeDir); props.setProperty("calipso.home", calipsoHomeDir.getAbsolutePath()); //====================================================================== File attachmentsFile = new File(calipsoHome + "/attachments"); createIfNotExisting(attachmentsFile); File indexesFile = new File(calipsoHome + "/indexes"); createIfNotExisting(indexesFile); //====================================================================== File propsFile = new File(calipsoHomeDir, "calipso.properties"); if (!propsFile.exists()) { logger.info("properties file does not exist, creating '" + propsFile.getPath() + "'"); propsFile.createNewFile(); OutputStream os = new FileOutputStream(propsFile); Writer out = new PrintWriter(os); try { out.write("database.driver=org.hsqldb.jdbcDriver\n"); out.write("database.url=jdbc:hsqldb:file:${calipso.home}/db/calipso\n"); out.write("database.username=sa\n"); out.write("database.password=\n"); out.write("hibernate.dialect=org.hibernate.dialect.HSQLDialect\n"); out.write("hibernate.show_sql=false\n"); // Can be used to set mysql as default, commenting out // to preserve HSQLDB as default // out.write("database.driver=com.mysql.jdbc.Driver\n"); // out.write("database.url=jdbc:mysql://localhost/calipso21\n"); // out.write("database.username=root\n"); // out.write("database.password=\n"); // out.write("hibernate.dialect=org.hibernate.dialect.MySQLDialect\n"); // out.write("hibernate.show_sql=false\n"); } finally { out.close(); os.close(); } logger.info("HSQLDB will be used. Finished creating '" + propsFile.getPath() + "'"); } else { logger.info("'calipso.properties' file exists: '" + propsFile.getPath() + "'"); } //====================================================================== String version = getClass().getPackage().getImplementationVersion(); String timestamp = "0000"; // ClassPathResource versionResource = new ClassPathResource("calipso-version.properties"); // if(versionResource.exists()) { // logger.info("found 'calipso-version.properties' on classpath, processing..."); // Properties versionProps = loadProps(versionResource.getFile()); // version = versionProps.getProperty("calipso.version"); // timestamp = versionProps.getProperty("calipso.timestamp"); // } else { // logger.info("did not find 'calipso-version.properties' on classpath"); // } props.setProperty("calipso.version", version); props.setProperty("calipso.timestamp", timestamp); /* * TODO: A better way (default value) to check the database should be used for Apache DBCP. * The current "SELECT...FROM DUAL" only works on Oracle (and MySQL). * Other databases also support "SELECT 1+1" as query * (e.g. PostgreSQL, Hypersonic 2 (H2), MySQL, etc.). */ props.setProperty("database.validationQuery", "SELECT 1 FROM DUAL"); props.setProperty("ldap.url", ""); props.setProperty("ldap.activeDirectoryDomain", ""); props.setProperty("ldap.searchBase", ""); props.setProperty("database.datasource.jndiname", ""); // set default properties that can be overridden by user if required setProperties(props); // finally set the property that spring is expecting, manually FileSystemResource fsr = new FileSystemResource(propsFile); setLocation(fsr); Log.info("Calipso configured, calling postProcessBeanFactory with:" + beanFactory); }
From source file:com.laxser.blitz.scanning.BlitzScanner.java
/** * ???jar?/*from w ww.j a v a 2 s.c o m*/ * * @param resourceLoader * @return * @throws IOException */ public List<ResourceRef> getJarResources() throws IOException { if (jarResources == null) { if (logger.isInfoEnabled()) { logger.info("[jarFile] start to found available jar files for blitz to scanning..."); } List<ResourceRef> jarResources = new LinkedList<ResourceRef>(); Resource[] metaInfResources = resourcePatternResolver.getResources("classpath*:/META-INF/"); for (Resource metaInfResource : metaInfResources) { URL urlObject = metaInfResource.getURL(); if (ResourceUtils.isJarURL(urlObject)) { try { String path = URLDecoder.decode(urlObject.getPath(), "UTF-8"); // fix 20% if (path.startsWith("file:")) { path = path.substring("file:".length(), path.lastIndexOf('!')); } else { path = path.substring(0, path.lastIndexOf('!')); } Resource resource = new FileSystemResource(path); if (jarResources.contains(resource)) { if (logger.isDebugEnabled()) { logger.debug("[jarFile] skip replicated jar resource: " + path);// linux ???,fix it! } } else { ResourceRef ref = ResourceRef.toResourceRef(resource); if (ref.getModifiers() != null) { jarResources.add(ref); if (logger.isInfoEnabled()) { logger.info("[jarFile] add jar resource: " + ref); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not blitz jar resource: " + path); } } } } catch (Exception e) { logger.error(urlObject, e); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not blitz type(not a jar) " + urlObject); } } } this.jarResources = jarResources; if (logger.isInfoEnabled()) { logger.info("[jarFile] found " + jarResources.size() + " jar files: " + jarResources); } } else { if (logger.isInfoEnabled()) { logger.info("[jarFile] found cached " + jarResources.size() + " jar files: " + jarResources); } } return Collections.unmodifiableList(jarResources); }
From source file:com.gzj.tulip.load.RoseScanner.java
/** * ???jar?// w w w .j a v a2 s.c om * * @param resourceLoader * @return * @throws IOException */ public List<ResourceRef> getJarResources() throws IOException { if (jarResources == null) { if (logger.isInfoEnabled()) { logger.info("[jarFile] start to found available jar files for rose to scanning..."); } List<ResourceRef> jarResources = new LinkedList<ResourceRef>(); Resource[] metaInfResources = resourcePatternResolver.getResources("classpath*:/META-INF/"); for (Resource metaInfResource : metaInfResources) { URL urlObject = metaInfResource.getURL(); if (ResourceUtils.isJarURL(urlObject)) { try { String path = URLDecoder.decode(urlObject.getPath(), "UTF-8"); // fix 20% if (path.startsWith("file:")) { path = path.substring("file:".length(), path.lastIndexOf('!')); } else { path = path.substring(0, path.lastIndexOf('!')); } Resource resource = new FileSystemResource(path); if (jarResources.contains(resource)) { if (logger.isDebugEnabled()) { logger.debug("[jarFile] skip replicated jar resource: " + path);// linux ???,fix it! } } else { ResourceRef ref = ResourceRef.toResourceRef(resource); if (ref.getModifiers() != null) { jarResources.add(ref); if (logger.isInfoEnabled()) { logger.info("[jarFile] add jar resource: " + ref); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not rose jar resource: " + path); } } } } catch (Exception e) { logger.error(urlObject, e); } } else { if (logger.isDebugEnabled()) { logger.debug("[jarFile] not rose type(not a jar) " + urlObject); } } } this.jarResources = jarResources; if (logger.isInfoEnabled()) { logger.info("[jarFile] found " + jarResources.size() + " jar files: " + jarResources); } } else { if (logger.isInfoEnabled()) { logger.info("[jarFile] found cached " + jarResources.size() + " jar files: " + jarResources); } } return Collections.unmodifiableList(jarResources); }
From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java
protected AbstractResource getTemplateResource(String template) throws IOException { String name = "src/templates/scaffolding/" + template; AbstractResource templateFile = new FileSystemResource(new File(basedir, name).getAbsoluteFile()); if (!templateFile.exists()) { templateFile = new FileSystemResource(new File(getPluginDir(), name).getAbsoluteFile()); }//from w w w . j a va2 s . c o m return templateFile; }
From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java
protected Resource createSharedOverrideResource() throws IOException { String path = System.getProperty(SHARED_PROPERTY_OVERRIDE); return StringUtils.isBlank(path) ? null : new FileSystemResource(path); }