/*
  * (non-Javadoc)
  *
  * @see org.sakaiproject.portal.api.PortalSiteHelper#getSitesView(org.sakaiproject.portal.api.SiteView.View,
  *      javax.servlet.http.HttpServletRequest,
  *      org.sakaiproject.tool.api.Session, java.lang.String)
  */
 public SiteView getSitesView(
     View view, HttpServletRequest request, Session session, String siteId) {
   switch (view) {
     case CURRENT_SITE_VIEW:
       return new CurrentSiteViewImpl(
           this,
           portal.getSiteNeighbourhoodService(),
           request,
           session,
           siteId,
           SiteService.getInstance(),
           ServerConfigurationService.getInstance(),
           PreferencesService.getInstance());
     case ALL_SITES_VIEW:
       return new AllSitesViewImpl(
           this,
           portal.getSiteNeighbourhoodService(),
           request,
           session,
           siteId,
           SiteService.getInstance(),
           ServerConfigurationService.getInstance(),
           PreferencesService.getInstance());
     case DEFAULT_SITE_VIEW:
       return new DefaultSiteViewImpl(
           this,
           portal.getSiteNeighbourhoodService(),
           request,
           session,
           siteId,
           SiteService.getInstance(),
           ServerConfigurationService.getInstance(),
           PreferencesService.getInstance());
     case DHTML_MORE_VIEW:
       return new MoreSiteViewImpl(
           this,
           portal.getSiteNeighbourhoodService(),
           request,
           session,
           siteId,
           SiteService.getInstance(),
           ServerConfigurationService.getInstance(),
           PreferencesService.getInstance());
     case SUB_SITES_VIEW:
       return new SubSiteViewImpl(
           this,
           portal.getSiteNeighbourhoodService(),
           request,
           session,
           siteId,
           SiteService.getInstance(),
           ServerConfigurationService.getInstance(),
           PreferencesService.getInstance());
   }
   return null;
 }
  /**
   * Do the getSiteVisit, but if not found and the id is a user site, try translating from user EID
   * to ID.
   *
   * @param siteId The Site Id.
   * @return The Site.
   * @throws PermissionException If not allowed.
   * @throws IdUnusedException If not found.
   */
  public Site getSiteVisit(String siteId) throws PermissionException, IdUnusedException {
    try {
      return SiteService.getSiteVisit(siteId);
    } catch (IdUnusedException e) {
      if (SiteService.isUserSite(siteId)) {
        try {
          String userEid = SiteService.getSiteUserId(siteId);
          String userId = UserDirectoryService.getUserId(userEid);
          String alternateSiteId = SiteService.getUserSiteId(userId);
          return SiteService.getSiteVisit(alternateSiteId);
        } catch (UserNotDefinedException ee) {
        }
      } else {
        String reference = portal.getSiteNeighbourhoodService().parseSiteAlias(siteId);
        Reference ref = EntityManager.getInstance().newReference(reference);
        try {
          return SiteService.getSiteVisit(ref.getId());
        } catch (IdUnusedException iue) {
        }
      }

      // re-throw if that didn't work
      throw e;
    }
  }
  /**
   * If this is a user site, return an id based on the user EID, otherwise just return the site id.
   *
   * @param site The site.
   * @return The effective site id.
   */
  public String getSiteEffectiveId(Site site) {
    if (SiteService.isUserSite(site.getId())) {
      try {
        String userId = SiteService.getSiteUserId(site.getId());
        String eid = UserDirectoryService.getUserEid(userId);
        return SiteService.getUserSiteId(eid);
      } catch (UserNotDefinedException e) {
        log.warn("getSiteEffectiveId: user eid not found for user site: " + site.getId());
      }
    } else {
      String displayId =
          portal.getSiteNeighbourhoodService().lookupSiteAlias(site.getReference(), null);
      if (displayId != null) {
        return displayId;
      }
    }

    return site.getId();
  }