ariba.util.core
Class URLUtil

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

public final class URLUtil
extends Object

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


Method Summary
static URL asURL(URL context, String spec)
          Evaluates a string of a possibly relative url in the context of a different url.
static URL concatURL(String path, String file)
          Create a URL from a path and file name.
static File file(URL urlContext, boolean warning)
          Generate a File for a URL.
static URL formURL(String url, String context)
          Create a URL to a web server.
static String formURLString(String url, String context)
          Create a URL string to a web server.
static boolean fullyQualifiedURLSpec(String spec)
          Returns whether the specified specification is a fully-qualified URL.
static URL makeURL(String spec)
          Wrapper class to create a new URL object.
static URL makeURL(String protocol, String host, int port, String file)
          Wrapper class to create a new URL object.
static boolean maybeURLExists(URL url)
          Returns true if the URL may exist.
static URL url()
          Creates a URL for the application working directory.
static URL url(File file)
          Creates a URL relative to the application working directory.
static URL url(String spec)
          Creates a URL relative to the application working directory.
static URL urlAbsolute(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 File file(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(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 URL asURL(URL context,
                        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 URL url(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 URL url(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 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 URL urlAbsolute(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(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 URL formURL(String url,
                          String context)
                   throws 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:
MalformedURLException

concatURL

public static URL concatURL(String path,
                            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 URL makeURL(String spec)
                   throws 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:
MalformedURLException - if the spec is illegal.

makeURL

public static URL makeURL(String protocol,
                          String host,
                          int port,
                          String file)
                   throws 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:
MalformedURLException - if the spec is illegal.

formURLString

public static String formURLString(String url,
                                   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-2009 Ariba, Inc. All Rights Reserved.