org.foray.common.url
Class URLUtil

java.lang.Object
  extended by org.foray.common.url.URLUtil

public final class URLUtil
extends Object

This utility class contains various URL-related static utility methods.


Method Summary
static List<URL> buildURLList(URL[] baseURLs, String urlSpecified)
          This method is an attempt to standardize the way that URLs are constructed, and, more importantly, how they are converted into Streams or other i/o resources.
static boolean exists(URL url)
          Intended to be the equivalent of File.exists().
static boolean isDirectory(URL url)
          Indicates whether a given URL references a directory.
static String normalizeURISpecification(String input)
          Converts standard-based uri-specification to a normalized String from which a java.net.URL instance can be constructed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildURLList

public static List<URL> buildURLList(URL[] baseURLs,
                                     String urlSpecified)
                              throws MalformedURLException

This method is an attempt to standardize the way that URLs are constructed, and, more importantly, how they are converted into Streams or other i/o resources. There is no way to know when a URL is constructed whether it can actually be opened or not. So it is frequently the case that resources identified by URL must be tried several times as various possibilities are attempted. To standardize this, three possibilities were considered:

  1. Loop through the possibilities here, attempting to open each one. When one is successfully opened, return the URL.
  2. Set up something stateful that would create the next possible URL on demand.
  3. Build and return a collection of possibilities & let the client manage the process.

Of these three, 1 forces the URL to be opened twice, which was deemed wasteful. 2 seems like way too much trouble for such a simple task. An object would have to be created to manage the state information. 3, while somewhat wasteful, seems much less wasteful than the other two, and is the plan that was adopted.

Parameters:
baseURLs - Array of URLs containing possible paths that should be tried used as the base for relative URLs.
urlSpecified - String containing the name of the URL.
Returns:
A List of URLs that the client should try to open, in the order that they should be tried.
Throws:
MalformedURLException - If it is unable to create even one URL instance.

normalizeURISpecification

public static String normalizeURISpecification(String input)
Converts standard-based uri-specification to a normalized String from which a java.net.URL instance can be constructed. Some standards, XSL-FO among them, require that uri-specification consists of the URI preceded by "url(" and followed by ")". This method validates and normalizes that input.

Parameters:
input - The uri-specification as defined in the XSL-FO Standard 1.0, Section 5.11.
Returns:
The normalized String, or null if the input is not valid.

exists

public static boolean exists(URL url)
Intended to be the equivalent of File.exists().

Parameters:
url - The URL whose existence is to be tested.
Returns:
True if the URL exists, false otherwise. "Existence" is defined as the ability to open a connection to the URL.

isDirectory

public static boolean isDirectory(URL url)
Indicates whether a given URL references a directory.

Parameters:
url - The URL to be tested.
Returns:
True iff url references a directory.


Copyright © 2017. All rights reserved.