Debian Codegraph @

src/main/java/com/github/markusbernhardt/proxy/search/desktop/DesktopProxySearchStrategy.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.search.desktop;
2
3 import java.net.ProxySelector;
4
5 import com.github.markusbernhardt.proxy.ProxySearchStrategy;
6 import com.github.markusbernhardt.proxy.search.desktop.gnome.GnomeProxySearchStrategy;
7 import com.github.markusbernhardt.proxy.search.desktop.kde.KdeProxySearchStrategy;
8 import com.github.markusbernhardt.proxy.search.desktop.osx.OsxProxySearchStrategy;
9 import com.github.markusbernhardt.proxy.search.desktop.win.WinProxySearchStrategy;
10 import com.github.markusbernhardt.proxy.util.Logger;
11 import com.github.markusbernhardt.proxy.util.PlatformUtil;
12 import com.github.markusbernhardt.proxy.util.ProxyException;
13 import com.github.markusbernhardt.proxy.util.Logger.LogLevel;
14 import com.github.markusbernhardt.proxy.util.PlatformUtil.Desktop;
15 import com.github.markusbernhardt.proxy.util.PlatformUtil.Platform;
16
17 /*****************************************************************************
18 * This search provider will try to find out on which desktop platform we are
19 * running and then will initialize the default proxy search.
20 *
21 * @author Markus Bernhardt, Copyright 2016
22 * @author Bernd Rosstauscher, Copyright 2009
23 ****************************************************************************/
24
25 public class DesktopProxySearchStrategy implements ProxySearchStrategy {
26
27 /*************************************************************************
28 * Gets the default ProxySelector for the current platform.
29 *
30 * @return a ProxySelector, null if none is found.
31 * @throws ProxyException
32 * on error.
33 ************************************************************************/
34
35 @Override
36 public ProxySelector getProxySelector() throws ProxyException {
37 ProxySearchStrategy strategy = findDesktopSpecificStrategy();
38 return strategy == null ? null : strategy.getProxySelector();
39 }
40
41 /*************************************************************************
42 * Gets the printable name of the search strategy.
43 *
44 * @return the printable name of the search strategy
45 ************************************************************************/
46
47 @Override
48 public String getName() {
49 return "desktop";
50 }
51
52 /*************************************************************************
53 * Determine the desktop and create a strategy for it.
54 *
55 * @return a desktop specific strategy, null if none was found.
56 ************************************************************************/
57
58 private ProxySearchStrategy findDesktopSpecificStrategy() {
59 Platform pf = PlatformUtil.getCurrentPlattform();
60 Desktop dt = PlatformUtil.getCurrentDesktop();
61
62 Logger.log(getClass(), LogLevel.TRACE, "Detecting system settings.");
63
64 ProxySearchStrategy strategy = null;
65
66 if (pf == Platform.WIN) {
67 Logger.log(getClass(), LogLevel.TRACE, "We are running on Windows.");
68 strategy = new WinProxySearchStrategy();
69 } else if (dt == Desktop.KDE) {
70 Logger.log(getClass(), LogLevel.TRACE, "We are running on KDE.");
71 strategy = new KdeProxySearchStrategy();
72 } else if (dt == Desktop.GNOME) {
73 Logger.log(getClass(), LogLevel.TRACE, "We are running on Gnome.");
74 strategy = new GnomeProxySearchStrategy();
75 } else if (dt == Desktop.MAC_OS) {
76 Logger.log(getClass(), LogLevel.TRACE, "We are running on Mac OSX.");
77 strategy = new OsxProxySearchStrategy();
78 }
79 return strategy;
80 }
81
82 }