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 the IPluginResourceLoader. Obtains resources by searching the root directory of a PluginClassLoader.

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. See PentahoSystem.getSystemSetting(String, String) and ISystemSettings. System settings are expected in a file named settings.xml in the root of the plugin directory.
Author:
aphillips
  • Constructor Details

    • PluginResourceLoader

      public PluginResourceLoader()
  • Method Details

    • 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 overridden getClassLoader(Class).
      Force the resource loader to look for resources in this root directory. If null, the resource loader will consult the PluginClassLoader 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 interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getResourceAsString

      public String getResourceAsString(Class<? extends Object> clazz, String resourcePath) throws UnsupportedEncodingException
      Specified by:
      getResourceAsString in interface org.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 interface org.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 interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getResourceAsStream

      public InputStream getResourceAsStream(ClassLoader classLoader, String resourcePath)
      Specified by:
      getResourceAsStream in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • findResources

      public List<URL> findResources(Class<?> clazz, String namePattern)
      Specified by:
      findResources in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • findResources

      public List<URL> findResources(ClassLoader classLoader, String namePattern)
      Specified by:
      findResources in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getResourceBundle

      public ResourceBundle getResourceBundle(Class<?> clazz, String resourcePath)
      Specified by:
      getResourceBundle in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getPluginSetting

      public String getPluginSetting(Class<?> pluginClass, String key)
      Specified by:
      getPluginSetting in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getPluginSetting

      public String getPluginSetting(Class<?> pluginClass, String key, String defaultVal)
      Specified by:
      getPluginSetting in interface org.pentaho.platform.api.engine.IPluginResourceLoader
    • getPluginSetting

      public String getPluginSetting(ClassLoader classLoader, String key, String defaultVal)
      Specified by:
      getPluginSetting in interface org.pentaho.platform.api.engine.IPluginResourceLoader