~ubuntu-branches/ubuntu/trusty/netbeans/trusty

« back to all changes in this revision

Viewing changes to subversion/main/src/org/netbeans/modules/subversion/util/ProxySettings.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
package org.netbeans.modules.subversion.util;
 
42
 
 
43
import java.util.prefs.Preferences;
 
44
 
 
45
/**
 
46
 *
 
47
 * @author Tomas Stupka
 
48
 */
 
49
public class ProxySettings {
 
50
 
 
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";
 
59
    
 
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";
 
64
            
 
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;
 
74
      
 
75
    private String toString = null;
 
76
    
 
77
    public ProxySettings() {
 
78
        init();
 
79
    };
 
80
        
 
81
    private void init() {
 
82
        Preferences prefs = org.openide.util.NbPreferences.root ().node ("org/netbeans/core");                              // NOI18N    
 
83
        proxyType           = prefs.get        ( PROXY_TYPE,                     ""    );                                   // NOI18N                                        
 
84
 
 
85
        if(proxyType.equals(DIRECT_CONNECTION)) {
 
86
            useAuth             = false;
 
87
            username            = "";                                                                                       // NOI18N
 
88
            password            = "";                                                                                       // NOI18N            
 
89
        
 
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                
 
99
 
 
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            
 
109
        
 
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            
 
115
        }
 
116
    }
 
117
    
 
118
    public boolean isDirect() {
 
119
        return proxyType.equals(DIRECT_CONNECTION);
 
120
    }
 
121
 
 
122
    public boolean isManualSetProxy() {
 
123
        return proxyType.equals(MANUAL_SET_PROXY);
 
124
    }
 
125
    
 
126
    public boolean hasAuth() {
 
127
        return useAuth;
 
128
    }
 
129
    
 
130
    public String getHttpHost() {
 
131
        return httpHost;
 
132
    }
 
133
    
 
134
    public int getHttpPort() {
 
135
        if(httpPort.equals("")) {
 
136
            return 8080;
 
137
        }
 
138
        return Integer.parseInt(httpPort);
 
139
    }
 
140
 
 
141
    public String getHttpsHost() {
 
142
        return httpsHost;
 
143
    }
 
144
    
 
145
    public int getHttpsPort() {
 
146
        if(httpsPort.equals("")) {
 
147
            return 443; 
 
148
        }
 
149
        return Integer.parseInt(httpsPort);
 
150
    }
 
151
    
 
152
    public String getUsername() {
 
153
        return username;
 
154
    }
 
155
    
 
156
    public String getPassword() {
 
157
        return password;
 
158
    }    
 
159
    
 
160
    public String getNotProxyHosts() {
 
161
        return notProxyHosts;
 
162
    }
 
163
    
 
164
    public boolean equals(Object obj) {
 
165
        if(obj == null) {
 
166
            return false;
 
167
        }
 
168
        if(! (obj instanceof ProxySettings) ) {
 
169
            return false;
 
170
        } 
 
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;                   
 
181
    }
 
182
    
 
183
    public String toString() {
 
184
        if(toString == null) {
 
185
            StringBuffer sb = new StringBuffer();
 
186
            sb.append("[");
 
187
            sb.append(httpHost);
 
188
            sb.append(",");        
 
189
            sb.append(httpPort);
 
190
            sb.append(",");        
 
191
            sb.append(httpsHost);
 
192
            sb.append(",");        
 
193
            sb.append(httpsPort);
 
194
            sb.append(",");        
 
195
            sb.append(notProxyHosts);
 
196
            sb.append(",");        
 
197
            sb.append(password);
 
198
            sb.append(",");        
 
199
            sb.append(proxyType);
 
200
            sb.append(",");        
 
201
            sb.append(username);
 
202
            sb.append(",");        
 
203
            sb.append(useAuth);                
 
204
            sb.append("]");
 
205
            toString = sb.toString();
 
206
        }        
 
207
        return toString;
 
208
    }
 
209
 
 
210
    public int hashCode() {
 
211
        return toString().hashCode();
 
212
    }
 
213
    
 
214
    
 
215
}