use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class LocalizationServlet method getBundle.
/**
* Retrieve a {@link java.util.ResourceBundle} from a plugin.
*
* @param pluginId
* ID of the plugin to load the resource bundle from
* @param name
* Resource bundle name that resides in the plugin
* @return Resource bundle for the name provided in the plugin referenced by {@code pluginId}
* @throws IllegalArgumentException
* Invalid plugin Id
* @throws java.util.MissingResourceException
* Invalid resource bundle name
*/
protected ResourceBundle getBundle(String pluginId, String name) {
IPluginManager pm = PentahoSystem.get(IPluginManager.class);
ClassLoader pluginClassLoader = pm.getClassLoader(pluginId);
if (pluginClassLoader == null) {
throw new IllegalArgumentException(Messages.getInstance().getErrorString("LocalizationServlet.ERROR_0001_INVALID_PLUGIN_ID", // $NON-NLS-1$
pluginId));
}
if (name == null || name.length() == 0) {
throw new IllegalArgumentException(Messages.getInstance().getErrorString("LocalizationServlet.ERROR_0002_INVALID_RESOURCE_NAME", // $NON-NLS-1$
name));
}
ResourceBundle bundle = ResourceBundle.getBundle(name, LocaleHelper.getLocale(), pluginClassLoader);
// Clear the bundle's cached messages if we shouldn't be caching them
if (!isMessageCachingEnabled(pm, pluginId)) {
ResourceBundle.clearCache();
}
return bundle;
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PentahoSystemReadyListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
IPentahoSession session = PentahoSessionHolder.getSession();
IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
try {
List<IPlatformPlugin> providedPlugins = pluginProvider.getPlugins(session);
for (IPlatformPlugin plugin : providedPlugins) {
try {
if (!StringUtils.isEmpty(plugin.getLifecycleListenerClassname())) {
ClassLoader loader = pluginManager.getClassLoader(plugin.getId());
Object listener = loader.loadClass(plugin.getLifecycleListenerClassname()).newInstance();
if (IPlatformReadyListener.class.isAssignableFrom(listener.getClass())) {
((IPlatformReadyListener) listener).ready();
}
}
} catch (Exception e) {
Logger.warn(PentahoSystemReadyListener.class.getName(), e.getMessage(), e);
}
}
} catch (PlatformPluginRegistrationException e) {
Logger.warn(PentahoSystemReadyListener.class.getName(), e.getMessage(), e);
}
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluggableUploadFileServletTest method testXSSUsingPathInfo.
@Test
public void testXSSUsingPathInfo() throws Exception {
when(httpServletRequest.getPathInfo()).thenReturn("<script>alert('XSS')</script>");
IPluginManager pluginManager = mock(IPluginManager.class);
when(pluginManager.isBeanRegistered(anyString())).thenReturn(false);
PentahoSystem.registerObject(pluginManager);
try (StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter)) {
when(httpServletResponse.getWriter()).thenReturn(printWriter);
pluggableUploadFileServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(stringWriter.toString().contains("<script>alert('XSS')</script>"));
}
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluginAdapter method publish.
public String publish(IPentahoSession session, int loggingLevel) {
// from IPentahoPublisher
try {
PluginMessageLogger.clear();
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, "IPluginManager", session);
if (pluginManager == null) {
// we cannot continue without the PluginSettings
Logger.error(getClass().toString(), Messages.getInstance().getErrorString(// $NON-NLS-1$
"PluginAdapter.ERROR_0001_PLUGIN_MANAGER_NOT_CONFIGURED"));
// $NON-NLS-1$
return Messages.getInstance().getString("PluginAdapter.ERROR_0001_PLUGIN_MANAGER_NOT_CONFIGURED");
}
pluginManager.reload(session);
String rtn = PluginMessageLogger.getAll().toString();
return rtn;
} finally {
PluginMessageLogger.clear();
}
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluginAdapter method startup.
public boolean startup(IPentahoSession session) {
// from IPentahoSystemListener
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, "IPluginManager", session);
if (pluginManager == null) {
// we cannot continue without the PluginSettings
Logger.error(getClass().toString(), Messages.getInstance().getErrorString(// $NON-NLS-1$
"PluginAdapter.ERROR_0001_PLUGIN_MANAGER_NOT_CONFIGURED"));
return false;
}
pluginManager.reload();
return true;
}
Aggregations