summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/btr/proxy/search/desktop/DesktopProxySearchStrategy.java
blob: 8a5a5d8565c0ce2087aacb7a5cc6eb5598950b0f (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
package com.btr.proxy.search.desktop;

import java.net.ProxySelector;

import com.btr.proxy.search.ProxySearchStrategy;
import com.btr.proxy.search.desktop.gnome.GnomeProxySearchStrategy;
import com.btr.proxy.search.desktop.kde.KdeProxySearchStrategy;
import com.btr.proxy.search.desktop.osx.OsxProxySearchStrategy;
import com.btr.proxy.search.desktop.win.WinProxySearchStrategy;
import com.btr.proxy.util.Logger;
import com.btr.proxy.util.PlatformUtil;
import com.btr.proxy.util.ProxyException;
import com.btr.proxy.util.Logger.LogLevel;
import com.btr.proxy.util.PlatformUtil.Desktop;
import com.btr.proxy.util.PlatformUtil.Platform;

/*****************************************************************************
 * This search provider will try to find out on which desktop platform we 
 * are running and then will initialize the default proxy search. 
 *
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ****************************************************************************/

public class DesktopProxySearchStrategy implements ProxySearchStrategy {

	/*************************************************************************
	 * Gets the default ProxySelector for the current platform.
	 * @return a ProxySelector, null if none is found.
	 * @throws ProxyException on error.
	 ************************************************************************/
	
	public ProxySelector getProxySelector() throws ProxyException {
		ProxySearchStrategy strategy = findDesktopSpecificStrategy();
		return strategy == null? null : strategy.getProxySelector();
	}

	/*************************************************************************
	 * Determine the desktop and create a strategy for it.
	 * @return a desktop specific strategy, null if none was found.
	 ************************************************************************/
	
	private ProxySearchStrategy findDesktopSpecificStrategy() {
		Platform pf = PlatformUtil.getCurrentPlattform();
		Desktop dt = PlatformUtil.getCurrentDesktop();
		
		Logger.log(getClass(), LogLevel.TRACE, "Detecting system settings.");
		
		ProxySearchStrategy strategy = null;
		
		if (pf == Platform.WIN) {
			Logger.log(getClass(), LogLevel.TRACE, "We are running on Windows.");
			strategy = new WinProxySearchStrategy();
		} else
		if (dt == Desktop.KDE) {
			Logger.log(getClass(), LogLevel.TRACE, "We are running on KDE.");
			strategy = new KdeProxySearchStrategy();
		} else 
		if (dt == Desktop.GNOME) {
			Logger.log(getClass(), LogLevel.TRACE, "We are running on Gnome.");
			strategy = new GnomeProxySearchStrategy();
		} else
		if (dt == Desktop.MAC_OS) {
			Logger.log(getClass(), LogLevel.TRACE, "We are running on Mac OSX.");
			strategy = new OsxProxySearchStrategy();
		}
		return strategy;
	}

}