NetworkSettings
added+ Added new useful methods for getting Network Proxy for specified URI. +
+hostname
part of network proxy address
+ * based on given URI to access the resource at.
+ * Returns null
for direct connection.
+ *
+ * @param u The URI that a connection is required to
+ * @return the hostname part of the Proxy address
+ */
+ public static String getProxyHost(URI u) {
+ if (getPreferences() == null) {
+ return null;
+ }
+ InetSocketAddress sa = analyzeProxy(u);
+ return sa == null ? null : sa.getHostName();
+ }
+
+ /** Returns the port
part of network proxy address
+ * based on given URI to access the resource at.
+ * Returns null
for direct connection.
+ *
+ * @param u The URI that a connection is required to
+ * @return the port part of the Proxy address
+ */
+ public static String getProxyPort(URI u) {
+ if (getPreferences() == null) {
+ return null;
+ }
+ InetSocketAddress sa = analyzeProxy(u);
+ return sa == null ? null : Integer.toString(sa.getPort());
+ }
+
+ /** Returns the username
for Proxy Authentication.
+ * Returns null
if no authentication required.
+ *
+ * @param u The URI that a connection is required to
+ * @return username for Proxy Authentication
+ */
+ public static String getAuthenticationUsername(URI u) {
+ if (getPreferences() == null) {
+ return null;
+ }
+ if (getPreferences().getBoolean(USE_PROXY_AUTHENTICATION, false)) {
+ return getPreferences().get(PROXY_AUTHENTICATION_USERNAME, "");
+ }
+ return null;
+ }
+
+ /** Returns the key
for reading password for Proxy Authentication.
+ * Use {@link Keyring} for reading the password from the ring.
+ * Returns null
if no authentication required.
+ *
+ * @param u The URI that a connection is required to
+ * @return the key for reading password for Proxy Authentication from the ring
+ */
+ public static String getKeyForAuthenticationPassword(URI u) {
+ if (getPreferences() == null) {
+ return null;
+ }
+ if (getPreferences().getBoolean(USE_PROXY_AUTHENTICATION, false)) {
+ return PROXY_AUTHENTICATION_USERNAME;
+ }
+ return null;
+ }
+
+ private static Preferences getPreferences() {
+ return NbPreferences.root().node("org/netbeans/core"); // NOI18N
+ }
+
+ private static InetSocketAddress analyzeProxy(URI u) {
+ List