Example usage for org.springframework.core.io.support PathMatchingResourcePatternResolver PathMatchingResourcePatternResolver

List of usage examples for org.springframework.core.io.support PathMatchingResourcePatternResolver PathMatchingResourcePatternResolver

Introduction

In this page you can find the example usage for org.springframework.core.io.support PathMatchingResourcePatternResolver PathMatchingResourcePatternResolver.

Prototype

public PathMatchingResourcePatternResolver(@Nullable ClassLoader classLoader) 

Source Link

Document

Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader.

Usage

From source file:ai.emot.demo.EmotAIDemo.java

public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length != 2) {
        printUsage();/*from   w  w w .ja  v a2  s  . c  om*/
        System.exit(0);
    }

    String emotAIAPIBaseUrl = args[0];
    String accessToken = args[1];

    PathMatchingResourcePatternResolver fileResolver = new PathMatchingResourcePatternResolver(
            EmotAIDemo.class.getClassLoader());
    Resource[] resources = fileResolver.getResources("images");
    File dir = resources[0].getFile();
    File imagesDir = new File(dir, "/face/cropped");

    EmotAI emotAI = new EmotAITemplate(emotAIAPIBaseUrl, accessToken);

    // Create a display for the images
    ImageDisplay<Long> imageDisplay = new ImageDisplay<Long>(250, 250);

    for (File imageFile : imagesDir.listFiles(new JpegFileFilter())) {
        // Read each image
        BufferedImage image = ImageIO.read(imageFile);

        // Get the emotion profile for each image
        EmotionProfile emotionProfile = emotAI.emotionOperations().getFaceImageEmotionProfile(image);

        // Output emotion, and display image
        System.out.println(imageFile.getName() + " : " + emotionProfile);
        imageDisplay.onFrameUpdate(new SerializableBufferedImageAdapter(image), 1l);

        // Sleep for 1 second
        Thread.sleep(1000);

    }

    System.exit(1);
}

From source file:org.syncope.hibernate.HibernateEnhancer.java

public static void main(final String[] args) throws Exception {

    if (args.length != 1) {
        throw new IllegalArgumentException("Expecting classpath as single argument");
    }// w  w  w . j  a v a2s  .c om

    ClassPool classPool = ClassPool.getDefault();
    classPool.appendClassPath(args[0]);

    PathMatchingResourcePatternResolver resResolver = new PathMatchingResourcePatternResolver(
            classPool.getClassLoader());
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    for (Resource resource : resResolver.getResources("classpath*:org/syncope/core/**/*.class")) {

        MetadataReader metadataReader = cachingMetadataReaderFactory.getMetadataReader(resource);
        if (metadataReader.getAnnotationMetadata().isAnnotated(Entity.class.getName())) {

            Class entity = Class.forName(metadataReader.getClassMetadata().getClassName());
            classPool.appendClassPath(new ClassClassPath(entity));
            CtClass ctClass = ClassPool.getDefault().get(entity.getName());
            if (ctClass.isFrozen()) {
                ctClass.defrost();
            }
            ClassFile classFile = ctClass.getClassFile();
            ConstPool constPool = classFile.getConstPool();

            for (Field field : entity.getDeclaredFields()) {
                if (field.isAnnotationPresent(Lob.class)) {
                    AnnotationsAttribute typeAttr = new AnnotationsAttribute(constPool,
                            AnnotationsAttribute.visibleTag);
                    Annotation typeAnnot = new Annotation("org.hibernate.annotations.Type", constPool);
                    typeAnnot.addMemberValue("type",
                            new StringMemberValue("org.hibernate.type.StringClobType", constPool));
                    typeAttr.addAnnotation(typeAnnot);

                    CtField lobField = ctClass.getDeclaredField(field.getName());
                    lobField.getFieldInfo().addAttribute(typeAttr);
                }
            }

            ctClass.writeFile(args[0]);
        }
    }
}

From source file:org.springsource.sinspctr.rest.ResourceLocator.java

public static String[] findResourcesPaths(String locationPattern) throws IOException {
    ClassLoader loader = findClassLoader();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
    Resource[] resources = resolver.getResources(locationPattern);
    // use project-relative path if appropriate
    String rootPath = resolver.getResource(".").getFile().getPath();
    String[] results = new String[resources.length];
    for (int i = 0; i < resources.length; i++) {
        String path = resources[i].getFile().getPath();
        if (path.startsWith(rootPath)) {
            path = path.substring(rootPath.length(), path.length());
        }//from  w w w . j a  v a  2s.co  m
        results[i] = path;
    }
    return results;
}

From source file:com.jk.annotations.AnnotationDetector.java

/**
 * Utility method to scan the given package and handler for the annotation
 * of the given class. Its uses the Spring annotation detector
 *
 * @param clas//from   www  .  j a  v  a2  s  .  co  m
 *            the clas
 * @param basePackage
 *            the base package
 * @param handler
 *            the handler
 */
public static void scan(final Class<? extends Annotation> clas, final String[] basePackage,
        final AnnotationHandler handler) {
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);
    scanner.setResourceLoader(
            new PathMatchingResourcePatternResolver(Thread.currentThread().getContextClassLoader()));
    scanner.addIncludeFilter(new AnnotationTypeFilter(clas));
    for (final String pck : basePackage) {
        for (final BeanDefinition bd : scanner.findCandidateComponents(pck)) {
            handler.handleAnnotationFound(bd.getBeanClassName());
        }
    }
}

From source file:com.github.mybatis.repository.autoconfig.SpringBootVFS.java

public SpringBootVFS() {
    this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
}

From source file:com.czy.core.orm.config.mybatis.SpringBootVFS.java

@Override
protected List<String> list(URL url, String path) throws IOException {
    ClassLoader cl = this.getClass().getClassLoader();
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource[] resources = resolver.getResources("classpath*:" + path + "/**/*.class");
    List<Resource> resources1 = Arrays.asList(resources);
    List<String> resourcePaths = new ArrayList<String>();
    for (Resource resource : resources1) {
        resourcePaths.add(preserveSubpackageName(resource.getURI(), path));
    }//  w  w  w  .j av a 2  s  .c  o m
    return resourcePaths;
}

From source file:de.tudarmstadt.ukp.lmf.hibernate.HibernateConnect.java

/**
 * Creates Hibernate {@link Configuration} and adds all files from Hibernate mapping folder to
 * the model./*  ww w. j  av  a2  s .c om*/
 *
 * @param dbConfig
 *            database configuration holder
 *
 * @return the created Hibernate Configuration
 */
public static Configuration getConfiguration(DBConfig dbConfig) {
    Configuration cfg = new Configuration()
            .addProperties(getProperties(dbConfig.getJdbc_url(), dbConfig.getJdbc_driver_class(),
                    dbConfig.getDb_vendor(), dbConfig.getUser(), dbConfig.getPassword(), dbConfig.isShowSQL()));

    // load hibernate mappings
    ClassLoader cl = HibernateConnect.class.getClassLoader();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource[] mappings = null;
    try {
        mappings = resolver.getResources("hibernatemap/access/**/*.hbm.xml");
        for (Resource mapping : mappings) {
            cfg.addURL(mapping.getURL());
        }

    } catch (IOException e) {
        logger.error("Hibernate mappings not found!");
        e.printStackTrace();
    }

    return cfg;
}

From source file:org.apache.uima.ruta.resource.RutaResourceLoader.java

/**
 * @param resourcePaths Resource paths to search in priority.
 *///from w w  w. j av a  2s.  c om
public RutaResourceLoader(String[] resourcePaths) {
    this.wrapped = new PathMatchingResourcePatternResolver(new ResourcePathResourceLoader(resourcePaths));
    this.fallback = new DefaultResourceLoader();
}

From source file:griffon.plugins.i18n.ExtendedResourceBundleMessageSource.java

private void createResolver() {
    resolver = new PathMatchingResourcePatternResolver(getBundleClassLoader());
}

From source file:io.wcm.devops.conga.resource.ClasspathResourceCollectionImpl.java

ClasspathResourceCollectionImpl(String path, ResourceLoader resourceLoader) {
    super(path, resourceLoader.getClassLoader());
    this.resourceLoader = resourceLoader;

    try {/*w ww.  ja  v a2s.  c o  m*/
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
                this.classLoader);
        org.springframework.core.io.Resource[] classpathResources = resolver
                .getResources("classpath*:" + convertPath(path) + "/*");
        for (org.springframework.core.io.Resource resource : classpathResources) {
            if (isFolder(resource)) {
                folderPaths.add(path + "/" + resource.getFilename());
            } else {
                fileUrls.add(resource.getURL());
            }
        }
    } catch (FileNotFoundException ex) {
        // empty folder
    } catch (IOException ex) {
        throw new ResourceException("Unable to enumerate classpath resources at " + path, ex);
    }
}