KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > client > SvnClientCallback


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.client;
20
21 import java.awt.Dialog JavaDoc;
22 import javax.swing.JButton JavaDoc;
23 import org.netbeans.modules.subversion.ui.repository.Repository;
24 import org.netbeans.modules.subversion.ui.repository.RepositoryConnection;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.util.HelpCtx;
28 import org.tigris.subversion.svnclientadapter.ISVNPromptUserPassword;
29 import org.tigris.subversion.svnclientadapter.SVNUrl;
30
31 /**
32  *
33  * @author Tomas Stupka
34  */

35 public class SvnClientCallback implements ISVNPromptUserPassword {
36     
37     private final SVNUrl url;
38     private final int handledExceptions;
39     
40     private String JavaDoc username = null;
41     private String JavaDoc password = null;
42
43     private final boolean prompt;
44     
45     /** Creates a new instance of SvnClientCallback */
46     public SvnClientCallback(SVNUrl url, int handledExceptions) {
47         this.url = url;
48         this.handledExceptions = handledExceptions;
49         this.prompt = (SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) == SvnClientExceptionHandler.EX_AUTHENTICATION;
50     }
51
52     public boolean askYesNo(String JavaDoc string, String JavaDoc string0, boolean b) {
53         // TODO implement me
54
return false;
55     }
56
57     public String JavaDoc getUsername() {
58         if((SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) != SvnClientExceptionHandler.EX_AUTHENTICATION) {
59             return null;
60         }
61         if(username == null) {
62             getAuthData();
63         }
64         String JavaDoc ret = username;
65         username = null;
66         return ret;
67     }
68
69     public String JavaDoc getPassword() {
70         if((SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) != SvnClientExceptionHandler.EX_AUTHENTICATION) {
71             return null;
72         }
73         if(password == null) {
74             getAuthData();
75         }
76         String JavaDoc ret = password;
77         password = null;
78         return ret;
79     }
80
81     public int askTrustSSLServer(String JavaDoc certMessage, boolean b) {
82         
83         if((SvnClientExceptionHandler.EX_NO_CERTIFICATE & handledExceptions) != SvnClientExceptionHandler.EX_NO_CERTIFICATE) {
84             return -1; // XXX test me
85
}
86         
87         AcceptCertificatePanel acceptCertificatePanel = new AcceptCertificatePanel();
88         acceptCertificatePanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Error_CertFailed"));
89         acceptCertificatePanel.certificatePane.setText(certMessage);
90         
91         DialogDescriptor dialogDescriptor = new DialogDescriptor(acceptCertificatePanel, org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Error_CertFailed")); // NOI18N
92

93         JButton JavaDoc permanentlyButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_AcceptPermanently")); // NOI18N
94
JButton JavaDoc temporarilyButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_AcceptTemp")); // NOI18N
95
JButton JavaDoc rejectButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_Reject")); // NOI18N
96

97         dialogDescriptor.setOptions(new Object JavaDoc[] { permanentlyButton, temporarilyButton, rejectButton });
98
99         showDialog(dialogDescriptor);
100
101         if(dialogDescriptor.getValue()!=permanentlyButton) {
102             return ISVNPromptUserPassword.AcceptPermanently;
103         } else if(dialogDescriptor.getValue()!=temporarilyButton) {
104             return ISVNPromptUserPassword.AcceptTemporary;
105         } else {
106             return ISVNPromptUserPassword.Reject;
107         }
108     }
109
110     public boolean prompt(String JavaDoc string, String JavaDoc string0, boolean b) {
111         return prompt;
112     }
113
114     public String JavaDoc askQuestion(String JavaDoc string, String JavaDoc string0, boolean b, boolean b0) {
115         // TODO implement me
116
return null;
117     }
118
119     public boolean userAllowedSave() {
120         return true;
121     }
122
123     public boolean promptSSH(String JavaDoc string, String JavaDoc string0, int i, boolean b) {
124         // TODO implement me
125
return false;
126     }
127
128     public String JavaDoc getSSHPrivateKeyPath() {
129         // TODO implement me
130
return null;
131     }
132
133     public String JavaDoc getSSHPrivateKeyPassphrase() {
134         // TODO implement me
135
return null;
136     }
137
138     public int getSSHPort() {
139         // TODO implement me
140
return -1;
141     }
142
143     public boolean promptSSL(String JavaDoc string, boolean b) {
144         // TODO implement me
145
return false;
146     }
147
148     public String JavaDoc getSSLClientCertPassword() {
149         // TODO implement me
150
return null;
151     }
152
153     public String JavaDoc getSSLClientCertPath() {
154         // TODO implement me
155
return null;
156     }
157
158     private void showDialog(DialogDescriptor dialogDescriptor) {
159         dialogDescriptor.setModal(true);
160         dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass()));
161         dialogDescriptor.setValid(false);
162
163         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
164         dialog.setVisible(true);
165     }
166     
167     private void getAuthData() {
168         String JavaDoc title = org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "MSG_Error_ConnectionParameters"); // NOI18N
169

170         Repository repository = new Repository(title);
171         repository.selectUrl(url, true);
172         
173         JButton JavaDoc retryButton = new JButton JavaDoc(org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Action_Retry")); // NOI18N
174
Object JavaDoc option = repository.show(org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "MSG_Error_AuthFailed"), // NOI18N
175
new HelpCtx(this.getClass()),
176                                         new Object JavaDoc[] {retryButton, org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Action_Cancel")}); // NOI18N
177

178
179         boolean ret = (option == retryButton);
180         if(ret) {
181             RepositoryConnection rc = repository.getSelectedRC();
182             username = rc.getUsername();
183             password = rc.getPassword();
184             // XXX we don't need this and it also should be assured that the adapter isn't precofigured with auth data as long it's not the commandline ...
185
//adapter.setUsername(username);
186
//adapter.setPassword(password);
187
}
188     }
189
190 }
191
Popular Tags