01: /*
02: * $Id: ResourceFinderResourceStreamLocator.java,v 1.6 2006/01/02 07:13:35
03: * jdonnerstag Exp $ $Revision: 461190 $ $Date: 2006-06-28 08:35:51 +0200 (Wed, 28 Jun 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.util.resource.locator;
19:
20: import java.net.URL;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24:
25: import wicket.util.file.IResourceFinder;
26: import wicket.util.resource.IResourceStream;
27: import wicket.util.resource.UrlResourceStream;
28:
29: /**
30: * IResourceStreamLocator implementation that locates resources along a
31: * filesystem search path.
32: *
33: * @author Juergen Donnerstag
34: * @author Jonathan Locke
35: */
36: public class ResourceFinderResourceStreamLocator extends
37: AbstractResourceStreamLocator {
38: /** Logging */
39: private static final Log log = LogFactory
40: .getLog(ResourceFinderResourceStreamLocator.class);
41:
42: /** The finder to use to locate the resource stream */
43: private IResourceFinder finder;
44:
45: /**
46: * Constructor
47: *
48: * @param finder
49: * The path to search
50: */
51: public ResourceFinderResourceStreamLocator(
52: final IResourceFinder finder) {
53: this .finder = finder;
54: }
55:
56: /**
57: * @see wicket.util.resource.locator.AbstractResourceStreamLocator#locate(Class,
58: * java.lang.String)
59: */
60: public IResourceStream locate(final Class clazz, final String path) {
61: // Log attempt
62: if (log.isDebugEnabled()) {
63: log.debug("Attempting to locate resource '" + path
64: + "' on path " + finder);
65: }
66:
67: // Try to find file resource on the path supplied
68: final URL file = finder.find(path);
69:
70: // Found resource?
71: if (file != null) {
72: // Return file resource
73: return new UrlResourceStream(file);
74: }
75: return null;
76: }
77: }
|