1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / editor / WikiEditorPlugin.java
1 package net.sourceforge.phpeclipse.wiki.editor;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.lang.reflect.InvocationTargetException;
6 import java.lang.reflect.Method;
7 import java.net.MalformedURLException;
8 import java.net.URL;
9 import java.sql.SQLException;
10 import java.text.MessageFormat;
11 import java.util.ArrayList;
12 import java.util.Hashtable;
13 import java.util.List;
14 import java.util.MissingResourceException;
15 import java.util.PropertyResourceBundle;
16 import java.util.ResourceBundle;
17
18 import net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.IWikipedia;
19 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
20 import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
21 import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB;
22
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.core.resources.IProject;
25 import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.resources.IWorkspace;
27 import org.eclipse.core.resources.ResourcesPlugin;
28 import org.eclipse.core.runtime.IAdapterFactory;
29 import org.eclipse.core.runtime.IAdapterManager;
30 import org.eclipse.core.runtime.IExtension;
31 import org.eclipse.core.runtime.IPluginDescriptor;
32 import org.eclipse.core.runtime.IStatus;
33 import org.eclipse.core.runtime.Path;
34 import org.eclipse.core.runtime.Platform;
35 import org.eclipse.core.runtime.Status;
36 import org.eclipse.jface.dialogs.MessageDialog;
37 import org.eclipse.jface.preference.IPreferenceStore;
38 import org.eclipse.jface.resource.ImageDescriptor;
39 import org.eclipse.jface.text.templates.ContextTypeRegistry;
40 import org.eclipse.jface.text.templates.persistence.TemplateStore;
41 import org.eclipse.swt.graphics.Image;
42 import org.eclipse.swt.widgets.Display;
43 import org.eclipse.ui.IContributorResourceAdapter;
44 import org.eclipse.ui.IPersistableElement;
45 import org.eclipse.ui.IWorkbenchPage;
46 import org.eclipse.ui.IWorkbenchWindow;
47 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
48 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
49 import org.eclipse.ui.plugin.AbstractUIPlugin;
50 import org.eclipse.ui.views.properties.IPropertySource;
51 import org.osgi.framework.BundleContext;
52
53 public class WikiEditorPlugin extends AbstractUIPlugin {
54
55   private static WikiEditorPlugin fgPlugin;
56
57   public final static String AUTOMATICALLY_CREATED = "<!-- automatically created -->";
58
59   public final static String WP_EXTENSION = "wp";
60
61   public final static String XML_START_1 = "<?xml version=\"1.0\" encoding=\"";
62
63   public final static String XML_START_2 = "\" ?>\n" + "<mediawiki version=\"0.1\">\n";
64
65   public final static String XML_END = "\n</mediawiki>";
66
67   public static final String PREFIX_LOAD = "Load ";
68
69   public static final String PREFIX_STORE = "Store ";
70
71   public static final String HTTP_QUERY = "HTTP Query";
72
73   //  public static final String WIKIPEDIA_GET_TEXT = "Load WikipediaEN";
74   //
75   //  public static final String WIKIPEDIA_SET_TEXT = "Store WikipediaEN";
76   public static final String WIKIPEDIA_SQL = "Wikipedia SQL access";
77
78   public static final String BLOG_A_WIKI = "Blog as Wiki Text";
79
80   public static final String BLOG_A_HTML = "Blog as HTML Text";
81
82   public static final String PLOG4U_DE_LOAD = PREFIX_LOAD + "Plog4UDE";
83
84   public static final String PLOG4U_DE_STORE = PREFIX_STORE + "Plog4UDE";
85
86   public static final String PLOG4U_ORG_LOAD = PREFIX_LOAD + "Plog4UORG";
87
88   public static final String PLOG4U_ORG_STORE = PREFIX_STORE + "Plog4UORG";
89
90   public static final String[] PREDEFINED_TYPES = {
91       HTTP_QUERY,
92       WIKIPEDIA_SQL,
93       PLOG4U_DE_LOAD,
94       PLOG4U_DE_STORE,
95       PLOG4U_ORG_LOAD,
96       PLOG4U_ORG_STORE,
97       BLOG_A_WIKI,
98       BLOG_A_HTML };
99
100   public static final String[] PREDEFINED_WIKIS = {
101       "WikibooksDE",
102       "WikibooksEN",
103       "WikinewsDE",
104       "WikinewsEN",
105       "WikipediaAR",
106       "WikipediaCA",
107       "WikipediaDE",
108       "WikipediaEN",
109       "WikipediaEO",
110       "WikipediaES",
111       "WikipediaET",
112       "WikipediaFI",
113       "WikipediaFR",
114       "WikipediaHE",
115       "WikipediaIA",
116       "WikipediaIT",
117       "WikipediaJA",
118       "WikipediaNL",
119       "WikipediaPL",
120       "WikipediaPT",
121       "WikipediaRO",
122       "WikipediaSL",
123       "WikipediaSV",
124       "WikipediaZH" };
125
126   public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
127
128   //image paths
129   public static final String ICON_PATH = "icons/full/"; //$NON-NLS-1$
130
131   public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.wiki";
132
133   public final static String HTML_OUTPUT_PATH = "__static_wiki_folder";
134
135   public final static String WIKI_TEXTS_BASE_PATH = "__wiki_texts_base_path";
136
137   public final static String LOCAL_TEMPLATE_FILE_NAME = "__local_template_file_name";
138
139   public final static String EXPORT_TEMPLATE_FILE_NAME = "__export_template_file_name";
140
141   public final static String LOCAL_CSS_URL = "__local_css_url";
142
143   public final static String EXPORT_CSS_URL = "__export_css_url";
144
145   public final static String PREF_STRING_CONFIGURATIONS = "__configurations4";
146
147   public final static String CONSOLE_OUTPUT = "__console_output";
148
149   public final static String HTTP_GET_THROTTLE = "http.get.throttle";
150
151   public final static String HTTP_PUT_THROTTLE = "http.put.throttle";
152
153   public final static String HTTP_TIMEOUT = "http.timeout";
154
155   public final static String HTTP_PROXYHOST = "http.proxyHost";
156
157   public final static String HTTP_PROXYPORT = "http.proxyPort";
158
159   public final static String HTTP_PROXYUSERNAME = "http.proxyUserName";
160
161   public final static String HTTP_PROXYPASSWORD = "http.proxyPassword";
162
163   /**
164    * A named preference that controls whether the 'wrap words' feature is enabled.
165    * <p>
166    * Value is of type <code>Boolean</code>.
167    * </p>
168    */
169   public final static String EDITOR_WRAP_WORDS = "editor.wrap.words"; //$NON-NLS-1$
170
171   public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<configurations>"
172       + "<config name=\"Google Search\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>"
173       + "<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
174       + "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
175
176       + "<config name=\"Plog4U.de Download\" type-id=\"" + PLOG4U_DE_LOAD
177       + "\" url=\"http://www.plog4u.de/index.php/Spezial:Export\"/>" + "<config name=\"Plog4U.org Download\" type-id=\""
178       + PLOG4U_ORG_LOAD + "\" url=\"http://www.plog4u.org/index.php/Special:Export\"/>"
179       + "<config name=\"Plog4U.de Upload\" type-id=\"" + PLOG4U_DE_STORE + "\" url=\"http://www.plog4u.de/index.php\"/>"
180       + "<config name=\"Plog4U.org Upload\" type-id=\"" + PLOG4U_ORG_STORE + "\" url=\"http://www.plog4u.org/index.php\"/>"
181
182       + "<config name=\"WikipediaEN Download\" type-id=\"" + PREFIX_LOAD
183       + "WikipediaEN\" url=\"http://en.wikipedia.org/wiki/Special:Export\"/>" + "<config name=\"WikibooksEN Download\" type-id=\""
184       + PREFIX_LOAD + "WikibooksEN\" url=\"http://en.wikibooks.org/wiki/Special:Export\"/>"
185       + "<config name=\"WikipediaEN Upload\" type-id=\"" + PREFIX_STORE
186       + "WikipediaEN\" url=\"http://en.wikipedia.org/w/index.php\"/>" + "<config name=\"WikibooksEN Upload\" type-id=\""
187       + PREFIX_STORE + "WikibooksEN\" url=\"http://en.wikibooks.org/w/index.php\"/>"
188       + "<config name=\"Wikipedia-SQL\" type-id=\"Wikipedia SQL access\" user=\"root\" url=\"jdbc:mysql://localhost/wikidb\"/>"
189       + "</configurations>";
190
191   public static WikipediaDB fWikiDB = null;
192
193   private static ConfigurationManager manager;
194
195   //
196   //  public static final String IMG_MONITOR_ON = "monitorOn";
197   //
198   //  public static final String IMG_MONITOR_OFF = "monitorOff";
199
200   /**
201    * Creates an image and places it in the image registry.
202    * 
203    * @param id
204    *          the identifier for the image
205    * @param baseURL
206    *          the base URL for the image
207    */
208   protected static void createImageDescriptor(WikiEditorPlugin plugin, String id, URL baseURL) {
209     // Delegate to the plugin instance to avoid concurrent class loading problems
210     plugin.privateCreateImageDescriptor(id, baseURL);
211   }
212
213   public static WikiEditorPlugin getDefault() {
214     return fgPlugin;
215   }
216
217   /**
218    * Returns the image descriptor for the given image ID. Returns null if there is no such image.
219    * 
220    * @param id
221    *          the identifier for the image to retrieve
222    * @return the image associated with the given ID
223    */
224   public static ImageDescriptor getImageDescriptor(String id) {
225     // Delegate to the plugin instance to avoid concurrent class loading problems
226     return getDefault().privateGetImageDescriptor(id);
227   }
228
229   /**
230    * Convenience method to get an image descriptor for an extension
231    * 
232    * @param extension
233    *          the extension declaring the image
234    * @param subdirectoryAndFilename
235    *          the path to the image
236    * @return the image
237    */
238   public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) {
239     IPluginDescriptor pluginDescriptor = extension.getDeclaringPluginDescriptor();
240     URL path = pluginDescriptor.getInstallURL();
241     URL fullPathString = null;
242     try {
243       fullPathString = new URL(path, subdirectoryAndFilename);
244       return ImageDescriptor.createFromURL(fullPathString);
245     } catch (MalformedURLException e) {
246     }
247     return null;
248   }
249
250   public static String getResourceString(String key) {
251     ResourceBundle bundle = WikiEditorPlugin.getDefault().getResourceBundle();
252     try {
253       return (bundle != null) ? bundle.getString(key) : key;
254     } catch (MissingResourceException e) {
255       return key;
256     }
257   }
258
259   /**
260    * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
261    * If so, this display is returned. Otherwise the method returns the default display.
262    */
263   public static Display getStandardDisplay() {
264     Display display = Display.getCurrent();
265     if (display == null) {
266       display = Display.getDefault();
267     }
268     return display;
269   }
270
271   private ContributionContextTypeRegistry fContextTypeRegistry;
272
273   private ResourceBundle fResourceBundle;
274
275   private ContributionTemplateStore fTemplateStore;
276
277   private Hashtable imageDescriptors = new Hashtable(20);
278
279   public WikiEditorPlugin(IPluginDescriptor descriptor) {
280     super(descriptor);
281     initializeImages();
282     fgPlugin = this;
283     for (int i = 0; i < PREDEFINED_TYPES.length; i++) {
284       CONFIGURATION_TYPES.add(PREDEFINED_TYPES[i]);
285     }
286
287     for (int i = 0; i < PREDEFINED_WIKIS.length; i++) {
288       CONFIGURATION_TYPES.add(PREFIX_LOAD + PREDEFINED_WIKIS[i]);
289     }
290     for (int i = 0; i < PREDEFINED_WIKIS.length; i++) {
291       CONFIGURATION_TYPES.add(PREFIX_STORE + PREDEFINED_WIKIS[i]);
292     }
293     manager = ConfigurationManager.getInstance();
294     try {
295       fResourceBundle = ResourceBundle.getBundle("net.sourceforge.phpeclipse.wiki.editor.WikiEditorMessages");
296     } catch (MissingResourceException x) {
297       fResourceBundle = null;
298     }
299   }
300
301   /**
302    * Creates an image and places it in the image registry.
303    */
304   protected void createImageDescriptor(String id, URL baseURL) {
305     URL url = null;
306     try {
307       url = new URL(baseURL, ICON_PATH + id);
308     } catch (MalformedURLException e) {
309     }
310     ImageDescriptor desc = ImageDescriptor.createFromURL(url);
311     imageDescriptors.put(id, desc);
312   }
313
314   public IWorkbenchPage getActivePage() {
315     IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
316     if (window != null)
317       return window.getActivePage();
318     return null;
319   }
320
321   public ContextTypeRegistry getContextTypeRegistry() {
322     if (fContextTypeRegistry == null) {
323       fContextTypeRegistry = new ContributionContextTypeRegistry();
324       fContextTypeRegistry.addContextType("net.sourceforge.phpeclipse.wiki.editor.templates");
325     }
326     return fContextTypeRegistry;
327   }
328
329   public Image getImage(String key) {
330     Image image = getImageRegistry().get(key);
331     if (image == null) {
332       ImageDescriptor d = getImageDescriptor(key);
333       image = d.createImage();
334       getImageRegistry().put(key, image);
335     }
336     return image;
337   }
338
339   public ResourceBundle getResourceBundle() {
340     return fResourceBundle;
341   }
342
343   public TemplateStore getTemplateStore() {
344     if (fTemplateStore == null) {
345       fTemplateStore = new ContributionTemplateStore(getContextTypeRegistry(), getDefault().getPreferenceStore(), "templates");
346       try {
347         fTemplateStore.load();
348       } catch (IOException e) {
349         e.printStackTrace();
350       }
351     }
352
353     return fTemplateStore;
354   }
355
356   private static boolean isDefined(String test) {
357     if (test != null && test.length() > 0) {
358       for (int i = 0; i < test.length(); i++) {
359         if (!Character.isWhitespace(test.charAt(i))) {
360           return false;
361         }
362       }
363     }
364     return true;
365   }
366
367   /*
368    * (non-Javadoc)
369    * 
370    * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
371    */
372   protected void initializeDefaultPreferences(IPreferenceStore store) {
373     store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
374     store.setDefault(CONSOLE_OUTPUT, "true");
375
376     String operatingSystem = Platform.getOS();
377     // operatingSystem ==> maxosx, linux, solaris, win32,...
378     try {
379       InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
380       PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
381
382       String key = EDITOR_WRAP_WORDS;
383       try {
384         String wordWrap = resourceBundle.getString(key);
385         Boolean b = Boolean.valueOf(wordWrap);
386         if (b.booleanValue()) {
387           store.setDefault(key, "true");
388         } else {
389           store.setDefault(key, "false");
390         }
391       } catch (Exception e) {
392         store.setDefault(key, "false");
393       }
394
395       key = HTTP_GET_THROTTLE;
396       try {
397         String timeout = resourceBundle.getString(key);
398         int val = Integer.parseInt(timeout);
399         if (val > 0) {
400           val *= 1000;
401         } else {
402           val = 1000;
403         }
404         store.setDefault(key, Integer.toString(val));
405       } catch (Exception e) {
406         store.setDefault(key, "1000"); // 1 second
407       }
408
409       key = HTTP_PUT_THROTTLE;
410       try {
411         String timeout = resourceBundle.getString(key);
412         int val = Integer.parseInt(timeout);
413         if (val > 0) {
414           val *= 1000;
415         } else {
416           val = 5000;
417         }
418         store.setDefault(key, Integer.toString(val));
419       } catch (Exception e) {
420         store.setDefault(key, "5000"); // 5 seconds
421       }
422
423       key = HTTP_TIMEOUT;
424       try {
425         String timeout = resourceBundle.getString(key);
426         int val = Integer.parseInt(timeout);
427         if (val > 0) {
428           val *= 1000;
429         } else {
430           val = 30000;
431         }
432         store.setDefault(key, Integer.toString(val));
433       } catch (Exception e) {
434         store.setDefault(key, "30000"); // 30 seconds timeout
435       }
436
437       key = HTTP_PROXYHOST;
438       try {
439         String proxyHost = resourceBundle.getString(key);
440         if (isDefined(proxyHost)) {
441           store.setDefault(key, proxyHost);
442         } else {
443           store.setDefault(key, System.getProperty(key, ""));
444         }
445       } catch (Exception e) {
446         store.setDefault(key, System.getProperty(key, ""));
447       }
448
449       key = HTTP_PROXYPORT;
450       try {
451         String proxyPort = resourceBundle.getString(key);
452         if (isDefined(proxyPort)) {
453           // check for integer parse exception:
454           Integer.parseInt(proxyPort);
455           store.setDefault(key, proxyPort);
456         } else {
457           store.setDefault(key, System.getProperty(key, "80"));
458         }
459       } catch (Exception e) {
460         store.setDefault(key, System.getProperty(key, "80"));
461       }
462
463       key = HTTP_PROXYUSERNAME;
464       try {
465         String proxyUserName = resourceBundle.getString(key);
466         if (isDefined(proxyUserName)) {
467           store.setDefault(key, proxyUserName);
468         } else {
469           store.setDefault(key, System.getProperty(key, ""));
470         }
471       } catch (Exception e) {
472         store.setDefault(key, System.getProperty(key, ""));
473       }
474
475       key = HTTP_PROXYPASSWORD;
476       try {
477         String proxyPassWord = resourceBundle.getString(key);
478         if (isDefined(proxyPassWord)) {
479           store.setDefault(key, proxyPassWord);
480         } else {
481           store.setDefault(key, System.getProperty(key, ""));
482         }
483       } catch (Exception e) {
484         store.setDefault(key, System.getProperty(key, ""));
485       }
486
487     } catch (Exception e) {
488     }
489
490   }
491
492   /*
493    * Initializes the table of images used in this plugin. The plugin is provided because this method is called before the plugin
494    * staic variable has been set. See the comment on the getPlugin() method for a description of why this is required.
495    */
496   private void initializeImages() {
497     URL baseURL = getDescriptor().getInstallURL();
498
499     //  special
500     createImageDescriptor("glyphs/glyph1.gif", baseURL); //$NON-NLS-1$
501     createImageDescriptor("glyphs/glyph2.gif", baseURL); //$NON-NLS-1$
502     createImageDescriptor("glyphs/glyph3.gif", baseURL); //$NON-NLS-1$
503     createImageDescriptor("glyphs/glyph4.gif", baseURL); //$NON-NLS-1$
504     createImageDescriptor("glyphs/glyph5.gif", baseURL); //$NON-NLS-1$
505     createImageDescriptor("glyphs/glyph6.gif", baseURL); //$NON-NLS-1$
506     createImageDescriptor("glyphs/glyph7.gif", baseURL); //$NON-NLS-1$
507     createImageDescriptor("glyphs/glyph8.gif", baseURL); //$NON-NLS-1$
508
509   }
510
511   public void log(String message) {
512     getDefault().getLog().log(new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, null));
513   }
514
515   public void log(String message, Exception e) {
516     getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, "Caught exception", e));
517   }
518
519   public void logAndReport(String title, String message, Exception e) {
520     log(message, e);
521     reportError(title, message);
522   }
523
524   private void privateCreateImageDescriptor(String id, URL baseURL) {
525     URL url = null;
526     try {
527       url = new URL(baseURL, ICON_PATH + id);
528     } catch (MalformedURLException e) {
529     }
530     ImageDescriptor desc = ImageDescriptor.createFromURL(url);
531     imageDescriptors.put(id, desc);
532   }
533
534   private ImageDescriptor privateGetImageDescriptor(String id) {
535     if (!imageDescriptors.containsKey(id)) {
536       URL baseURL = WikiEditorPlugin.getDefault().getDescriptor().getInstallURL();
537       createImageDescriptor(getDefault(), id, baseURL);
538     }
539     return (ImageDescriptor) imageDescriptors.get(id);
540   }
541
542   public void reportError(String title, String message) {
543     try {
544       //      Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
545       MessageDialog.openError(null, title, message);
546     } catch (RuntimeException e) {
547       log(e.getLocalizedMessage(), e);
548     }
549   }
550
551   //  public void startup() throws CoreException {
552   //    super.startup();
553   //  }
554
555   /**
556    * Returns the translated String found with the given key.
557    * 
558    * @return java.lang.String
559    * @param key
560    *          java.lang.String
561    */
562   public static String getResource(String key) {
563     try {
564       return Platform.getResourceString(getDefault().getBundle(), key);
565     } catch (Exception e) {
566       return key;
567     }
568   }
569
570   /**
571    * Returns the translated String found with the given key, and formatted with the given object.
572    * 
573    * @param key
574    *          java.lang.String
575    * @param obj
576    *          java.lang.Object[]
577    * @return java.lang.String
578    */
579   public static String getResource(String key, Object[] obj) {
580     try {
581       return MessageFormat.format(getResource(key), obj);
582     } catch (Exception e) {
583       return key;
584     }
585   }
586
587   /**
588    * Returns the translated String found with the given key, and formatted with the given object.
589    * 
590    * @param key
591    *          java.lang.String
592    * @param s
593    *          java.lang.String
594    * @return java.lang.String
595    */
596   public static String getResource(String key, String s) {
597     try {
598       return MessageFormat.format(getResource(key), new String[] { s });
599     } catch (Exception e) {
600       return key;
601     }
602   }
603
604   /**
605    * Return a list of all the existing configurations.
606    * 
607    * @return java.util.List
608    */
609   public static List getConfigurations() {
610     return manager.getConfigurations();
611   }
612
613   /**
614    * Create a new monitor.
615    * 
616    * @return working copy
617    */
618   public static IConfigurationWorkingCopy createConfiguration() {
619     return manager.createConfiguration();
620   }
621
622   public static ArrayList getTypes() {
623     return CONFIGURATION_TYPES;
624   }
625
626   public static void addType(String type) {
627     CONFIGURATION_TYPES.add(type);
628   }
629
630   /*
631    * (non - Javadoc) Method declared in Plugin
632    */
633   public void start(BundleContext context) throws Exception {
634     super.start(context);
635   }
636
637   /*
638    * @see org.eclipse.core.runtime.Plugin#stop
639    */
640   public void stop(BundleContext context) throws Exception {
641     try {
642       if (fWikiDB != null) {
643         try {
644           fWikiDB.shutdown();
645         } catch (SQLException e) {
646         }
647       }
648     } finally {
649       super.stop(context);
650     }
651   }
652
653   public static void log(int severity, String message) {
654     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
655     log(status);
656   }
657
658   public static void log(IStatus status) {
659     getDefault().getLog().log(status);
660   }
661
662   public static void log(Throwable e) {
663     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
664   }
665
666   /**
667    * Get a IWikpedia singleton instance through reflection (i.e. Method#invoke() )
668    * 
669    * @param wikiLocale
670    * @return
671    * @throws NoSuchMethodException
672    * @throws IllegalAccessException
673    * @throws ClassNotFoundException
674    * @throws InvocationTargetException
675    */
676   public static IWikipedia getWikiInstance(String wikiLocale) throws NoSuchMethodException, IllegalAccessException,
677       ClassNotFoundException, InvocationTargetException {
678     String className = "net.sourceforge.phpeclipse.wiki.actions.mediawiki.config." + wikiLocale;
679     Class cls = Class.forName(className);
680     Method method = cls.getMethod("getInstance", new Class[0]);
681     return (IWikipedia) method.invoke(null, new Object[0]);
682   }
683
684   /**
685    * Returns the workspace instance.
686    */
687   public static IWorkspace getWorkspace() {
688     return ResourcesPlugin.getWorkspace();
689   }
690
691   // test code
692   //  public static void main(String[] args) {
693   //    try {
694   //      getWikiInstance("WikipediaEN");
695   //    } catch (NoSuchMethodException e) {
696   //      // TODO Auto-generated catch block
697   //      e.printStackTrace();
698   //    } catch (IllegalAccessException e) {
699   //      // TODO Auto-generated catch block
700   //      e.printStackTrace();
701   //    } catch (ClassNotFoundException e) {
702   //      // TODO Auto-generated catch block
703   //      e.printStackTrace();
704   //    } catch (InvocationTargetException e) {
705   //      // TODO Auto-generated catch block
706   //      e.printStackTrace();
707   //    }
708   //  }
709
710 }