URIUtil Class

com.bea.ide.util
URIUtil Class

public class URIUtil

    extends Object

URIs are a crucial part of the Workshop API. This class provides a number of simple methods to improve manipulation of URIs. Wherever possible, these methods should be used to create, manipulate and inspect URIs. In particular there are a number of inconsistencies in the Java Runtime implementation of URI. UNC paths are not handled consistently between URI and java.io.File. Also URIs can be hard to inspect safely for filenames, extensions, etc... The methods below provide safe ways to perform these actions and should be used exclusively.


Hierarchy
Object
  URIUtil

Constructor Summary

URIUtil()

 

Method Summary

public static URI
changeScheme(URI uri, String newScheme)
Change the scheme of a URI
public static URI
createFromParent(URI uriParent, String sName, boolean isDir)
creates a new URI using the specified URI as the parent of the new URI
public static URI
createURI(String unencodedUriString)
Create a URI encoding the string as appropriate
public static URI
createURI(String unencodedScheme, String unencodedSSP, String unencodedFragment)
Create a URI encoding the strings as appropriate
public static URI
createURI(String unencodedScheme, String unencodedSSP)
Create a URI encoding the strings as appropriate
public static URI
createURINoEncode(String encodedUriString)
Create a URI from an already encoded string
public static URI
createURINoEncode(String encodedScheme, String encodedSSP, String encodedFragment)
Create a URI from an already encoded set of strings
public static URI
createURINoEncode(String encodedScheme, String encodedSSP)
Create a URI from an already encoded set of strings
public static String
decode(String s)
public static String
encode(String s)
public static URI
fromFile(File f)
Construct a URI from the given file.
public static URI
fromString(String path)
Create a URI from the given string.
public static String
getExtension(URI uri)
Get the file extension for this URI.
public static String
getFilename(URI uri)
returns the filename portion of the uri
public static String
getFilePath(URI uri)
This will return the path portion of the uri as an OS-specific path to the file if the URI points to a file, or just the path if it is not.
public static String
getInternalPath(URI uri)
public static String
getParentPath(URI uri)
returns the parent path of the URI.
public static URI
getParentURI(URI uri)
returns the parent URI of the URI.
public static String
getScheme(URI uri)
Return the scheme of this uri.
public static boolean
isAncestor(URI parent, URI child)
Determines whether one URI is the parent of another
public static boolean
isDirectory(URI uri)
Determines if the given URI is a directory.
public static boolean
isFile(URI uri)
Determines if the given URI is a file.
public static boolean
isFileURI(URI uri)
Determine if the given URI represents a file object
public static boolean
isUrlURI(URI uri)
Determine if the given URI represents an http or ftp object
public static URI
normalize(URI uri)
Normalize the URI.
public static URI
resolve(URI base, URI child)
Resolve the URI.
public static URI
resolve(URI base, String child)
Resolve the URI.
public static File
toFile(URI uri)
Converts the given URI into a Java file object.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Constructor Detail

URIUtil

public URIUtil()
 

Method Detail

changeScheme(URI, String) Method

public static URI changeScheme(URI uri, 
                               String newScheme)
Change the scheme of a URI

Parameters

uri
URI to change
newScheme
new scheme to give to the uri

Returns

new URI with the given scheme or null if the new URI could not be constructed

createFromParent(URI, String, boolean) Method

public static URI createFromParent(URI uriParent, 
                                   String sName, 
                                   boolean isDir)
creates a new URI using the specified URI as the parent of the new URI

Parameters

uriParent
parent URI to use in constructing the new URI
sName
object name to concatentate onto the parent URI.
isDir
true if the given sName represents a directory

Returns

new URI that represents the object sName as a child of uriParent, or null if the URI cannot be constructed

createURI(String) Method

DEPRECATED

public static URI createURI(String unencodedUriString)
throws URISyntaxException
Create a URI encoding the string as appropriate

Exceptions

URISyntaxException

createURI(String, String, String) Method

DEPRECATED

public static URI createURI(String unencodedScheme, 
                            String unencodedSSP, 
                            String unencodedFragment)
throws URISyntaxException
Create a URI encoding the strings as appropriate

Exceptions

URISyntaxException

createURI(String, String) Method

DEPRECATED

public static URI createURI(String unencodedScheme, 
                            String unencodedSSP)
throws URISyntaxException
Create a URI encoding the strings as appropriate

Exceptions

URISyntaxException

createURINoEncode(String) Method

DEPRECATED

public static URI createURINoEncode(String encodedUriString)
throws URISyntaxException
Create a URI from an already encoded string

Exceptions

URISyntaxException

createURINoEncode(String, String, String) Method

DEPRECATED

public static URI createURINoEncode(String encodedScheme, 
                                    String encodedSSP, 
                                    String encodedFragment)
throws URISyntaxException
Create a URI from an already encoded set of strings

Exceptions

URISyntaxException

createURINoEncode(String, String) Method

DEPRECATED

public static URI createURINoEncode(String encodedScheme, 
                                    String encodedSSP)
throws URISyntaxException
Create a URI from an already encoded set of strings

Exceptions

URISyntaxException

decode(String) Method

public static String decode(String s)

encode(String) Method

public static String encode(String s)

fromFile(File) Method

public static URI fromFile(File f)
Construct a URI from the given file. This method will canonicalize the file before converting it to a URI

Parameters

f
File to get the URI for

Returns

URI for the file

fromString(String) Method

public static URI fromString(String path)
Create a URI from the given string.

Parameters

path
String representing the new URI path

Returns

new URI or null if the URI could not be constructed

getExtension(URI) Method

public static String getExtension(URI uri)
Get the file extension for this URI.

Parameters

uri
uri of file to check

Returns

characters following last . in the file (exclusive) or an empty string, if there is none.

getFilename(URI) Method

DEPRECATED Please use FileSvc.get().getIFile(uri).getName().

public static String getFilename(URI uri)
returns the filename portion of the uri

Returns

string representing the filename of the URI

getFilePath(URI) Method

public static String getFilePath(URI uri)
This will return the path portion of the uri as an OS-specific path to the file if the URI points to a file, or just the path if it is not. For instance, on Windows, the leading '/' is trimmed for windows drive letters, and UNC paths are resolved correctly.

Returns

String representation of the logical path of the file

getInternalPath(URI) Method

public static String getInternalPath(URI uri)

Returns

null if the URI isn't a file in an archive, or the archive path to the file if it is.

getParentPath(URI) Method

public static String getParentPath(URI uri)
returns the parent path of the URI. if this uri is a directory, it will return the parent of the directory.

Returns

string representing the parent directory of this uri or the empty string if it is a root directory

getParentURI(URI) Method

DEPRECATED Please use FileSvc.get().getIFile(uri).getParentIFile().getURI().

public static URI getParentURI(URI uri)
returns the parent URI of the URI. this is a shortcut for generating a new uri using the parent path.

Returns

parent URI or null if there is no parent

getScheme(URI) Method

public static String getScheme(URI uri)
Return the scheme of this uri.

Parameters

uri
uri to retrieve the scheme of

Returns

the scheme of the uri

isAncestor(URI, URI) Method

public static boolean isAncestor(URI parent, 
                                 URI child)
Determines whether one URI is the parent of another

Parameters

parent
asserted parent URI
child
asserted child URI

Returns

true if the asserted parent URI is a parent directory of the object represented by the asserted child URI

isDirectory(URI) Method

public static boolean isDirectory(URI uri)
Determines if the given URI is a directory. The standard mechanism is to check for a trailing "/". This method will attempt to conver the URI to a file if appropriate and verify this assumption. If the file is a directory, but doesn't have a "/" it will assert.

Parameters

uri
uri to check

Returns

true if the URI represents a directory, false otherwise

isFile(URI) Method

public static boolean isFile(URI uri)
Determines if the given URI is a file. This merely means that it is not a directory.

Parameters

uri
URI of file to check

Returns

true if this file is not a directory

isFileURI(URI) Method

public static boolean isFileURI(URI uri)
Determine if the given URI represents a file object

Parameters

uri
URI to check

Returns

true if the given URI represents an object in the filesystem, false otherwise

isUrlURI(URI) Method

public static boolean isUrlURI(URI uri)
Determine if the given URI represents an http or ftp object

Parameters

uri
URI to check

Returns

true if the given URI represents an object on an http or ftp server.

normalize(URI) Method

public static URI normalize(URI uri)
Normalize the URI. This is just like URI.normalize() however it is consistent with java.io.File in how it constructs URIs for UNC Paths, preserving the leading double slash and empty authority.


resolve(URI, URI) Method

public static URI resolve(URI base, 
                          URI child)
Resolve the URI. This is just like URI.resolve(String) however it is consistent with java.io.File in how it constructs URIs for UNC Paths, preserving the leading double slash and empty authority.


resolve(URI, String) Method

public static URI resolve(URI base, 
                          String child)
Resolve the URI. This is just like URI.resolve(String) however it is consistent with java.io.File in how it constructs URIs for UNC Paths, preserving the leading double slash and empty authority


toFile(URI) Method

DEPRECATED Please use FileSvc.get().getIFile(URI).getFile() if you need a file. Please consider not using the final getFile() if an IFile will suffice.

public static File toFile(URI uri)
Converts the given URI into a Java file object.

Parameters

uri
URI to convert

Returns

File object for the given URI or null if the URI does not represent a file