Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 852a76672fe232a4df6cae64d71234ad35789d6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
 * Copyright (c) 2009, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.help.remote;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.IHelpBaseConstants;

public class RemotePreferenceStore {
	
	private static String namePreference;
	private static String hostPreference;
	private static String pathPreference;
	private static String protocolPreference;
	private static String portPreference;
	private static String icEnabledPreference;
	private static String helpOn;
	private static String defaultPort;
	private static String remoteHelpPreferred;
	private static String pageNotFound;
	
	public static void savePreferences() throws Exception {
	    namePreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_NAME,
			      "", null);
	     hostPreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_HOST,
			      "", null);
		pathPreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PATH,
			      "", null);
		protocolPreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PROTOCOL,
			      "", null);
		portPreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT,
			      "", null);
		icEnabledPreference = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled,
			      "", null);
		defaultPort = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_DEFAULT_PORT,
			      "", null);
		helpOn = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON,
			      "", null); 
		remoteHelpPreferred = Platform.getPreferencesService().getString
	     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED,
			      "", null); 
		pageNotFound = Platform.getPreferencesService().getString
				     (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_PAGE_NOT_FOUND,
						      "", null); 
	}
	
	public static void restorePreferences() throws Exception {
		IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_NAME, namePreference);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_HOST, hostPreference);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PATH, pathPreference);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PROTOCOL, protocolPreference);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT, portPreference);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_DEFAULT_PORT, defaultPort);
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, helpOn);		
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled, icEnabledPreference);	
		prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, remoteHelpPreferred);	
		prefs.put(IHelpBaseConstants.P_PAGE_NOT_FOUND, pageNotFound);
	}

	public static void setMockRemoteServer() throws Exception {
        TestServerManager.start("ua.test", 0);
		RemotePreferenceTest.setPreference("remoteHelpOn", "true");
		RemotePreferenceTest.setPreference("remoteHelpHost", "localhost");
		RemotePreferenceTest.setPreference("remoteHelpPath", "/help");
		RemotePreferenceTest.setPreference("remoteHelpProtocol", "http");
		RemotePreferenceTest.setPreference("remoteHelpUseDefaultPort", "");
		RemotePreferenceTest.setPreference("remoteHelpPort", "" + TestServerManager.getPort(0));
		RemotePreferenceTest.setPreference("remoteHelpName", "uatest");
		RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true");
		RemotePreferenceTest.setPreference("remoteHelpICContributed", "false");
	}	

	public static void setTwoMockRemoteServers() throws Exception {
        TestServerManager.start("ua.test", 0);
        TestServerManager.start("ua.test2", 1);
		RemotePreferenceTest.setPreference("remoteHelpOn", "true");
		RemotePreferenceTest.setPreference("remoteHelpHost", "localhost,localhost");
		RemotePreferenceTest.setPreference("remoteHelpPath", "/help,/help");
		RemotePreferenceTest.setPreference("remoteHelpProtocol", "http,http");
		RemotePreferenceTest.setPreference("remoteHelpUseDefaultPort", ",");
		RemotePreferenceTest.setPreference("remoteHelpPort", "" 
				+ TestServerManager.getPort(0) + ',' + TestServerManager.getPort(1));
		RemotePreferenceTest.setPreference("remoteHelpName", "uatest,uatest2");
		RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true");
		RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false");
	}
	public static void setTwoMockRemoteServersReversePriority() throws Exception {
        TestServerManager.start("ua.test", 0);
        TestServerManager.start("ua.test2", 1);
		RemotePreferenceTest.setPreference("remoteHelpOn", "true");
		RemotePreferenceTest.setPreference("remoteHelpHost", "localhost,localhost");
		RemotePreferenceTest.setPreference("remoteHelpPath", "/help,/help");
		RemotePreferenceTest.setPreference("remoteHelpProtocol", "http,http");
		RemotePreferenceTest.setPreference("remoteHelpUseDefaultPort", "true,true");
		RemotePreferenceTest.setPreference("remoteHelpPort", "" 
				+ TestServerManager.getPort(1) + ',' + TestServerManager.getPort(0));
		RemotePreferenceTest.setPreference("remoteHelpName", "uatest,uatest2");
		RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true");
		RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false");
	}
	
	public static void disableRemoteHelp() throws Exception {
		RemotePreferenceTest.setPreference("remoteHelpOn", "false");
	}
	
	public static void disableErrorPage() throws Exception {
		RemotePreferenceTest.setPreference(IHelpBaseConstants.P_PAGE_NOT_FOUND, "");
	}

	public static void setMockLocalPriority() throws Exception {
		RemotePreferenceTest.setPreference("remoteHelpOn", "true");
		RemotePreferenceTest.setPreference("remoteHelpPreferred", "false");
	}
	
	public static void setMockRemotePriority() throws Exception {
		RemotePreferenceTest.setPreference("remoteHelpOn", "true");
		RemotePreferenceTest.setPreference("remoteHelpPreferred", "true");
	}
}

Back to the top