Java URI Value Check isValidURI(final String namespace)

Here you can find the source of isValidURI(final String namespace)

Description

Determine if the supplied name is a valid URI.

License

Open Source License

Parameter

Parameter Description
namespace the string being checked

Return

true if the supplied name is indeed a valid URI, or false otherwise

Declaration

public static boolean isValidURI(final String namespace) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 SAP AG.//from   ww  w  .ja  va2 s . c  om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Emil Simeonov - initial API and implementation.
 *    Dimitar Donchev - initial API and implementation.
 *    Dimitar Tenev - initial API and implementation.
 *    Nevena Manova - initial API and implementation.
 *    Georgi Konstantinov - initial API and implementation.
 *    Keshav Veerapaneni - initial API and implementation.
 *******************************************************************************/

import java.net.URISyntaxException;

public class Main {
    /**
     * Determine if the supplied name is a valid URI.
     * 
     * @param namespace
     *            the string being checked
     * @return true if the supplied name is indeed a valid URI, or false
     *         otherwise
     */
    public static boolean isValidURI(final String namespace) {
        if (namespace == null || namespace.length() == 0)
            return false;
        try {
            new java.net.URI(namespace);
        } catch (final URISyntaxException e) {
            return false;
        }
        return true;
    }
}

Related

  1. isURI(String uri)
  2. isUriValid(String uri)
  3. isUsingNonDefaultPort(URI uri)
  4. isValid(String uri)
  5. isValid(URI uri)
  6. isValidURI(String uri)
  7. isValidUri(String uri, StringBuilder errMsg)
  8. isValidUri(String uriCandidate)
  9. isValidURI(String uriRef)