01: package com.jat.presentation.help;
02:
03: import java.util.Enumeration;
04: import java.util.Vector;
05:
06: import com.jat.core.config.Config;
07:
08: /**
09: * <p>Title: JAT</p>
10: * <p>Description: </p>
11: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
12: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
13: * @author stf
14: * @version 1.0
15: * @since 1.2
16: */
17:
18: public class Help {
19:
20: public static String HELP_SECTION = "help";
21: public static String HELP_KEY = "help";
22: public static String FIELD_TITLE = ".title";
23: public static String FIELD_TOPIC_KEY = ".topic";
24: public static String FIELD_CONTENT_KEY = ".content";
25:
26: public boolean containsTitle(String title) throws Exception {
27: return this .getKeyByTitle(title) != null;
28: }
29:
30: public Vector getTopics() throws Exception {
31: Config config = Config.getCurrent();
32: Vector ret = new Vector();
33: for (Enumeration e = config.getSubKeys(HELP_SECTION, HELP_KEY)
34: .elements(); e.hasMoreElements();) {
35: String key = (String) e.nextElement();
36: Vector topics = this .getContentsByTitle(key);
37: for (Enumeration el = topics.elements(); el
38: .hasMoreElements();) {
39: String topic = (String) el.nextElement();
40: if (!ret.contains(topic))
41: ret.addElement(topic);
42: }
43: }
44: return ret;
45: }
46:
47: public Vector getTopicsByTitle(String title) throws Exception {
48: Vector ret = new Vector();
49: String key = this .getKeyByTitle(title);
50: if (key != null)
51: ret = Config.getCurrent().getSubValues(HELP_SECTION,
52: key + FIELD_TOPIC_KEY);
53: return ret;
54: }
55:
56: public Vector getTitlesByTopic(String topic) throws Exception {
57: Config config = Config.getCurrent();
58: Vector ret = new Vector();
59: for (Enumeration e = config.getSubKeys(HELP_SECTION, HELP_KEY)
60: .elements(); e.hasMoreElements();) {
61: String key = (String) e.nextElement();
62: Vector topics = config.getSubValues(HELP_SECTION, key
63: + FIELD_TOPIC_KEY);
64: if (topics.contains(topic)) {
65: String title = config.getValue(HELP_SECTION, key
66: + FIELD_TITLE);
67: ret.addElement(title);
68: }
69: }
70: return ret;
71: }
72:
73: public Vector getContentsByTitle(String title) throws Exception {
74: Vector ret = new Vector();
75: String key = this .getKeyByTitle(title);
76: if (key != null)
77: ret = Config.getCurrent().getSubValues(HELP_SECTION,
78: key + FIELD_CONTENT_KEY);
79: return ret;
80: }
81:
82: public String getKeyByTitle(String title) throws Exception {
83: Config config = Config.getCurrent();
84: for (Enumeration e = config.getSubKeys(HELP_SECTION, HELP_KEY)
85: .elements(); e.hasMoreElements();) {
86: String key = (String) e.nextElement();
87: String tit = config.getValue(HELP_SECTION, key
88: + FIELD_TITLE);
89: if (tit.equals(title))
90: return key;
91: }
92: return null;
93: }
94:
95: }
|