2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.modules.subversion.util;
43
import java.util.prefs.Preferences;
47
* @author Tomas Stupka
49
public class ProxySettings {
51
private static final String PROXY_HTTP_HOST = "proxyHttpHost";
52
private static final String PROXY_HTTP_PORT = "proxyHttpPort";
53
private static final String PROXY_HTTPS_HOST = "proxyHttpsHost";
54
private static final String PROXY_HTTPS_PORT = "proxyHttpsPort";
55
private static final String NOT_PROXY_HOSTS = "proxyNonProxyHosts";
56
private static final String USE_PROXY_AUTHENTICATION = "useProxyAuthentication";
57
private static final String PROXY_AUTHENTICATION_USERNAME = "proxyAuthenticationUsername";
58
private static final String PROXY_AUTHENTICATION_PASSWORD = "proxyAuthenticationPassword";
60
private static final String PROXY_TYPE = "proxyType";
61
private static final String DIRECT_CONNECTION = "0";
62
private static final String AUTO_DETECT_PROXY = "1"; // as default
63
private static final String MANUAL_SET_PROXY = "2";
65
private String username;
66
private String password;
67
private String notProxyHosts;
68
private boolean useAuth;
69
private String httpHost;
70
private String httpPort;
71
private String httpsHost;
72
private String httpsPort;
73
private String proxyType;
75
private String toString = null;
77
public ProxySettings() {
82
Preferences prefs = org.openide.util.NbPreferences.root ().node ("org/netbeans/core"); // NOI18N
83
proxyType = prefs.get ( PROXY_TYPE, "" ); // NOI18N
85
if(proxyType.equals(DIRECT_CONNECTION)) {
87
username = ""; // NOI18N
88
password = ""; // NOI18N
90
notProxyHosts = ""; // NOI18N
91
httpHost = ""; // NOI18N
92
httpPort = ""; // NOI18N
93
httpsHost = ""; // NOI18N
94
httpsPort = ""; // NOI18N
95
} else if(isManualSetProxy()) {
96
useAuth = prefs.getBoolean ( USE_PROXY_AUTHENTICATION, false ); // NOI18N
97
username = prefs.get ( PROXY_AUTHENTICATION_USERNAME, "" ); // NOI18N
98
password = prefs.get ( PROXY_AUTHENTICATION_PASSWORD, "" ); // NOI18N
100
notProxyHosts = prefs.get ( NOT_PROXY_HOSTS, "" ).replace("|", " ,"); // NOI18N
101
httpHost = prefs.get ( PROXY_HTTP_HOST, "" ); // NOI18N
102
httpPort = prefs.get ( PROXY_HTTP_PORT, "" ); // NOI18N
103
httpsHost = prefs.get ( PROXY_HTTPS_HOST, "" ); // NOI18N
104
httpsPort = prefs.get ( PROXY_HTTPS_PORT, "" ); // NOI18N
105
} else { // AUTO_DETECT_PROXY or DEFAULT
106
useAuth = false; // no way known yet!
107
username = ""; // NOI18N
108
password = ""; // NOI18N
110
notProxyHosts = System.getProperty("http.nonProxyHosts", ""); // NOI18N
111
httpHost = System.getProperty("http.proxyHost", ""); // NOI18N
112
httpPort = System.getProperty("http.proxyPort", ""); // NOI18N
113
httpsHost = System.getProperty("https.proxyHost", ""); // NOI18N
114
httpsPort = System.getProperty("https.proxyPort", ""); // NOI18N
118
public boolean isDirect() {
119
return proxyType.equals(DIRECT_CONNECTION);
122
public boolean isManualSetProxy() {
123
return proxyType.equals(MANUAL_SET_PROXY);
126
public boolean hasAuth() {
130
public String getHttpHost() {
134
public int getHttpPort() {
135
if(httpPort.equals("")) {
138
return Integer.parseInt(httpPort);
141
public String getHttpsHost() {
145
public int getHttpsPort() {
146
if(httpsPort.equals("")) {
149
return Integer.parseInt(httpsPort);
152
public String getUsername() {
156
public String getPassword() {
160
public String getNotProxyHosts() {
161
return notProxyHosts;
164
public boolean equals(Object obj) {
168
if(! (obj instanceof ProxySettings) ) {
171
ProxySettings ps = (ProxySettings) obj;
172
return ps.httpHost.equals(httpHost) &&
173
ps.httpPort.equals(httpPort) &&
174
ps.httpsHost.equals(httpsHost) &&
175
ps.httpsPort.equals(httpsPort) &&
176
ps.notProxyHosts.equals(notProxyHosts) &&
177
ps.password.equals(password) &&
178
ps.proxyType.equals(proxyType) &&
179
ps.username.equals(username) &&
180
ps.useAuth == useAuth;
183
public String toString() {
184
if(toString == null) {
185
StringBuffer sb = new StringBuffer();
191
sb.append(httpsHost);
193
sb.append(httpsPort);
195
sb.append(notProxyHosts);
199
sb.append(proxyType);
205
toString = sb.toString();
210
public int hashCode() {
211
return toString().hashCode();