Upload/Download of multiple files now possible
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / editor / WikiEditorPlugin.java
index 6226851..eebe5e1 100644 (file)
@@ -1,17 +1,25 @@
 package net.sourceforge.phpeclipse.wiki.editor;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.sql.SQLException;
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
-import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.IWikipedia;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
+import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB;
 
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IExtension;
 import org.eclipse.core.runtime.IPluginDescriptor;
@@ -36,15 +44,75 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
 public class WikiEditorPlugin extends AbstractUIPlugin {
 
   private static WikiEditorPlugin fgPlugin;
+
+  public final static String AUTOMATICALLY_CREATED = "<!-- automatically created -->";
+
+  public final static String WP_EXTENSION = "wp";
+  public final static String XML_START_1 = "<?xml version=\"1.0\" encoding=\"";
+  public final static String XML_START_2 = "\" ?>\n"
+    + "<mediawiki version=\"0.1\">\n";
+  public final static String XML_END ="\n</mediawiki>";
+  public static final String PREFIX_LOAD = "Load ";
+
+  public static final String PREFIX_STORE = "Store ";
+
   public static final String HTTP_QUERY = "HTTP Query";
-  public static final String WIKIPEDIA_GET_TEXT = "Wikipedia-Load Text";
-  public static final String WEBLOG_API_SEND = "MetaWeblog API-Post";
-  
-  public static final String[] CONFIGURATION_TYPES = {
+
+  //  public static final String WIKIPEDIA_GET_TEXT = "Load WikipediaEN";
+  //
+  //  public static final String WIKIPEDIA_SET_TEXT = "Store WikipediaEN";
+  public static final String WIKIPEDIA_SQL = "Wikipedia SQL access";
+
+  public static final String BLOG_A_WIKI = "Blog as Wiki Text";
+
+  public static final String BLOG_A_HTML = "Blog as HTML Text";
+
+  public static final String PLOG4U_DE_LOAD = PREFIX_LOAD + "Plog4UDE";
+
+  public static final String PLOG4U_DE_STORE = PREFIX_STORE + "Plog4UDE";
+
+  public static final String PLOG4U_ORG_LOAD = PREFIX_LOAD + "Plog4UORG";
+
+  public static final String PLOG4U_ORG_STORE = PREFIX_STORE + "Plog4UORG";
+
+  public static final String[] PREDEFINED_TYPES = {
       HTTP_QUERY,
-      WIKIPEDIA_GET_TEXT, 
-      WEBLOG_API_SEND
-  };
+      WIKIPEDIA_SQL,
+      PLOG4U_DE_LOAD,
+      PLOG4U_DE_STORE,
+      PLOG4U_ORG_LOAD,
+      PLOG4U_ORG_STORE,
+      BLOG_A_WIKI,
+      BLOG_A_HTML };
+
+  public static final String[] PREDEFINED_WIKIS = {
+      "WikibooksDE",
+      "WikibooksEN",
+      "WikinewsDE",
+      "WikinewsEN",
+      "WikipediaAR",
+      "WikipediaCA",
+      "WikipediaDE",
+      "WikipediaEN",
+      "WikipediaEO",
+      "WikipediaES",
+      "WikipediaET",
+      "WikipediaFI",
+      "WikipediaFR",
+      "WikipediaHE",
+      "WikipediaIA",
+      "WikipediaIT",
+      "WikipediaJA",
+      "WikipediaNL",
+      "WikipediaPL",
+      "WikipediaPT",
+      "WikipediaRO",
+      "WikipediaSL",
+      "WikipediaSV",
+      "WikipediaZH" };
+
+  public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
+
   //image paths
   public static final String ICON_PATH = "icons/full/"; //$NON-NLS-1$
 
@@ -54,11 +122,44 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
 
   public final static String WIKI_TEXTS_BASE_PATH = "__wiki_texts_base_path";
 
-  private static ConfigurationManager manager;
+  public final static String LOCAL_TEMPLATE_FILE_NAME = "__local_template_file_name";
+
+  public final static String EXPORT_TEMPLATE_FILE_NAME = "__export_template_file_name";
+
+  public final static String LOCAL_CSS_URL = "__local_css_url";
+
+  public final static String EXPORT_CSS_URL = "__export_css_url";
+
+  public final static String PREF_STRING_CONFIGURATIONS = "__configurations3";
+
+  public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<configurations>"
+      + "<config name=\"Google Search\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>"
+      + "<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
+      + "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
+
+      + "<config name=\"Plog4U.de Download\" type-id=\"" + PLOG4U_DE_LOAD
+      + "\" url=\"http://www.plog4u.de/index.php/Spezial:Export\"/>" + "<config name=\"Plog4U.org Download\" type-id=\""
+      + PLOG4U_ORG_LOAD + "\" url=\"http://www.plog4u.org/index.php/Special:Export\"/>"
+      + "<config name=\"Plog4U.de Upload\" type-id=\"" + PLOG4U_DE_STORE + "\" url=\"http://en.wikipedia.org/w/index.php\"/>"
+      + "<config name=\"Plog4U.org Upload\" type-id=\"" + PLOG4U_ORG_STORE + "\" url=\"http://en.wikibooks.org/w/index.php\"/>"
 
-  public static final String IMG_MONITOR_ON = "monitorOn";
+      + "<config name=\"WikipediaEN Download\" type-id=\"" + PREFIX_LOAD
+      + "WikipediaEN\" url=\"http://en.wikipedia.org/wiki/Special:Export\"/>" + "<config name=\"WikibooksEN Download\" type-id=\""
+      + PREFIX_LOAD + "WikibooksEN\" url=\"http://en.wikibooks.org/wiki/Special:Export\"/>"
+      + "<config name=\"WikipediaEN Upload\" type-id=\"" + PREFIX_STORE
+      + "WikipediaEN\" url=\"http://en.wikipedia.org/w/index.php\"/>" + "<config name=\"WikibooksEN Upload\" type-id=\""
+      + PREFIX_STORE + "WikibooksEN\" url=\"http://en.wikibooks.org/w/index.php\"/>"
+      + "<config name=\"Wikipedia-SQL\" type-id=\"Wikipedia SQL access\" user=\"root\" url=\"jdbc:mysql://localhost/wikidb\"/>"
+      + "</configurations>";
 
-  public static final String IMG_MONITOR_OFF = "monitorOff";
+  public static WikipediaDB fWikiDB = null;
+
+  private static ConfigurationManager manager;
+
+  //
+  //  public static final String IMG_MONITOR_ON = "monitorOn";
+  //
+  //  public static final String IMG_MONITOR_OFF = "monitorOff";
 
   /**
    * Creates an image and places it in the image registry.
@@ -143,6 +244,16 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
     super(descriptor);
     initializeImages();
     fgPlugin = this;
+    for (int i = 0; i < PREDEFINED_TYPES.length; i++) {
+      CONFIGURATION_TYPES.add(PREDEFINED_TYPES[i]);
+    }
+
+    for (int i = 0; i < PREDEFINED_WIKIS.length; i++) {
+      CONFIGURATION_TYPES.add(PREFIX_LOAD + PREDEFINED_WIKIS[i]);
+    }
+    for (int i = 0; i < PREDEFINED_WIKIS.length; i++) {
+      CONFIGURATION_TYPES.add(PREFIX_STORE + PREDEFINED_WIKIS[i]);
+    }
     manager = ConfigurationManager.getInstance();
     try {
       fResourceBundle = ResourceBundle.getBundle("net.sourceforge.phpeclipse.wiki.editor.WikiEditorMessages");
@@ -212,6 +323,7 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
    * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
    */
   protected void initializeDefaultPreferences(IPreferenceStore store) {
+    store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
   }
 
   /*
@@ -343,8 +455,85 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
   public static IConfigurationWorkingCopy createConfiguration() {
     return manager.createConfiguration();
   }
-  
-  public static String[] getTypes() {
+
+  public static ArrayList getTypes() {
     return CONFIGURATION_TYPES;
   }
+
+  public static void addType(String type) {
+    CONFIGURATION_TYPES.add(type);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.core.runtime.Plugin#shutdown()
+   */
+  public void shutdown() throws CoreException {
+    if (fWikiDB != null) {
+      try {
+        fWikiDB.shutdown();
+      } catch (SQLException e) {
+      }
+    }
+    super.shutdown();
+  }
+
+  public static void log(int severity, String message) {
+    Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
+    log(status);
+  }
+
+  public static void log(IStatus status) {
+    getDefault().getLog().log(status);
+  }
+
+  public static void log(Throwable e) {
+    log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+  }
+
+  /**
+   * Get a IWikpedia singleton instance through reflection (i.e. Method#invoke() )
+   * 
+   * @param wikiLocale
+   * @return
+   * @throws NoSuchMethodException
+   * @throws IllegalAccessException
+   * @throws ClassNotFoundException
+   * @throws InvocationTargetException
+   */
+  public static IWikipedia getWikiInstance(String wikiLocale) throws NoSuchMethodException, IllegalAccessException,
+      ClassNotFoundException, InvocationTargetException {
+    String className = "net.sourceforge.phpeclipse.wiki.actions.mediawiki.config." + wikiLocale;
+    Class cls = Class.forName(className);
+    Method method = cls.getMethod("getInstance", new Class[0]);
+    return (IWikipedia) method.invoke(null, new Object[0]);
+  }
+
+  /**
+   * Returns the workspace instance.
+   */
+  public static IWorkspace getWorkspace() {
+    return ResourcesPlugin.getWorkspace();
+  }
+
+  // test code
+  //  public static void main(String[] args) {
+  //    try {
+  //      getWikiInstance("WikipediaEN");
+  //    } catch (NoSuchMethodException e) {
+  //      // TODO Auto-generated catch block
+  //      e.printStackTrace();
+  //    } catch (IllegalAccessException e) {
+  //      // TODO Auto-generated catch block
+  //      e.printStackTrace();
+  //    } catch (ClassNotFoundException e) {
+  //      // TODO Auto-generated catch block
+  //      e.printStackTrace();
+  //    } catch (InvocationTargetException e) {
+  //      // TODO Auto-generated catch block
+  //      e.printStackTrace();
+  //    }
+  //  }
+
 }
\ No newline at end of file