KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > config > SVNCredentialFile


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.config;
20
21 import java.io.File JavaDoc;
22 import java.security.MessageDigest JavaDoc;
23 import java.security.NoSuchAlgorithmException JavaDoc;
24 import org.openide.ErrorManager;
25
26 /**
27  * Handles the Subversion credential files.
28  *
29  * @author Tomas Stupka
30  *
31  */

32 public abstract class SVNCredentialFile extends KVFile {
33
34
35     /**
36      * Creates sa new instance
37      */

38     protected SVNCredentialFile(File JavaDoc file) {
39         super(file);
40     }
41
42     /**
43      * Returns the filename for a realmString as a MD5 value in hex form.
44      */

45     protected static String JavaDoc getFileName(String JavaDoc realmString) {
46         assert realmString != null;
47         String JavaDoc fileName = ""; // NOI18N
48
try {
49             MessageDigest JavaDoc md5 = MessageDigest.getInstance("MD5"); // NOI18N
50
md5.update(realmString.getBytes());
51             byte[] md5digest = md5.digest();
52             for (int i = 0; i < md5digest.length; i++) {
53                 String JavaDoc hex = Integer.toHexString(md5digest[i] & 0x000000FF);
54                 if(hex.length()==1) {
55                     hex = "0" + hex; // NOI18N
56
}
57                 fileName += hex;
58             }
59         } catch (NoSuchAlgorithmException JavaDoc e) {
60             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); // should not happen
61
}
62         
63         return fileName;
64     }
65     
66     protected abstract String JavaDoc getRealmString();
67     protected abstract void setRealmString(String JavaDoc realm);
68 }
69
Popular Tags