Java 类org.springframework.core.io.DefaultResourceLoader 实例源码

项目:cas-5.1.0    文件:Beans.java   
/**
 * 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());
    }
}
项目:spring4-understanding    文件:CallbacksSecurityTests.java   
@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);
}
项目:alfresco-repository    文件:OOoContentTransformerHelper.java   
public void afterPropertiesSet() throws Exception
{
    // load the document conversion configuration
    if (documentFormatsConfiguration != null)
    {
        DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
        try
        {
            InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream();
            formatRegistry = new JsonDocumentFormatRegistry(is);
            // We do not need to explicitly close this InputStream as it is closed for us within the XmlDocumentFormatRegistry
        }
        catch (IOException e)
        {
            throw new AlfrescoRuntimeException(
                    "Unable to load document formats configuration file: "
                    + this.documentFormatsConfiguration);
        }
    }
    else
    {
        formatRegistry = new DefaultDocumentFormatRegistry();
    }
}
项目:alfresco-repository    文件:ImporterComponent.java   
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);
    }
}
项目:gemini.blueprint    文件:ClassUtilsTest.java   
public void testAppContextClassHierarchy() {
    Class<?>[] clazz =
            ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
    Class<?>[] expected =
            new Class<?>[] { OsgiBundleXmlApplicationContext.class,
                    AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
                    AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
                    DefaultResourceLoader.class, ResourceLoader.class,
                    AutoCloseable.class,
                    DelegatedExecutionOsgiBundleApplicationContext.class,
                    ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
                    ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
                    HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
                    MessageSource.class, BeanFactory.class, DisposableBean.class };

    assertTrue(compareArrays(expected, clazz));
}
项目:angit    文件:DatasourceConfig.java   
/**
 * Dynamic sql session factory sql session factory.
 *
 * @param dynamicDataSource the dynamic data source
 * @param properties        the properties
 * @return the sql session factory
 */
@Bean
@ConfigurationProperties(prefix = MybatisProperties.MYBATIS_PREFIX)
public SqlSessionFactory dynamicSqlSessionFactory(
        @Qualifier("dynamicDataSource") DataSource dynamicDataSource,
        MybatisProperties properties) {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dynamicDataSource);
    sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(properties.getConfigLocation()));
    sessionFactory.setMapperLocations(properties.resolveMapperLocations());
    try {
        return sessionFactory.getObject();
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
项目:Shop-for-JavaWeb    文件:StringUtils.java   
/**
   * 获取工程路径
   * @return
   */
  public static String getProjectPath(){
String projectPath = "";
try {
    File file = new DefaultResourceLoader().getResource("").getFile();
    if (file != null){
        while(true){
            File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
            if (f == null || f.exists()){
                break;
            }
            if (file.getParentFile() != null){
                file = file.getParentFile();
            }else{
                break;
            }
        }
        projectPath = file.toString();
    }
} catch (IOException e) {
    e.printStackTrace();
}
return projectPath;
  }
项目:spring-boot-security-saml    文件:KeyManagerConfigurerTest.java   
@Before
    public void setup() {
        SAMLSSOProperties properties = mock(SAMLSSOProperties.class);
        keyManagerProperties = mock(KeyManagerProperties.class);
        when(properties.getKeyManager()).thenReturn(keyManagerProperties);
//        when(keyManagerProperties.getDefaultKey()).thenReturn("default");
//        when(keyManagerProperties.getKeyPasswords()).thenReturn(Collections.singletonMap("default", "password"));
//        when(keyManagerProperties.getPrivateKeyDerLocation()).thenReturn("classpath:localhost:key.der");
//        when(keyManagerProperties.getPublicKeyPemLocation()).thenReturn("classpath:localhost.cert");
//        when(keyManagerProperties.getStoreLocation()).thenReturn("classpath:KeyStore.jks");
//        when(keyManagerProperties.getStorePass()).thenReturn("storePass");
        builder = mock(ServiceProviderBuilder.class);
        when(builder.getSharedObject(KeyManager.class)).thenReturn(null);
        when(builder.getSharedObject(SAMLSSOProperties.class)).thenReturn(properties);
        when(builder.getSharedObject(ResourceLoader.class)).thenReturn(new DefaultResourceLoader());
    }
项目:spring-boot-security-saml    文件:KeyManagerConfigurerTest.java   
@Test
public void testArguments_keystore() throws Exception {
    KeyManagerConfigurer configurer = new KeyManagerConfigurer();
    configurer
            .keyStore(new KeystoreFactory(new DefaultResourceLoader()).createEmptyKeystore());
    configurer.init(builder);
    configurer.configure(builder);
    ArgumentCaptor<KeyManager> providerCaptor = ArgumentCaptor.forClass(KeyManager.class);
    verify(builder).setSharedObject(eq(KeyManager.class), providerCaptor.capture());
    verify(keyManagerProperties).getDefaultKey();
    verify(keyManagerProperties).getKeyPasswords();
    verify(keyManagerProperties).getPrivateKeyDerLocation();
    verify(keyManagerProperties).getPublicKeyPemLocation();
    verify(keyManagerProperties).getStoreLocation();
    verify(keyManagerProperties).getStorePass();
    assertThat(providerCaptor.getValue()).isNotNull();
    KeyManager keyManager = providerCaptor.getValue();
    assertThat(keyManager.getAvailableCredentials()).isEmpty();
}
项目:spring-boot-security-saml    文件:MetadataManagerConfigurerTest.java   
@Before
public void setup() {
    properties = mock(SAMLSSOProperties.class);
    metadataManagerProperties = spy(new MetadataManagerProperties());
    extendedMetadataDelegateProperties = spy(new ExtendedMetadataDelegateProperties());
    idpConfiguration = spy(new IdentityProvidersProperties());
    extendedMetadata = spy(new ExtendedMetadata());
    when(properties.getMetadataManager()).thenReturn(metadataManagerProperties);
    when(properties.getExtendedDelegate()).thenReturn(extendedMetadataDelegateProperties);
    when(properties.getIdp()).thenReturn(idpConfiguration);
    builder = mock(ServiceProviderBuilder.class);
    when(builder.getSharedObject(SAMLSSOProperties.class)).thenReturn(properties);
    when(builder.getSharedObject(ExtendedMetadata.class)).thenReturn(extendedMetadata);
    resourceLoader = new DefaultResourceLoader();
    when(builder.getSharedObject(ResourceLoader.class)).thenReturn(resourceLoader);
    parserPool = mock(ParserPool.class);
    when(builder.getSharedObject(ParserPool.class)).thenReturn(parserPool);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplication.java   
private Banner printBanner(ConfigurableEnvironment environment) {
    if (this.bannerMode == Banner.Mode.OFF) {
        return null;
    }
    if (printBannerViaDeprecatedMethod(environment)) {
        return null;
    }
    ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader
            : new DefaultResourceLoader(getClassLoader());
    SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(
            resourceLoader, this.banner);
    if (this.bannerMode == Mode.LOG) {
        return bannerPrinter.print(environment, this.mainApplicationClass, logger);
    }
    return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplication.java   
/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclasses can
 * apply additional processing as required.
 * @param context the application context
 */
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
    if (this.beanNameGenerator != null) {
        context.getBeanFactory().registerSingleton(
                AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
                this.beanNameGenerator);
    }
    if (this.resourceLoader != null) {
        if (context instanceof GenericApplicationContext) {
            ((GenericApplicationContext) context)
                    .setResourceLoader(this.resourceLoader);
        }
        if (context instanceof DefaultResourceLoader) {
            ((DefaultResourceLoader) context)
                    .setClassLoader(this.resourceLoader.getClassLoader());
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DataSourceInitializerTests.java   
@Test
public void multipleScriptsAppliedInLexicalOrder() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.initialize:true",
            "spring.datasource.schema:" + ClassUtils
                    .addResourcePathToPackagePath(getClass(), "lexical-schema-*.sql"),
            "spring.datasource.data:" + ClassUtils
                    .addResourcePathToPackagePath(getClass(), "data.sql"));
    this.context.register(DataSourceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    ReverseOrderResourceLoader resourceLoader = new ReverseOrderResourceLoader(
            new DefaultResourceLoader());
    this.context.setResourceLoader(resourceLoader);
    this.context.refresh();
    DataSource dataSource = this.context.getBean(DataSource.class);
    assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
    assertThat(dataSource).isNotNull();
    JdbcOperations template = new JdbcTemplate(dataSource);
    assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class))
            .isEqualTo(1);
}
项目:alfresco-simple-content-stores    文件:DummyFallbackContentStore.java   
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;
}
项目:spring-boot-concourse    文件:SpringApplication.java   
private Banner printBanner(ConfigurableEnvironment environment) {
    if (this.bannerMode == Banner.Mode.OFF) {
        return null;
    }
    if (printBannerViaDeprecatedMethod(environment)) {
        return null;
    }
    ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader
            : new DefaultResourceLoader(getClassLoader());
    SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(
            resourceLoader, this.banner);
    if (this.bannerMode == Mode.LOG) {
        return bannerPrinter.print(environment, this.mainApplicationClass, logger);
    }
    return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
项目:spring-boot-concourse    文件:SpringApplication.java   
/**
 * Apply any relevant post processing the {@link ApplicationContext}. Subclasses can
 * apply additional processing as required.
 * @param context the application context
 */
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
    if (this.webEnvironment) {
        if (context instanceof ConfigurableWebApplicationContext) {
            ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext) context;
            if (this.beanNameGenerator != null) {
                configurableContext.getBeanFactory().registerSingleton(
                        AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
                        this.beanNameGenerator);
            }
        }
    }
    if (this.resourceLoader != null) {
        if (context instanceof GenericApplicationContext) {
            ((GenericApplicationContext) context)
                    .setResourceLoader(this.resourceLoader);
        }
        if (context instanceof DefaultResourceLoader) {
            ((DefaultResourceLoader) context)
                    .setClassLoader(this.resourceLoader.getClassLoader());
        }
    }
}
项目:dhis2-core    文件:HelpAction.java   
@Override
public String execute()
    throws Exception
{
    List<Locale> locales = localeManager.getLocalesOrderedByPriority();

    ResourceLoader resourceLoader = new DefaultResourceLoader();

    for ( Locale locale : locales )
    {
        String helpPage = helpPagePreLocale + locale.toString() + helpPagePostLocale;

        if ( resourceLoader.getResource( helpPage ) != null )
        {
            this.helpPage = helpPage;

            return SUCCESS;
        }
    }

    return SUCCESS;
}
项目:edoras-one-initializr    文件:TemplateRenderer.java   
private static TemplateLoader mustacheTemplateLoader() {
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    String prefix = "classpath:/templates/";
    Charset charset = Charset.forName("UTF-8");
    return name -> new InputStreamReader(
            resourceLoader.getResource(prefix + name).getInputStream(), charset);
}
项目:framework    文件:Global.java   
/**
 * 获取工程路径.
 *
 * @return 工程路径
 */
public static String getProjectPath() {
    // 如果配置了工程路径,则直接返回,否则自动获取。
    String projectPath = Global.getConfig("projectPath");
    if (StringUtils.isNotBlank(projectPath)) {
        return projectPath;
    }
    try {
        File file = new DefaultResourceLoader().getResource("").getFile();
        if (file != null) {
            while (true) {
                File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
                if (f == null || f.exists()) {
                    break;
                }
                if (file.getParentFile() != null) {
                    file = file.getParentFile();
                } else {
                    break;
                }
            }
            projectPath = file.toString();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return projectPath;
}
项目:alfresco-repository    文件:VersionHistoryImplTest.java   
/**
 * @see {@link #DESERIALIZE_V22SP4}
 * @see {@link #DESERIALIZE_V310_DEV}
 * @see {@link #DESERIALIZE_V310}
 */
public void testDeserializeV22SP4() throws Exception
{
    String[] resourceLocations = new String[] {
            DESERIALIZE_V22SP4,
            DESERIALIZE_V310_DEV,
            DESERIALIZE_V310
    };
    for (String resourceLocation : resourceLocations)
    {
        Resource resource = new DefaultResourceLoader().getResource(resourceLocation);
        assertNotNull("Unable to find " + resourceLocation, resource);
        assertTrue("Unable to find " + resourceLocation, resource.exists());

        @SuppressWarnings("unused")
        VersionHistoryImpl vhObj;
        ObjectInputStream is = new ObjectInputStream(resource.getInputStream());
        try
        {
            vhObj = (VersionHistoryImpl) is.readObject();
        }
        finally
        {
            try { is.close(); } catch (Throwable e) {}
        }
    }
}
项目:syndesis    文件:DataManagerTest.java   
@Before
public void setup() {
    cacheManager = new LRUCacheManager(100);

    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();

    //Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
    dataManager.init();
    dataManager.resetDeploymentData();
}
项目:gemini.blueprint    文件:BaseIoTest.java   
protected void onSetUp() throws Exception {
    // load file using absolute path
    defaultLoader = new DefaultResourceLoader();
    thisClass = defaultLoader.getResource(getClass().getName().replace('.', '/').concat(".class"));
    bundle = bundleContext.getBundle();
    loader = new OsgiBundleResourceLoader(bundle);
    patternLoader = new OsgiBundleResourcePatternResolver(loader);

}
项目:gemini.blueprint    文件:AbstractOnTheFlyBundleCreatorTests.java   
/**
 * Returns the current test bundle manifest. The method tries to read the
 * manifest from the given location; in case the location is
 * <code>null</code> (default), it will search for
 * <code>META-INF/MANIFEST.MF</code> file in jar content (as specified
 * through the patterns) and, if it cannot find the file,
 * <em>automatically</em> create a <code>Manifest</code> object
 * containing default entries.
 * 
 * <p/> Subclasses can override this method to enhance the returned
 * Manifest.
 * 
 * @return Manifest used for this test suite.
 * 
 * @see #createDefaultManifest()
 */
protected Manifest getManifest() {
    // return cached manifest
    if (manifest != null)
        return manifest;

    String manifestLocation = getManifestLocation();
    if (StringUtils.hasText(manifestLocation)) {
        logger.info("Using Manifest from specified location=[" + getManifestLocation() + "]");
        DefaultResourceLoader loader = new DefaultResourceLoader();
        manifest = createManifestFrom(loader.getResource(manifestLocation));
    }

    else {
        // set root path
        jarCreator.setRootPath(getRootPath());
        // add the content pattern
        jarCreator.setContentPattern(getBundleContentPattern());

        // see if the manifest already exists in the classpath
        // to resolve the patterns
        jarEntries = jarCreator.resolveContent();

           for (Object o : jarEntries.entrySet()) {
               Map.Entry entry = (Map.Entry) o;
               if (META_INF_JAR_LOCATION.equals(entry.getKey())) {
                   logger.info("Using Manifest from the test bundle content=[/META-INF/MANIFEST.MF]");
                   manifest = createManifestFrom((Resource) entry.getValue());
               }
           }
        // fallback to default manifest creation

        if (manifest == null) {
            logger.info("Automatically creating Manifest for the test bundle");
            manifest = createDefaultManifest();
        }
    }

    return manifest;
}
项目:gemini.blueprint    文件:CaseWithVisibleMethodsBaseTest.java   
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;
}
项目:gemini.blueprint    文件:OsgiBundleResourcePatternResolverTest.java   
/**
 * Test method for
 * {@link org.springframework.osgi.context.OsgiBundleResourcePatternResolver#OsgiBundleResourcePatternResolver(org.springframework.core.io.ResourceLoader)}.
 */
public void testOsgiBundleResourcePatternResolverResourceLoader() {
    ResourceLoader resLoader = new DefaultResourceLoader();
    resolver = new OsgiBundleResourcePatternResolver(resLoader);
    ResourceLoader res = resolver.getResourceLoader();

    assertSame(resLoader, res);
    assertEquals(resLoader.getResource("foo"), resolver.getResource("foo"));
}
项目:lams    文件:ResourceLoaderClassLoadHelper.java   
@Override
public void initialize() {
    if (this.resourceLoader == null) {
        this.resourceLoader = SchedulerFactoryBean.getConfigTimeResourceLoader();
        if (this.resourceLoader == null) {
            this.resourceLoader = new DefaultResourceLoader();
        }
    }
}
项目:easyweb    文件:Global.java   
/**
   * 获取工程路径
   * @return
   */
  public  String getProjectPath(){
    // 如果配置了工程路径,则直接返回,否则自动获取。
String projectPath = getConfig("projectPath");
if (StringUtils.isNotBlank(projectPath)){
    return projectPath;
}
try {
    File file = new DefaultResourceLoader().getResource("").getFile();
    if (file != null){
        while(true){
            File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
            if (f == null || f.exists()){
                break;
            }
            if (file.getParentFile() != null){
                file = file.getParentFile();
            }else{
                break;
            }
        }
        projectPath = file.toString();
    }
} catch (IOException e) {
    e.printStackTrace();
}
return projectPath;
  }
项目:holon-datastore-jdbc    文件:AbstractDatastoreIntegrationTest.java   
protected static void initSQL(DataSource dataSource, String... scripts) {
    try {
        ResourceLoader rl = new DefaultResourceLoader();
        ResourceDatabasePopulator rbp = new ResourceDatabasePopulator();
        for (String script : scripts) {
            rbp.addScripts(rl.getResource(script));
        }
        try (Connection connection = dataSource.getConnection()) {
            rbp.populate(connection);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to init SQL scripts", e);
    }
}
项目:spring-cloud-gcp    文件:GoogleStorageProtocolResolver.java   
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    if (DefaultResourceLoader.class.isAssignableFrom(resourceLoader.getClass())) {
        ((DefaultResourceLoader) resourceLoader).addProtocolResolver(this);
    }
    else {
        logger.warn("The provided delegate resource loader is not an implementation "
                + "of DefaultResourceLoader. Custom Protocol using gs:// prefix will not be enabled.");
    }
}
项目:sshd-shell-spring-boot    文件:ShellBanner.java   
@PostConstruct
void init() {
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    String location = environment.getProperty("banner.image.location");
    if (StringUtils.hasLength(location)) {
        addBanner(resourceLoader, location, resource -> new ImageBanner(resource));
    } else {
        for (String ext : SUPPORTED_IMAGES) {
            addBanner(resourceLoader, "banner." + ext, resource -> new ImageBanner(resource));
        }
    }
    addBanner(resourceLoader, environment.getProperty("banner.location", "banner.txt"),
            resource -> new ResourceBanner(resource));
}
项目:dntown    文件:ContextUtils.java   
public static String getResourceRootRealPath(){
    String rootRealPath ="";
    try {
        rootRealPath=new DefaultResourceLoader().getResource("").getFile().getAbsolutePath();
    } catch (IOException e) {
        logger.warn("获取资源根目录失败");
    }
    return rootRealPath;
}
项目:melon    文件:Global.java   
/**
 * 获取工程路径
 *
 * @return
 */
public static String getProjectPath() {
    // 如果配置了工程路径,则直接返回,否则自动获取。
    String projectPath = Global.getConfig("projectPath");
    if (StringUtils.isNotBlank(projectPath)) {
        return projectPath;
    }
    try {
        File file = new DefaultResourceLoader().getResource("").getFile();
        if (file != null) {
            while (true) {
                File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
                if (f == null || f.exists()) {
                    break;
                }
                if (file.getParentFile() != null) {
                    file = file.getParentFile();
                } else {
                    break;
                }
            }
            projectPath = file.toString();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return projectPath;
}
项目:spring4-understanding    文件:MockPortletContext.java   
/**
 * Create a new MockPortletContext.
 * @param resourceBasePath the WAR root directory (should not end with a slash)
 * @param resourceLoader the ResourceLoader to use (or null for the default)
 */
public MockPortletContext(String resourceBasePath, ResourceLoader resourceLoader) {
    this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");
    this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());

    // Use JVM temp dir as PortletContext temp dir.
    String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
    if (tempDir != null) {
        this.attributes.put(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File(tempDir));
    }
}
项目:spring4-understanding    文件:AsmCircularImportDetectionTests.java   
@Override
protected ConfigurationClassParser newParser() {
    return new ConfigurationClassParser(
            new CachingMetadataReaderFactory(),
            new FailFastProblemReporter(),
            new StandardEnvironment(),
            new DefaultResourceLoader(),
            new AnnotationBeanNameGenerator(),
            new DefaultListableBeanFactory());
}
项目:spring4-understanding    文件:FreeMarkerConfigurerTests.java   
@Test  // SPR-12448
public void freeMarkerConfigurationAsBean() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
    loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
    loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
    RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
    configDef.getPropertyValues().add("templateLoader", loaderDef);
    beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
    beanFactory.getBean(Configuration.class);
}
项目:spring4-understanding    文件:MockServletContext.java   
/**
 * Create a new {@code MockServletContext} using the supplied resource base
 * path and resource loader.
 * <p>Registers a {@link MockRequestDispatcher} for the Servlet named
 * {@literal 'default'}.
 * @param resourceBasePath the root directory of the WAR (should not end with a slash)
 * @param resourceLoader the ResourceLoader to use (or null for the default)
 * @see #registerNamedDispatcher
 */
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) {
    this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
    this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");

    // Use JVM temp dir as ServletContext temp dir.
    String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
    if (tempDir != null) {
        this.attributes.put(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File(tempDir));
    }

    registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
}
项目:spring4-understanding    文件:MockPortletContext.java   
/**
 * Create a new MockPortletContext.
 * @param resourceBasePath the WAR root directory (should not end with a slash)
 * @param resourceLoader the ResourceLoader to use (or null for the default)
 */
public MockPortletContext(String resourceBasePath, ResourceLoader resourceLoader) {
    this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");
    this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());

    // Use JVM temp dir as PortletContext temp dir.
    String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
    if (tempDir != null) {
        this.attributes.put(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File(tempDir));
    }
}
项目:spring4-understanding    文件:MockServletContext.java   
/**
 * Create a new {@code MockServletContext} using the supplied resource base
 * path and resource loader.
 * <p>Registers a {@link MockRequestDispatcher} for the Servlet named
 * {@literal 'default'}.
 * @param resourceBasePath the root directory of the WAR (should not end with a slash)
 * @param resourceLoader the ResourceLoader to use (or null for the default)
 * @see #registerNamedDispatcher
 */
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) {
    this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
    this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");

    // Use JVM temp dir as ServletContext temp dir.
    String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
    if (tempDir != null) {
        this.attributes.put(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File(tempDir));
    }

    registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
}
项目:spring4-understanding    文件:ResourceLoaderClassLoadHelper.java   
@Override
public void initialize() {
    if (this.resourceLoader == null) {
        this.resourceLoader = SchedulerFactoryBean.getConfigTimeResourceLoader();
        if (this.resourceLoader == null) {
            this.resourceLoader = new DefaultResourceLoader();
        }
    }
}
项目:leopard    文件:ClassPathModelAndView.java   
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Configuration config = configurer.getConfiguration();
    // config.setTemplateLoader(new ClassTemplateLoader(this.getClass(), folder));
    config.setTemplateLoader(new SpringTemplateLoader(new DefaultResourceLoader(), folder));
    // return config.getTemplate(name, "UTF-8");

    Template template = config.getTemplate(viewName + ".ftl", "UTF-8");
    response.setContentType(getContentType());
    Writer out = response.getWriter();
    template.process(model, out);
}