/**
   * Remove an application from a workspace application list.
   *
   * @param appName the application to remove from the list
   * @param spaceName the name of the workspace to remove the application from
   * @param withData delete all data belonging to the application (located in its wiki space) if
   *     true, only hides the application from the list otherwise.
   */
  public void removeApplicationFromSpace(
      String appName, String spaceName, boolean withData, XWikiContext context)
      throws WorkspacesManagerException {
    try {
      XWikiApplication app = getXWikiApplicationManagerApi(context).getApplicationDocument(appName);

      if (app == null)
        throw new WorkspacesManagerException(
            WorkspacesManagerException.MODULE_PLUGIN_XWS,
            WorkspacesManagerException.ERROR_XWSMGR_APPNOTFOUND_ON_INSTALL,
            "Could not find application descriptor when trying to install application ["
                + appName
                + "]"
                + "in space ["
                + spaceName
                + "]");

      String appSpace = spaceName + XWIKI_WORKSPACE_APPSEPARATOR + app.getAppName();

      if (!withData) {
        // not implemented yet.
        throw new WorkspacesManagerException();
      } else {
        ApplicationManagerExtension ext = getApplicationManagerExtension(app, context);
        // execute, if needed pre uninstall operations
        if (ext != null) {
          ext.preUninstall(appSpace, context);
        }
        // remove all documents that belong to the wiki space in which lives the application
        for (XWikiDocument doc :
            context
                .getWiki()
                .getStore()
                .searchDocuments("where doc.web = '" + appSpace + "'", context)) {
          context.getWiki().deleteAllDocuments(doc, false, context);
        }
        // execute, if needed post uninstall operations
        if (ext != null) {
          ext.postUninstall(appSpace, context);
        }
      }
    } catch (XWikiException e) {
      throw new WorkspacesManagerException(e);
    }
  }