public List getUsersFirstNameChars() {
    List usersFirstNameChars = new ArrayList();
    Iterator principalIterator = this.infogluePrincipals.iterator();
    while (principalIterator.hasNext()) {
      InfoGluePrincipal infogluePrincipal = (InfoGluePrincipal) principalIterator.next();
      if (!usersFirstNameChars.contains(infogluePrincipal.getName().charAt(0)))
        usersFirstNameChars.add(infogluePrincipal.getName().charAt(0));
      // else
      //	System.out.println("Exists:" + infogluePrincipal.getName().charAt(0));
    }

    Collections.sort(usersFirstNameChars);

    return usersFirstNameChars;
  }
  public void removeContentReferences(
      Map<ContentVersionVO, RegistryVO> contentVersionRegistryPair,
      InfoGluePrincipal infoGluePrincipal,
      Database db)
      throws SystemException, Exception {
    ContentVersionVO contentVersionVO;
    RegistryVO registryVO;
    for (Map.Entry<ContentVersionVO, RegistryVO> pair : contentVersionRegistryPair.entrySet()) {
      contentVersionVO = pair.getKey();
      registryVO = pair.getValue();
      if (logger.isDebugEnabled()) {
        logger.debug(
            "About to clean ContentVersion "
                + contentVersionVO.getContentVersionId()
                + " for references to: "
                + registryVO.getEntityName()
                + "<"
                + registryVO.getEntityId()
                + ">");
      }
      String versionValue = contentVersionVO.getVersionValue();

      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_LINK))
        versionValue = deleteInlineLinks(versionValue, new Integer(registryVO.getEntityId()), db);
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_ASSET))
        versionValue = deleteInlineAssets(versionValue, new Integer(registryVO.getEntityId()));
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_SITE_NODE_RELATION))
        versionValue =
            deleteInlineSiteNodeRelations(versionValue, new Integer(registryVO.getEntityId()));
      if (registryVO.getReferenceType().equals(RegistryVO.INLINE_CONTENT_RELATION))
        versionValue =
            deleteInlineContentRelations(versionValue, new Integer(registryVO.getEntityId()));

      contentVersionVO.setVersionModifier(infoGluePrincipal.getName());
      contentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
      contentVersionVO.setVersionValue(versionValue);

      // ContentVersionController.getContentVersionController().update(contentVersionVO.getContentId(), contentVersionVO.getLanguageId(), contentVersionVO, db);
      ContentVersionController.getContentVersionController()
          .update(
              contentVersionVO.getContentId(),
              contentVersionVO.getLanguageId(),
              contentVersionVO,
              infoGluePrincipal,
              true,
              db,
              true);
    }
  }
  public List getFilteredInfogluePrincipals() {
    List subList = new ArrayList();

    char filterChar = ((InfoGluePrincipal) this.infogluePrincipals.get(0)).getFirstName().charAt(0);
    if (this.filterChar != null && this.filterChar.length() == 1)
      filterChar = this.filterChar.charAt(0);

    Iterator infogluePrincipalsIterator = this.infogluePrincipals.iterator();
    boolean foundSection = false;
    while (infogluePrincipalsIterator.hasNext()) {
      InfoGluePrincipal infogluePrincipal = (InfoGluePrincipal) infogluePrincipalsIterator.next();
      if (infogluePrincipal.getName().charAt(0) == filterChar) {
        subList.add(infogluePrincipal);
        foundSection = true;
      } else if (foundSection) break;
    }

    return subList;
  }
  public String doUserListSearch() throws Exception {
    String searchString = this.getRequest().getParameter("searchString");
    List<InfoGluePrincipal> searchResult =
        UserControllerProxy.getController().getFilteredUsers(searchString, null, null, null, null);
    ServletOutputStream myOut = getResponse().getOutputStream();

    myOut.print(
        "<select name=\"searchResult\" size=\"10\" class=\"userSelectBox\" multiple=\"true\">");

    for (InfoGluePrincipal igp : searchResult) {
      myOut.print(
          "<option value=\""
              + igp.getName()
              + "\">"
              + igp.getFirstName()
              + " "
              + igp.getLastName()
              + "</option>");
    }

    myOut.print("</select>");

    return "none";
  }
  /** Gets all roles available. */
  public List<InfoGluePrincipalBean> getPrincipalsWithGroup(String groupName) {
    if (!ServerNodeController.getController().getIsIPAllowed(getRequest())) {
      logger.error(
          "A client with IP "
              + getRequest().getRemoteAddr()
              + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
      return null;
    }

    List<InfoGluePrincipalBean> users = new ArrayList<InfoGluePrincipalBean>();

    logger.info("***************************************");
    logger.info("Getting all principals through webservice..");
    logger.info("***************************************");

    try {
      List principalList = GroupControllerProxy.getController().getInfoGluePrincipals(groupName);

      Iterator principalListIterator = principalList.iterator();
      while (principalListIterator.hasNext()) {
        InfoGluePrincipal principal = (InfoGluePrincipal) principalListIterator.next();
        InfoGluePrincipalBean bean = new InfoGluePrincipalBean();
        bean.setName(principal.getName());
        bean.setDisplayName(principal.getDisplayName());
        bean.setEmail(principal.getEmail());
        bean.setFirstName(principal.getFirstName());
        bean.setLastName(principal.getLastName());
        bean.setAdministrator(false);
        bean.setMetaInformation(principal.getMetaInformation());

        List groups = new ArrayList();
        Iterator groupsListIterator = principal.getGroups().iterator();
        while (groupsListIterator.hasNext()) {
          InfoGlueGroup group = (InfoGlueGroup) groupsListIterator.next();
          InfoGlueGroupBean groupBean = new InfoGlueGroupBean();
          groupBean.setName(group.getName());
          groupBean.setDisplayName(group.getDisplayName());
          groupBean.setDescription(group.getDescription());
          groups.add(groupBean);
        }
        bean.setGroups(groups);

        List roles = new ArrayList();
        Iterator rolesListIterator = principal.getRoles().iterator();
        while (rolesListIterator.hasNext()) {
          InfoGlueRole role = (InfoGlueRole) rolesListIterator.next();
          InfoGlueRoleBean roleBean = new InfoGlueRoleBean();
          roleBean.setName(role.getName());
          roleBean.setDisplayName(role.getDisplayName());
          roleBean.setDescription(role.getDescription());
          roles.add(roleBean);
        }
        bean.setRoles(roles);

        users.add(bean);
      }
    } catch (Exception e) {
      logger.error(
          "En error occurred when we tried to create a new contentVersion:" + e.getMessage(), e);
    }

    return users;
  }
  /** Gets a principal. */
  public InfoGluePrincipalBean getPrincipal(String userName) {
    if (!ServerNodeController.getController().getIsIPAllowed(getRequest())) {
      logger.error(
          "A client with IP "
              + getRequest().getRemoteAddr()
              + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct.");
      return null;
    }

    InfoGluePrincipalBean bean = null;

    logger.info("***************************************");
    logger.info("Getting all principals through webservice..");
    logger.info("***************************************");

    try {
      InfoGluePrincipal principal = UserControllerProxy.getController().getUser(userName);

      if (principal != null) {
        bean = new InfoGluePrincipalBean();
        bean.setName(principal.getName());
        bean.setDisplayName(principal.getDisplayName());
        bean.setEmail(principal.getEmail());
        bean.setFirstName(principal.getFirstName());
        bean.setLastName(principal.getLastName());
        bean.setAdministrator(false);
        bean.setMetaInformation(principal.getMetaInformation());

        List groups = new ArrayList();
        Iterator groupsListIterator = principal.getGroups().iterator();
        while (groupsListIterator.hasNext()) {
          InfoGlueGroup group = (InfoGlueGroup) groupsListIterator.next();
          InfoGlueGroupBean groupBean = new InfoGlueGroupBean();
          groupBean.setName(group.getName());
          groupBean.setDisplayName(group.getDisplayName());
          groupBean.setDescription(group.getDescription());
          groups.add(groupBean);
        }
        bean.setGroups(groups);

        List roles = new ArrayList();
        Iterator rolesListIterator = principal.getRoles().iterator();
        while (rolesListIterator.hasNext()) {
          InfoGlueRole role = (InfoGlueRole) rolesListIterator.next();
          InfoGlueRoleBean roleBean = new InfoGlueRoleBean();
          roleBean.setName(role.getName());
          roleBean.setDisplayName(role.getDisplayName());
          roleBean.setDescription(role.getDescription());
          roles.add(roleBean);
        }
        bean.setRoles(roles);
      } else {
        logger.error("User asked for was not in the system:" + userName);
        bean = new InfoGluePrincipalBean();
        bean.setName(userName);
        bean.setDisplayName(userName);
        bean.setEmail("*****@*****.**");
        bean.setFirstName("Not valid user");
        bean.setLastName("");
        bean.setAdministrator(false);

        List groups = new ArrayList();
        bean.setGroups(groups);

        List roles = new ArrayList();
        bean.setRoles(roles);
      }
    } catch (Exception e) {
      logger.error(
          "En error occurred when we tried to create a new contentVersion:" + e.getMessage(), e);
    }

    return bean;
  }
  /**
   * @deprecated This method handles clean up of ContentVersions poorly. Please refer to {@link
   *     #removeContentReferences(Map, InfoGluePrincipal, Database)} and {@link
   *     #removeSiteNodeReferences(Map, InfoGluePrincipal, Database)} instead.
   */
  public void removeReferences(Integer registryId, InfoGluePrincipal infoGluePrincipal, Database db)
      throws SystemException, Exception {
    RegistryVO registryVO = RegistryController.getController().getRegistryVOWithId(registryId, db);
    String referencingEntityName = registryVO.getReferencingEntityName();
    String referencingEntityCompletingName = registryVO.getReferencingEntityCompletingName();
    Integer referencingEntityId = new Integer(registryVO.getReferencingEntityId());

    if (referencingEntityCompletingName.equals(SiteNode.class.getName())) {
      SiteNodeVO siteNodeVO =
          SiteNodeController.getController()
              .getSiteNodeVOWithId(new Integer(registryVO.getReferencingEntityCompletingId()), db);
      if (siteNodeVO != null) {
        Integer metaInfoContentId = siteNodeVO.getMetaInfoContentId();
        LanguageVO masterLanguageVO =
            LanguageController.getController().getMasterLanguage(siteNodeVO.getRepositoryId(), db);
        String pageStructure =
            ContentController.getContentController()
                .getContentAttribute(
                    db, metaInfoContentId, masterLanguageVO.getId(), "ComponentStructure");

        if (registryVO.getReferenceType().equals(RegistryVO.PAGE_COMPONENT))
          pageStructure =
              deleteComponentFromXML(pageStructure, new Integer(registryVO.getEntityId()));
        if (registryVO.getReferenceType().equals(RegistryVO.PAGE_COMPONENT_BINDING))
          pageStructure =
              deleteComponentBindingFromXML(
                  pageStructure, new Integer(registryVO.getEntityId()), registryVO.getEntityName());

        ContentVersionVO contentVersionVO =
            ContentVersionController.getContentVersionController()
                .getLatestActiveContentVersionVO(metaInfoContentId, masterLanguageVO.getId(), db);
        ContentVersionController.getContentVersionController()
            .updateAttributeValue(
                contentVersionVO.getContentVersionId(),
                "ComponentStructure",
                pageStructure,
                infoGluePrincipal,
                db);
      }
    } else if (referencingEntityCompletingName.equals(Content.class.getName())) {
      if (referencingEntityName.equals(ContentVersion.class.getName())) {
        ContentVersionVO contentVersionVO =
            ContentVersionController.getContentVersionController()
                .getContentVersionVOWithId(referencingEntityId, db);
        if (contentVersionVO != null) {
          String versionValue = contentVersionVO.getVersionValue();

          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_LINK))
            versionValue =
                deleteInlineLinks(versionValue, new Integer(registryVO.getEntityId()), db);
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_ASSET))
            versionValue = deleteInlineAssets(versionValue, new Integer(registryVO.getEntityId()));
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_SITE_NODE_RELATION))
            versionValue =
                deleteInlineSiteNodeRelations(versionValue, new Integer(registryVO.getEntityId()));
          if (registryVO.getReferenceType().equals(RegistryVO.INLINE_CONTENT_RELATION))
            versionValue =
                deleteInlineContentRelations(versionValue, new Integer(registryVO.getEntityId()));

          contentVersionVO.setVersionModifier(infoGluePrincipal.getName());
          contentVersionVO.setModifiedDateTime(DateHelper.getSecondPreciseDate());
          contentVersionVO.setVersionValue(versionValue);

          ContentVersionController.getContentVersionController()
              .update(
                  contentVersionVO.getContentVersionId(), contentVersionVO, infoGluePrincipal, db);
        }
      }
    } else {
      logger.error(
          "The registry contained a not supported referencingEntityCompletingName:"
              + referencingEntityCompletingName);
    }
  }