import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.*;
import java.io.*;
import java.net.*;


class URLValidator{
	
   public URLValidator(){}
	  
   public static String validateURL(String URI,boolean absoluteURLonly) throws Exception {
   
   if (URI == null) return "";
   
   try {
   
	URI uri = new URI(URI);
	
	// no permitir URLs relativas si absoluteURLonly=true
	if (absoluteURLonly) {
	
		if (!uri.isAbsolute())
			throw new Exception("URI no absoluta");
	}
	
	
	// requerir http o https en URLs
    if (!"http".equals(uri.getScheme()) &&!"https".equals(uri.getScheme()))
		throw new Exception("only support HTTP");
		
	// normalizar URI
	uri = uri.normalize();
	
	System.out.println("Host:"+uri.getHost());
	
	//comprobar host contra una whitelist/blacklist
	// checkWhiteList(uri.getHost())
	// checkBlackList(uri.getHost())
	
	return uri.toASCIIString();
	
	
   } catch (URISyntaxException use) {
     throw  new Exception(use.getMessage());
   }
   
}
	
}

public class validateURL extends Object {
	public static void main(String[] args) throws Exception{
		String url=URLValidator.validateURL("http://www.domain.com/././directory/dir/../page.html",Boolean.TRUE);
		System.out.println(url);
		
	}
}