"
+ public final static String CONSOLE_OUTPUT = "__console_output";
+
+ 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.
+ *
+ * Value is of type Boolean
.
+ *
+ */
+ public final static String EDITOR_WRAP_WORDS = "editor.wrap.words"; //$NON-NLS-1$
+
+ public final static String CONFIG_MEMENTO = "" + ""
+ ""
+ ""
+ ""
- + ""
- + ""
+
+ + "" + ""
+ + ""
+ + ""
+
+ + "" + ""
+ + "" + ""
+ + ""
+ "";
public static WikipediaDB fWikiDB = null;
@@ -169,6 +276,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");
@@ -232,6 +349,17 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
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)
*
@@ -239,6 +367,94 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
*/
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_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) {
+ }
+
}
/*
@@ -293,16 +509,16 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
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.
@@ -371,22 +587,92 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
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()
+ * (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) {
+ 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