Class FileLocator
- Since:
- org.eclipse.equinox.common 3.2
- Restriction:
- This class is not intended to be instantiated by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic URL
Returns the URL of a resource inside a bundle corresponding to the given URL.static URL
Returns a URL for the given path in the given bundle.static URL
Returns a URL for the given path in the given bundle.static URL[]
findEntries
(Bundle bundle, IPath path) This is a convenience method, fully equivalent tofindEntries(Bundle, IPath, Map)
, with a value ofnull
for the map argument.static URL[]
This method is the same asfind(Bundle, IPath, Map)
except multiple entries can be returned if more than one entry matches the path in the host and any of its fragments.static File
getBundleFile
(Bundle bundle) Deprecated.getBundleFileLocation
(Bundle bundle) Returns anOptional
File
, that (if present) describes the bundle's root location on the file system.static InputStream
openStream
(Bundle bundle, IPath file, boolean substituteArgs) Returns an input stream for the specified file.static URL
Converts a URL that uses a client-defined protocol into a URL that uses a protocol which is native to the Java class library (file, jar, http, etc).static URL
Converts a URL that uses a user-defined protocol into a URL that uses the file protocol.
-
Method Details
-
find
Returns a URL for the given path in the given bundle. Returnsnull
if the URL could not be computed or created.This method looks for the path in the given bundle and any attached fragments.
null
is returned if no such entry is found. Note that there is no specific order to the fragments.The following variables may also be used as entries in the provided path:
- $nl$ - for language specific information
- $os$ - for operating system specific information
- $ws$ - for windowing system specific information
A path of "$nl$/about.properties" in an environment with a default locale of en_CA will return a URL corresponding to the first location about.properties is found according to the following order:
plugin root/nl/en/CA/about.properties fragment1 root/nl/en/CA/about.properties fragment2 root/nl/en/CA/about.properties ... plugin root/nl/en/about.properties fragment1 root/nl/en/about.properties fragment2 root/nl/en/about.properties ... plugin root/about.properties fragment1 root/about.properties fragment2 root/about.properties ...
The current environment variable values can be overridden using the override map argument or
null
can be specified if this is not desired.- Parameters:
bundle
- the bundle in which to searchpath
- file path relative to plug-in installation locationoverride
- map of override substitution arguments to be used for any $arg$ path elements. The map keys correspond to the substitution arguments (eg. "$nl$" or "$os$"). The resulting values must be of type java.lang.String. If the map isnull
, or does not contain the required substitution argument, the default is used.- Returns:
- a URL for the given path or
null
. The actual form of the returned URL is not specified.
-
find
Returns a URL for the given path in the given bundle. Returnsnull
if the URL could not be computed or created.This method looks for the path in the given bundle and any attached fragments.
null
is returned if no such entry is found. Note that there is no specific order to the fragments.The following variables may also be used as entries in the provided path:
- $nl$ - for language specific information
- $os$ - for operating system specific information
- $ws$ - for windowing system specific information
A path of "$nl$/about.properties" in an environment with a default locale of en_CA will return a URL corresponding to the first location about.properties is found according to the following order:
plugin root/nl/en/CA/about.properties fragment1 root/nl/en/CA/about.properties fragment2 root/nl/en/CA/about.properties ... plugin root/nl/en/about.properties fragment1 root/nl/en/about.properties fragment2 root/nl/en/about.properties ... plugin root/about.properties fragment1 root/about.properties fragment2 root/about.properties ...
- Parameters:
bundle
- the bundle in which to searchpath
- file path relative to plug-in installation location- Returns:
- a URL for the given path or
null
. The actual form of the returned URL is not specified. - Since:
- 3.10
- See Also:
-
findEntries
This method is the same asfind(Bundle, IPath, Map)
except multiple entries can be returned if more than one entry matches the path in the host and any of its fragments.- Parameters:
bundle
- the bundle in which to searchpath
- file path relative to plug-in installation locationoverride
- map of override substitution arguments to be used for any $arg$ path elements. The map keys correspond to the substitution arguments (eg. "$nl$" or "$os$"). The resulting values must be of type java.lang.String. If the map isnull
, or does not contain the required substitution argument, the default is used.- Returns:
- an array of entries which match the given path. An empty array is returned if no matches are found.
- Since:
- org.eclipse.equinox.common 3.3
-
find
Returns the URL of a resource inside a bundle corresponding to the given URL. Returnsnull
if the URL could not be computed or created.This method looks for a bundle resource described by the given input URL, and returns the URL of the first resource found in the bundle or any attached fragments.
null
is returned if no such entry is found. Note that there is no specific order to the fragments.The following variables may also be used as segments in the path of the provided URL:
- $nl$ - for language specific information
- $os$ - for operating system specific information
- $ws$ - for windowing system specific information
For example, a URL of "platform:/plugin/org.eclipse.core.runtime/$nl$/about.properties" in an environment with a default locale of en_CA will return a URL corresponding to the first location about.properties is found according to the following order:
plugin root/nl/en/CA/about.properties fragment1 root/nl/en/CA/about.properties fragment2 root/nl/en/CA/about.properties ... plugin root/nl/en/about.properties fragment1 root/nl/en/about.properties fragment2 root/nl/en/about.properties ... plugin root/about.properties fragment1 root/about.properties fragment2 root/about.properties ...
- Parameters:
url
- The location of a bundle entry that potentially includes the above environment variables- Returns:
- The URL of the bundle entry matching the input URL, or
null
if no matching entry could be found. The actual form of the returned URL is not specified. - Since:
- org.eclipse.equinox.common 3.5
-
findEntries
This is a convenience method, fully equivalent tofindEntries(Bundle, IPath, Map)
, with a value ofnull
for the map argument.- Parameters:
bundle
- the bundle in which to searchpath
- file path relative to plug-in installation location- Returns:
- an array of entries which match the given path. An empty array is returned if no matches are found.
- Since:
- org.eclipse.equinox.common 3.3
-
openStream
public static InputStream openStream(Bundle bundle, IPath file, boolean substituteArgs) throws IOException Returns an input stream for the specified file. The file path must be specified relative to this plug-in's installation location. Optionally, the path specified may contain $arg$ path elements that can be used as substitution arguments. If this option is used then the $arg$ path elements are processed in the same way asfind(Bundle, IPath, Map)
.The caller must close the returned stream when done.
- Parameters:
bundle
- the bundle in which to searchfile
- path relative to plug-in installation locationsubstituteArgs
-true
to process substitution arguments, andfalse
for the file exactly as specified without processing any substitution arguments.- Returns:
- an input stream
- Throws:
IOException
- if the given path cannot be found in this plug-in
-
toFileURL
Converts a URL that uses a user-defined protocol into a URL that uses the file protocol. The contents of the URL may be extracted into a cache on the file-system in order to get a file URL.If the protocol for the given URL is not recognized by this converter, the original URL is returned as-is.
- Parameters:
url
- the original URL- Returns:
- the converted file URL or the original URL passed in if it is not recognized by this converter
- Throws:
IOException
- if an error occurs during the conversion
-
resolve
Converts a URL that uses a client-defined protocol into a URL that uses a protocol which is native to the Java class library (file, jar, http, etc).Note however that users of this API should not assume too much about the results of this method. While it may consistently return a file: URL in certain installation configurations, others may result in jar: or http: URLs.
If the protocol is not recognized by this converter, then the original URL is returned as-is.
- Parameters:
url
- the original URL- Returns:
- the resolved URL or the original if the protocol is unknown to this converter
- Throws:
IOException
- if unable to resolve URLIOException
- if an error occurs during the resolution
-
getBundleFile
Deprecated.usegetBundleFileLocation(Bundle)
insteadReturns a file for the contents of the specified bundle. Depending on how the bundle is installed the returned file may be a directory or a jar file containing the bundle content.- Parameters:
bundle
- the bundle- Returns:
- a file with the contents of the bundle
- Throws:
IOException
- if an error occurs during the resolution- Since:
- org.eclipse.equinox.common 3.4
-
getBundleFileLocation
Returns anOptional
File
, that (if present) describes the bundle's root location on the file system.Depending on how the bundle is installed the returned file may be a directory or a jar file containing the bundle content. In case the location cannot be determined the returned
Optional
is empty, which is for example usually the case forCONNECT
bundles.- Parameters:
bundle
- the bundle- Returns:
- the optional file to the location of the bundle's root
- Since:
- 3.16
-
getBundleFileLocation(Bundle)
instead