Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of the Droid Roach project
 * Copyright 2013 Stefano Gabryel
 * Author: Stefano Gabryel
 * License: GPL v3 - http://www.gnu.org/licenses/gpl-3.0.html
 * Author website: http://www.stefano-workshop.com
 * Project website: http://droid-roach.stefano-workshop.com
 * 
 */

import java.net.URI;
import java.util.Locale;

public class Main {
    public static boolean isURI(String str) {

        if (str.indexOf(':') == -1)
            return false;
        str = str.toLowerCase(Locale.ENGLISH).trim();

        if (!str.startsWith("http://") && !str.startsWith("https://") && !str.startsWith("ftp://"))
            return false;

        try {

            URI uri = new URI(str);
            String proto = uri.getScheme();

            if (proto == null)
                return false;

            if (proto.equals("http") || proto.equals("https") || proto.equals("ftp")) {

                if (uri.getHost() == null)
                    return false;

                String path = uri.getPath();
                if (path != null) {

                    int len = path.length();
                    for (int i = 0; i < len; i++) {

                        if ("?<>:*|\"".indexOf(path.charAt(i)) > -1)
                            return false;
                    }
                }
            }

            return true;
        } catch (Exception ex) {

            return false;
        }
    }
}