List of usage examples for org.apache.commons.validator.routines UrlValidator UrlValidator
public UrlValidator(long options)
From source file:url.Path.java
public String reverseDomains(String str) { String revDomain = ""; try {//from ww w. ja va 2 s.co m UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); //System.out.println("URL: "+str); if (defaultValidator.isValid("http://" + str)) { URL host_path = new URL("http://" + str); String host = host_path.getHost().toLowerCase(); host = host.replace(",", ""); String path = host_path.getPath(); String out[] = host.split("\\."); boolean www = false; // System.out.println("Host: "+host); // System.out.println("Path: "+path); for (int j = out.length - 1; j >= 0; j--) { if (out[j].trim().equals("WWW") || out[j].trim().equals("www")) { www = true; } else { revDomain += "\"" + out[j] + "\"" + "#"; } } if (revDomain.endsWith("#")) { revDomain = revDomain.substring(0, revDomain.length() - 1); } //System.out.println("Host reverse: "+revDomain); if (www) { revDomain += "#" + "\"" + "www" + "\""; www = false; } revDomain += ":"; String path_split[] = path.split("[/]"); //System.out.println("Path Split: "+ Arrays.toString(path_split)); for (int i = 1; i < path_split.length; i++) { revDomain += "\"" + path_split[i].replace(",", "") + "\"" + "#"; } if (revDomain.endsWith("#")) { revDomain = revDomain.substring(0, revDomain.length() - 1); } //System.out.println("URL: "+str); //System.out.println("reverse URL: "+revDomain); } else { System.out.println("Not valid: " + str); } } catch (MalformedURLException ex) { //Logger.getLogger(URLprocess_path.class.getName()).log(Level.SEVERE, null, ex); } return revDomain; }