KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > htmlviewer > HTMLViewerFactory


1 package org.columba.core.gui.htmlviewer;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import javax.swing.JOptionPane JavaDoc;
6
7 import org.columba.api.plugin.IExtension;
8 import org.columba.api.plugin.IExtensionHandler;
9 import org.columba.api.plugin.IExtensionHandlerKeys;
10 import org.columba.api.plugin.PluginException;
11 import org.columba.api.plugin.PluginHandlerNotFoundException;
12 import org.columba.core.gui.frame.FrameManager;
13 import org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin;
14 import org.columba.core.logging.Logging;
15 import org.columba.core.plugin.PluginManager;
16
17
18 public class HTMLViewerFactory {
19
20     private static final Logger JavaDoc LOG = Logger
21             .getLogger("org.columba.core.gui.htmlviewer.HTMLViewerFactory");
22
23     public static IHTMLViewerPlugin createHTMLViewer() {
24 // OptionsItem optionsItem = MailConfig.getInstance().getOptionsItem();
25
// String selectedBrowser = optionsItem.getStringWithDefault(
26
// OptionsItem.MESSAGEVIEWER, OptionsItem.SELECTED_BROWSER,
27
// "Default");
28
String JavaDoc selectedBrowser = "Default";
29         IHTMLViewerPlugin viewerPlugin;
30
31         try {
32             viewerPlugin = createHTMLViewerPluginInstance(selectedBrowser);
33             // in case of an error -> fall-back to Swing's built-in JTextPane
34
if (viewerPlugin == null || !viewerPlugin.initialized()) {
35                 JOptionPane.showMessageDialog(FrameManager.getInstance()
36                         .getActiveFrame(),
37                         "Error while trying to load html viewer");
38
39                 LOG
40                         .severe("Error while trying to load html viewer -> falling back to default");
41
42                 viewerPlugin = createHTMLViewerPluginInstance("Default");
43             }
44         } catch (Exception JavaDoc e) {
45             viewerPlugin = createHTMLViewerPluginInstance("Default");
46
47             if (Logging.DEBUG)
48                 e.printStackTrace();
49         } catch (Error JavaDoc e) {
50             viewerPlugin = createHTMLViewerPluginInstance("Default");
51
52             if (Logging.DEBUG)
53                 e.printStackTrace();
54         }
55
56         return viewerPlugin;
57     }
58
59     private static IHTMLViewerPlugin createHTMLViewerPluginInstance(
60             String JavaDoc pluginId) {
61         IHTMLViewerPlugin plugin = null;
62         try {
63
64             IExtensionHandler handler = PluginManager.getInstance()
65                     .getExtensionHandler(
66                             IExtensionHandlerKeys.ORG_COLUMBA_CORE_HTMLVIEWER);
67
68             IExtension extension = handler.getExtension(pluginId);
69             if (extension == null)
70                 return null;
71
72             plugin = (IHTMLViewerPlugin) extension.instanciateExtension(null);
73
74             return plugin;
75         } catch (PluginHandlerNotFoundException e) {
76             LOG.severe("Error while loading viewer plugin: " + e.getMessage());
77             if (Logging.DEBUG)
78                 e.printStackTrace();
79         } catch (PluginException e) {
80             LOG.severe("Error while loading viewer plugin: " + e.getMessage());
81             if (Logging.DEBUG)
82                 e.printStackTrace();
83         }
84
85         return null;
86     }
87
88 }
89
Popular Tags