/*
  * (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;
 }
  /**
   * This method takes a list of sites and organizes it into a list of maps of properties. There is
   * an additional complication that the depth contains informaiton arround.
   *
   * @see
   *     org.sakaiproject.portal.api.PortalSiteHelper#convertSitesToMaps(javax.servlet.http.HttpServletRequest,
   *     java.util.List, java.lang.String, java.lang.String, java.lang.String, boolean, boolean,
   *     boolean, boolean, java.lang.String, boolean)
   */
  public List<Map> convertSitesToMaps(
      HttpServletRequest req,
      List mySites,
      String prefix,
      String currentSiteId,
      String myWorkspaceSiteId,
      boolean includeSummary,
      boolean expandSite,
      boolean resetTools,
      boolean doPages,
      String toolContextPath,
      boolean loggedIn) {
    List<Map> l = new ArrayList<Map>();
    Map<String, Integer> depthChart = new HashMap<String, Integer>();
    boolean motdDone = false;

    // We only compute the depths if there is no user chosen order
    boolean computeDepth = true;
    Session session = SessionManager.getCurrentSession();
    if (session != null) {
      Preferences prefs = PreferencesService.getPreferences(session.getUserId());
      ResourceProperties props = prefs.getProperties("sakai:portal:sitenav");

      List propList = props.getPropertyList("order");
      if (propList != null) {
        computeDepth = false;
      }
    }

    // Determine the depths of the child sites if needed
    for (Iterator i = mySites.iterator(); i.hasNext(); ) {
      Site s = (Site) i.next();

      // The first site is the current site
      if (currentSiteId == null) currentSiteId = s.getId();

      Integer cDepth = Integer.valueOf(0);
      if (computeDepth) {
        ResourceProperties rp = s.getProperties();
        String ourParent = rp.getProperty(PROP_PARENT_ID);
        // System.out.println("Depth Site:"+s.getTitle()+
        // "parent="+ourParent);
        if (ourParent != null) {
          Integer pDepth = depthChart.get(ourParent);
          if (pDepth != null) {
            cDepth = pDepth + 1;
          }
        }
        depthChart.put(s.getId(), cDepth);
        // System.out.println("Depth = "+cDepth);
      }

      Map m =
          convertSiteToMap(
              req,
              s,
              prefix,
              currentSiteId,
              myWorkspaceSiteId,
              includeSummary,
              expandSite,
              resetTools,
              doPages,
              toolContextPath,
              loggedIn);

      // Add the Depth of the site
      m.put("depth", cDepth);

      if (includeSummary && m.get("rssDescription") == null) {
        if (!motdDone) {
          summarizeTool(m, s, "sakai.motd");
          motdDone = true;
        } else {
          summarizeTool(m, s, "sakai.announcements");
        }
      }
      l.add(m);
    }
    return l;
  }