1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.common; |
17 | |
18 | import java.net.URL; |
19 | |
20 | import javax.help.HelpBroker; |
21 | import javax.help.HelpSet; |
22 | import javax.help.HelpSetException; |
23 | |
24 | import net.sf.jomic.tools.LocaleTools; |
25 | |
26 | /** |
27 | * Conveniance methods to simplify interaction with JavaHelp. |
28 | * |
29 | * @author Thomas Aglassinger |
30 | */ |
31 | public final class JomicHelpTools |
32 | { |
33 | private static JomicHelpTools instance; |
34 | private HelpBroker helpBroker; |
35 | |
36 | private HelpSet helpSet; |
37 | |
38 | private LocaleTools localeTools; |
39 | |
40 | private JomicHelpTools() { |
41 | localeTools = LocaleTools.instance(); |
42 | |
43 | String helpSetName = "jhelpset.hs"; |
44 | ClassLoader loader = JomicHelpTools.class.getClassLoader(); |
45 | URL helpSetUrl = HelpSet.findHelpSet(loader, helpSetName); |
46 | |
47 | try { |
48 | if (helpSetUrl == null) { |
49 | String message = localeTools.getMessage("errors.cannotFindHelpSet", helpSetName); |
50 | |
51 | throw new HelpSetException(message); |
52 | } |
53 | helpSet = new HelpSet(null, helpSetUrl); |
54 | helpBroker = helpSet.createHelpBroker(); |
55 | } catch (HelpSetException error) { |
56 | String message = localeTools.getMessage("errors.cannotLoadOnlineHelp"); |
57 | IllegalStateException error2 = new IllegalStateException(message); |
58 | |
59 | error2.initCause(error); |
60 | throw error2; |
61 | } |
62 | } |
63 | |
64 | public HelpBroker getHelpBroker() { |
65 | return helpBroker; |
66 | } |
67 | |
68 | public HelpSet getHelpSet() { |
69 | return helpSet; |
70 | } |
71 | |
72 | public static synchronized JomicHelpTools instance() { |
73 | if (instance == null) { |
74 | instance = new JomicHelpTools(); |
75 | } |
76 | return instance; |
77 | } |
78 | } |