| 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 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class DesktopProxySearchStrategy implements ProxySearchStrategy { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 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 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
@Override |
| 48 |
public String getName() { |
| 49 |
return "desktop"; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 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 |
} |