KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > format > util > CLLoader


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9
10 package org.jboss.portal.format.util;
11
12 import java.io.InputStream JavaDoc;
13
14 /**
15  * Loader implementation that loads through a ClassLoader.
16  *
17  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
18  * @version $Revision: 1.1.1.1 $
19  */

20 public class CLLoader implements Loader
21 {
22
23    private final ClassLoader JavaDoc cl;
24    private String JavaDoc base;
25
26    public CLLoader()
27    {
28       this(Thread.currentThread().getContextClassLoader(), null);
29    }
30
31    public CLLoader(ClassLoader JavaDoc cl, String JavaDoc base)
32    {
33       this.cl = cl;
34       setBase(base);
35    }
36
37    public CLLoader(ClassLoader JavaDoc cl)
38    {
39       this(cl, null);
40    }
41
42    public CLLoader(String JavaDoc base)
43    {
44       this(Thread.currentThread().getContextClassLoader(), base);
45    }
46
47    public String JavaDoc getBase()
48    {
49       return base;
50    }
51
52    public void setBase(String JavaDoc base)
53    {
54       this.base = base != null ? base : "";
55    }
56
57    public InputStream JavaDoc load(String JavaDoc name)
58    {
59       return cl.getResourceAsStream(base.length() == 0 ? name.substring(1) : base + name);
60    }
61 }
62
Popular Tags