Package org.springframework.core.io.support

Examples of org.springframework.core.io.support.ResourcePatternResolver


    public List<EventCategoryTO> listAuditEvents() {
        // use set to avoi duplications or null elements
        final Set<EventCategoryTO> events = new HashSet<EventCategoryTO>();

        try {
            final ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
            final MetadataReaderFactory metadataReaderFactory =
                    new CachingMetadataReaderFactory(resourcePatternResolver);

            final String packageSearchPath =
                    ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                    + ClassUtils.convertClassNameToResourcePath(
                    SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName()))
                    + "/" + "**/*.class";

            final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    final Class<?> clazz = Class.forName(metadataReader.getClassMetadata().getClassName());

View Full Code Here


   * @return A resource set.
   * @throws IOException If a resource file fail to be loaded.
   */
  private List<Resource> findResources(final String[] locations)
      throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Set<Resource> resources = Sets.newLinkedHashSet();
    for (String location : locations) {
      Resource[] candidates = resolver.getResources(location);
      for (Resource resource : candidates) {
        if (resource.exists()) {
          resources.add(resource);
        } else {
          logger.warn("Could not find any property file for: {}", location);
View Full Code Here

    protected ResourcePatternResolver getResolver() {
        return new PathMatchingResourcePatternResolver();
    }
   
    public Collection<ModuleDefinition> locateModules(String context) throws IOException {
        ResourcePatternResolver resolver = getResolver();
       
        Map<String, ModuleDefinition> allModules = discoverModules(context, resolver);
       
        return allModules.values();
    }
View Full Code Here

        }
      }
      // using spring power :)
      String script = "#an error has occured whilst resolving the include:" + templateName.toString() + "#";

      ResourcePatternResolver resolver = createResourceResolver();

      Resource[] groovyFiles = resolver.getResources(templateName.toString());
      for (Resource resource : groovyFiles) {
        SimpleTemplate template = new SimpleTemplate();
        InputStreamReader isReader = new InputStreamReader(resource.getInputStream());
        script = template.parse(isReader, false);
      }
View Full Code Here

        }
      }
      // using spring power :)
      String script = "#an error has occured whilst resolving the include:" + templateName.toString() + "#";

      ResourcePatternResolver resolver = createResourceResolver();

      Resource[] groovyFiles = resolver.getResources(templateName.toString());
      for (Resource resource : groovyFiles) {
        SimpleTemplate template = new SimpleTemplate();
        InputStreamReader isReader = new InputStreamReader(resource.getInputStream());
        script = template.parse(isReader, false);
      }
View Full Code Here


  public void testResolveResourceWithFilePrefix() throws Exception {
    Bundle bundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, EXPANDED_BUNDLE_SYM_NAME);
    assertTrue(bundle.getLocation().startsWith(REFERENCE_PROTOCOL));
    ResourcePatternResolver resolver = new OsgiBundleResourcePatternResolver(bundle);
    Resource res = resolver.getResource("resource.res");
    assertTrue(res.getFile().exists());
  }
View Full Code Here

  public void testResolveResourceWithReferenceFilePrefix() throws Exception {
    Bundle bundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, EXPANDED_BUNDLE_SYM_NAME);
    assertTrue(bundle.getLocation().startsWith(REFERENCE_PROTOCOL));
    assertNotNull(new URL(bundle.getLocation()).getFile());
    ResourcePatternResolver resolver = new OsgiBundleResourcePatternResolver(bundle);
    Resource res = resolver.getResource("/META-INF/MANIFEST.MF");
    assertTrue(res.getFile().exists());
  }
View Full Code Here

   *
   * @return
   * @throws Exception
   */
  private Resource[][] resolveResources() {
    ResourcePatternResolver resolver = getPatternResolver();

    String[] patterns = getContentPattern();
    Resource[][] resources = new Resource[patterns.length][];

    // transform Strings into Resources
    for (int i = 0; i < patterns.length; i++) {
      StringBuffer buffer = new StringBuffer(rootPath);

      // do checking on lost slashes
      if (!rootPath.endsWith(JarUtils.SLASH) && !patterns[i].startsWith(JarUtils.SLASH))
        buffer.append(JarUtils.SLASH);

      buffer.append(patterns[i]);
      try {
        resources[i] = resolver.getResources(buffer.toString());
      }
      catch (IOException ex) {
        IllegalStateException re = new IllegalStateException("cannot resolve pattern " + buffer.toString());
        re.initCause(ex);
        throw re;
View Full Code Here

    assertNotNull("noRootClassPath bundle was not found", bnd);
    return new OsgiBundleResourcePatternResolver(bnd);
  }

  public void testNoRootCpBundleResourceInRootNotFound() throws Exception {
    ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
    Resource[] res = resolver.getResources("classpath:root.file");
    // since there is no pattern matching, the loader will return a non-existing resource
    assertFalse("resource should not be found since / is not in the classpath", res[0].exists());
    System.out.println("classpath:root.file resources");
    printPathWithinContext(res);
  }
View Full Code Here

    System.out.println("classpath:root.file resources");
    printPathWithinContext(res);
  }

  public void testNoRootCpBundleResourceInRootNotFoundOnAllClasspaths() throws Exception {
    ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
    Resource[] res = resolver.getResources("classpath*:root.file");
    assertTrue("resource should not be found since / is not in the classpath", ObjectUtils.isEmpty(res));
    System.out.println("root.file resources");
    System.out.println("classpath*:root.file resources");
    printPathWithinContext(res);
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.io.support.ResourcePatternResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.