1 /**********************************************************************
 
   2 Copyright (c) 2000, 2002 IBM Corp. and others.
 
   3 All rights reserved. This program and the accompanying materials
 
   4 are made available under the terms of the Common Public License v1.0
 
   5 which accompanies this distribution, and is available at
 
   6 http://www.eclipse.org/legal/cpl-v10.html
 
   9     IBM Corporation - Initial implementation
 
  10     Klaus Hartlage - www.eclipseproject.de
 
  11 **********************************************************************/
 
  12 package net.sourceforge.phpeclipse;
 
  14 import java.util.MissingResourceException;
 
  15 import java.util.ResourceBundle;
 
  17 import org.eclipse.core.resources.IWorkspace;
 
  18 import org.eclipse.core.resources.ResourcesPlugin;
 
  19 import org.eclipse.core.runtime.IPluginDescriptor;
 
  20 import org.eclipse.jface.preference.IPreferenceStore;
 
  21 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
  24  * The main plugin class to be used in the desktop.
 
  26 public class PHPeclipsePlugin extends AbstractUIPlugin {
 
  27         public static final String LOCALHOST_PREF = "_localhost";
 
  28         public static final String DOCUMENTROOT_PREF = "_documentroot";
 
  29         public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
 
  30         public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
 
  31         public static final String MYSQL_PREF = "_my_sql";
 
  32         public static final String APACHE_START_PREF = "_apache_start";
 
  33         public static final String APACHE_STOP_PREF = "_apache_stop";
 
  34         public static final String APACHE_RESTART_PREF = "_apache_restart";
 
  35         //The shared instance.
 
  36         private static PHPeclipsePlugin plugin;
 
  38         private ResourceBundle resourceBundle;
 
  40         * The Java virtual machine that we are running on.  
 
  42         private static int jvm;
 
  45         private static final int MRJ_2_0 = 0;
 
  47         /** MRJ 2.1 or later */
 
  48         private static final int MRJ_2_1 = 1;
 
  50         /** Java on Mac OS X 10.0 (MRJ 3.0) */
 
  51         private static final int MRJ_3_0 = 3;
 
  54         private static final int MRJ_3_1 = 4;
 
  57         private static final int WINDOWS_NT = 5;
 
  60         private static final int WINDOWS_9x = 6;
 
  62         /** JVM constant for any other platform */
 
  63         private static final int OTHER = -1;
 
  67         public PHPeclipsePlugin(IPluginDescriptor descriptor) {
 
  72                         resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
 
  73                 } catch (MissingResourceException x) {
 
  74                         resourceBundle = null;
 
  78         public static void setJVM() {
 
  79                 String osName = System.getProperty("os.name");
 
  81                 if (osName.startsWith("Mac OS")) {
 
  82                         String mrjVersion = System.getProperty("mrj.version");
 
  83                         String majorMRJVersion = mrjVersion.substring(0, 3);
 
  87                                 double version = Double.valueOf(majorMRJVersion).doubleValue();
 
  91                                 } else if (version >= 2.1 && version < 3) {
 
  93                                 } else if (version == 3.0) {
 
  95                                 } else if (version >= 3.1) {
 
  96                                         // Assume that all 3.1 and later versions of MRJ work the same.
 
 100                         } catch (NumberFormatException nfe) {
 
 104                 } else if (osName.startsWith("Windows")) {
 
 105                         if (osName.indexOf("9") != -1) {
 
 112         public static int getJVM() {
 
 116          * Returns the shared instance.
 
 118         public static PHPeclipsePlugin getDefault() {
 
 123          * Returns the workspace instance.
 
 125         public static IWorkspace getWorkspace() {
 
 126                 return ResourcesPlugin.getWorkspace();
 
 130          * Returns the string from the plugin's resource bundle,
 
 131          * or 'key' if not found.
 
 133         public static String getResourceString(String key) {
 
 134                 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
 
 136                         return bundle.getString(key);
 
 137                 } catch (MissingResourceException e) {
 
 143          * Returns the plugin's resource bundle,
 
 145         public ResourceBundle getResourceBundle() {
 
 146                 return resourceBundle;
 
 149         protected void initializeDefaultPreferences(IPreferenceStore store) {
 
 150                 // windows preferences:
 
 151                 store.setDefault(LOCALHOST_PREF, "http://localhost");
 
 153                 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
 
 154                 if (jvm == WINDOWS_9x) {
 
 155                         store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
 
 156                 } else if (jvm == WINDOWS_NT) {
 
 157                         store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
 
 159                         store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
 
 161                 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
 
 162       store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
 
 163                         store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
 
 164                         store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe \"DocumentRoot \"{0}\"\"");
 
 165                         store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
 
 166                         store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
 
 168       store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
 
 169                         store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
 
 170                         store.setDefault(APACHE_START_PREF, "/apache/apache \"DocumentRoot \"{0}\"\"");
 
 171                         store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
 
 172                         store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");