org.springframework.core.io.DefaultResourceLoader#getResource ( )源码实例Demo

下面列出了org.springframework.core.io.DefaultResourceLoader#getResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
protected Resource getDummyFileResource(final String mimetype)
{
    final String extension = this.mimetypeService.getExtension(mimetype);
    Resource resource = null;
    final List<String> pathsToSearch = new ArrayList<>(this.dummyFilePaths);
    Collections.reverse(pathsToSearch);

    final DefaultResourceLoader resourceLoader = new DefaultResourceLoader();

    for (final String path : pathsToSearch)
    {
        resource = resourceLoader.getResource(path + "/dummy." + extension);
        if (resource != null)
        {
            if (resource.exists())
            {
                break;
            }
            // nope'd
            resource = null;
        }
    }
    LOGGER.trace("Found dummy file resource {} for extension {}", resource, extension);
    return resource;
}
 
@Test
void testGetResourceWithExistingResource() {

	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	ObjectMetadata metadata = new ObjectMetadata();
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(metadata);

	String resourceName = "s3://bucket/object/";
	Resource resource = resourceLoader.getResource(resourceName);
	assertThat(resource).isNotNull();
}
 
源代码6 项目: secure-data-service   文件: SmooksGenerator.java
public SmooksGenerator() {
    complexTypes = new HashMap<String, XmlSchemaComplexType>();
    simpleTypes = new HashMap<String, XmlSchemaSimpleType>();
    complexTypesData = new HashMap<String, ComplexTypeData>();

    resourceLoader = new DefaultResourceLoader();
    Resource xsdResource = resourceLoader.getResource(xsdLocation);
    Resource extensionXsdResource = resourceLoader.getResource(extensionXsdLocation);

    // extract complex types from base schema
    cacheTypesFromResource(xsdResource, xsdParentLocation);
    // extract complex types from extension schema
    cacheTypesFromResource(extensionXsdResource, extensionXsdParentLocation);

    // extract data from complex data including hierarchy
    cacheComplexTypeData();
}
 
源代码7 项目: spring-tsers-auth   文件: WebSecurityConfig.java
@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader
            .getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}
 
源代码8 项目: spring-tsers-auth   文件: WebSecurityConfig.java
@Bean
@Qualifier("idp-ssocircle")
public ExtendedMetadataDelegate ssoCircleExtendedMetadataProvider()
        throws MetadataProviderException {


    AbstractMetadataProvider provider = new AbstractMetadataProvider() {
        @Override
        protected XMLObject doGetMetadata() throws MetadataProviderException {
            DefaultResourceLoader loader = new DefaultResourceLoader();
            Resource storeFile = loader.getResource("classPath:/saml/idp-metadata.xml");

            ParserPool parser = parserPool();
            try {
                Document mdDocument = parser.parse(storeFile.getInputStream());
                Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(mdDocument.getDocumentElement());
                return unmarshaller.unmarshall(mdDocument.getDocumentElement());
            } catch (Exception e) {
                e.printStackTrace();
                throw new MetadataProviderException();
            }


        }
    };
    ExtendedMetadataDelegate extendedMetadataDelegate =
            new ExtendedMetadataDelegate(provider, extendedMetadata());
    extendedMetadataDelegate.setMetadataTrustCheck(false);
    extendedMetadataDelegate.setMetadataRequireSignature(false);
    return extendedMetadataDelegate;
}
 
@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader
            .getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}
 
@Test
void testGetResourceWithNonExistingResource() {

	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	String resourceName = "s3://bucket/object/";
	Resource resource = resourceLoader.getResource(resourceName);
	assertThat(resource).isNotNull();
}
 
@Test
void testValidS3Pattern() {
	AmazonS3 amazonS3 = mock(AmazonS3.class);

	DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
	resourceLoader.addProtocolResolver(new SimpleStorageProtocolResolver(amazonS3));

	// None of the patterns below should throw an exception
	resourceLoader.getResource("s3://bucket/key");
	resourceLoader.getResource("S3://BuCket/key");
	resourceLoader.getResource("s3://bucket/folder1/folder2/key");
	resourceLoader.getResource("s3://bucket/folder1/folder2/key^versionIdValue");
}
 
源代码12 项目: cougar   文件: PropertyLoader.java
/**
 * @return returns an array of validated Resources for use with overlaid property files
 */
public Resource[] constructResourceList() {
    String configHost = System.getProperties().getProperty(DEFAULT_CONFIG_HOST_PROPERTY);
    if (configHost == null) {
        log("No config Host defined - assuming " + DEFAULT_CONFIG_HOST_PROPERTY_VALUE);
        configHost = DEFAULT_CONFIG_HOST_PROPERTY_VALUE;
    }
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource configOverrideResource = loader.getResource(configHost + configOverride);

    return handleConfig(defaultConfig, appProperties, configOverrideResource);

}
 
源代码13 项目: tutorials   文件: TestHelper.java
private void runScript(String scriptName, DataSource dataSouorce) throws SQLException {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource script = resourceLoader.getResource(scriptName);
    try (Connection con = dataSouorce.getConnection()) {
        ScriptUtils.executeSqlScript(con, script);
    }
}
 
源代码14 项目: cuba   文件: AbstractWebAppContextLoader.java
protected void loadPropertiesFromConfig(ServletContext sc, Properties properties, String propsConfigName) {
    SpringProfileSpecificNameResolver nameResolver = new SpringProfileSpecificNameResolver(sc);
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    StringTokenizer tokenizer = new StringTokenizer(propsConfigName);
    tokenizer.setQuoteChar('"');
    for (String str : tokenizer.getTokenArray()) {
        log.trace("Processing properties location: {}", str);
        String baseName = StringSubstitutor.replaceSystemProperties(str);
        for (String name : nameResolver.getDerivedNames(baseName)) {
            InputStream stream = null;
            try {
                if (ResourceUtils.isUrl(name) || name.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
                    Resource resource = resourceLoader.getResource(name);
                    if (resource.exists())
                        stream = resource.getInputStream();
                } else {
                    stream = sc.getResourceAsStream(name);
                }

                if (stream != null) {
                    log.info("Loading app properties from {}", name);
                    BOMInputStream bomInputStream = new BOMInputStream(stream);
                    try (Reader reader = new InputStreamReader(bomInputStream, StandardCharsets.UTF_8)) {
                        properties.load(reader);
                    }
                } else {
                    log.trace("Resource {} not found, ignore it", name);
                }
            } catch (IOException e) {
                throw new RuntimeException("Unable to read properties from stream", e);
            } finally {
                try {
                    if (stream != null) {
                        stream.close();
                    }
                } catch (final IOException ioe) {
                    // ignore
                }
            }
        }
    }
}
 
源代码15 项目: kfs   文件: DataDictionary.java
protected Resource getFileResource(String sourceName) {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
    return resourceLoader.getResource(sourceName);
}
 
源代码16 项目: rice   文件: DataDictionary.java
protected Resource getFileResource(String sourceName) {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());

    return resourceLoader.getResource(sourceName);
}