Class PluginResourceLoader
- java.lang.Object
-
- org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader
-
- All Implemented Interfaces:
org.pentaho.platform.api.engine.IPluginResourceLoader
public class PluginResourceLoader extends Object implements org.pentaho.platform.api.engine.IPluginResourceLoader
The default implementation of theIPluginResourceLoader
. Obtains resources by searching the root directory of aPluginClassLoader
.Resource discovery
PluginResourceLoader
will search the following places for plugin classes:- the /lib folder under the plugin's root directory, e.g. "myplugin/lib"
PluginResourceLoader
will search for non-class resources in several locations:- inside jar files located in the lib directory
- from the filesystem relative to the root directory of the plugin
resourcePath
This class requires resource paths to be the relative paths to plugin resources, relative the root directory of the plugin. A resource path can be specified either using '/' or '.' (or both) in the path, depending on the particular method you are using. It is usually best to specify the path using '/' since both the filesystem and the classloader can handle this delimiter, whereas '.' will not be handled correctly if you are trying to load a resource from the filesystem.Plugin Settings
This class backs the plugin settings APIs with the PentahoSystem settings service. SeePentahoSystem.getSystemSetting(String, String)
andISystemSettings
. System settings are expected in a file named settings.xml in the root of the plugin directory.- Author:
- aphillips
-
-
Constructor Summary
Constructors Constructor Description PluginResourceLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<URL>
findResources(Class<?> clazz, String namePattern)
List<URL>
findResources(ClassLoader classLoader, String namePattern)
protected ClassLoader
getClassLoader(Class<?> clazz)
protected PluginClassLoader
getOverrideClassloader()
protected File
getPluginDir(ClassLoader classLoader)
String
getPluginSetting(Class<?> pluginClass, String key)
String
getPluginSetting(Class<?> pluginClass, String key, String defaultVal)
String
getPluginSetting(ClassLoader classLoader, String key, String defaultVal)
byte[]
getResourceAsBytes(Class<? extends Object> clazz, String resourcePath)
InputStream
getResourceAsStream(Class<?> clazz, String resourcePath)
InputStream
getResourceAsStream(ClassLoader classLoader, String resourcePath)
String
getResourceAsString(Class<? extends Object> clazz, String resourcePath)
String
getResourceAsString(Class<? extends Object> clazz, String resourcePath, String charsetName)
ResourceBundle
getResourceBundle(Class<?> clazz, String resourcePath)
String
getSystemRelativePluginPath(ClassLoader classLoader)
void
setOverrideClassloader(PluginClassLoader pluginClassloader)
Deprecated.void
setRootDir(File rootDir)
Deprecated.instead of setting the root dir, have your application use a subclass of PluginResourceLoader that returns an appropriately pathed PluginClassLoader from an overriddengetClassLoader(Class)
.void
setSettingsPath(String settingsPath)
-
-
-
Method Detail
-
setSettingsPath
public void setSettingsPath(String settingsPath)
-
setOverrideClassloader
@Deprecated public void setOverrideClassloader(PluginClassLoader pluginClassloader)
Deprecated.
-
getOverrideClassloader
protected PluginClassLoader getOverrideClassloader()
-
setRootDir
public void setRootDir(File rootDir)
Deprecated.instead of setting the root dir, have your application use a subclass of PluginResourceLoader that returns an appropriately pathed PluginClassLoader from an overriddengetClassLoader(Class)
.Force the resource loader to look for resources in this root directory. If null, the resource loader will consult thePluginClassLoader
for the root directory.- Parameters:
rootDir
- the root directory in which to search for resources
-
getResourceAsBytes
public byte[] getResourceAsBytes(Class<? extends Object> clazz, String resourcePath)
- Specified by:
getResourceAsBytes
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceAsString
public String getResourceAsString(Class<? extends Object> clazz, String resourcePath) throws UnsupportedEncodingException
- Specified by:
getResourceAsString
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
- Throws:
UnsupportedEncodingException
-
getResourceAsString
public String getResourceAsString(Class<? extends Object> clazz, String resourcePath, String charsetName) throws UnsupportedEncodingException
- Specified by:
getResourceAsString
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
- Throws:
UnsupportedEncodingException
-
getSystemRelativePluginPath
public String getSystemRelativePluginPath(ClassLoader classLoader)
-
getPluginDir
protected File getPluginDir(ClassLoader classLoader)
-
getClassLoader
protected ClassLoader getClassLoader(Class<?> clazz)
-
getResourceAsStream
public InputStream getResourceAsStream(Class<?> clazz, String resourcePath)
- Specified by:
getResourceAsStream
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceAsStream
public InputStream getResourceAsStream(ClassLoader classLoader, String resourcePath)
- Specified by:
getResourceAsStream
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
findResources
public List<URL> findResources(Class<?> clazz, String namePattern)
- Specified by:
findResources
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
findResources
public List<URL> findResources(ClassLoader classLoader, String namePattern)
- Specified by:
findResources
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceBundle
public ResourceBundle getResourceBundle(Class<?> clazz, String resourcePath)
- Specified by:
getResourceBundle
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(Class<?> pluginClass, String key)
- Specified by:
getPluginSetting
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(Class<?> pluginClass, String key, String defaultVal)
- Specified by:
getPluginSetting
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(ClassLoader classLoader, String key, String defaultVal)
- Specified by:
getPluginSetting
in interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
-