01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: AbstractResourceFinder.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.resources;
09:
10: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
11: import com.uwyn.rife.tools.InnerClassException;
12: import com.uwyn.rife.tools.InputStreamUser;
13: import java.net.URL;
14:
15: /**
16: * This abstract class offers common implementations of several
17: * <code>ResourceFinder</code> methods. This makes it easier to implement
18: * specific <code>ResourceFinder</code> classes.
19: * <p>
20: * All method implementations here accept resource specification as names and
21: * correctly defer the actual logic to the methods that accept resource
22: * specification as URLs.
23: *
24: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
25: * @version $Revision: 3634 $
26: * @see com.uwyn.rife.resources.ResourceFinder
27: * @since 1.0
28: */
29: public abstract class AbstractResourceFinder implements ResourceFinder {
30: public <ResultType> ResultType useStream(String name,
31: InputStreamUser user) throws ResourceFinderErrorException,
32: InnerClassException {
33: if (null == name || null == user) {
34: return null;
35: }
36:
37: URL resource = getResource(name);
38: if (null == resource) {
39: return null;
40: }
41:
42: return (ResultType) useStream(resource, user);
43: }
44:
45: public String getContent(String name)
46: throws ResourceFinderErrorException {
47: return getContent(name, null);
48: }
49:
50: public String getContent(String name, String encoding)
51: throws ResourceFinderErrorException {
52: if (null == name) {
53: return null;
54: }
55:
56: URL resource = getResource(name);
57: if (null == resource) {
58: return null;
59: }
60:
61: return getContent(resource, encoding);
62: }
63:
64: public String getContent(URL resource)
65: throws ResourceFinderErrorException {
66: return getContent(resource, null);
67: }
68:
69: public long getModificationTime(String name)
70: throws ResourceFinderErrorException {
71: if (null == name) {
72: return -1;
73: }
74:
75: URL resource = getResource(name);
76: if (null == resource) {
77: return -1;
78: }
79:
80: return getModificationTime(resource);
81: }
82: }
|