|
|||||||||||||||||||
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 | |||||||||||||||
FileResource.java | 100% | 88.9% | 100% | 93.1% |
|
1 |
// Copyright 2004 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.io.File;
|
|
18 |
import java.net.MalformedURLException;
|
|
19 |
import java.net.URL;
|
|
20 |
import java.util.Locale;
|
|
21 |
|
|
22 |
import org.apache.commons.logging.Log;
|
|
23 |
import org.apache.commons.logging.LogFactory;
|
|
24 |
import org.apache.hivemind.Resource;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* An implementation of {@link org.apache.hivemind.Resource} built around
|
|
28 |
* {@link java.io.File}.
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
*/
|
|
32 |
public class FileResource extends AbstractResource |
|
33 |
{ |
|
34 |
private static final Log LOG = LogFactory.getLog(FileResource.class); |
|
35 |
|
|
36 | 14 |
public FileResource(String path)
|
37 |
{ |
|
38 | 14 |
super(path);
|
39 |
} |
|
40 |
|
|
41 | 1 |
public FileResource(String path, Locale locale)
|
42 |
{ |
|
43 | 1 |
super(path, locale);
|
44 |
} |
|
45 |
|
|
46 | 1 |
protected Resource newResource(String path)
|
47 |
{ |
|
48 | 1 |
return new FileResource(path); |
49 |
} |
|
50 |
|
|
51 | 10 |
private File getFile()
|
52 |
{ |
|
53 | 10 |
return new File(getPath()); |
54 |
} |
|
55 |
|
|
56 | 10 |
public URL getResourceURL()
|
57 |
{ |
|
58 | 10 |
File file = getFile(); |
59 |
|
|
60 | 10 |
try
|
61 |
{ |
|
62 | 10 |
if (file == null || !file.exists()) |
63 | 1 |
return null; |
64 |
|
|
65 | 9 |
return file.toURL();
|
66 |
} |
|
67 |
catch (MalformedURLException ex)
|
|
68 |
{ |
|
69 | 0 |
LOG.error(UtilMessages.badFileURL(getPath(), ex), ex); |
70 | 0 |
return null; |
71 |
} |
|
72 |
} |
|
73 |
|
|
74 | 2 |
public Resource getLocalization(Locale locale)
|
75 |
{ |
|
76 | 2 |
LocalizedFileResourceFinder f = new LocalizedFileResourceFinder();
|
77 |
|
|
78 | 2 |
String path = getPath(); |
79 |
|
|
80 | 2 |
String finalPath = f.findLocalizedPath(path, locale); |
81 |
|
|
82 | 2 |
if (finalPath.equals(path))
|
83 | 1 |
return this; |
84 |
|
|
85 | 1 |
return newResource(finalPath);
|
86 |
} |
|
87 |
|
|
88 | 9 |
public String toString()
|
89 |
{ |
|
90 | 9 |
return getPath();
|
91 |
} |
|
92 |
|
|
93 |
} |
|
94 |
|
|