Class FileLoader
- java.lang.Object
 - 
- java.util.Observable
 - 
- com.microstrategy.utils.FileLoader
 
 
 
- 
public class FileLoader extends java.util.ObservableTheFileLoaderis 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 providesInputStreaminstances 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 theContainerServicesContext. If provided, theFileLoaderwill use aContainerServicesContextinstance to resolve relative paths and create the correspondingInputStreaminstances.
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 theContainerServicesContext. 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 associatedContainerServicesContext) the FileLoader provides a base path property, in the absence of theContainerServicesContextthe 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 validContainerServicesContextfor all future requests.- Since:
 - MicroStrategy Web 7.5.1
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringABSOLUTE_PREFIXRepresents the prefix added to paths to indicate their absolute.static charPLUGIN_PREFIXRepresents the first character of a relative path that indicates the path to points to a file on a specific pluginstatic java.lang.StringRELATIVE_PREFIXRepresents the prefix added to paths to indicate their relative to the application's root folder. 
- 
Constructor Summary
Constructors Constructor Description FileLoader(ContainerServices cs)Deprecated.replaced byFileLoader(ContainerServicesContext)FileLoader(ContainerServicesContext cs)This constructor takes the container services that will be used to resolve relative paths and createInputStreaminstances.FileLoader(java.lang.String basePath)This constructor takes the basePath that shall be used as root folder to resolve relative paths.FileLoader(java.lang.String basePath, java.lang.String plugInsPath)This constructor takes the basePath and the plugInsPath that shall be used as root folder to resolve relative paths. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearCaches()This method clears all internal cachesbooleanexists(java.lang.String path)Returns whether the given relative path exists in the file system.java.lang.StringgetApplicationPath(java.lang.String relativePath)Returns a path that its always relative to the application's root folder.java.lang.StringgetBasePath()Returns the current base path for this file loader.static java.net.URLConnectiongetConnection(java.net.URL url)ContainerServicesgetContainerServices()Deprecated.replaced bygetContainerServicesContext()ContainerServicesContextgetContainerServicesContext()Returns the underlyingContainerServicesContext.static java.lang.StringgetCustomizationPrefix(java.lang.String name)Returns the prefix to be used in a relative path, that identifies that path to belong to the given customization.java.io.InputStreamgetDTDInputStream(java.lang.String dtdFileName)Returns an InputStream for the givendtdFileName.java.lang.StringgetDTDsPath()Returns the path of the folder where dtd files, used to validate the syntax fo xml files, are located.java.lang.StringgetFileContents(java.lang.String filePath)Returns the contents of a file as a String objectjava.lang.StringgetFileContents(java.lang.String filePath, java.lang.String encoding)Returns the contents of a file as a String objectjava.io.InputStreamgetFileInputStream(java.lang.String filePath)Returns the contents of a file as an InputStream objectstatic FileLoadergetInstance()The method to return the singleton instance of this class.longgetLastModifiedTime(java.lang.String path)Returns the last time the resource was modified in milliseconds.java.lang.StringgetPlugInsPath()Returns the plugInsPath.java.lang.StringgetRealPath(java.lang.String filePath)Resolves the real (absolute) path from the given relative path.static java.lang.StringgetRealPath(java.lang.String filePath, ContainerServicesContext cs)java.lang.StringgetRelativePath(java.lang.String absolutePath)Returns a relative path for the given absolute path.java.lang.StringgetRelativePath(java.lang.String absolutePath, CustomizationInfo ci)Returns a relative path for the given absolute path.voidinit(ContainerServices cs)Deprecated.replaced byinit(ContainerServicesContext)voidinit(ContainerServicesContext cs)Initializes this FileLoader with aContainerServicesContextthat will then be used to resolve paths and to createInputStreaminstances to load files.voidsetBasePath(java.lang.String basePath)Sets the base path for this file loader.voidsetDTDsPath(java.lang.String path)Sets the path of the folder where dtd files are located.voidsetPlugInsPath(java.lang.String path)Sets the plugins path. 
 - 
 
- 
- 
Field Detail
- 
ABSOLUTE_PREFIX
public static final java.lang.String ABSOLUTE_PREFIX
Represents the prefix added to paths to indicate their absolute.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 - Constant Field Values
 
 
- 
RELATIVE_PREFIX
public static final java.lang.String RELATIVE_PREFIX
Represents the prefix added to paths to indicate their relative to the application's root folder.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 - Constant Field Values
 
 
- 
PLUGIN_PREFIX
public static final char PLUGIN_PREFIX
Represents the first character of a relative path that indicates the path to points to a file on a specific plugin- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 getRelativePath(String), Constant Field Values
 
 - 
 
- 
Constructor Detail
- 
FileLoader
public FileLoader(ContainerServicesContext cs)
This constructor takes the container services that will be used to resolve relative paths and createInputStreaminstances.- Since:
 - MicroStrategy Web 9.0.1
 
 
- 
FileLoader
@Deprecated public FileLoader(ContainerServices cs)
Deprecated.replaced byFileLoader(ContainerServicesContext)This constructor takes the container services that will be used to resolve relative paths and createInputStreaminstances. 
- 
FileLoader
public FileLoader(java.lang.String basePath)
This constructor takes the basePath that shall be used as root folder to resolve relative paths.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
FileLoader
public FileLoader(java.lang.String basePath, java.lang.String plugInsPath)This constructor takes the basePath and the plugInsPath that shall be used as root folder to resolve relative paths.- Since:
 - MicroStrategy Web 9.0.0
 
 
 - 
 
- 
Method Detail
- 
getInstance
public static FileLoader getInstance()
The method to return the singleton instance of this class.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
init
@Deprecated public void init(ContainerServices cs)
Deprecated.replaced byinit(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.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
init
public void init(ContainerServicesContext cs)
Initializes this FileLoader with aContainerServicesContextthat will then be used to resolve paths and to createInputStreaminstances to load files.- Since:
 - MicroStrategy Web 9.0.1
 
 
- 
setBasePath
public void setBasePath(java.lang.String basePath)
Sets the base path for this file loader. In the absence of aContainerServices, the base-path is used to calculate the real location of relative paths.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 FileLoader
 
- 
getBasePath
public java.lang.String getBasePath()
Returns the current base path for this file loader. In the absence of aContainerServices, the base-path is used to calculate the real location of relative paths.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 FileLoader
 
- 
setDTDsPath
public void setDTDsPath(java.lang.String path)
Sets the path of the folder where dtd files are located. This value is used by thegetDTDInputStream(java.lang.String)to create the input stream for the given dtd. If this value is not explicitly set, it is calculated from the associatedContainerServicesinstance.- Parameters:
 path- The relative path location of the folder where dtd files are located.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 getDTDsPath()
 
- 
getDTDsPath
public java.lang.String getDTDsPath()
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(java.lang.String), then this method will read thedtdsLocation(ApplicationParameters.DTD_PATHinit parameter from the associatedContainerServicesclass, if any.It returns
nullif the value has not been explicitly set or there is noContainerServicesinstance associated.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
setPlugInsPath
public void setPlugInsPath(java.lang.String path)
Sets the plugins path. Normally all plugins' paths are resolved based on the plugin name and the settings on theCustomizationsclass. 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 !
- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getPlugInsPath
public java.lang.String getPlugInsPath()
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.- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 setPlugInsPath(java.lang.String)
 
- 
getContainerServices
@Deprecated public ContainerServices getContainerServices()
Deprecated.replaced bygetContainerServicesContext()Returns theContainerServicesinstance currently associated with- Returns:
 - ContainerServices The 
ContainerServicesobject. - Since:
 - MicroStrategy Web 8.0.0
 
 
- 
getContainerServicesContext
public ContainerServicesContext getContainerServicesContext()
Returns the underlyingContainerServicesContext.- Since:
 - MicroStrategy Web 9.0.1
 
 
- 
clearCaches
public void clearCaches()
This method clears all internal caches- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getFileContents
public java.lang.String getFileContents(java.lang.String filePath)
Returns the contents of a file as a String object- Parameters:
 filePath- A relative file location.- Returns:
 - the contents of the file
 - See Also:
 getRelativePath(java.lang.String)
 
- 
getFileContents
public java.lang.String getFileContents(java.lang.String filePath, java.lang.String encoding)Returns the contents of a file as a String object- Parameters:
 filePath- A relative file location.- Returns:
 - the contents of the file
 - See Also:
 getRelativePath(java.lang.String)
 
- 
getFileInputStream
public java.io.InputStream getFileInputStream(java.lang.String filePath)
Returns the contents of a file as an InputStream object- Parameters:
 filePath- A relative file location.- Returns:
 - the contents of the file
 - See Also:
 getRelativePath(java.lang.String)
 
- 
getDTDInputStream
public java.io.InputStream getDTDInputStream(java.lang.String dtdFileName)
Returns an InputStream for the givendtdFileName. It uses thegetDTDsPath()method to calculate the location of the file, ifnull, it just tries to load the file from the application's root folder.- Parameters:
 dtdFileName- The name of the file. Typically specified as the SYSTEM attribute of the xml's DOCTYPE.- Returns:
 - InputStream for the given dtd if found; 
nullotherwise. - Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getLastModifiedTime
public long getLastModifiedTime(java.lang.String path)
Returns the last time the resource was modified in milliseconds.- Parameters:
 path- String- Returns:
 - long
 - Since:
 - MicroStrategy Web 8.0.1
 
 
- 
exists
public boolean exists(java.lang.String path)
Returns whether the given relative path exists in the file system.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getRealPath
public java.lang.String getRealPath(java.lang.String filePath)
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:- If there is container services instance associated, the relative path is resolved by the container services (which typically uses the virtual directory folder as the root).
 - If there is no container services defined but the base path has been specified, the base path is used as root folder.
 - Otherwise, the user directory (i.e. the folder where the JVM was started from) is used as the root folder.
 
- Parameters:
 filePath- Always a relative location. If it is an absolute path, it must haveABSOLUTE_PREFIX.- Returns:
 - An absolute path as used by the File System.
 - See Also:
 getRelativePath(java.lang.String)
 
- 
getRealPath
public static java.lang.String getRealPath(java.lang.String filePath, ContainerServicesContext cs)- Parameters:
 filePath- Always a relative location. If it is an absolute path, it must haveABSOLUTE_PREFIX.cs-ContainerServicesContextused to resolve relative paths- Returns:
 - An absolute path as used by the File System.
 - Since:
 - MicroStrategy Web 9.0.1
 - See Also:
 getRealPath(String)
 
- 
getApplicationPath
public java.lang.String getApplicationPath(java.lang.String relativePath)
Returns a path that its always relative to the application's root folder.- If the path is already relative to the application's root folder, returns the same value.
 - If the path is relative to a customization folder but that folder doesn't exist, it throws an IllegalArgumentException, otherwise it returns the corresponding relative path.
 - If the path is prefixed with "ABSOLUTE:", it returns the same value without the prefix.
 
- Since:
 - MicroStrategy Web 9.0.0
 - See Also:
 getRelativePath(java.lang.String)
 
- 
getRelativePath
public java.lang.String getRelativePath(java.lang.String absolutePath)
Returns a relative path for the given absolute path. The path returned is relative to the applications root folder.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getRelativePath
public java.lang.String getRelativePath(java.lang.String absolutePath, CustomizationInfo ci)Returns a relative path for the given absolute path. A FileLoader supports the following relative paths:- Paths relative to the application's root folder
 - Paths relative to a specific customization's root folder.
 - Paths outside the application's root folder.
 
Paths that are relative the application's root folder start either with "/" or are prefixed with "RELATIVE:", for example:
- "/jsp/mstrWeb.jsp"
 - "RELATIVE:/WEB-INF/xml"
 
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:
- "@Customizations:/jsp/mstrWeb.jsp"
 - "@MapInfo:/jsp/mstrWeb.jsp"
 
Paths to files that are not part of the application are prefixed with "ABSOLUTE:", for example:
- "ABSOLUTE:Z:\Program Files\Common Files\MyFile.txt"
 
- if a CustomizationInfo is provided and the file is member of the customization's root folder or one of its subfolders, it will return a path relative to the customization's root folder.
 - else, if the file is member of the application's s root folder or one of its subfolders, it will return a path relative to the application's root folder.
 - otherwise, it will return the same path prefix with "ABSOLUTE:".
 
 
- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getCustomizationPrefix
public static java.lang.String getCustomizationPrefix(java.lang.String name)
Returns the prefix to be used in a relative path, that identifies that path to belong to the given customization.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getConnection
public static java.net.URLConnection getConnection(java.net.URL url) throws java.io.IOException- Throws:
 java.io.IOException
 
 - 
 
 -