1 package org.apache.maven.wagon.proxy; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.StringTokenizer; 23 24 /** 25 * @author <a href="mailto:lafeuil@gmail.com">Thomas Champagne</a> 26 */ 27 public final class ProxyUtils 28 { 29 private ProxyUtils() 30 { 31 } 32 33 /** 34 * Check if the specified host is in the list of non proxy hosts. 35 * 36 * @param proxy the proxy info object contains set of properties. 37 * @param targetHost the target hostname 38 * @return true if the hostname is in the list of non proxy hosts, false otherwise. 39 */ 40 public static boolean validateNonProxyHosts( ProxyInfo proxy, String targetHost ) 41 { 42 if ( targetHost == null ) 43 { 44 targetHost = new String(); 45 } 46 if ( proxy == null ) 47 { 48 return false; 49 } 50 String nonProxyHosts = proxy.getNonProxyHosts(); 51 if ( nonProxyHosts == null ) 52 { 53 return false; 54 } 55 56 StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|" ); 57 58 while ( tokenizer.hasMoreTokens() ) 59 { 60 String pattern = tokenizer.nextToken(); 61 pattern = pattern.replaceAll( "\\.", "\\\\." ).replaceAll( "\\*", ".*" ); 62 if ( targetHost.matches( pattern ) ) 63 { 64 return true; 65 } 66 } 67 return false; 68 } 69 }