public class IlpDefaultURLAccessService extends Object implements IlpURLAccessService
Class.Loader.getResource
to allow the use of an explicit search path as well as the Java classpath when deploying
an application using CPL.
A possible use of this service is for accessing icons and configuration files.
This default implementation uses one base URL that is usually
defined according to the deployment mode. Applets use
setDocumentBase
to register their base URL. Applications
can use setDocumentBase
as well, but do not need to; by
default, the current directory is used instead.
Additional paths can be added to the locations where a given filename will be searched for:
addRelative
.addAbsolute
.addRelative
with a jar file name.addAbsolute
with a jar file name.To retrieve the absolute URL of a file, call
getFileLocation
with a relative URL. This function will locate
the file relative to the registered base URLs.
For example, consider the following code:
IlpDefaultURLAccessService accessService = new IltDefaultURLAccessService(); accessService.setDocumentBase(new URL("file:C:/myfiles/")); accessService.addRelative("myname/"); acesssService.addAbsolute(new URL("file:/nfs/shared/resources/")); accessService.addRelative("my.jar"); accessService.addAbsolute(new URL("file:/nfs/shared/resources.jar"));A call to getFileLocation("myresource") will return one of the following URLs:
file:C:/myfiles/myname/myresource file://nfs/shared/resources/myresource jar:file:C:/myfiles/my.jar!/myresource jar:file://nfs/shared/resources.jar!/myresource
Constructor and Description |
---|
IlpDefaultURLAccessService()
Creates the service.
|
Modifier and Type | Method and Description |
---|---|
void |
addAbsolute(URL pathOrJar)
Adds an absolute directory or jar file specification to the search path.
|
void |
addRelative(String pathOrJar)
Adds a relative directory or jar file specification to the search path.
|
List |
getBases()
Returns the list of base URLs, ignoring syntactically invalid URLs.
|
static String |
getCurrentDirectory()
Returns the current directory, or
null if unavailable. |
URL |
getDocumentBase()
Returns the document base.
|
URL |
getFileLocation(String filename)
Returns the URL of a file in the path or
null if it is not found. |
URL |
getFileLocation(String filename,
boolean searchClassPathFirst,
boolean searchClassPathLast)
Returns the URL of a file in the path, or
null if it is not found. |
static boolean |
isIgnoreSyntheticHttpURLs()
Returns
true if synthetic HTTP URLs are ignored
by this service. |
void |
setDocumentBase(URL baseURL)
Sets the document base.
|
static void |
setIgnoreSyntheticHttpURLs(boolean ignoreThem)
Specifies whether synthetic HTTP URLs are ignored by this service.
|
void |
setVerbose(boolean flag)
Sets the verbosity of the service.
|
public IlpDefaultURLAccessService()
public URL getDocumentBase()
public void setDocumentBase(URL baseURL)
The typical use in an applet is:
context.setDocumentBase(getDocumentBase())
.
Applications do not need to call this function; by default, the current
directory is used instead.
public static String getCurrentDirectory()
null
if unavailable.public void addRelative(String pathOrJar)
The empty string stands for the document base or, if none is set, in applications, for the current directory.
If the document base points into a jar file, a string starting with "!" denotes a pathname relative to the directory containing the jar file.
pathOrJar
- A relative pathname to a directory or jar file. It uses
'/' as directory separator, as in URLs. It is not
'%'-escaped like URIs and URLs. A prefix of "!"
can be used to escape from the jar file containing the
document base.public void addAbsolute(URL pathOrJar)
Note: URLs that represent directories usually end with a slash
(for the http:
protocol) or in the directory
separator character (for the file:
protocol).
public List getBases()
public URL getFileLocation(String filename)
null
if it is not found.
Each element of the file location path is tried in turn with the given
relative filename. The first one that refers to an existing URL is returned.getFileLocation
in interface IlpURLAccessService
filename
- A relative URL or pathname.public URL getFileLocation(String filename, boolean searchClassPathFirst, boolean searchClassPathLast)
null
if it is not found.
First, if searchClassPathFirst is true, the CLASSPATH is searched. Then, in turn, each element of the file location path is tried with the given relative filename.
Finally, if searchClassPathLast is true, the CLASSPATH is searched. The first one that refers to an existing URL is returned.
getFileLocation
in interface IlpURLAccessService
filename
- A relative URL or pathname.searchClassPathFirst
- If true, the file shall be searched in the CLASSPATH
(directories and jars) before the usual path.searchClassPathLast
- If true, the file shall be searched in the CLASSPATH
(directories and jars) after the usual path.public static boolean isIgnoreSyntheticHttpURLs()
true
if synthetic HTTP URLs are ignored
by this service.public static void setIgnoreSyntheticHttpURLs(boolean ignoreThem)
These are URLs that are not backed by a file, but are synthesized by the HTTP server on demand. Some HTTP servers synthesize some default HTML, containing an error message, for all URLs that do not correspond to existing files.
The default value of this setting is true
.
public void setVerbose(boolean flag)
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.