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
PluginResourceLoaderwill search the following places for plugin classes:- the /lib folder under the plugin's root directory, e.g. "myplugin/lib"
PluginResourceLoaderwill 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 ClassLoadergetClassLoader(Class<?> clazz)protected PluginClassLoadergetOverrideClassloader()protected FilegetPluginDir(ClassLoader classLoader)StringgetPluginSetting(Class<?> pluginClass, String key)StringgetPluginSetting(Class<?> pluginClass, String key, String defaultVal)StringgetPluginSetting(ClassLoader classLoader, String key, String defaultVal)byte[]getResourceAsBytes(Class<? extends Object> clazz, String resourcePath)InputStreamgetResourceAsStream(Class<?> clazz, String resourcePath)InputStreamgetResourceAsStream(ClassLoader classLoader, String resourcePath)StringgetResourceAsString(Class<? extends Object> clazz, String resourcePath)StringgetResourceAsString(Class<? extends Object> clazz, String resourcePath, String charsetName)ResourceBundlegetResourceBundle(Class<?> clazz, String resourcePath)StringgetSystemRelativePluginPath(ClassLoader classLoader)voidsetOverrideClassloader(PluginClassLoader pluginClassloader)Deprecated.voidsetRootDir(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).voidsetSettingsPath(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 thePluginClassLoaderfor 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:
getResourceAsBytesin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceAsString
public String getResourceAsString(Class<? extends Object> clazz, String resourcePath) throws UnsupportedEncodingException
- Specified by:
getResourceAsStringin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader- Throws:
UnsupportedEncodingException
-
getResourceAsString
public String getResourceAsString(Class<? extends Object> clazz, String resourcePath, String charsetName) throws UnsupportedEncodingException
- Specified by:
getResourceAsStringin 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:
getResourceAsStreamin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceAsStream
public InputStream getResourceAsStream(ClassLoader classLoader, String resourcePath)
- Specified by:
getResourceAsStreamin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
findResources
public List<URL> findResources(Class<?> clazz, String namePattern)
- Specified by:
findResourcesin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
findResources
public List<URL> findResources(ClassLoader classLoader, String namePattern)
- Specified by:
findResourcesin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getResourceBundle
public ResourceBundle getResourceBundle(Class<?> clazz, String resourcePath)
- Specified by:
getResourceBundlein interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(Class<?> pluginClass, String key)
- Specified by:
getPluginSettingin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(Class<?> pluginClass, String key, String defaultVal)
- Specified by:
getPluginSettingin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
getPluginSetting
public String getPluginSetting(ClassLoader classLoader, String key, String defaultVal)
- Specified by:
getPluginSettingin interfaceorg.pentaho.platform.api.engine.IPluginResourceLoader
-
-