1 11 package org.eclipse.help.internal.base.remote; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.runtime.ListenerList; 17 import org.eclipse.core.runtime.Preferences; 18 import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; 19 import org.eclipse.help.internal.base.BaseHelpSystem; 20 import org.eclipse.help.internal.base.HelpBasePlugin; 21 import org.eclipse.help.internal.base.IHelpBaseConstants; 22 23 26 public class RemoteHelp { 27 28 private static final String PROTOCOL_HTTP = "http"; private static ListenerList listeners; 30 private static Throwable error; 31 32 36 public static void addPreferenceChangeListener(IPreferenceChangeListener listener) { 37 if (listeners == null) { 38 listeners = new ListenerList(); 39 } 40 listeners.add(listener); 41 } 42 43 46 public static void removePreferenceChangeListener(IPreferenceChangeListener listener) { 47 if (listeners != null) { 48 listeners.remove(listener); 49 } 50 } 51 52 56 public static void notifyPreferenceChange() { 57 if (listeners != null) { 58 Object [] array = listeners.getListeners(); 59 for (int i=0;i<array.length;++i) { 60 IPreferenceChangeListener listener = (IPreferenceChangeListener)array[i]; 61 listener.preferenceChange(null); 62 } 63 } 64 } 65 66 public static URL getURL(String pathSuffix) throws MalformedURLException { 67 String host = RemoteHelp.getHost(); 68 String path = RemoteHelp.getPath() + pathSuffix; 69 int port = RemoteHelp.getPort(); 70 return new URL (PROTOCOL_HTTP, host, port, path); 71 } 72 73 77 public static boolean isAllowed() { 78 return (BaseHelpSystem.getMode() != BaseHelpSystem.MODE_INFOCENTER); 79 } 80 81 85 public static boolean isEnabled() { 86 if (isAllowed()) { 87 Preferences prefs = HelpBasePlugin.getDefault().getPluginPreferences(); 88 return prefs.getBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON); 89 } 90 return false; 91 } 92 93 96 public static void clearError() { 97 error = null; 98 } 99 100 104 public static Throwable getError() { 105 return error; 106 } 107 108 112 public static void setError(Throwable t) { 113 error = t; 114 } 115 116 120 private static String getHost() { 121 return HelpBasePlugin.getDefault().getPluginPreferences().getString(IHelpBaseConstants.P_KEY_REMOTE_HELP_HOST); 122 } 123 124 128 private static String getPath() { 129 String path = HelpBasePlugin.getDefault().getPluginPreferences().getString(IHelpBaseConstants.P_KEY_REMOTE_HELP_PATH); 130 if (!path.startsWith("/")) { path = '/' + path; 132 } 133 if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); 135 } 136 return path; 137 } 138 139 142 private static int getPort() { 143 Preferences prefs = HelpBasePlugin.getDefault().getPluginPreferences(); 144 if (prefs.getBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_DEFAULT_PORT) == true) { 145 prefs.getDefaultInt(IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT); 146 } 147 return prefs.getInt(IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT); 148 } 149 150 } 151 | Popular Tags |