ariba.util.core
Class URLUtil

java.lang.Object
  extended by ariba.util.core.URLUtil

public final class URLUtil
extends java.lang.Object

URL Utilities. These are helper functions for dealing with urls.


Method Summary
static java.net.URL asURL(java.net.URL context, java.lang.String spec)
          Evaluates a string of a possibly relative url in the context of a different url.
static java.net.URL concatURL(java.lang.String path, java.lang.String file)
          Create a URL from a path and file name.
static java.io.File file(java.net.URL urlContext, boolean warning)
          Generate a File for a URL.
static java.net.URL formURL(java.lang.String url, java.lang.String context)
          Create a URL to a web server.
static java.lang.String formURLString(java.lang.String url, java.lang.String context)
          Create a URL string to a web server.
static boolean fullyQualifiedURLSpec(java.lang.String spec)
          Returns whether the specified specification is a fully-qualified URL.
static java.net.URL makeURL(java.lang.String spec)
          Wrapper class to create a new URL object.
static java.net.URL makeURL(java.lang.String protocol, java.lang.String host, int port, java.lang.String file)
          Wrapper class to create a new URL object.
static boolean maybeURLExists(java.net.URL url)
          Returns true if the URL may exist.
static java.net.URL url()
          Creates a URL for the application working directory.
static java.net.URL url(java.io.File file)
          Creates a URL relative to the application working directory.
static java.net.URL url(java.lang.String spec)
          Creates a URL relative to the application working directory.
static java.net.URL urlAbsolute(java.io.File file)
          Creates a URL that references the given file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

file

public static java.io.File file(java.net.URL urlContext,
                                boolean warning)
Generate a File for a URL.

Parameters:
urlContext - a URL to open in a file. Assumes URL is of type file protocol (e.g. file://) and is not null.
warning - if true, on error, a warning will be printed
Returns:
a File representing the URL, or null if the file could not be opened

maybeURLExists

public static boolean maybeURLExists(java.net.URL url)
Returns true if the URL may exist. If the URL is a file: url, we convert it to a File and call exists(), which is faster than dealing with a FileNotFoundException. This is primarily when the file is likely not to exist, such as in the ResourceService which probes many possible filenames.

Parameters:
url - the input URL
Returns:
boolean indicating if URL may exist

asURL

public static java.net.URL asURL(java.net.URL context,
                                 java.lang.String spec)
Evaluates a string of a possibly relative url in the context of a different url.

Parameters:
context - the context in which to parse the specification.
spec - a string representation of a URL.
Returns:
a new URL, or null if there was an exception in the creation
See Also:
URL.URL(URL, String)

url

public static java.net.URL url(java.io.File file)
Creates a URL relative to the application working directory. This method should only be used within server code or by command line (i.e. non-GUI) clients. If you are in GUI code, use Widgets.url(). If you are in shared code, use Base.service().url().

Parameters:
file - the file object used to create the url, cannot be null.
Returns:
the URL created, or null if it cannot be created.

url

public static java.net.URL url(java.lang.String spec)
Creates a URL relative to the application working directory. This method should only be used within server code or by command line (i.e. non-GUI) clients. If you are in GUI code, use Widgets.url(). If you are in shared code, use Base.service().url().

Parameters:
spec - the String that specifies the resource (typically a file). This String must be a relative path (relative to the application working directory).
Returns:
the URL representing the given spec.

url

public static java.net.URL url()
Creates a URL for the application working directory. This method should only be used within server code or by command line clients. If you are in GUI code, use Application.codeBase().


urlAbsolute

public static java.net.URL urlAbsolute(java.io.File file)
Creates a URL that references the given file. This method should only be used within server code or by command line clients.


fullyQualifiedURLSpec

public static boolean fullyQualifiedURLSpec(java.lang.String spec)
Returns whether the specified specification is a fully-qualified URL. The heuristic that we use is to check whether it contains the string ":/" before any other slashes. Note: Applet file codebases a prefixed by "file:/". This is why we check for only one slash.


formURL

public static java.net.URL formURL(java.lang.String url,
                                   java.lang.String context)
                            throws java.net.MalformedURLException
Create a URL to a web server. If the url is absolute (includes http) use it as is. Otherwise, assume the URL is relative to the context.

Parameters:
url - the URL string we are making a URL object for
context - the root URL
Returns:
a new URL as requested
Throws:
java.net.MalformedURLException

concatURL

public static java.net.URL concatURL(java.lang.String path,
                                     java.lang.String file)
Create a URL from a path and file name. The resulting URL will be constructed independently of what VM (1.1 or 1.2) is being used.

Parameters:
path - the path (either absolute or relative)
file - the file name.
Returns:
a new URL as requested

makeURL

public static java.net.URL makeURL(java.lang.String spec)
                            throws java.net.MalformedURLException
Wrapper class to create a new URL object. Did this to centralize the logic to pass in the https URLStreamHandler. new java.net.URL (String) should not be called directly. This method should be called instead.

Parameters:
spec - the URL spec, cannot be null.
Returns:
the URL instance given the spec.
Throws:
java.net.MalformedURLException - if the spec is illegal.

makeURL

public static java.net.URL makeURL(java.lang.String protocol,
                                   java.lang.String host,
                                   int port,
                                   java.lang.String file)
                            throws java.net.MalformedURLException
Wrapper class to create a new URL object. Did this to centralize the logic to pass in the https URLStreamHandler. new java.net.URL (...) should not be called directly. This method should be called instead.

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 URL instance given the spec.
Throws:
java.net.MalformedURLException - if the spec is illegal.

formURLString

public static java.lang.String formURLString(java.lang.String url,
                                             java.lang.String context)
Create a URL string to a web server. If the url is absolute (includes http) use it as is. Otherwise, assume the URL is relative to the context, e.g. "http://hostname/AribaORMS".

Parameters:
url - url string we are making a URL object for
context - the root url
Returns:
a String representing the URL


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.