Java Code Examples for org.springframework.core.io.support.ResourcePatternResolver

Following code examples demonstrate how to use org.springframework.core.io.support.ResourcePatternResolver from spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.core.io.support.ResourcePatternResolver and various code implementation of this class.
Example 1
Project : spring-framework Source File : ResourceEditorRegistrar.java View Source Code on GitHub

	public void registerCustomEditors(PropertyEditorRegistry registry) {
		ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader);
		registry.registerCustomEditor(Resource.class, baseEditor);
		registry.registerCustomEditor(InputStream.class, new InputStreamEditor(baseEditor));
		registry.registerCustomEditor(File.class, new FileEditor(baseEditor));
		registry.registerCustomEditor(URL.class, new URLEditor(baseEditor));

		ClassLoader classLoader = this.resourceLoader.getClassLoader();
		registry.registerCustomEditor(Class.class, new ClassEditor(classLoader));
		registry.registerCustomEditor(URI.class, new URIEditor(classLoader));

		if (this.resourceLoader instanceof ResourcePatternResolver) {
			registry.registerCustomEditor(Resource[].class,
					new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader));
		}
	}
			
Example 2
Project : spring-framework Source File : NamedQueryUtil.java View Source Code on GitHub

    public static <Condition extends BaseQueryCondition> String getDynamicSql(Class<Condition> condition) {

        String text = null;
        String classpath = ReflectUtil.getClasspath(condition);
        String name = ReflectUtil.getName(condition);
        String queryName = name.substring(0, name.lastIndexOf("Condition"));
            try {
                String searchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                        + org.springframework.util.ClassUtils.convertClassNameToResourcePath(classpath) + "/"
                        + name.substring(0, name.lastIndexOf("Condition")) + ".hbm.xml";
                org.springframework.core.io.support.ResourcePatternResolver resourcePatternResolver = new org.springframework.core.io.support.PathMatchingResourcePatternResolver();
                org.springframework.core.io.Resource[] resources = resourcePatternResolver.getResources(searchPath);
                InputStream is = resources[0].getInputStream();
                XmlParseUtil parseUtil = XmlParseUtil.getInstance(is);
                List<Element> children = parseUtil.getChildElement("sql-query");
                Element child = children.get(0);
                text = child.getText().trim();
                
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
            text = queryStringMap.get(queryName);
        }
			
Example 3
Project : spring-framework Source File : NamedQueryUtil.java View Source Code on GitHub

    public static <Condition extends BaseQueryCondition> String getSql(Class<Condition> condition) {
        NamedSQLQueryDefinition nsq;
        String classpath = ReflectUtil.getClasspath(condition);
        String name = ReflectUtil.getName(condition);
        String queryName = name.substring(0, name.lastIndexOf("Condition"));

            try {
                String searchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                        + org.springframework.util.ClassUtils.convertClassNameToResourcePath(classpath) + "/"
                        + name.substring(0, name.lastIndexOf("Condition")) + ".hbm.xml";
                Configuration cfg = new Configuration();
                org.springframework.core.io.support.ResourcePatternResolver resourcePatternResolver = new org.springframework.core.io.support.PathMatchingResourcePatternResolver();
                org.springframework.core.io.Resource[] resources = resourcePatternResolver.getResources(searchPath);
                cfg.addInputStream(resources[0].getInputStream());
                cfg.buildMappings();
                Object obj = cfg.getNamedSQLQueries().get(queryName);
                nsq = (NamedSQLQueryDefinition) obj;
                String queryStr = nsq.getQuery();

                queryStringMap.put(queryName, queryStr);

                return queryStr;
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }