Here you can find the source of isAbsoluteUri(String uriAsString)
Parameter | Description |
---|---|
uriAsString | the potential URI, as a string |
public static boolean isAbsoluteUri(String uriAsString)
//package com.java2s; /**************************************************************************** * * Copyright (c) 2008-2011, EBM WebSourcing * * This source code is available under agreement available at * http://www.petalslink.com/legal/licenses/petals-studio * * You should have received a copy of the agreement along with this program. * If not, write to EBM WebSourcing (4, rue Amelie - 31200 Toulouse, France). * *****************************************************************************/ import java.net.URI; import java.net.URL; public class Main { /**//w ww. jav a2 s . c om * Determines whether a string is an absolute URI. * @param uriAsString the potential URI, as a string * @return true if it is an absolute URI, false otherwise or if it is not a valid URI */ public static boolean isAbsoluteUri(String uriAsString) { boolean result; try { URI uri = urlToUri(uriAsString); result = uri.isAbsolute(); } catch (Exception e) { result = false; } return result; } /** * Builds an URI from an URL (with an handle for URLs not compliant with RFC 2396). * @param url * @return */ public static URI urlToUri(URL url) { URI uri; try { // Possible failing step. uri = url.toURI(); } catch (Exception e) { // URL did not comply with RFC 2396 => illegal un-escaped characters. try { uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); } catch (Exception e1) { // No automatic repair. throw new IllegalArgumentException("Broken URL: " + url); } } uri = uri.normalize(); return uri; } /** * Builds an URI from an URL string (with an handle for URLs not compliant with RFC 2396). * @param urlAsString * @return */ public static URI urlToUri(String urlAsString) { try { URL url = new URL(urlAsString); return urlToUri(url); } catch (Exception e) { // e.printStackTrace(); } throw new IllegalArgumentException("Broken URL: " + urlAsString); } }