com.alee.managers.proxy
Class ProxyManager

java.lang.Object
  extended by com.alee.managers.proxy.ProxyManager

public final class ProxyManager
extends java.lang.Object

This manager allows you to quickly manage application's global proxy settings. When activated this manager might cause a proxy chooser or an authentification popup to pop. That will happen in case it will detect that your proxy settings does not match system proxy settings.

Author:
Mikle Garin

Field Summary
static java.lang.String ALWAYS_USE_SYSTEM_SETTINGS
          Settings key for system proxy settings usage option.
static java.lang.String AUTO_SETTINGS_ON
          Settings key for automated proxy settings option.
static java.lang.String PROXY_SETTINGS
          Settings key for proxy settings.
static java.lang.String SAVE_SETTINGS
          Settings key for proxy settings save option.
static java.lang.String SETTINGS_GROUP
          Settings group key for proxy settings.
 
Constructor Summary
ProxyManager()
           
 
Method Summary
static java.net.Authenticator getAuthenticator()
          Returns current proxy authenticator.
static ProxySettings getProxySettings()
          Returns current proxy settings or default proxy settings if none installed.
static SystemProxyConfirmationSupport getSystemProxyConfirmationSupport()
          Returns system proxy settings confirmation dialog support.
static ProxySettings getSystemProxySettings()
          Returns single system proxy settings object.
static java.net.URLConnection getURLConnection(java.net.URL url)
          Opens URL connection with current proxy settings.
static void initialize()
          Initializes manager if it wasn't already initialized.
static boolean isAlwaysUseSystemSettings()
          Returns whether system proxy settings usage is enabled or not.
static boolean isAutoDetectionEnabled()
          Returns whether automatic proxy detection is enabled or not.
static boolean isAutoSettingsInitialization()
          Returns whether auto initialization of proxy settings is enabled or not.
static void setAlwaysUseSystemSettings(boolean useSystem)
          Sets whether enable system proxy settings usage or not.
static void setAuthenticator(java.net.Authenticator authenticator)
          Changes current proxy authenticator to the specified one.
static void setAutoDetectionEnabled(boolean enabled)
          Sets whether automatic proxy detection is enabled or not.
static void setAutoSettingsInitialization(boolean enabled)
          Sets whether enable auto initialization of proxy settings or not.
static void setEmptyProxySettings()
          Installs empty proxy settings.
static void setProxySettings()
          Installs saved or system proxy settings.
static void setProxySettings(ProxySettings setttings)
          Installs proxy settings with specified host, port and proxy login and password.
static void setProxySettings(ProxySettings setttings, boolean save)
          Installs proxy settings with specified host, port and proxy login and password.
static void setProxySettings(java.lang.String host, java.lang.String port)
          Installs proxy settings with specified host and port.
static void setProxySettings(java.lang.String host, java.lang.String port, java.lang.String login, java.lang.String password)
          Installs proxy settings with specified host, port and proxy login and password.
static void setSystemProxyConfirmationSupport(SystemProxyConfirmationSupport support)
          Sets system proxy settings confirmation dialog support.
static ProxySettings setSystemProxySettings()
          Installs system proxy settings.
static void setupProxy(java.net.URLConnection urlConnection)
          Installs current proxy settings to URL connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SETTINGS_GROUP

public static java.lang.String SETTINGS_GROUP
Settings group key for proxy settings.


PROXY_SETTINGS

public static java.lang.String PROXY_SETTINGS
Settings key for proxy settings.


AUTO_SETTINGS_ON

public static java.lang.String AUTO_SETTINGS_ON
Settings key for automated proxy settings option.


ALWAYS_USE_SYSTEM_SETTINGS

public static java.lang.String ALWAYS_USE_SYSTEM_SETTINGS
Settings key for system proxy settings usage option.


SAVE_SETTINGS

public static java.lang.String SAVE_SETTINGS
Settings key for proxy settings save option.

Constructor Detail

ProxyManager

public ProxyManager()
Method Detail

initialize

public static void initialize()
Initializes manager if it wasn't already initialized.


isAutoDetectionEnabled

public static boolean isAutoDetectionEnabled()
Returns whether automatic proxy detection is enabled or not.

Returns:
true if automatic proxy detection is enabled, false otherwise

setAutoDetectionEnabled

public static void setAutoDetectionEnabled(boolean enabled)
Sets whether automatic proxy detection is enabled or not.

Parameters:
enabled - whether automatic proxy detection is enabled or not

getAuthenticator

public static java.net.Authenticator getAuthenticator()
Returns current proxy authenticator.

Returns:
current proxy authenticator

setAuthenticator

public static void setAuthenticator(java.net.Authenticator authenticator)
Changes current proxy authenticator to the specified one.

Parameters:
authenticator - new proxy authenticator

setAutoSettingsInitialization

public static void setAutoSettingsInitialization(boolean enabled)
Sets whether enable auto initialization of proxy settings or not.

Parameters:
enabled - whether enable auto initialization of proxy settings or not

isAutoSettingsInitialization

public static boolean isAutoSettingsInitialization()
Returns whether auto initialization of proxy settings is enabled or not.

Returns:
true if auto initialization of proxy settings is enabled, false otherwise

setAlwaysUseSystemSettings

public static void setAlwaysUseSystemSettings(boolean useSystem)
Sets whether enable system proxy settings usage or not.

Parameters:
useSystem - whether enable system proxy settings usage or not

isAlwaysUseSystemSettings

public static boolean isAlwaysUseSystemSettings()
Returns whether system proxy settings usage is enabled or not.

Returns:
true if system proxy settings usage is enabled, false otherwise

getProxySettings

public static ProxySettings getProxySettings()
Returns current proxy settings or default proxy settings if none installed.

Returns:
current proxy settings or default proxy settings if none installed

setProxySettings

public static void setProxySettings()
Installs saved or system proxy settings. This method will install existing proxy settings that were saved before. If old proxy settings could not be found then system proxy settigns will be retrieved and installed.


setEmptyProxySettings

public static void setEmptyProxySettings()
Installs empty proxy settings. This method simply disables proxy.


setSystemProxySettings

public static ProxySettings setSystemProxySettings()
Installs system proxy settings.

Returns:
single system proxy settings object

setProxySettings

public static void setProxySettings(java.lang.String host,
                                    java.lang.String port)
Installs proxy settings with specified host and port. If the specified proxy requires authentification user will get prompted.

Parameters:
host - proxy host
port - proxy port

setProxySettings

public static void setProxySettings(java.lang.String host,
                                    java.lang.String port,
                                    java.lang.String login,
                                    java.lang.String password)
Installs proxy settings with specified host, port and proxy login and password.

Parameters:
host - proxy host
port - proxy port
login - proxy login
password - proxy password

setProxySettings

public static void setProxySettings(ProxySettings setttings)
Installs proxy settings with specified host, port and proxy login and password.

Parameters:
setttings - single proxy settings object

setProxySettings

public static void setProxySettings(ProxySettings setttings,
                                    boolean save)
Installs proxy settings with specified host, port and proxy login and password.

Parameters:
setttings - single proxy settings object
save - whether save these settings or not

getURLConnection

public static java.net.URLConnection getURLConnection(java.net.URL url)
                                               throws java.io.IOException
Opens URL connection with current proxy settings.

Parameters:
url - url to process
Returns:
opened URL connection
Throws:
java.io.IOException

setupProxy

public static void setupProxy(java.net.URLConnection urlConnection)
Installs current proxy settings to URL connection.

Parameters:
urlConnection - URL connection to modify

getSystemProxySettings

public static ProxySettings getSystemProxySettings()
Returns single system proxy settings object.

Returns:
single system proxy settings object

getSystemProxyConfirmationSupport

public static SystemProxyConfirmationSupport getSystemProxyConfirmationSupport()
Returns system proxy settings confirmation dialog support.

Returns:
system proxy settings confirmation dialog support

setSystemProxyConfirmationSupport

public static void setSystemProxyConfirmationSupport(SystemProxyConfirmationSupport support)
Sets system proxy settings confirmation dialog support.

Parameters:
support - system proxy settings confirmation dialog support