01: /*--
02:
03: Copyright (C) 2000-2003 Anthony Eden.
04: All rights reserved.
05:
06: Redistribution and use in source and binary forms, with or without
07: modification, are permitted provided that the following conditions
08: are met:
09:
10: 1. Redistributions of source code must retain the above copyright
11: notice, this list of conditions, and the following disclaimer.
12:
13: 2. Redistributions in binary form must reproduce the above copyright
14: notice, this list of conditions, and the disclaimer that follows
15: these conditions in the documentation and/or other materials
16: provided with the distribution.
17:
18: 3. The name "EdenLib" must not be used to endorse or promote products
19: derived from this software without prior written permission. For
20: written permission, please contact me@anthonyeden.com.
21:
22: 4. Products derived from this software may not be called "EdenLib", nor
23: may "EdenLib" appear in their name, without prior written permission
24: from Anthony Eden (me@anthonyeden.com).
25:
26: In addition, I request (but do not require) that you include in the
27: end-user documentation provided with the redistribution and/or in the
28: software itself an acknowledgement equivalent to the following:
29: "This product includes software developed by
30: Anthony Eden (http://www.anthonyeden.com/)."
31:
32: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
33: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
36: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42: POSSIBILITY OF SUCH DAMAGE.
43:
44: For more information on EdenLib, please see <http://edenlib.sf.net/>.
45:
46: */
47:
48: package com.anthonyeden.lib.resource;
49:
50: import java.io.InputStream;
51:
52: import org.apache.commons.logging.Log;
53: import org.apache.commons.logging.LogFactory;
54:
55: import com.anthonyeden.lib.util.ClassUtilities;
56: import com.anthonyeden.lib.util.IOUtilities;
57:
58: /** Implementation of the ResourceLoader interface which loads data from
59: the class path. This ResourceLoader does not monitor the resource.
60:
61: @author Anthony Eden
62: */
63:
64: public class ClassPathResourceLoader extends AbstractResourceLoader {
65:
66: private static final Log log = LogFactory
67: .getLog(ClassPathResourceLoader.class);
68:
69: /** Load the resource specified by the given path. This ResourceLoader
70: does not monitor the resource even if the value of monitor is true.
71:
72: @param path The path
73: @param handler The ResourceRecipient callback
74: @param monitor Ignored by this resource loader
75: @throws ResourceException
76: */
77:
78: public void loadResource(String path, ResourceRecipient handler,
79: boolean monitor) throws ResourceException {
80: InputStream in = null;
81: try {
82: in = ClassUtilities.getResourceAsStream(path, this );
83: log.debug("Resource path: " + path);
84: handler.load(in);
85: } catch (Exception e) {
86: e.printStackTrace();
87: throw new ResourceException(e);
88: } finally {
89: IOUtilities.close(in);
90: }
91: }
92:
93: }
|