Search in sources :

Example 11 with IPluginManager

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;
}
Also used : IPluginManager(org.pentaho.platform.api.engine.IPluginManager) ResourceBundle(java.util.ResourceBundle)

Example 12 with IPluginManager

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);
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) IPlatformReadyListener(org.pentaho.platform.api.engine.IPlatformReadyListener) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin)

Example 13 with IPluginManager

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("&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;"));
    }
}
Also used : StringWriter(java.io.StringWriter) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 14 with IPluginManager

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();
    }
}
Also used : IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Example 15 with IPluginManager

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;
}
Also used : IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Aggregations

IPluginManager (org.pentaho.platform.api.engine.IPluginManager)24 ArrayList (java.util.ArrayList)7 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 Facet (org.codehaus.enunciate.Facet)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)2 IContentInfo (org.pentaho.platform.api.engine.IContentInfo)2 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)2 IPluginOperation (org.pentaho.platform.api.engine.IPluginOperation)2 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)2 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1