本文整理汇总了Java中org.springframework.core.io.ResourceLoader.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceLoader.getResource方法的具体用法?Java ResourceLoader.getResource怎么用?Java ResourceLoader.getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.io.ResourceLoader
的用法示例。
在下文中一共展示了ResourceLoader.getResource方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newCredentialSelectionPredicate
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Gets credential selection predicate.
*
* @param selectionCriteria the selection criteria
* @return the credential selection predicate
*/
public static Predicate<org.apereo.cas.authentication.Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
try {
if (StringUtils.isBlank(selectionCriteria)) {
return credential -> true;
}
if (selectionCriteria.endsWith(".groovy")) {
final ResourceLoader loader = new DefaultResourceLoader();
final Resource resource = loader.getResource(selectionCriteria);
if (resource != null) {
final String script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
final GroovyClassLoader classLoader = new GroovyClassLoader(Beans.class.getClassLoader(),
new CompilerConfiguration(), true);
final Class<Predicate> clz = classLoader.parseClass(script);
return clz.newInstance();
}
}
final Class predicateClazz = ClassUtils.getClass(selectionCriteria);
return (Predicate<org.apereo.cas.authentication.Credential>) predicateClazz.newInstance();
} catch (final Exception e) {
final Predicate<String> predicate = Pattern.compile(selectionCriteria).asPredicate();
return credential -> predicate.test(credential.getId());
}
}
示例2: buildLoggerContext
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Build logger context logger context.
*
* @param environment the environment
* @param resourceLoader the resource loader
* @return the logger context
*/
public static Pair<Resource, LoggerContext> buildLoggerContext(final Environment environment, final ResourceLoader resourceLoader) {
try {
final String logFile = environment.getProperty("logging.config", "classpath:/log4j2.xml");
LOGGER.debug("Located logging configuration reference in the environment as [{}]", logFile);
if (ResourceUtils.doesResourceExist(logFile, resourceLoader)) {
final Resource logConfigurationFile = resourceLoader.getResource(logFile);
LOGGER.debug("Loaded logging configuration resource [{}]. Initializing logger context...", logConfigurationFile);
final LoggerContext loggerContext = Configurator.initialize("CAS", null, logConfigurationFile.getURI());
LOGGER.debug("Installing log configuration listener to detect changes and update");
loggerContext.getConfiguration().addListener(reconfigurable -> loggerContext.updateLoggers(reconfigurable.reconfigure()));
return Pair.of(logConfigurationFile, loggerContext);
}
LOGGER.warn("Logging configuration cannot be found in the environment settings");
} catch (final Exception e) {
throw Throwables.propagate(e);
}
return null;
}
示例3: importStream
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
public InputStream importStream(String content)
{
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource(content);
if (resource.exists() == false)
{
throw new ImporterException("Content URL " + content + " does not exist.");
}
try
{
return resource.getInputStream();
}
catch(IOException e)
{
throw new ImporterException("Failed to retrieve input stream for content URL " + content);
}
}
示例4: getPropsResources
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
protected Resource[] getPropsResources(ResourceLoader resourceLoader) {
PropertySource sourceAnnotation = WebMvcApplicationConfig.class.getAnnotation(PropertySource.class);
String[] props = sourceAnnotation.value();
if (props.length > 0) {
List<Resource> list = new ArrayList<Resource>(1);
for (String prop : props) {
Resource resource = resourceLoader.getResource(prop);
if (resource.exists())
list.add(resource);
}
if (!CollectionUtils.isEmpty(list)) {
Resource[] resources = new Resource[list.size()];
list.toArray(resources);
//print log
printLog(Global.BEAN_NAME_ROOT_PROPS, resources);
return resources;
}
}
return null;
}
示例5: deploySingleProcess
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* 部署单个流程定义
*
* @param resourceLoader {@link ResourceLoader}
* @param processKey 模块名称
* @throws IOException 找不到zip文件时
*/
private void deploySingleProcess(ResourceLoader resourceLoader, String processKey, String exportDir) throws IOException {
String classpathResourceUrl = "classpath:/deployments/" + processKey + ".bar";
logger.debug("read workflow from: {}", classpathResourceUrl);
Resource resource = resourceLoader.getResource(classpathResourceUrl);
InputStream inputStream = resource.getInputStream();
if (inputStream == null) {
logger.warn("ignore deploy workflow module: {}", classpathResourceUrl);
} else {
logger.debug("finded workflow module: {}, deploy it!", classpathResourceUrl);
ZipInputStream zis = new ZipInputStream(inputStream);
Deployment deployment = repositoryService.createDeployment().addZipInputStream(zis).deploy();
// export diagram
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
for (ProcessDefinition processDefinition : list) {
WorkflowUtils.exportDiagramToFile(repositoryService, processDefinition, exportDir);
}
}
}
示例6: loadPropertiesFromPaths
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
private static Properties loadPropertiesFromPaths(ResourceLoader resourceLoader, List<String> paths) {
Properties configurationProperties = new Properties();
for (String path : paths) {
Resource resource = resourceLoader.getResource(path);
InputStream is = null;
try {
is = resource.getInputStream();
Properties properties = new Properties();
properties.loadFromXML(is);
configurationProperties.putAll(properties);
} catch (IOException ex) {
log.error("Failed to load configuration properties. Resource - " + path, ex);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException ioe) {
// ignore
ioe.printStackTrace();
}
}
}
return configurationProperties;
}
示例7: buildSignatureValidationFilter
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Build signature validation filter if needed.
*
* @param resourceLoader the resource loader
* @param signatureResourceLocation the signature resource location
* @return the metadata filter
* @throws Exception the exception
*/
public static SignatureValidationFilter buildSignatureValidationFilter(final ResourceLoader resourceLoader,
final String signatureResourceLocation) throws Exception {
try {
final Resource resource = resourceLoader.getResource(signatureResourceLocation);
return buildSignatureValidationFilter(resource);
} catch (final Exception e){
LOGGER.debug(e.getMessage(), e);
}
return null;
}
示例8: doesResourceExist
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Does resource exist?
*
* @param resource the resource
* @param resourceLoader the resource loader
* @return the boolean
*/
public static boolean doesResourceExist(final String resource, final ResourceLoader resourceLoader) {
try {
if (StringUtils.isNotBlank(resource)) {
final Resource res = resourceLoader.getResource(resource);
return doesResourceExist(res);
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return false;
}
示例9: getResource
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
@Override
public Resource getResource(String location) {
String urlPrefix = getUrlPrefix(location);
if (urlPrefix == null) {
throw new IllegalStateException("Can't detect URL prefix for location: " + location);
}
ResourceLoader resourceLoader = urlPrefixToResourceLoader.get(urlPrefix);
if (resourceLoader == null) {
throw new IllegalStateException("Unsupported resource URL prefix: " + urlPrefix);
}
return resourceLoader.getResource(location);
}
示例10: getRootPath
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
public String getRootPath() {
ResourceLoader fileLoader = new DefaultResourceLoader();
try {
String classFile = CaseWithVisibleMethodsBaseTest.class.getName().replace('.', '/').concat(".class");
Resource res = fileLoader.getResource(classFile);
String fileLocation = "file:/" + res.getFile().getAbsolutePath();
String classFileToPlatform = CaseWithVisibleMethodsBaseTest.class.getName().replace('.', File.separatorChar).concat(
".class");
return fileLocation.substring(0, fileLocation.indexOf(classFileToPlatform));
}
catch (Exception ex) {
}
return null;
}
示例11: testOsgiBundleResourcePatternResolverBundle
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Test method for
* {@link org.springframework.osgi.context.OsgiBundleResourcePatternResolver#OsgiBundleResourcePatternResolver(org.osgi.framework.Bundle)}.
*/
public void testOsgiBundleResourcePatternResolverBundle() {
ResourceLoader res = resolver.getResourceLoader();
assertTrue(res instanceof OsgiBundleResourceLoader);
Resource resource = res.getResource("foo");
assertSame(bundle, ((OsgiBundleResource) resource).getBundle());
assertEquals(res.getResource("foo"), resolver.getResource("foo"));
}
示例12: convertToScriptSource
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
/**
* Convert the given script source locator to a ScriptSource instance.
* <p>By default, supported locators are Spring resource locations
* (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh")
* and inline scripts ("inline:myScriptText...").
* @param beanName the name of the scripted bean
* @param scriptSourceLocator the script source locator
* @param resourceLoader the ResourceLoader to use (if necessary)
* @return the ScriptSource instance
*/
protected ScriptSource convertToScriptSource(String beanName, String scriptSourceLocator,
ResourceLoader resourceLoader) {
if (scriptSourceLocator.startsWith(INLINE_SCRIPT_PREFIX)) {
return new StaticScriptSource(scriptSourceLocator.substring(INLINE_SCRIPT_PREFIX.length()), beanName);
}
else {
return new ResourceScriptSource(resourceLoader.getResource(scriptSourceLocator));
}
}
示例13: addBanner
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
private void addBanner(ResourceLoader resourceLoader, String bannerResourceName,
Function<Resource, Banner> function) {
Resource bannerResource = resourceLoader.getResource(bannerResourceName);
if (bannerResource.exists()) {
banners.add(new BannerDecorator(function.apply(bannerResource)));
}
}
示例14: testOneResource
import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
private void testOneResource(ResourceLoader loader) {
Resource res = loader.getResource(NON_EXISTING);
assertFalse(res.exists());
}