private static String callPlugin(
      final String pluginName, final String method, final Map<String, Object> parameters)
      throws ReportDataFactoryException {

    final IPentahoSession userSession = PentahoSessionHolder.getSession();
    final IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, userSession);

    try {
      Object cdaBean = pluginManager.getBean("cda.api");
      Class cdaBeanClass = cdaBean.getClass();

      Class[] paramTypes;
      Object[] paramValues;
      Method m;
      final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

      if ("listParameters".equals(method)) {
        IParameterProvider params = new SimpleParameterProvider(parameters);

        paramTypes =
            new Class[] {
              String.class,
              String.class,
              String.class,
              String.class,
              String.class,
              HttpServletResponse.class,
              HttpServletRequest.class
            };
        m = cdaBeanClass.getMethod("listParameters", paramTypes);
        paramValues = new Object[7];
        paramValues[0] = params.getStringParameter("path", null);
        paramValues[1] = params.getStringParameter("solution", "");
        paramValues[2] = params.getStringParameter("file", "");
        paramValues[3] = params.getStringParameter("outputType", "json");
        paramValues[4] = params.getStringParameter("dataAccessId", "<blank>");
        paramValues[5] = getResponse(outputStream);
        paramValues[6] = getRequest(parameters);

        m.invoke(cdaBean, paramValues);

        return outputStream.toString();

      } else {
        paramTypes = new Class[] {HttpServletRequest.class};
        m = cdaBeanClass.getMethod("doQueryInterPlugin", paramTypes);

        paramValues = new Object[1];
        paramValues[0] = getRequest(parameters);

        return (String) m.invoke(cdaBean, paramValues);
      }

    } catch (Exception e) {
      throw new ReportDataFactoryException("Failed to acquire " + pluginName + " plugin: ", e);
    }
  }
  public AbstractJcrBackedRoleBindingDao(
      final Map<String, List<IAuthorizationAction>> immutableRoleBindings,
      final Map<String, List<String>> bootstrapRoleBindings,
      final String superAdminRoleName,
      final ITenantedPrincipleNameResolver tenantedRoleNameUtils,
      final List<IAuthorizationAction> authorizationActions) {
    this();
    // TODO: replace with IllegalArgumentException
    Assert.notNull(immutableRoleBindings);
    Assert.notNull(bootstrapRoleBindings);
    Assert.notNull(superAdminRoleName);
    Assert.notNull(authorizationActions);

    setAuthorizationActions(authorizationActions);

    this.immutableRoleBindings = immutableRoleBindings;
    this.bootstrapRoleBindings = bootstrapRoleBindings;
    this.superAdminRoleName = superAdminRoleName;
    this.tenantedRoleNameUtils = tenantedRoleNameUtils;

    immutableRoleBindingNames = new HashMap<String, List<String>>();
    for (final Entry<String, List<IAuthorizationAction>> entry : immutableRoleBindings.entrySet()) {
      final List<String> roles = new ArrayList<String>();
      for (final IAuthorizationAction a : entry.getValue()) {
        roles.add(a.getName());
      }
      immutableRoleBindingNames.put(entry.getKey(), roles);
    }

    // TODO this code can be replaced for 7.0 version by commit
    // https://github.com/AliaksandrDrebenchuk/pentaho-platform/commit/3adf0df3a337b6dc1b864e74b62143510d0381ee
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    if (pluginManager != null) {
      pluginManager.addPluginManagerListener(
          new IPluginManagerListener() {

            private boolean loaded = false;

            @Override
            public void onReload() {
              if (!loaded) {
                setAuthorizationActions(PentahoSystem.getAll(IAuthorizationAction.class));
                updateImmutableRoleBindingNames();
                loaded = true;
              }
            }
          });
    }
  }
 protected void determineExecutableTypes() {
   IPluginManager pluginManager = null;
   try {
     pluginManager = PentahoSystem.get(IPluginManager.class, null);
   } catch (Exception ignored) {
     log.debug("Executing outside the BIPLATFORM");
   }
   executableTypes = new HashSet<String>();
   if (pluginManager != null && pluginManager.getContentTypes() != null) {
     executableTypes.addAll(pluginManager.getContentTypes());
   }
   // Add the non-plugin types
   executableTypes.add("xaction");
   executableTypes.add("url");
 }
  /**
   * Returns the list of admin related settings
   *
   * @return list of settings
   */
  @GET
  @Path("/getAdminContent")
  @Produces({APPLICATION_JSON, APPLICATION_XML})
  public List<Setting> getAdminContent() {

    ArrayList<Setting> settings = new ArrayList<Setting>();
    try {
      IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, 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;
  }
  protected XulMenubar getXulMenubar(String id, String documentPath, IPentahoSession session) {
    XulDomContainer container = getXulContainer(documentPath, session);
    if (container == null) {
      return null;
    }
    List<XulComponent> components =
        container.getDocumentRoot().getElementsByTagName("menubar"); // $NON-NLS-1$
    for (XulComponent component : components) {
      if (component instanceof XulMenubar && component.getId().equals(id)) {
        XulMenubar menubar = (XulMenubar) component;
        // now get customizations to it
        IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session);
        List<?> menuCustomizations = pluginManager.getMenuCustomizations();
        for (Object custom : menuCustomizations) {
          if (custom instanceof IMenuCustomization) {
            IMenuCustomization item = (IMenuCustomization) custom;
            try {
              // apply each customization and log any failures
              MenuUtil.customizeMenu(menubar, item, getXulLoader());
            } catch (Exception e) {
              session.error(
                  Messages.getString(
                      "BaseMenuProvider.ERROR_0004_COULD_NOT_CUSTOMIZE_MENU",
                      item.getId(),
                      item.getLabel()),
                  e); //$NON-NLS-1$
            }
          }
        }

        return menubar;
      }
    }
    Logger.error(
        getClass().getName(),
        Messages.getErrorString(
            "BaseMenuProvider.ERROR_0002_COULD_NOT_GET_MENUBAR")); //$NON-NLS-1$
    return null;
  }
  /**
   * Return the current user console settings
   *
   * @return current settings
   */
  @GET
  @Path("/settings")
  @Produces({APPLICATION_JSON, APPLICATION_XML})
  public List<Setting> getMantleSettings() {
    ArrayList<Setting> settings = new ArrayList<Setting>();
    settings.add(
        new Setting(
            "login-show-users-list",
            PentahoSystem.getSystemSetting(
                "login-show-users-list", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "documentation-url",
            PentahoSystem.getSystemSetting(
                "documentation-url", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "submit-on-enter-key",
            PentahoSystem.getSystemSetting(
                "submit-on-enter-key", "true"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "user-console-revision",
            PentahoSystem.getSystemSetting(
                "user-console-revision", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "startupPerspective",
            PentahoSystem.getSystemSetting(
                "startup-perspective", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "showOnlyPerspective",
            PentahoSystem.getSystemSetting(
                "show-only-perspective", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    int startupUrls = Integer.parseInt(PentahoSystem.getSystemSetting("num-startup-urls", "0"));
    settings.add(
        new Setting(
            "num-startup-urls",
            PentahoSystem.getSystemSetting(
                "num-startup-urls", "0"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    for (int i = 1; i <= startupUrls; i++) {
      settings.add(
          new Setting(
              "startup-url-" + i,
              PentahoSystem.getSystemSetting("startup-url-" + i, ""))); // $NON-NLS-1$
      settings.add(
          new Setting(
              "startup-name-" + i,
              PentahoSystem.getSystemSetting("startup-name-" + i, ""))); // $NON-NLS-1$
    }

    // Check for override of New Analysis View via pentaho.xml
    // Poked in via pentaho.xml entries
    // <new-analysis-view>
    // <command-url>http://www.google.com</command-url>
    // <command-title>Marc Analysis View</command-title>
    // </new-analysis-view>
    // <new-report>
    // <command-url>http://www.yahoo.com</command-url>
    // <command-title>Marc New Report</command-title>
    // </new-report>
    //
    String overrideNewAnalysisViewCommmand =
        PentahoSystem.getSystemSetting("new-analysis-view/command-url", null); // $NON-NLS-1$
    String overrideNewAnalysisViewTitle =
        PentahoSystem.getSystemSetting("new-analysis-view/command-title", null); // $NON-NLS-1$
    if ((overrideNewAnalysisViewCommmand != null) && (overrideNewAnalysisViewTitle != null)) {
      settings.add(
          new Setting(
              "new-analysis-view-command-url", overrideNewAnalysisViewCommmand)); // $NON-NLS-1$
      settings.add(
          new Setting(
              "new-analysis-view-command-title", overrideNewAnalysisViewTitle)); // $NON-NLS-1$
    }
    String overrideNewReportCommmand =
        PentahoSystem.getSystemSetting("new-report/command-url", null); // $NON-NLS-1$
    String overrideNewReportTitle =
        PentahoSystem.getSystemSetting("new-report/command-title", null); // $NON-NLS-1$
    if ((overrideNewReportCommmand != null) && (overrideNewReportTitle != null)) {
      settings.add(new Setting("new-report-command-url", overrideNewReportCommmand)); // $NON-NLS-1$
      settings.add(new Setting("new-report-command-title", overrideNewReportTitle)); // $NON-NLS-1$
    }

    IPluginManager pluginManager =
        PentahoSystem.get(IPluginManager.class, getPentahoSession()); // $NON-NLS-1$
    if (pluginManager != null) {
      // load content types from IPluginSettings
      int i = 0;
      for (String contentType : pluginManager.getContentTypes()) {
        IContentInfo info = pluginManager.getContentTypeInfo(contentType);
        if (info != null) {
          settings.add(
              new Setting(
                  "plugin-content-type-" + i, "." + contentType)); // $NON-NLS-1$ //$NON-NLS-2$
          settings.add(
              new Setting("plugin-content-type-icon-" + i, info.getIconUrl())); // $NON-NLS-1$
          int j = 0;
          for (IPluginOperation operation : info.getOperations()) {
            settings.add(
                new Setting(
                    "plugin-content-type-" + i + "-command-" + j,
                    operation.getId())); // $NON-NLS-1$
            settings.add(
                new Setting(
                    "plugin-content-type-" + i + "-command-perspective-" + j,
                    operation.getPerspective())); // $NON-NLS-1$
            j++;
          }
          i++;
        }
      }
    }

    return settings;
  }