01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.resolver;
19:
20: import java.util.regex.Matcher;
21: import java.util.regex.Pattern;
22:
23: import org.apache.ivy.plugins.repository.vfs.VfsRepository;
24:
25: /**
26: *
27: */
28: public class VfsResolver extends RepositoryResolver {
29: private static final Pattern URL_PATTERN = Pattern
30: .compile("[a-z]*://(.+):(.+)@.*");
31:
32: private static final int PASSWORD_GROUP = 2;
33:
34: public VfsResolver() {
35: setRepository(new VfsRepository());
36: }
37:
38: public String getTypeName() {
39: return "vfs";
40: }
41:
42: public String hidePassword(String name) {
43: return prepareForDisplay(name);
44: }
45:
46: public static String prepareForDisplay(String name) {
47: StringBuffer s = new StringBuffer(name);
48: Matcher m = URL_PATTERN.matcher(s);
49: if (m.matches()) {
50: final String password = m.group(PASSWORD_GROUP);
51: final int passwordposi = s.indexOf(password);
52: StringBuffer stars = new StringBuffer(password);
53: for (int posi = 0; posi < password.length(); posi++) {
54: stars.setCharAt(posi, '*');
55: }
56: String replacement = stars.toString();
57: s = s.replace(passwordposi, passwordposi
58: + password.length(), replacement);
59: }
60: return s.toString();
61:
62: }
63: }
|