Java URL is Absolute isAbsoluteUrl(String url)

Here you can find the source of isAbsoluteUrl(String url)

Description

<#if locale="en">

Return the url is absolute url or not.

License

Apache License

Parameter

Parameter Description
url a parameter

Declaration

public static boolean isAbsoluteUrl(String url) 

Method Source Code

//package com.java2s;
/*//  w  ww .j  a  v a2s  .c o  m
 * Copyright 2008-2010 the T2 Project ant the Others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    protected static final String VALID_SCHEME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";

    /**
     * <#if locale="en">
     * <p>
     * Return the url is absolute url or not.
     * 
     * </p>
     * <#else>
     * <p>
     * 
     * </p>
     * </#if>
     * 
     * @param url
     * @return
     */
    public static boolean isAbsoluteUrl(String url) {
        if (url == null) {
            return false;
        }
        int colonPos;
        if ((colonPos = url.indexOf(":")) == -1) {
            return false;
        }
        for (int i = 0; i < colonPos; i++) {
            if (VALID_SCHEME_CHARS.indexOf(url.charAt(i)) == -1) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. isAbsoluteURI(String uri)
  2. isAbsoluteUrl(String imageUrl)
  3. isAbsoluteUrl(String ref)
  4. isAbsoluteURL(String str)
  5. isAbsoluteURL(String url)
  6. isAbsoluteURL(String url)
  7. isAbsoluteURL(String url)