|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.http.serve.FileLocator
public class FileLocator
The FileLocator
provides an implementation of the
Locator
interface for locating files from a list of
directories. This will use the list of directories to search for
named files. The list of files is searched by increasing index so
the first occurrence of a named file found in the search path will
be used. This accepts the name of the file to be used, so for
example if the file required was example.xml
then
the name alone should be supplied. If however path information
is supplied it can be in a URI or platform specific format.
Constructor Summary | |
---|---|
FileLocator()
Constructor for the FileLocator object. |
|
FileLocator(java.io.File path)
Constructor for the FileLocator object. |
|
FileLocator(java.io.File[] list)
Constructor for the FileLocator object. |
Method Summary | |
---|---|
java.io.File |
getFile(java.lang.String name)
This is used to produce a File object pointing
to the location of the named resource. |
java.lang.String |
getLocation(java.lang.String name)
This is used to discover the location of a resource using the name of the resource. |
java.util.Properties |
getProperties(java.lang.String name)
This is used to produce a Properties object
that contains the contents of the named Java properties file. |
java.net.URL |
getResource(java.lang.String name)
This is provided so that a ClassLoader can be
used to load the named resource. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileLocator()
FileLocator
object. This
no argument constructor will contain an empty search path
and as a result will only search for resources within the
current working directory.
public FileLocator(java.io.File path)
FileLocator
object. This
constructor requires a single path for searching. The path
is searched for the named resources and if found it is
used, however if the resource is not found in the given
path the current working directory is searched.
path
- this is the path to search for the resourcespublic FileLocator(java.io.File[] list)
FileLocator
object. This
constructor requires a list of directories with which to
search for resources. The resources are searched for in
increasing index, so index zero is the first directory
searched followed by index one and so on. This uses the
current working directory if the search fails.
list
- this is the list of files to search withinMethod Detail |
---|
public java.lang.String getLocation(java.lang.String name) throws LocateException
FileContext.getRealPath
method, however it
should be supplied with only the name of the resource with
no path information, which keeps any code interacting with
this portable across systems using different path formats.
getLocation
in interface Locator
name
- the name of the resource that is to be located
LocateException
- thrown if the named resource
could not be found after exhausting all lookup meanspublic java.io.File getFile(java.lang.String name) throws LocateException
File
object pointing
to the location of the named resource. This method mirrors
the FileContext.getFile
method, however it
should be supplied with only the name of the resource with
no path information, which keeps any code interacting with
this portable across systems using different path formats.
getFile
in interface Locator
name
- the name of the resource that is to be located
File
referencing the named resource
LocateException
- thrown if the named resource
could not be found after exhausting all lookup meanspublic java.util.Properties getProperties(java.lang.String name) throws LocateException
Properties
object
that contains the contents of the named Java properties file.
This mirrors the FileContext.getProperties
method, however it should be supplied with only the name of
the resource with no path information, which keeps any code
interacting with this portable across different platforms.
getProperties
in interface Locator
name
- the name of the resource that is to be located
Properties
object for the resource
LocateException
- thrown if the named resource
could not be found after exhausting all lookup meanspublic java.net.URL getResource(java.lang.String name) throws LocateException
ClassLoader
can be
used to load the named resource. This method enables the
configuration information to be loaded from the specified
class path, which enables the files to be stored within a
JAR resource or at any desired location. This only needs
the name of the resource, no path information is required,
this keeps the code portable and simple.
getResource
in interface Locator
name
- the name of the resource that is to be located
URL
referencing the named resource
LocateException
- thrown if the named resource
could not be found after exhausting all lookup means
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |