|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ClasspathResource.java | 83.3% | 94.7% | 100% | 93.8% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.util;
|
|
16 |
|
|
17 |
import java.net.URL;
|
|
18 |
import java.util.Locale;
|
|
19 |
|
|
20 |
import org.apache.hivemind.ClassResolver;
|
|
21 |
import org.apache.hivemind.Resource;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Implementation of {@link org.apache.hivemind.Resource}
|
|
25 |
* for resources found within the classpath.
|
|
26 |
*
|
|
27 |
*
|
|
28 |
* @author Howard Lewis Ship
|
|
29 |
*/
|
|
30 |
|
|
31 |
public class ClasspathResource extends AbstractResource |
|
32 |
{ |
|
33 |
private ClassResolver _resolver;
|
|
34 |
|
|
35 | 105 |
public ClasspathResource(ClassResolver resolver, String path)
|
36 |
{ |
|
37 | 105 |
this(resolver, path, null); |
38 |
} |
|
39 |
|
|
40 | 107 |
public ClasspathResource(ClassResolver resolver, String path, Locale locale)
|
41 |
{ |
|
42 | 107 |
super(path, locale);
|
43 |
|
|
44 | 107 |
_resolver = resolver; |
45 |
} |
|
46 |
|
|
47 |
/**
|
|
48 |
* Locates the localization of the
|
|
49 |
* resource using {@link LocalizedResourceFinder}.
|
|
50 |
*/
|
|
51 |
|
|
52 | 7 |
public Resource getLocalization(Locale locale)
|
53 |
{ |
|
54 | 7 |
String path = getPath(); |
55 | 7 |
LocalizedResourceFinder finder = new LocalizedResourceFinder(_resolver);
|
56 |
|
|
57 | 7 |
LocalizedResource localizedResource = finder.resolve(path, locale); |
58 |
|
|
59 | 7 |
if (localizedResource == null) |
60 | 2 |
return null; |
61 |
|
|
62 | 5 |
String localizedPath = localizedResource.getResourcePath(); |
63 | 5 |
Locale pathLocale = localizedResource.getResourceLocale(); |
64 |
|
|
65 | 5 |
if (localizedPath == null) |
66 | 0 |
return null; |
67 |
|
|
68 | 5 |
if (path.equals(localizedPath))
|
69 | 3 |
return this; |
70 |
|
|
71 | 2 |
return new ClasspathResource(_resolver, localizedPath, pathLocale); |
72 |
} |
|
73 |
|
|
74 |
/**
|
|
75 |
* Invokes {@link ClassResolver#getResource(String)} with the path.
|
|
76 |
*/
|
|
77 |
|
|
78 | 6 |
public URL getResourceURL()
|
79 |
{ |
|
80 | 6 |
return _resolver.getResource(getPath());
|
81 |
} |
|
82 |
|
|
83 | 28 |
public String toString()
|
84 |
{ |
|
85 | 28 |
return "classpath:" + getPath(); |
86 |
} |
|
87 |
|
|
88 | 8 |
public int hashCode() |
89 |
{ |
|
90 | 8 |
return 4783 & getPath().hashCode();
|
91 |
} |
|
92 |
|
|
93 | 16 |
protected Resource newResource(String path)
|
94 |
{ |
|
95 | 16 |
return new ClasspathResource(_resolver, path); |
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
|
|