org.foray.common.url
Class URLFactory

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

public final class URLFactory
extends Object

Creates URL instances using the FOray custom URLStreamHandler capabilities. The public methods in this class have a one-to-one correspondence with the URL constructors, and are intended to be a replacement for them. This class essentially interposes itself between the calling code and the URL constructors to use its own URLStreamHandler resolution. This is needed because there is no clean way to be assured that the URL constructors use the desired custom URLStreamHandler implementation.

See Also:
where the various strategies for dealing with custom {@link URLStreamHandler} implementations are discussed, and where one can be selected.

Method Summary
static URL createURL(String spec)
          Creates a URL instance.
static URL createURL(String protocol, String host, int port, String file)
          Creates a URL instance.
static URL createURL(String protocol, String host, int port, String file, URLStreamHandler handler)
          Creates a URL instance.
static URL createURL(String protocol, String host, String file)
          Creates a URL instance.
static URL createURL(URL context, String spec)
          Creates a URL instance.
static URL createURL(URL context, String spec, URLStreamHandler handler)
          Creates a URL instance.
static boolean isValidProtocol(String protocol)
          Returns true if specified string is a valid protocol name.
static String parseProtocol(String spec)
          Extracts the protocol portion of a URL specification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createURL

public static URL createURL(String spec)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
spec - The String to parse as a URL.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

createURL

public static URL createURL(String protocol,
                            String host,
                            int port,
                            String file)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
protocol - The name of the protocol to use.
host - The name of the host.
port - The port number on the host.
file - The file on the host.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

createURL

public static URL createURL(String protocol,
                            String host,
                            int port,
                            String file,
                            URLStreamHandler handler)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
protocol - The name of the protocol to use.
host - The name of the host.
port - The port number on the host.
file - The file on the host.
handler - The stream handler for the URL.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

createURL

public static URL createURL(String protocol,
                            String host,
                            String file)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
protocol - The name of the protocol to use.
host - The name of the host.
file - The file on the host.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

createURL

public static URL createURL(URL context,
                            String spec)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
context - The context in which to parse the specification.
spec - The String to parse as a URL.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

createURL

public static URL createURL(URL context,
                            String spec,
                            URLStreamHandler handler)
                     throws MalformedURLException
Creates a URL instance.

Parameters:
context - The context in which to parse the specification.
spec - The String to parse as a URL.
handler - The stream handler for the URL.
Returns:
The newly created URL.
Throws:
MalformedURLException - If an unknown protocol is specified.
See Also:
which this method mimics.

parseProtocol

public static String parseProtocol(String spec)
Extracts the protocol portion of a URL specification.

Parameters:
spec - The URL specifications from which a protocol should be extracted.
Returns:
The extracted protocol.
See Also:
from which this code is derived.

isValidProtocol

public static boolean isValidProtocol(String protocol)
Returns true if specified string is a valid protocol name. This method is derived from the URL method with the same signature.

Parameters:
protocol - The String to be tested for validity.
Returns:
True iff the protocol is valid.


Copyright © 2017. All rights reserved.