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

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

Introduction

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

Prototype

public boolean isValid(String value) 

Source Link

Document

Checks if a field has a valid url address.

Usage

From source file:pt.ua.scaleus.api.API.java

/**
 * Removes the given triple statement in the database.
 *
 * @param database//from ww w.j  a v a  2  s.  c  o  m
 * @param triple
 */
public void removeStatement(String database, NTriple triple) {
    Dataset dataset = getDataset(database);
    dataset.begin(ReadWrite.WRITE);
    try {
        Model model = dataset.getDefaultModel();

        Resource s = model.createResource(triple.getS());
        Property p = model.createProperty(triple.getP());

        UrlValidator urlValidator = new UrlValidator();
        if (urlValidator.isValid(triple.getO())) {
            Resource o = model.createResource(triple.getO());
            Statement stat = model.createStatement(s, p, o);
            model.remove(stat);
        } else {
            Statement stat = model.createLiteralStatement(s, p, triple.getO());
            if (model.contains(stat)) {
                model.remove(stat);
            }
        }

        dataset.commit();
        //model.close();
    } finally {
        dataset.end();
    }
}

From source file:pt.ua.scaleus.api.API.java

/**
 * Adds the given quad statement to the database.
 *
 * @param database//from w w w  . j a  va 2s  .co m
 * @param quad
 * @return success of the operation.
 */
public boolean addStatement(String database, NQuad quad) {
    Dataset dataset = getDataset(database);
    dataset.begin(ReadWrite.WRITE);

    try {

        DatasetGraph ds = dataset.asDatasetGraph();
        Node c = NodeFactory.createURI(quad.getC());
        Node s = NodeFactory.createURI(quad.getS());
        Node p = NodeFactory.createURI(quad.getP());

        UrlValidator urlValidator = new UrlValidator();
        if (urlValidator.isValid(quad.getO())) {
            Node o = NodeFactory.createURI(quad.getO());
            ds.add(c, s, p, o);
        } else {
            Node o = NodeFactory.createLiteral(quad.getO());
            ds.add(c, s, p, o);
        }

        dataset.commit();
        //model.close();
    } catch (Exception e) {
        log.error("Add statement failed", e);
    } finally {
        dataset.end();
    }
    return true;
}

From source file:pt.ua.scaleus.api.API.java

/**
 * Adds the given triple statement to the database.
 *
 * @param database//from  w w  w  . j a va  2s  .c o m
 * @param triple
 * @return success of the operation.
 */
public boolean addStatement(String database, NTriple triple) {
    Dataset dataset = getDataset(database);
    dataset.begin(ReadWrite.WRITE);

    try {
        Model model = dataset.getDefaultModel();
        Resource s = model.createResource(triple.getS());
        Property p = model.createProperty(triple.getP());

        UrlValidator urlValidator = new UrlValidator();
        if (urlValidator.isValid(triple.getO())) {
            Resource o = model.createResource(triple.getO());
            model.add(s, p, o);
        } else {
            model.add(s, p, triple.getO());
        }

        dataset.commit();
        //model.close();
    } catch (Exception e) {
        log.error("Add statement failed", e);
    } finally {
        dataset.end();
    }
    return true;
}

From source file:sk.svec.jan.acb.main.Main.java

private static boolean validateUrl(String value) {
    StringBuilder errors = new StringBuilder();
    UrlValidator urlValidator = new UrlValidator();
    if (!value.startsWith("http://")) {
        value = "http://" + value;
    }/*from   www  .  ja v  a  2 s.com*/
    boolean valid = urlValidator.isValid(value);
    if (value == null || value.isEmpty()) {
        errors.append("Zadajte prosm url.");
        return false;
    } else if (!valid) {
        errors.append("Url ").append(value).append(" je neplatn. Zadajte prosm platn url.");
        return false;
    }
    return true;
}

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

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

    return value;
}

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 w w  . j  a va  2  s  .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:uk.co.develop4.security.utils.decoders.DecoderUtils.java

public static URL isUrl(String url) {
    String[] schemes = { "http", "https" };
    UrlValidator urlValidator = new UrlValidator(schemes);
    if (urlValidator.isValid(url)) {
        try {//from   w  w  w  . j  a  va 2s . c o m
            URL u = new URL(url);
            return u;
        } catch (MalformedURLException ex) {
            // -- System.out.println("url is invalid: \"" + url + "\"");
        }
    } else {
        // -- System.out.println("url is invalid: \"" + url + "\"");
    }
    return null;
}

From source file:url.Domain.java

public String reverseDomains(String str) {
    String revDomain = "";
    try {// www  . jav  a2s .c  om

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

From source file:url.DomainPathFile.java

public void createDomainPathFile(String inputFile, String domainFile, String domainPathFile) {
    BufferedReader br = null;/*w w  w. ja v  a  2  s  .  co m*/
    PrintWriter domainwriter = null, pathwriter = null;
    String line = "";

    UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
    try {

        br = new BufferedReader(new FileReader(inputFile));
        domainwriter = new PrintWriter(domainFile, "UTF-8");
        pathwriter = new PrintWriter(domainPathFile, "UTF-8");

        while ((line = br.readLine()) != null) {

            if (defaultValidator.isValid(line)) {
                java.net.URL host_path = new java.net.URL(line);
                String host = host_path.getHost();
                String path = host_path.getPath();
                domainwriter.println(host);
                pathwriter.println(host + path);
            }

        }

        domainwriter.close();
        pathwriter.close();
        System.out.println("Write to file-->" + domainFile + " File: " + domainPathFile);
    } catch (Exception e) {
        System.out.println(e);
    }
    System.out.println("Done");
}

From source file:url.DomainPathSeperation.java

public void getUrlDomainPath(String inputFile, String domainFile, String domainPathFile) {
    BufferedReader br = null;//  www  . ja  va 2s .co  m
    PrintWriter domainwriter = null, pathwriter = null;
    String line = "";

    UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
    try {

        br = new BufferedReader(new FileReader(inputFile));
        domainwriter = new PrintWriter(domainFile, "UTF-8");
        pathwriter = new PrintWriter(domainPathFile, "UTF-8");

        while ((line = br.readLine()) != null) {

            if (defaultValidator.isValid(line)) {
                URL host_path = new URL(line);
                String host = host_path.getHost();
                String path = host_path.getPath();
                domainwriter.println(host);
                pathwriter.println(host + path);
            }

        }

        domainwriter.close();
        pathwriter.close();
        System.out.println("Write to file-->" + domainFile + "domain+path File: " + domainPathFile);
    } catch (Exception e) {
        System.out.println(e);
    }
    System.out.println("Done");
}