当前位置: 首页>>代码示例>>Java>>正文


Java ResourceLoader.getResource方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:Beans.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:ControllerUtils.java

示例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);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:ImporterComponent.java

示例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;
}
 
开发者ID:cyanqueen,项目名称:backbone,代码行数:22,代码来源:WebMvcApplicationConfig.java

示例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);
        }
    }
}
 
开发者ID:batizhao,项目名称:microservice,代码行数:27,代码来源:WorkflowProcessDefinitionService.java

示例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;
}
 
开发者ID:profullstack,项目名称:spring-seed,代码行数:26,代码来源:ProfileApplicationContextInitializer.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:SamlUtils.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:ResourceUtils.java

示例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);
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:15,代码来源:RouterResourceLoader.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:16,代码来源:CaseWithVisibleMethodsBaseTest.java

示例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"));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:OsgiBundleResourcePatternResolverTest.java

示例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));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ScriptFactoryPostProcessor.java

示例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)));
    }
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:8,代码来源:ShellBanner.java

示例14: testOneResource

import org.springframework.core.io.ResourceLoader; //导入方法依赖的package包/类
private void testOneResource(ResourceLoader loader) {
	Resource res = loader.getResource(NON_EXISTING);
	assertFalse(res.exists());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:5,代码来源:InvalidLocationsTest.java


注:本文中的org.springframework.core.io.ResourceLoader.getResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。