Example usage for org.apache.commons.validator.routines UrlValidator UrlValidator

List of usage examples for org.apache.commons.validator.routines UrlValidator UrlValidator

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines UrlValidator UrlValidator.

Prototype

public UrlValidator() 

Source Link

Document

Create a UrlValidator with default properties.

Usage

From source file:sk.svec.jan.acb.web.SettingsForm.java

private static String validateUrl(String value, String fieldName, StringBuilder errors) {
    UrlValidator urlValidator = new UrlValidator();
    if (!value.startsWith("http://")) {
        value = "http://" + value;
    }/*from w ww  . j a v  a 2s .c o  m*/
    boolean valid = urlValidator.isValid(value);
    if (value == null || value.isEmpty()) {
        errors.append("Zadajte prosm url. do poa '").append(fieldName).append("'").append(". <br />");
    } else if (!valid) {
        errors.append("Url ").append(value).append(" je neplatn. Zadajte prosm platn url. <br />");
    }

    return value;
}

From source file:url.Domain.java

public String reverseDomains(String str) {
    String revDomain = "";
    try {//  www .  j a  va2s. c  o m

        UrlValidator defaultValidator = new UrlValidator();
        //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 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 (!nodeColorMap.containsKey(out[j])) {
                        nodeColorMap.put(out[j], getColor());
                    }

                }

            }
            if (revDomain.endsWith("#")) {
                revDomain = revDomain.substring(0, revDomain.length() - 1);
            }
            //System.out.println("Host reverse: "+revDomain);
            if (www) {
                revDomain += "#" + "www";
                www = false;
            }
            revDomain += "#" + "end";

            //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;
}