KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > resolver > VfsResolver


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.resolver;
7
8 import fr.jayasoft.ivy.repository.vfs.VfsRepository;
9
10 import java.util.regex.Matcher JavaDoc;
11 import java.util.regex.Pattern JavaDoc;
12
13 /**
14  * @author S. Nesbitt
15  *
16  */

17 public class VfsResolver extends RepositoryResolver {
18     private static Pattern JavaDoc URLPattern = Pattern.compile("[a-z]*://(.+):(.+)@.*");
19     private static int PASSWORD_GROUP = 2;
20     public VfsResolver() {
21         setRepository(new VfsRepository());
22     }
23
24     public String JavaDoc getTypeName() {
25         return "vfs";
26     }
27
28     public String JavaDoc hidePassword(String JavaDoc name) {
29         return prepareForDisplay(name);
30     }
31     public static String JavaDoc prepareForDisplay(String JavaDoc name) {
32         StringBuffer JavaDoc s = new StringBuffer JavaDoc(name);
33         Matcher JavaDoc m = URLPattern.matcher(s);
34         if (m.matches()) {
35             final String JavaDoc password = m.group(PASSWORD_GROUP);
36             final int passwordposi = s.indexOf(password);
37             StringBuffer JavaDoc stars = new StringBuffer JavaDoc(password);
38             for (int posi = 0; posi < password.length(); posi++) {
39                 stars.setCharAt(posi, '*');
40             }
41             String JavaDoc replacement = stars.toString();
42             s = s.replace(passwordposi, passwordposi + password.length(), replacement);
43         }
44         return s.toString();
45
46     }
47 }
48
Popular Tags