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

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

Introduction

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

Prototype

@Override
    public Resource[] getResources(String locationPattern) throws IOException 

Source Link

Usage

From source file:org.wallride.tools.Hbm2ddl.java

public static void main(String[] args) throws Exception {
    String locationPattern = "classpath:/org/wallride/domain/*";

    final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
    final MetadataSources metadataSources = new MetadataSources(registry);
    final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry);

    registryBuilder.applySetting(AvailableSettings.DIALECT,
            ExtendedMySQL5InnoDBDialect.class.getCanonicalName());
    registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true);
    registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY,
            PhysicalNamingStrategySnakeCaseImpl.class);

    final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    final Resource[] resources = resourcePatternResolver.getResources(locationPattern);
    final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    for (Resource resource : resources) {
        MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
        AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
        if (metadata.hasAnnotation(Entity.class.getName())) {
            metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName()));
        }//from   w  w  w .j  a v  a2 s .  c  o  m
    }

    final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build();
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl);

    new SchemaExport().setHaltOnError(true).setDelimiter(";").create(EnumSet.of(TargetType.STDOUT),
            metadataBuilder.build());
}

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 .j  a v  a2 s .  c o m
        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");
    }// www .  j  a  va  2  s.  c  o  m

    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:fr.certu.chouette.command.Command.java

/**
 * @param args/* w  w  w.j  a v a2s  .  c  om*/
 */
public static void main(String[] args) {
    // pattern partially work
    String[] context = { "classpath*:/chouetteContext.xml" };

    if (args.length >= 1) {
        if (args[0].equalsIgnoreCase("-help") || args[0].equalsIgnoreCase("-h")) {
            printHelp();
            System.exit(0);
        }

        if (args[0].equalsIgnoreCase("-noDao")) {
            List<String> newContext = new ArrayList<String>();
            PathMatchingResourcePatternResolver test = new PathMatchingResourcePatternResolver();
            try {
                Resource[] re = test.getResources("classpath*:/chouetteContext.xml");
                for (Resource resource : re) {
                    if (!resource.getURL().toString().contains("dao")) {
                        newContext.add(resource.getURL().toString());
                    }
                }
                context = newContext.toArray(new String[0]);
                dao = false;
            } catch (Exception e) {

                System.err.println("cannot remove dao : " + e.getLocalizedMessage());
            }
        }
        applicationContext = new ClassPathXmlApplicationContext(context);
        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
        Command command = (Command) factory.getBean("Command");

        initDao();

        command.execute(args);

        closeDao();

        System.runFinalization();

    } else {
        printHelp();
    }
}

From source file:dkpro.toolbox.corpus.util.ToolboxUtils.java

public static Resource[] getResources(String path) throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    return resolver.getResources(path);
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.data.util.DataUtil.java

public static Map<String, String> getAllDatasets(String path, String[] extensions) throws IOException {

    Map<String, String> datasetMap = new HashMap<String, String>();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (Resource resource : resolver.getResources(path)) {
        for (File datasetFile : FileUtils.listFiles(resource.getFile(), extensions, true)) {
            datasetMap.put(datasetFile.getAbsolutePath(), datasetFile.getParentFile().getName());
        }//from   w  w  w  . j a  v  a 2  s .  com
    }

    return datasetMap;
}

From source file:com.jaxio.celerio.util.XsdHelper.java

public static String getResourceContentAsString(String resourcePath) {
    PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver();

    try {//w ww.  ja  v a 2s .  c  o m
        Resource packInfosAsResource[] = o.getResources(resourcePath);
        for (Resource r : packInfosAsResource) {
            return IOUtils.toString(r.getInputStream());
        }
        return null;
    } catch (IOException ioe) {
        throw new RuntimeException("Error while searching for : " + resourcePath, ioe);
    }
}

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. ja  v  a2  s. c o  m*/
        results[i] = path;
    }
    return results;
}

From source file:com.charandeepmatta.database.di.Schema.java

public static void createDatabase(final DataSource dataSource) throws IOException {
    JdbcTemplate jdbc = new JdbcTemplate(dataSource);
    updateSqlFromFile(jdbc, "base.sql");
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Integer i = 0;//from   ww  w  .  j a v a 2  s  .  c o m
    while (true) {
        i++;
        Resource[] resources = resolver.getResources("classpath*:" + leftPad(i.toString(), 3, "0") + "_*.sql");
        if (resources.length == 0) {
            break;
        }
        updateSqlTo(jdbc, resources[0].getInputStream());
    }
}

From source file:com.textocat.textokit.morph.dictionary.MorphDictionaryAPIFactory.java

private static synchronized void initialize() {
    if (defaultApi != null) {
        return;/*from www.j a va 2  s . c om*/
    }
    log.info("Searching for MorphDictionaryAPI implementations...");
    Set<String> implClassNames = Sets.newHashSet();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        for (Resource implDeclRes : resolver
                .getResources("classpath*:META-INF/uima-ext/morph-dictionary-impl.txt")) {
            InputStream is = implDeclRes.getInputStream();
            try {
                String implClassName = IOUtils.toString(is, "UTF-8").trim();
                if (!implClassNames.add(implClassName)) {
                    throw new IllegalStateException(
                            String.format(
                                    "The classpath contains duplicate declaration of implementation '%s'. "
                                            + "Last one has been read from %s.",
                                    implClassName, implDeclRes.getURL()));
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    if (implClassNames.isEmpty()) {
        throw new IllegalStateException(String.format("Can't find an implementation of MorphDictionaryAPI"));
    }
    if (implClassNames.size() > 1) {
        throw new IllegalStateException(String.format("More than one implementations have been found:\n%s\n"
                + "Adjust the app classpath or get an implementation by ID.", implClassNames));
    }
    String implClassName = implClassNames.iterator().next();
    log.info("Found MorphDictionaryAPI implementation: {}", implClassName);
    try {
        @SuppressWarnings("unchecked")
        Class<? extends MorphDictionaryAPI> implClass = (Class<? extends MorphDictionaryAPI>) Class
                .forName(implClassName);
        defaultApi = implClass.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException("Can't instantiate the MorphDictionaryAPI implementation", e);
    }
}