package net.sourceforge.phpeclipse.wiki.editor;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.Hashtable;
import java.util.List;
import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.IWikipedia;
import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy;
import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB;
-import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IContributorResourceAdapter;
+import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.osgi.framework.BundleContext;
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 = "Load WikipediaEN";
public static final String BLOG_A_HTML = "Blog as HTML Text";
- public static final String[] PREDEFINED_TYPES = { HTTP_QUERY, WIKIPEDIA_SQL, BLOG_A_WIKI, BLOG_A_HTML };
+ 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_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",
"WikipediaES",
"WikipediaET",
"WikipediaFI",
- "WikipediaFR" };
-
- public static final String PREFIX_LOAD = "Load ";
-
- public static final String PREFIX_STORE = "Store ";
+ "WikipediaFR",
+ "WikipediaHE",
+ "WikipediaIA",
+ "WikipediaIT",
+ "WikipediaJA",
+ "WikipediaNL",
+ "WikipediaPL",
+ "WikipediaPT",
+ "WikipediaRO",
+ "WikipediaSL",
+ "WikipediaSV",
+ "WikipediaZH" };
public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
public final static String EXPORT_CSS_URL = "__export_css_url";
- public final static String PREF_STRING_CONFIGURATIONS = "__configurations2";
+ public final static String PREF_STRING_CONFIGURATIONS = "__configurations4";
+
+ public final static String CONSOLE_OUTPUT = "__console_output";
+
+ public final static String HTTP_GET_THROTTLE = "http.get.throttle";
+
+ public final static String HTTP_PUT_THROTTLE = "http.put.throttle";
- public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<configurations>"
+ public final static String HTTP_TIMEOUT = "http.timeout";
+
+ public final static String HTTP_PROXYHOST = "http.proxyHost";
+
+ public final static String HTTP_PROXYPORT = "http.proxyPort";
+
+ public final static String HTTP_PROXYUSERNAME = "http.proxyUserName";
+
+ public final static String HTTP_PROXYPASSWORD = "http.proxyPassword";
+
+ /**
+ * A named preference that controls whether the 'wrap words' feature is enabled.
+ * <p>
+ * Value is of type <code>Boolean</code>.
+ * </p>
+ */
+ public final static String EDITOR_WRAP_WORDS = "editor.wrap.words"; //$NON-NLS-1$
+
+ 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=\"WikipediaEN Dwonload\" type-id=\"Load WikipediaEN\" url=\"http://en.wikipedia.org/w/index.php?title=$text.wikiname&action=raw\"/>"
- + "<config name=\"WikibooksEN Download\" type-id=\"Load WikibooksEN\" url=\"http://en.wikibooks.org/w/index.php?title=$text.wikiname&action=raw\"/>"
- + "<config name=\"WikipediaEN Upload\" type-id=\"Store WikipediaEN\" url=\"http://en.wikipedia.org/w/index.php\"/>"
- + "<config name=\"WikibooksEN Upload\" type-id=\"Store WikibooksEN\" url=\"http://en.wikibooks.org/w/index.php\"/>"
+
+ + "<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://www.plog4u.de/index.php\"/>"
+ + "<config name=\"Plog4U.org Upload\" type-id=\"" + PLOG4U_ORG_STORE + "\" url=\"http://www.plog4u.org/index.php\"/>"
+
+ + "<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>";
return fTemplateStore;
}
+ private static boolean isDefined(String test) {
+ if (test != null && test.length() > 0) {
+ for (int i = 0; i < test.length(); i++) {
+ if (!Character.isWhitespace(test.charAt(i))) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
/*
* (non-Javadoc)
*
*/
protected void initializeDefaultPreferences(IPreferenceStore store) {
store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
+ store.setDefault(CONSOLE_OUTPUT, "true");
+
+ String operatingSystem = Platform.getOS();
+ // operatingSystem ==> maxosx, linux, solaris, win32,...
+ try {
+ InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
+ PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
+
+ String key = EDITOR_WRAP_WORDS;
+ try {
+ String wordWrap = resourceBundle.getString(key);
+ Boolean b = Boolean.valueOf(wordWrap);
+ if (b.booleanValue()) {
+ store.setDefault(key, "true");
+ } else {
+ store.setDefault(key, "false");
+ }
+ } catch (Exception e) {
+ store.setDefault(key, "false");
+ }
+
+ key = HTTP_GET_THROTTLE;
+ try {
+ String timeout = resourceBundle.getString(key);
+ int val = Integer.parseInt(timeout);
+ if (val > 0) {
+ val *= 1000;
+ } else {
+ val = 1000;
+ }
+ store.setDefault(key, Integer.toString(val));
+ } catch (Exception e) {
+ store.setDefault(key, "1000"); // 1 second
+ }
+
+ key = HTTP_PUT_THROTTLE;
+ try {
+ String timeout = resourceBundle.getString(key);
+ int val = Integer.parseInt(timeout);
+ if (val > 0) {
+ val *= 1000;
+ } else {
+ val = 5000;
+ }
+ store.setDefault(key, Integer.toString(val));
+ } catch (Exception e) {
+ store.setDefault(key, "5000"); // 5 seconds
+ }
+
+ key = HTTP_TIMEOUT;
+ try {
+ String timeout = resourceBundle.getString(key);
+ int val = Integer.parseInt(timeout);
+ if (val > 0) {
+ val *= 1000;
+ } else {
+ val = 30000;
+ }
+ store.setDefault(key, Integer.toString(val));
+ } catch (Exception e) {
+ store.setDefault(key, "30000"); // 30 seconds timeout
+ }
+
+ key = HTTP_PROXYHOST;
+ try {
+ String proxyHost = resourceBundle.getString(key);
+ if (isDefined(proxyHost)) {
+ store.setDefault(key, proxyHost);
+ } else {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+ } catch (Exception e) {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+
+ key = HTTP_PROXYPORT;
+ try {
+ String proxyPort = resourceBundle.getString(key);
+ if (isDefined(proxyPort)) {
+ // check for integer parse exception:
+ Integer.parseInt(proxyPort);
+ store.setDefault(key, proxyPort);
+ } else {
+ store.setDefault(key, System.getProperty(key, "80"));
+ }
+ } catch (Exception e) {
+ store.setDefault(key, System.getProperty(key, "80"));
+ }
+
+ key = HTTP_PROXYUSERNAME;
+ try {
+ String proxyUserName = resourceBundle.getString(key);
+ if (isDefined(proxyUserName)) {
+ store.setDefault(key, proxyUserName);
+ } else {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+ } catch (Exception e) {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+
+ key = HTTP_PROXYPASSWORD;
+ try {
+ String proxyPassWord = resourceBundle.getString(key);
+ if (isDefined(proxyPassWord)) {
+ store.setDefault(key, proxyPassWord);
+ } else {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+ } catch (Exception e) {
+ store.setDefault(key, System.getProperty(key, ""));
+ }
+
+ } catch (Exception e) {
+ }
+
}
/*
public void reportError(String title, String message) {
try {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- MessageDialog.openError(shell, title, message);
+ // Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ MessageDialog.openError(null, title, message);
} catch (RuntimeException e) {
log(e.getLocalizedMessage(), e);
}
}
- public void startup() throws CoreException {
- super.startup();
- }
+ // public void startup() throws CoreException {
+ // super.startup();
+ // }
/**
* Returns the translated String found with the given key.
}
/*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugin#shutdown()
+ * (non - Javadoc) Method declared in Plugin
*/
- public void shutdown() throws CoreException {
- if (fWikiDB != null) {
- try {
- fWikiDB.shutdown();
- } catch (SQLException e) {
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * @see org.eclipse.core.runtime.Plugin#stop
+ */
+ public void stop(BundleContext context) throws Exception {
+ try {
+ if (fWikiDB != null) {
+ try {
+ fWikiDB.shutdown();
+ } catch (SQLException e) {
+ }
}
+ } finally {
+ super.stop(context);
}
- super.shutdown();
}
public static void log(int severity, String message) {
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 {