KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > core > io > support > ResourcePatternUtils


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.core.io.support;
18
19 import org.springframework.core.io.ResourceLoader;
20 import org.springframework.util.Assert;
21 import org.springframework.util.ResourceUtils;
22
23 /**
24  * Utility class for determining whether a given URL is a resource
25  * location that can be loaded via a ResourcePatternResolver.
26  *
27  * <p>Callers will usually assume that a location is a relative path
28  * if the <code>isUrl</code> method returns <code>false</code>.
29  *
30  * @author Juergen Hoeller
31  * @since 1.2.3
32  * @see #isUrl(String)
33  * @see org.springframework.util.ResourceUtils#isUrl(String)
34  */

35 public abstract class ResourcePatternUtils {
36
37     /**
38      * Return whether the given resource location is a URL: either a
39      * special "classpath" or "classpath*" pseudo URL or a standard URL.
40      * @see ResourcePatternResolver#CLASSPATH_URL_PREFIX
41      * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX
42      * @see org.springframework.util.ResourceUtils#isUrl(String)
43      * @see java.net.URL
44      */

45     public static boolean isUrl(String JavaDoc resourceLocation) {
46         if (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) {
47             return true;
48         }
49         return ResourceUtils.isUrl(resourceLocation);
50     }
51
52     /**
53      * Return a default ResourcePatternResolver for the given ResourceLoader.
54      * <p>This might be the ResourceLoader itself, if it implements the
55      * ResourcePatternResolver extension, or a PathMatchingResourcePatternResolver
56      * built on the given ResourceLoader.
57      * @param resourceLoader the ResourceLoader to build a pattern resolver for
58      * (not <code>null</code>)
59      * @return the ResourcePatternResolver
60      * @see PathMatchingResourcePatternResolver
61      */

62     public static ResourcePatternResolver getResourcePatternResolver(ResourceLoader resourceLoader) {
63         Assert.notNull(resourceLoader, "ResourceLoader must not be null");
64         if (resourceLoader instanceof ResourcePatternResolver) {
65             return (ResourcePatternResolver) resourceLoader;
66         }
67         else {
68             return new PathMatchingResourcePatternResolver(resourceLoader);
69         }
70     }
71
72 }
73
Popular Tags