Package org.springframework.core.io.support

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


        throws IOException {
        final List<URL> resourceURLs = new ArrayList<URL>();
        if (basePackages == null || basePackages.isEmpty()) {
            return resourceURLs;
        }
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
       
       
       
        for (final String basePackage: basePackages) {
            final boolean scanAllPackages = basePackage.equals(ALL_PACKAGES);
           
            String theBasePackage = basePackage;
            if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
                theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
            }
           
            final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(theBasePackage))
                + ALL_FILES + "." + extension;
           
            final Resource[] resources = resolver.getResources(packageSearchPath);                       
            for (final Resource resource: resources) {
                resourceURLs.add(resource.getURL());
            }                       
        }
       
View Full Code Here


   * @return the corresponding BeanFactory reference
   */
  protected BeanFactory createDefinition(String resourceLocation, String factoryKey) {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

    try {
      Resource[] configResources = resourcePatternResolver.getResources(resourceLocation);
      if (configResources.length == 0) {
        throw new FatalBeanException("Unable to find resource for specified definition. " +
            "Group resource name [" + this.resourceLocation + "], factory key [" + factoryKey + "]");
      }
      reader.loadBeanDefinitions(configResources);
View Full Code Here

            public void init(VelocityConfiguration configuration) throws Exception {
                this.configuration = configuration;
            }

            public Resource[] getMacros() throws IOException {
                ResourcePatternResolver resolver = (ResourcePatternResolver) configuration.getResourceLoader();
                String pattern = "classpath:" + PluginDelegator.class.getPackage().getName().replace('.', '/')
                                 + "/*.vm";
                Resource[] resources = resolver.getResources(pattern);

                return resources;
            }
        });

View Full Code Here

        // 无classpath前缀
        assertResource("java/lang/String.class", contextResourceType(), "java/util/List.class");

        // resource pattern
        ResourcePatternResolver resolver = createMock(ResourcePatternResolver.class);
        expect(resolver.getResources("WEB-INF/*")).andReturn(
                new Resource[] { new FileSystemResource(new File(srcdir, "beans.xml")) }).anyTimes();

        replay(resolver);

        loader.setResolver(resolver);
View Full Code Here

    wf.setMaxLength(maxLength);
    wf.setMinLength(minLength);
   
    cs.setWordFactory(wf);
   
    ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver();
    Resource resource = rpr.getResource("classpath:" + CACHE_FILE);
   
    try {
      CacheManager cacheManager = CacheManager.create(resource.getInputStream());
     
      cache = cacheManager.getCache(CACHE_NAME);
View Full Code Here

        // 无classpath前缀
        assertResource("java/lang/String.class", contextResourceType(), "java/util/List.class");

        // resource pattern
        ResourcePatternResolver resolver = createMock(ResourcePatternResolver.class);
        expect(resolver.getResources("WEB-INF/*")).andReturn(
                new Resource[] { new FileSystemResource(new File(srcdir, "beans.xml")) }).anyTimes();

        replay(resolver);

        loader.setResolver(resolver);
View Full Code Here

    fileSender.send(getResource(path).getFile());
    return true;
  }

  public int countFiles() {
    ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    Resource[] resources;
    try {
      resources = resolver.getResources("file:///" + outputDir.getAbsolutePath() + "/**");
    }
    catch (IOException e) {
      throw new IllegalStateException("Unexpected problem resolving files", e);
    }
    return resources.length;
View Full Code Here

    return new ArrayList<FileInfo>(files.subList(startFile, Math.min(startFile + pageSize, files.size())));

  }

  private List<FileInfo> getFiles(String pattern) {
    ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    List<Resource> resources = new ArrayList<Resource>();

    if (!pattern.startsWith("/")) {
      pattern = "/" + outputDir.getAbsolutePath() + "/" + pattern;
    }
    if (!pattern.startsWith("file:")) {
      pattern = "file:///" + pattern;
    }

    try {
      resources = Arrays.asList(resolver.getResources(pattern));
    }
    catch (IOException e) {
      logger.debug("Cannot locate files " + pattern, e);
      return new ArrayList<FileInfo>();
    }
View Full Code Here

  }

  public int delete(String pattern) throws IOException {

    ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
    if (!pattern.startsWith("/")) {
      pattern = "/" + outputDir.getAbsolutePath() + "/" + pattern;
    }
    if (!pattern.startsWith("file:")) {
      pattern = "file:///" + pattern;
    }

    Resource[] resources = resolver.getResources(pattern);

    int count = 0;
    for (Resource resource : resources) {
      File file = resource.getFile();
      if (file.isFile()) {
View Full Code Here

   * @return List包含className
   */
  @SuppressWarnings("all")
  public static List<String> scanPackages(String basePackages) throws IllegalArgumentException{
    Assert.notNull(basePackages,"'basePakcages' must be not null");
    ResourcePatternResolver rl = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(rl);
    List result = new ArrayList();
    String[] arrayPackages = basePackages.split(",");
    try {
      for(int j = 0; j < arrayPackages.length; j++) {
        String packageToScan = arrayPackages[j];
        String packagePart = packageToScan.replace('.', '/');
        String classPattern = "classpath*:/" + packagePart + "/**/*.class";
        Resource[] resources = rl.getResources(classPattern);
        for (int i = 0; i < resources.length; i++) {
          Resource resource = resources[i];
          MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);  
          String className = metadataReader.getClassMetadata().getClassName();
          result.add(className);
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.