KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > properties > TCCLXProperties


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

11 package org.jboss.portlet.forums.properties;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Properties JavaDoc;
19
20 import org.jboss.portlet.forums.ForumsConstants;
21 import org.jboss.portal.common.util.Tools;
22
23 /**
24  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
25  * @version $Revision: 1.3 $
26  */

27 public class TCCLXProperties
28    extends XProperties
29 {
30    private Map JavaDoc props = new HashMap JavaDoc();
31    private Map JavaDoc urls = new HashMap JavaDoc();
32
33    /**
34     * Creates a new {@link TCCLXProperties} object.
35     *
36     * @param base DOCUMENT_ME
37     * @param name DOCUMENT_ME
38     *
39     * @throws IOException DOCUMENT_ME
40     */

41    public TCCLXProperties(String JavaDoc base,
42                           String JavaDoc name)
43    throws IOException JavaDoc
44    {
45       this(Thread.currentThread().getContextClassLoader(), base, name);
46    }
47
48    /**
49     * Creates a new {@link TCCLXProperties} object.
50     *
51     * @param loader DOCUMENT_ME
52     * @param base DOCUMENT_ME
53     * @param name DOCUMENT_ME
54     *
55     * @throws IOException DOCUMENT_ME
56     */

57    public TCCLXProperties(ClassLoader JavaDoc loader,
58                           String JavaDoc base,
59                           String JavaDoc name)
60    throws IOException JavaDoc
61    {
62       InputStream JavaDoc in = null;
63       try
64       {
65          // load the data
66
in = loader.getResourceAsStream(base + "/" + name);
67
68          // feed the properties
69
Properties JavaDoc temp = new Properties JavaDoc();
70          temp.load(in);
71          props.putAll(temp);
72
73          // feed the URLs
74
// String resourceBase = base.substring("org.jboss.portlet/forums/".length()) + "/";
75
// String resourceBase = base + "/";
76
for (Iterator JavaDoc i = props.entrySet().iterator(); i.hasNext();)
77          {
78             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
79
80             // TODO: remove hardcoded link
81
urls.put(entry.getKey(),
82                      "/portal-forums/" + ForumsConstants.THEMENAME + "/" + entry.getValue());
83          }
84       }
85       finally
86       {
87          Tools.safeClose(in);
88       }
89    }
90
91    /**
92     * DOCUMENT_ME
93     *
94     * @param name DOCUMENT_ME
95     *
96     * @return DOCUMENT_ME
97     */

98    public String JavaDoc getProperty(String JavaDoc name)
99    {
100       Object JavaDoc value = props.get(name);
101       return (value != null) ? (String JavaDoc) value : "";
102    }
103
104    /**
105     * DOCUMENT_ME
106     *
107     * @param name DOCUMENT_ME
108     *
109     * @return DOCUMENT_ME
110     */

111    public String JavaDoc getResourceURL(String JavaDoc name)
112    {
113       Object JavaDoc value = urls.get(name);
114       return (value != null) ? (String JavaDoc) value : "";
115    }
116 }
Popular Tags