List of usage examples for org.springframework.core.io ResourceLoader getResource
Resource getResource(String location);
From source file:org.apache.uima.ruta.RutaEnvironment.java
public RutaTable getWordTable(String table) { RutaTable result = tables.get(table); if (result == null) { if (table.endsWith("csv")) { ResourceLoader resourceLoader = new RutaResourceLoader(getResourcePaths()); Resource resource = resourceLoader.getResource(table); if (resource.exists()) { try { tables.put(table, new CSVTable(resource)); } catch (IOException e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading csv table " + table, e); }//from w w w .ja v a 2 s. c o m } else { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Can't find " + table + "!"); } } else { try { RutaTable rutaTable = (RutaTable) owner.getContext().getResourceObject(table); tables.put(table, rutaTable); } catch (ResourceAccessException e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Can't find external resource table" + table, e); } } } return tables.get(table); }
From source file:org.apache.uima.ruta.RutaEnvironment.java
public RutaWordList getWordList(String list) { RutaWordList result = wordLists.get(list); UimaContext context = owner.getContext(); Boolean dictRemoveWS = false; if (context != null) { dictRemoveWS = (Boolean) context.getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS); if (dictRemoveWS == null) { dictRemoveWS = false;/* ww w .ja v a2 s . co m*/ } } if (result == null) { if (list.endsWith("txt") || list.endsWith("twl") || list.endsWith("mtwl")) { ResourceLoader resourceLoader = new RutaResourceLoader(getResourcePaths()); Resource resource = resourceLoader.getResource(list); if (resource.exists()) { try { if (list.endsWith("mtwl")) { wordLists.put(list, new MultiTreeWordList(resource)); } else { wordLists.put(list, new TreeWordList(resource, dictRemoveWS)); } } catch (IOException e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading word list" + list, e); } } else { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Can't find " + list + "!"); } } else { try { RutaWordList rutaTable = (RutaWordList) context.getResourceObject(list); wordLists.put(list, rutaTable); } catch (ResourceAccessException e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Can't find external resource table" + list, e); } } } return wordLists.get(list); }
From source file:com.greglturnquist.jlogo.TurtleGraphicsWindow.java
public static Resource filenameToResource(ResourceLoader loader, String filename) { return Optional.of(filename.startsWith("classpath:")).map(o -> loader.getResource(filename)) .orElse(loader.getResource("classpath:" + filename)); }
From source file:com.github.zhanhb.ckfinder.connector.support.XmlConfigurationParser.java
private WatermarkSettings parseWatermarkSettings(PluginInfo pluginInfo, ResourceLoader resourceLoader) { WatermarkSettings.Builder settings = WatermarkSettings.builder(); for (Map.Entry<String, String> entry : pluginInfo.getParams().entrySet()) { final String name = entry.getKey(); final String value = entry.getValue(); switch (name) { case "source": settings.source(resourceLoader.getResource(value)); break; case "transparency": settings.transparency(Float.parseFloat(value)); break; case "quality": final int parseInt = Integer.parseInt(value); final int name1 = parseInt % 101; final float name2 = name1 / 100f; settings.quality(name2);/*from ww w . j a v a 2 s.co m*/ break; case "marginBottom": settings.marginBottom(Integer.parseInt(value)); break; case "marginRight": settings.marginRight(Integer.parseInt(value)); break; } } return settings.build(); }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public boolean exists(String url) { ResourceLoader loader = new DefaultResourceLoader(); Resource resource = loader.getResource(url); return resource.exists(); }
From source file:org.data.support.beans.factory.xml.AbstractQueryDefinitionReader.java
/** * Load query definitions from the specified resource location. * <p>The location can also be a location pattern, provided that the * ResourceLoader of this bean definition reader is a ResourcePatternResolver. * @param location the resource location, to be loaded with the ResourceLoader * (or ResourcePatternResolver) of this bean definition reader * @param actualResources a Set to be filled with the actual Resource objects * that have been resolved during the loading process. May be <code>null</code> * to indicate that the caller is not interested in those Resource objects. * @return the number of query definitions found * @throws QueryDefinitionStoreException in case of loading or parsing errors *//* w w w. java2 s . c o m*/ public int loadQueryDefinitions(String location, Set<Resource> actualResources) throws QueryDefinitionStoreException { ResourceLoader resourceLoader = getResourceLoader(); if (resourceLoader == null) { throw new QueryDefinitionStoreException("Cannot import query definitions from location [" + location + "]: no ResourceLoader available."); } if (resourceLoader instanceof ResourcePatternResolver) { try { Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location); int loadCount = loadQueryDefinitions(resources); if (actualResources != null) { for (Resource resource : resources) { actualResources.add(resource); } } if (logger.isDebugEnabled()) { logger.debug( "Loaded " + loadCount + " query definitions from location pattern [" + location + "]"); } return loadCount; } catch (IOException ex) { throw new QueryDefinitionStoreException( "Could not resolve bean definition resource pattern [" + location + "]", ex); } } else { Resource resource = resourceLoader.getResource(location); int loadCount = loadQueryDefinitions(resource); if (actualResources != null) { actualResources.add(resource); } if (logger.isDebugEnabled()) { logger.debug("Loaded " + loadCount + " query definitions from location [" + location + "]"); } return loadCount; } }
From source file:com.netflix.genie.web.security.saml.SAMLConfigUnitTests.java
private SAMLProperties setupForKeyManager() { final ResourceLoader resourceLoader = Mockito.mock(ResourceLoader.class); this.config.setResourceLoader(resourceLoader); final Resource storeFile = Mockito.mock(Resource.class); final SAMLProperties properties = Mockito.mock(SAMLProperties.class); this.config.setSamlProperties(properties); final String keyStorePassword = UUID.randomUUID().toString(); final String keyStoreName = UUID.randomUUID().toString() + ".jks"; final String defaultKeyName = UUID.randomUUID().toString(); final String defaultKeyPassword = UUID.randomUUID().toString(); final SAMLProperties.Keystore keyStore = Mockito.mock(SAMLProperties.Keystore.class); final SAMLProperties.Keystore.DefaultKey defaultKey = Mockito .mock(SAMLProperties.Keystore.DefaultKey.class); Mockito.when(properties.getKeystore()).thenReturn(keyStore); Mockito.when(keyStore.getName()).thenReturn(keyStoreName); Mockito.when(keyStore.getPassword()).thenReturn(keyStorePassword); Mockito.when(keyStore.getDefaultKey()).thenReturn(defaultKey); Mockito.when(defaultKey.getName()).thenReturn(defaultKeyName); Mockito.when(defaultKey.getPassword()).thenReturn(defaultKeyPassword); Mockito.when(resourceLoader.getResource(Mockito.eq("classpath:" + keyStoreName))).thenReturn(storeFile); return properties; }
From source file:com.netflix.genie.web.services.impl.JobDirectoryServerServiceImpl.java
/** * Constructor that accepts a handler factory mock for easier testing. *///from w w w . j a v a 2s .c om @VisibleForTesting JobDirectoryServerServiceImpl(final ResourceLoader resourceLoader, final JobPersistenceService jobPersistenceService, final JobFileService jobFileService, final AgentFileStreamService agentFileStreamService, final MeterRegistry meterRegistry, final GenieResourceHandler.Factory genieResourceHandlerFactory) { this.resourceLoader = resourceLoader; this.jobPersistenceService = jobPersistenceService; this.jobFileService = jobFileService; this.agentFileStreamService = agentFileStreamService; this.meterRegistry = meterRegistry; this.genieResourceHandlerFactory = genieResourceHandlerFactory; // TODO: This is a local cache. It might be valuable to have a shared cluster cache? // TODO: May want to tweak parameters or make them configurable // TODO: Should we expire more proactively than just waiting for size to fill up? this.manifestCache = CacheBuilder.newBuilder().maximumSize(50L).recordStats() .build(new CacheLoader<String, ManifestCacheValue>() { @Override public ManifestCacheValue load(final String key) throws Exception { // TODO: Probably need more specific exceptions so we can map them to response codes final String archiveLocation = jobPersistenceService.getJobArchiveLocation(key) .orElseThrow(() -> new JobNotArchivedException("Job " + key + " wasn't archived")); final URI jobDirectoryRoot = new URI(archiveLocation + SLASH).normalize(); final URI manifestLocation; if (StringUtils.isBlank(JobArchiveService.MANIFEST_DIRECTORY)) { manifestLocation = jobDirectoryRoot.resolve(JobArchiveService.MANIFEST_NAME) .normalize(); } else { manifestLocation = jobDirectoryRoot .resolve(JobArchiveService.MANIFEST_DIRECTORY + SLASH) .resolve(JobArchiveService.MANIFEST_NAME).normalize(); } final Resource manifestResource = resourceLoader.getResource(manifestLocation.toString()); if (!manifestResource.exists()) { throw new GenieNotFoundException("No job manifest exists at " + manifestLocation); } final JobDirectoryManifest manifest = GenieObjectMapper.getMapper() .readValue(manifestResource.getInputStream(), JobDirectoryManifest.class); return new ManifestCacheValue(manifest, jobDirectoryRoot); } }); // TODO: Record metrics for cache using stats() method return }