Java Code Examples for org.springframework.core.io.ResourceLoader

The following are top voted examples for showing how to use org.springframework.core.io.ResourceLoader. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ARCLib   File: VelocityTemplateAvailabilityProvider.java   View source code 10 votes vote down vote up
@Override
public boolean isTemplateAvailable(String view, Environment environment,
                                   ClassLoader classLoader, ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment,
                "spring.velocity.");
        String loaderPath = resolver.getProperty("resource-loader-path",
                VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
        String prefix = resolver.getProperty("prefix",
                VelocityProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix",
                VelocityProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(loaderPath + prefix + view + suffix)
                             .exists();
    }
    return false;
}
 
Example 2
Project: cas-5.1.0   File: Beans.java   View source code 7 votes vote down vote up
/**
 * 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());
    }
}
 
Example 3
Project: springboot-shiro-cas-mybatis   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/webappContext.xml",
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 4
Project: springboot-shiro-cas-mybatis   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 5
Project: springboot-shiro-cas-mybatis   File: RegisteredServiceThemeBasedViewResolverTests.java   View source code 6 votes vote down vote up
@Test
public void verifyGetServiceWithTheme() throws Exception {
    final MockRequestContext requestContext = new MockRequestContext();
    RequestContextHolder.setRequestContext(requestContext);

    final WebApplicationService webApplicationService = new WebApplicationServiceFactory().createService("myServiceId");
    requestContext.getFlowScope().put("service", webApplicationService);

    final ResourceLoader loader = mock(ResourceLoader.class);
    final Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(loader.getResource(anyString())).thenReturn(resource);

    this.registeredServiceThemeBasedViewResolver.setResourceLoader(loader);

    assertEquals("/WEB-INF/view/jsp/myTheme/ui/casLoginView",
            this.registeredServiceThemeBasedViewResolver.buildView("casLoginView").getUrl());
}
 
Example 6
Project: springboot-shiro-cas-mybatis   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 7
Project: secrets-proxy   File: KeywhizKeyStore.java   View source code 6 votes vote down vote up
/**
 * Create a keywhiz key store to communicate with Keywhiz server.
 *
 * @param name             Keystore name
 * @param trustStoreConfig {@link OneOpsConfig.TrustStore} trust-store properties
 * @param keystoreConfig   {@link OneOpsConfig.Keystore} keystore properties
 * @param loader           {@link ResourceLoader} for loading resources from classpath for file system.
 */
public KeywhizKeyStore(Name name,
                       OneOpsConfig.TrustStore trustStoreConfig,
                       OneOpsConfig.Keystore keystoreConfig,
                       ResourceLoader loader) {
    this.name = name;
    this.loader = loader;
    if (trustStoreConfig != null) {
        trustStore = keyStoreFromResource(trustStoreConfig);
    } else {
        trustStore = null;
    }
    if (keystoreConfig != null) {
        keyStore = keyStoreFromResource(keystoreConfig);
        keyPassword = keystoreConfig.getKeyPassword();
    } else {
        keyStore = null;
        keyPassword = null;
    }
}
 
Example 8
Project: alfresco-repository   File: ImporterComponent.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 9
Project: cas4.0.x-server-wechat   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 10
Project: cas4.0.x-server-wechat   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 11
Project: microservice   File: WorkflowProcessDefinitionService.java   View source code 6 votes vote down vote up
/**
 * 部署单个流程定义
 *
 * @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);
        }
    }
}
 
Example 12
Project: cas-server-4.2.1   File: WiringTests.java   View source code 6 votes vote down vote up
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
 
Example 13
Project: spring-cloud-dashboard   File: AppRegistry.java   View source code 5 votes vote down vote up
public AppRegistry(UriRegistry uriRegistry, ResourceLoader resourceLoader, EavRegistryRepository eavRegistryRepository) {
	this.uriRegistry = uriRegistry;
	this.uriRegistryPopulator = new UriRegistryPopulator();
	this.uriRegistryPopulator.setResourceLoader(resourceLoader);
	this.resourceLoader = resourceLoader;
	this.eavRegistryRepository = eavRegistryRepository;
}
 
Example 14
Project: spring-cloud-skipper   File: SkipperServerConfiguration.java   View source code 5 votes vote down vote up
@Bean
public DelegatingResourceLoader delegatingResourceLoader(MavenConfigurationProperties mavenProperties) {
	DockerResourceLoader dockerLoader = new DockerResourceLoader();
	MavenResourceLoader mavenResourceLoader = new MavenResourceLoader(mavenProperties);
	Map<String, ResourceLoader> loaders = new HashMap<>();
	loaders.put("docker", dockerLoader);
	loaders.put("maven", mavenResourceLoader);
	return new DelegatingResourceLoader(loaders);
}
 
Example 15
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 16
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 17
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 18
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 19
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 20
Project: lams   File: LocalSessionFactoryBuilder.java   View source code 5 votes vote down vote up
/**
 * Create a new LocalSessionFactoryBuilder for the given DataSource.
 * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using
 * (may be {@code null})
 * @param resourceLoader the ResourceLoader to load application classes from
 */
@SuppressWarnings("deprecation")  // to be able to build against Hibernate 4.3
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
	getProperties().put(Environment.CURRENT_SESSION_CONTEXT_CLASS, SpringSessionContext.class.getName());
	if (dataSource != null) {
		getProperties().put(Environment.DATASOURCE, dataSource);
	}
	// APP_CLASSLOADER is deprecated as of Hibernate 4.3 but we need to remain compatible with 4.0+
	getProperties().put(AvailableSettings.APP_CLASSLOADER, resourceLoader.getClassLoader());
	this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
}
 
Example 21
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 22
Project: Learning-Spring-Boot-2.0-Second-Edition   File: ImageService.java   View source code 5 votes vote down vote up
public ImageService(ResourceLoader resourceLoader,
					ImageRepository imageRepository,
					MeterRegistry meterRegistry) {

	this.resourceLoader = resourceLoader;
	this.imageRepository = imageRepository;
	this.meterRegistry = meterRegistry;
}
 
Example 23
Project: cas-5.1.0   File: SamlUtils.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 24
Project: simple-openid-provider   File: OAuth2Configuration.java   View source code 5 votes vote down vote up
public OAuth2Configuration(ResourceLoader resourceLoader, OpenIdProviderProperties properties,
		ObjectProvider<JdbcOperations> jdbcOperations, ObjectProvider<AuthenticationManager> authenticationManager,
		ObjectProvider<HazelcastInstance> hazelcastInstance) {
	this.resourceLoader = resourceLoader;
	this.properties = properties;
	this.jdbcOperations = jdbcOperations.getObject();
	this.authenticationManager = authenticationManager.getObject();
	this.hazelcastInstance = hazelcastInstance.getObject();
}
 
Example 25
Project: xm-commons   File: XmLepResourceService.java   View source code 5 votes vote down vote up
public XmLepResourceService(String appName,
                            TenantScriptStorage tenantScriptStorage,
                            ResourceLoader routerResourceLoader) {
    this.appName = Objects.requireNonNull(appName, "appName can't be null");
    this.tenantScriptStorage = Objects.requireNonNull(tenantScriptStorage,
                                                      "tenantScriptStorage can't be null");
    this.routerResourceLoader = routerResourceLoader;
}
 
Example 26
Project: xm-commons   File: RouterResourceLoader.java   View source code 5 votes vote down vote up
@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);
}
 
Example 27
Project: spring-cloud-dashboard   File: AppRegistration.java   View source code 5 votes vote down vote up
/**
 * Construct an {@code AppRegistration} object.
 *
 * @param name app name
 * @param type app type
 * @param uri URI for the app resource
 * @param loader the {@link ResourceLoader} that loads the {@link Resource} for this app
 */
public AppRegistration(String name, String type, URI uri, ResourceLoader loader) {
	Assert.hasText(name, "name is required");
	Assert.notNull(type, "type is required");
	Assert.notNull(uri, "uri is required");
	Assert.notNull(loader, "ResourceLoader must not be null");
	this.name = name;
	this.type = type;
	this.uri = uri;
	this.loader = loader;
}
 
Example 28
Project: xm-commons   File: XmLepResourceServiceFileUnitTest.java   View source code 5 votes vote down vote up
@Before
public void before() throws IOException {
    oldUserHome = System.getProperty(USER_HOME);

    // init temp folder
    testScriptDir = folder.newFolder("home", "xm-online", "config", "tenants",
                                     TENANT_KEY_VALUE.toUpperCase(), APP_NAME,
                                     "lep", "resource", "service");


    // init system property
    File userHomeDir = Paths.get(folder.getRoot().toPath().toString(), "home").toFile();
    System.setProperty(USER_HOME, userHomeDir.getAbsolutePath());

    // copy script from classpath to file system tmp folder
    File scriptFile = Paths.get(testScriptDir.getAbsolutePath(), "Script$$before.groovy").toFile();
    if (!scriptFile.createNewFile()) {
        throw new IllegalStateException("Can't create file: " + scriptFile.getAbsolutePath());
    }
    InputStream scriptIn = resourceLoader.getResource(SCRIPT_CLASSPATH_URL).getInputStream();
    Files.copy(scriptIn, scriptFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    scriptIn.close();

    // init resource service
    Map<String, ResourceLoader> urlPrefixToResourceLoader = new HashMap<>();
    urlPrefixToResourceLoader.put("file:", new FileSystemResourceLoader());
    RouterResourceLoader routerResourceLoader = new RouterResourceLoader(urlPrefixToResourceLoader);
    resourceService = new XmLepResourceService(APP_NAME, FILE, routerResourceLoader);
}
 
Example 29
Project: syndesis   File: DataManager.java   View source code 5 votes vote down vote up
@Autowired
public DataManager(CacheManager caches,
                   List<DataAccessObject<?>> dataAccessObjects,
                   EventBus eventBus,
                   EncryptionComponent encryptionComponent,
                   ResourceLoader resourceLoader) {
    this.caches = caches;
    this.eventBus = eventBus;
    this.encryptionComponent = encryptionComponent;
    this.resourceLoader = resourceLoader;
    if (dataAccessObjects != null) {
        this.dataAccessObjects.addAll(dataAccessObjects);
    }
}
 
Example 30
Project: syndesis   File: DataManagerTest.java   View source code 5 votes vote down vote up
@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();
}
 
Example 31
Project: mylion-mvn   File: MydogTemplateLoader.java   View source code 5 votes vote down vote up
public MydogTemplateLoader(ResourceLoader resourceLoader, String templateLoaderPath ) {
	this.resourceLoader = resourceLoader;
	if (!templateLoaderPath.endsWith("/")) {
		templateLoaderPath += "/";
	}
	this.templateLoaderPath = templateLoaderPath;
	
	this.outputDirectory = new File(XmlConfigLoader.getConfigLoader().getOutputDirectory(), "target/classes/");
}
 
Example 32
Project: gemini.blueprint   File: ClassUtilsTest.java   View source code 5 votes vote down vote up
public void testInterfacesHierarchy() {
       //Closeable.class,
	Class<?>[] clazz = ClassUtils.getAllInterfaces(DelegatedExecutionOsgiBundleApplicationContext.class);
	Class<?>[] expected =
			{ ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
					ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
					HierarchicalBeanFactory.class, MessageSource.class, ApplicationEventPublisher.class,
					ResourcePatternResolver.class, BeanFactory.class, ResourceLoader.class, AutoCloseable.class };

	assertTrue(compareArrays(expected, clazz));
}
 
Example 33
Project: lams   File: SpringTemplateLoader.java   View source code 5 votes vote down vote up
/**
 * Create a new SpringTemplateLoader.
 * @param resourceLoader the Spring ResourceLoader to use
 * @param templateLoaderPath the template loader path to use
 */
public SpringTemplateLoader(ResourceLoader resourceLoader, String templateLoaderPath) {
	this.resourceLoader = resourceLoader;
	if (!templateLoaderPath.endsWith("/")) {
		templateLoaderPath += "/";
	}
	this.templateLoaderPath = templateLoaderPath;
	if (logger.isInfoEnabled()) {
		logger.info("SpringTemplateLoader for FreeMarker: using resource loader [" + this.resourceLoader +
				"] and template loader path [" + this.templateLoaderPath + "]");
	}
}
 
Example 34
Project: gemini.blueprint   File: OsgiBundleResourcePatternResolver.java   View source code 5 votes vote down vote up
public OsgiBundleResourcePatternResolver(ResourceLoader resourceLoader) {
	super(resourceLoader);
	if (resourceLoader instanceof OsgiBundleResourceLoader) {
		this.bundle = ((OsgiBundleResourceLoader) resourceLoader).getBundle();
	} else {
		this.bundle = null;
	}

	this.bundleContext = (bundle != null ? OsgiUtils.getBundleContext(this.bundle) : null);
	this.resolver = (bundleContext != null ? new PackageAdminResolver(bundleContext) : null);
}
 
Example 35
Project: mylion-mvn   File: MydogTemplateLoader.java   View source code 5 votes vote down vote up
public MydogTemplateLoader(ResourceLoader resourceLoader, String templateLoaderPath ) {
	this.resourceLoader = resourceLoader;
	if (!templateLoaderPath.endsWith("/")) {
		templateLoaderPath += "/";
	}
	this.templateLoaderPath = templateLoaderPath;
	
	this.outputDirectory = new File(XmlConfigLoader.getConfigLoader().getOutputDirectory(), "target/classes/");
}
 
Example 36
Project: gemini.blueprint   File: OsgiBundleResource.java   View source code 5 votes vote down vote up
/**
 * 
 * Constructs a new <code>OsgiBundleResource</code> instance.
 * 
 * @param bundle OSGi bundle used by this resource
 * @param path resource path inside the bundle.
 */
public OsgiBundleResource(Bundle bundle, String path) {
	Assert.notNull(bundle, "Bundle must not be null");
	this.bundle = bundle;

	// check path
	Assert.notNull(path, "Path must not be null");

	this.path = StringUtils.cleanPath(path);

	this.searchType = OsgiResourceUtils.getSearchType(this.path);

	switch (this.searchType) {
		case OsgiResourceUtils.PREFIX_TYPE_NOT_SPECIFIED:
			pathWithoutPrefix = path;
			break;
		case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_SPACE:
			pathWithoutPrefix = path.substring(BUNDLE_URL_PREFIX.length());
			break;
		case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_JAR:
			pathWithoutPrefix = path.substring(BUNDLE_JAR_URL_PREFIX.length());
			break;
		case OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE:
			pathWithoutPrefix = path.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
			break;
		// prefix unknown so the path will be resolved outside the context
		default:
			pathWithoutPrefix = null;
	}
}
 
Example 37
Project: gemini.blueprint   File: OsgiBundleResourcePatternResolverTest.java   View source code 5 votes vote down vote up
/**
 * 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"));
}
 
Example 38
Project: gemini.blueprint   File: OsgiBundleResourcePatternResolverTest.java   View source code 5 votes vote down vote up
/**
 * 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"));
}
 
Example 39
Project: mapper-boot-starter   File: MapperAutoConfiguration.java   View source code 5 votes vote down vote up
public MapperAutoConfiguration(MybatisProperties properties,
                               ObjectProvider<Interceptor[]> interceptorsProvider,
                               ResourceLoader resourceLoader,
                               ObjectProvider<DatabaseIdProvider> databaseIdProvider,
                               ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider) {
    this.properties = properties;
    this.interceptors = interceptorsProvider.getIfAvailable();
    this.resourceLoader = resourceLoader;
    this.databaseIdProvider = databaseIdProvider.getIfAvailable();
    this.configurationCustomizers = configurationCustomizersProvider.getIfAvailable();
}
 
Example 40
Project: didi-eureka-server   File: EurekaServerAutoConfiguration.java   View source code 5 votes vote down vote up
/**
 * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources
 * required by the Eureka server.
 */
@Bean
public javax.ws.rs.core.Application jerseyApplication(Environment environment,
		ResourceLoader resourceLoader) {

	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
			false, environment);

	// Filter to include only classes that have a particular annotation.
	//
	provider.addIncludeFilter(new AnnotationTypeFilter(Path.class));
	provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));

	// Find classes in Eureka packages (or subpackages)
	//
	Set<Class<?>> classes = new HashSet<Class<?>>();
	for (String basePackage : EUREKA_PACKAGES) {
		Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage);
		for (BeanDefinition bd : beans) {
			Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(),
					resourceLoader.getClassLoader());
			classes.add(cls);
		}
	}

	// Construct the Jersey ResourceConfig
	//
	Map<String, Object> propsAndFeatures = new HashMap<String, Object>();
	propsAndFeatures.put(
			// Skip static content used by the webapp
			ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
			EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");

	DefaultResourceConfig rc = new DefaultResourceConfig(classes);
	rc.setPropertiesAndFeatures(propsAndFeatures);

	return rc;
}