java.lang.Object | ||
↳ | java.util.Observable | |
↳ | com.microstrategy.utils.FileLoader |
The FileLoader
is the class used by MicroStrategy Web classes to load files
from the file-system or class-path.
Typically, an application server will take the war file and expand its contents, in which
case all files can be loaded directly from the file-system,
however some application servers have the capacity to run the web application without expanding
the war file and provides InputStream
instances for the resources inside the war file. This class
encapsulates this logic so it becomes transparent to all elements in the application that need
to load a file.
Differences along application servers are encapsulated by the
ContainerServicesContext
. If provided, the FileLoader
will use a ContainerServicesContext
instance to
resolve relative paths and create the corresponding InputStream
instances.
MicroStrategy Web always uses relative paths to specify the location of configuration files. The
path is always relative to where the application was installed, and the absolute path is resolved by
the ContainerServicesContext
. For those cases, like Microstrategy's Eclipse plug-in,
where MicroStrategy classes are used outside the context
of an application server (and therefore there is associated ContainerServicesContext
) the
FileLoader provides a base path property, in the absence of the ContainerServicesContext
the FileLoader will prefix this value to all relative paths when calculating the absolute path.
Starting with version 8.0.3, this class is used by MicroStrategy Web as a singleton.
When the application is started it will take care of initializing the instance with
a valid ContainerServicesContext
for all future requests.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ABSOLUTE_PREFIX | Represents the prefix added to paths to indicate their absolute. | |||||||||
char | PLUGIN_PREFIX | Represents the first character of a relative path that indicates the path to points to a file on a specific plugin | |||||||||
String | RELATIVE_PREFIX | Represents the prefix added to paths to indicate their relative to the application's root folder. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
FileLoader(ContainerServicesContext cs)
This constructor takes the container services that will be used to resolve relative paths
and create
InputStream instances. | |||||||||||
FileLoader(ContainerServices cs)
This constructor is deprecated.
replaced by
FileLoader(ContainerServicesContext)
| |||||||||||
FileLoader(String basePath)
This constructor takes the basePath that shall be used as root folder to resolve relative paths.
| |||||||||||
FileLoader(String basePath, String plugInsPath)
This constructor takes the basePath and the plugInsPath that shall be used as root folder to
resolve relative paths.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
clearCaches()
This method clears all internal caches
| ||||||||||
boolean |
exists(String path)
Returns whether the given relative path exists in the file system.
| ||||||||||
String |
getApplicationPath(String relativePath)
Returns a path that its always relative to the application's root folder.
| ||||||||||
String |
getBasePath()
Returns the current base path for this file loader.
| ||||||||||
ContainerServices |
getContainerServices()
This method is deprecated.
replaced by
getContainerServicesContext()
| ||||||||||
ContainerServicesContext |
getContainerServicesContext()
Returns the underlying
ContainerServicesContext . | ||||||||||
static String |
getCustomizationPrefix(String name)
Returns the prefix to be used in a relative path, that identifies that
path to belong to the given customization.
| ||||||||||
InputStream |
getDTDInputStream(String dtdFileName)
Returns an InputStream for the given
dtdFileName . | ||||||||||
String |
getDTDsPath()
Returns the path of the folder where dtd files, used to validate the syntax fo xml files, are located. | ||||||||||
String |
getFileContents(String filePath, String encoding)
Returns the contents of a file as a String object
| ||||||||||
String |
getFileContents(String filePath)
Returns the contents of a file as a String object
| ||||||||||
InputStream |
getFileInputStream(String filePath)
Returns the contents of a file as an InputStream object
| ||||||||||
static FileLoader |
getInstance()
The method to return the singleton instance of this class.
| ||||||||||
long |
getLastModifiedTime(String path)
Returns the last time the resource was modified in milliseconds.
| ||||||||||
String |
getPlugInsPath()
Returns the plugInsPath.
| ||||||||||
String |
getRealPath(String filePath)
Resolves the real (absolute) path from the given relative path.
| ||||||||||
static String | getRealPath(String filePath, ContainerServicesContext cs) | ||||||||||
String |
getRelativePath(String absolutePath, CustomizationInfo ci)
Returns a relative path for the given absolute path.
| ||||||||||
String |
getRelativePath(String absolutePath)
Returns a relative path for the given absolute path.
| ||||||||||
void |
init(ContainerServicesContext cs)
Initializes this FileLoader with a
ContainerServicesContext that
will then be used to resolve paths and to create InputStream
instances to load files. | ||||||||||
void |
init(ContainerServices cs)
This method is deprecated.
replaced by
init(ContainerServicesContext)
| ||||||||||
void |
setBasePath(String basePath)
Sets the base path for this file loader.
| ||||||||||
void |
setDTDsPath(String path)
Sets the path of the folder where dtd files are located.
| ||||||||||
void |
setPlugInsPath(String path)
Sets the plugins path.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Represents the prefix added to paths to indicate their absolute.
Represents the first character of a relative path that indicates the path to points to a file on a specific plugin
Represents the prefix added to paths to indicate their relative to the application's root folder.
This constructor takes the container services that will be used to resolve relative paths
and create InputStream
instances.
This constructor is deprecated.
replaced by FileLoader(ContainerServicesContext)
This constructor takes the container services that will be used to resolve relative paths
and create InputStream
instances.
This constructor takes the basePath that shall be used as root folder to resolve relative paths.
This constructor takes the basePath and the plugInsPath that shall be used as root folder to resolve relative paths.
This method clears all internal caches
Returns whether the given relative path exists in the file system.
Returns a path that its always relative to the application's root folder.
Returns the current base path for this file loader. In the absence of a ContainerServices
,
the base-path is used to calculate the real location of relative paths.
This method is deprecated.
replaced by getContainerServicesContext()
Returns the ContainerServices
instance currently associated with
ContainerServices
object.Returns the underlying ContainerServicesContext
.
Returns the prefix to be used in a relative path, that identifies that path to belong to the given customization.
Returns an InputStream for the given dtdFileName
.
It uses the getDTDsPath()
method to calculate the location
of the file, if null
, it just tries to load the file
from the application's root folder.
dtdFileName | The name of the file. Typically specified as the SYSTEM attribute of the xml's DOCTYPE. |
---|
null
otherwise.Returns the path of the folder where dtd files, used to validate the syntax fo xml
files, are located. If the location of this folder has not been explicitly
set through the setDTDsPath(String)
, then this method will read the
dtdsLocation
(DTD_PATH
init parameter from the
associated ContainerServices
class, if any.
It returns null
if the value has not been explicitly set or
there is no ContainerServices
instance associated.
Returns the contents of a file as a String object
filePath | A relative file location. |
---|
Returns the contents of a file as a String object
filePath | A relative file location. |
---|
Returns the contents of a file as an InputStream object
filePath | A relative file location. |
---|
Returns the last time the resource was modified in milliseconds.
path | String |
---|
Returns the plugInsPath. When not null, all relative paths that point to a plug-in or customization folder are resolved to be relative this path ,regardless of the customization they belong to.
Resolves the real (absolute) path from the given relative path. Note that the
resulting path does not necessarily point to a file/directory that exists.
The root folder used to resolve relative paths is defined as follows:
filePath | Always a relative location. If it is an absolute path, it must have ABSOLUTE_PREFIX . |
---|
filePath | Always a relative location. If it is an absolute path, it must have ABSOLUTE_PREFIX . |
---|---|
cs | ContainerServicesContext used to resolve relative paths |
Returns a relative path for the given absolute path. A FileLoader supports the following relative paths:
Paths that are relative the application's root folder start either with "/" or are prefixed with "RELATIVE:", for example:
Paths that are relative to a specific customization's root folder are prefixed with "@{NAME}:", where "{NAME}" corresponds to the customization's name, for example:
Paths to files that are not part of the application are prefixed with "ABSOLUTE:", for example:
Returns a relative path for the given absolute path. The path returned is relative to the applications root folder.
Initializes this FileLoader with a ContainerServicesContext
that
will then be used to resolve paths and to create InputStream
instances to load files.
This method is deprecated.
replaced by init(ContainerServicesContext)
Initializes this FileLoader with the given instance of a ContainerServices. The ContainerServices will then be used to resolve relative paths and to create InputStreams to load files.
Sets the base path for this file loader. In the absence of a ContainerServices
,
the base-path is used to calculate the real location of relative paths.
Sets the path of the folder where dtd files are located. This value is used by the
getDTDInputStream(String)
to create the input stream for the given dtd.
If this value is not explicitly set, it is calculated from the
associated ContainerServices
instance.
path | The relative path location of the folder where dtd files are located. |
---|
Sets the plugins path. Normally all plugins' paths are resolved based
on the plugin name and the settings on the Customizations
class.
When this plugins path is set, though, all relative paths that are part of a
plug-in or customization are resolved to be relative to this path, regardless of the
customization they belong to. For example:
FileLoader fl = new FileLoader(".");
fl.setPlugInsPath("/custom");
fl.getRealPath("@A:/test.xml"); //Returns: /custom/test.xml
fl.getRealPath("@B:/test.xml"); //Also returns /custom/test.xml !