use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluginFileContentGenerator method createContent.
@Override
public void createContent(OutputStream outputStream) throws Exception {
IPluginResourceLoader pluginResourceLoader = PentahoSystem.get(IPluginResourceLoader.class);
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
ClassLoader classLoader = pluginManager.getClassLoader(pluginId);
String filePath = !relativeFilePath.startsWith("/") ? "/" + relativeFilePath : relativeFilePath;
InputStream inputStream = pluginResourceLoader.getResourceAsStream(classLoader, filePath);
int val;
while ((val = inputStream.read()) != -1) {
outputStream.write(val);
}
outputStream.flush();
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class UserConsoleResource method getAdminContent.
/**
* Returns the list of admin related settings
*
* @return list of settings
*/
@GET
@Path("/getAdminContent")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public List<Setting> getAdminContent() {
ArrayList<Setting> settings = new ArrayList<Setting>();
try {
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, UserConsoleService.getPentahoSession());
List<String> pluginIds = pluginManager.getRegisteredPlugins();
nextPlugin: for (String pluginId : pluginIds) {
String adminContentInfo = (String) pluginManager.getPluginSetting(pluginId, "admin-content-info", null);
String exceptionMessage = (String) pluginManager.getPluginSetting(pluginId, "exception-message", null);
if (adminContentInfo != null) {
StringTokenizer nameValuePairs = new StringTokenizer(adminContentInfo, ";");
while (nameValuePairs.hasMoreTokens()) {
String currentToken = nameValuePairs.nextToken().trim();
if (currentToken.startsWith("conditional-logic-validator=")) {
String validatorName = currentToken.substring("conditional-logic-validator=".length());
Class<?> validatorClass = pluginManager.getClassLoader(pluginId).loadClass(validatorName);
IAdminContentConditionalLogic validator = (IAdminContentConditionalLogic) validatorClass.newInstance();
int status = validator.validate();
if (status == IAdminContentConditionalLogic.DISPLAY_ADMIN_CONTENT) {
settings.add(new Setting("admin-content-info", adminContentInfo));
}
if (status == IAdminContentConditionalLogic.DISPLAY_EXCEPTION_MESSAGE && exceptionMessage != null) {
settings.add(new Setting("exception-message", exceptionMessage));
}
if (status == IAdminContentConditionalLogic.AVOID_ADMIN_CONTENT) {
continue nextPlugin;
}
}
}
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return settings;
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PentahoWebContextFilterTest method setup.
@Before
public void setup() throws IOException, ServletException {
this.serverScheme = "https";
String serverName = "di.pentaho.local";
int port = 9055;
this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
this.contextRoot = "/the/context/root/";
this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
this.mockRequest = mock(HttpServletRequest.class);
ServletContext mockServletContext = mock(ServletContext.class);
ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
Collection<String> mappings = new ArrayList<>(1);
mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
when(mockServletRegistration.getMappings()).thenReturn(mappings);
when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
when(this.mockRequest.getServerName()).thenReturn(serverName);
when(this.mockRequest.getServerPort()).thenReturn(port);
when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
this.mockResponse = mock(HttpServletResponse.class);
this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
}
});
FilterConfig mockFilterConfig = mock(FilterConfig.class);
this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
this.activeTheme = "xptoTheme";
IUserSetting mockUserSetting = mock(IUserSetting.class);
when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
this.sessionName = "testSession";
IPentahoSession mockSession = mock(IPentahoSession.class);
when(mockSession.getName()).thenReturn(this.sessionName);
doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
this.reservedChars = new ArrayList<>(2);
this.reservedChars.add('r');
this.reservedChars.add('c');
doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
IPluginManager mockPluginManager = mock(IPluginManager.class);
doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
this.pentahoWebContextFilter.init(mockFilterConfig);
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PojoComponent method validateAction.
@Override
protected boolean validateAction() {
boolean ok = false;
if (pojo == null && isDefinedInput("class")) {
// $NON-NLS-1$
// $NON-NLS-1$
String className = getInputStringValue("class");
// try to load the class from a plugin
IPluginManager pluginMgr = PentahoSystem.get(IPluginManager.class, getSession());
if (pluginMgr != null && pluginMgr.isBeanRegistered(className)) {
try {
// "className" is actually the plugin bean id in this case
pojo = pluginMgr.getBean(className);
} catch (PluginBeanException e) {
// $NON-NLS-1$
error("Could not load bean class from plugin", e);
return false;
}
}
// the bean class was not found in a plugin, so try the default classloader
if (pojo == null) {
try {
// TODO support loading classes from the solution repository
Class<?> aClass = getClass().getClassLoader().loadClass(className);
pojo = aClass.newInstance();
} catch (Exception ex) {
// $NON-NLS-1$
error("Could not load bean class", ex);
return false;
}
}
}
if (pojo != null) {
// By the time we get here, we've got our class
try {
Method[] methods = pojo.getClass().getMethods();
// create a method map
for (Method method : methods) {
String name = method.getName();
Class<?>[] paramTypes = method.getParameterTypes();
if (name.equals("getOutputs")) {
// $NON-NLS-1$
runtimeOutputsMethod = method;
} else if (name.equals("setInputs")) {
// $NON-NLS-1$
runtimeInputsMethod = method;
} else if (name.equals("setResources")) {
// $NON-NLS-1$
resourcesMethod = method;
} else if (name.equals("setLogger")) {
// $NON-NLS-1$
if (paramTypes.length == 1 && paramTypes[0] == Log.class) {
loggerMethod = method;
}
} else if (name.equals("setSession")) {
// $NON-NLS-1$
if (paramTypes.length == 1 && paramTypes[0] == IPentahoSession.class) {
sessionMethod = method;
}
} else if (name.equalsIgnoreCase("configure")) {
// $NON-NLS-1$
configureMethod = method;
} else if (name.startsWith("set")) {
// $NON-NLS-1$
name = name.substring(3).toUpperCase();
if (name.equals("CLASS")) {
// $NON-NLS-1$
// $NON-NLS-1$
warn(Messages.getInstance().getString("PojoComponent.CANNOT_USE_SETCLASS"));
} else {
if (!setMethods.containsKey(name)) {
setMethods.put(name, new ArrayList<Method>());
}
setMethods.get(name).add(method);
}
} else if (name.startsWith("get")) {
// $NON-NLS-1$
name = name.substring(3).toUpperCase();
getMethods.put(name, method);
} else if (name.equalsIgnoreCase("execute")) {
// $NON-NLS-1$
executeMethod = method;
} else if (name.equalsIgnoreCase("validate")) {
// $NON-NLS-1$
validateMethod = method;
} else if (name.equalsIgnoreCase("done")) {
// $NON-NLS-1$
doneMethod = method;
}
}
ok = true;
} catch (Throwable ex) {
// $NON-NLS-1$
error("Could not load object class", ex);
}
}
return ok;
}
use of org.pentaho.platform.api.engine.IPluginManager in project pentaho-platform by pentaho.
the class PluggableUploadFileServlet method getUploaderBean.
protected IUploadFileServletPlugin getUploaderBean(String uploaderBeanId, HttpServletResponse response) throws PluginBeanException, IOException {
if (StringUtils.isEmpty(uploaderBeanId)) {
response.getWriter().write(// $NON-NLS-1$
Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0006_NO_UPLOADER_FOUND"));
return null;
}
IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
if (!pluginManager.isBeanRegistered(uploaderBeanId)) {
response.getWriter().write(Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0008_NO_UPLOADER_BY_ID", // $NON-NLS-1$
Encode.forHtml(uploaderBeanId)));
return null;
}
Object uploaderBean = pluginManager.getBean(uploaderBeanId);
if (!(uploaderBean instanceof IUploadFileServletPlugin)) {
response.getWriter().write(Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0007_UPLOADER_WRONG_TYPE", // $NON-NLS-1$
IUploadFileServletPlugin.class.getName()));
return null;
}
IUploadFileServletPlugin uploaderPlugin = (IUploadFileServletPlugin) uploaderBean;
return uploaderPlugin;
}
Aggregations