/**
  * Return current user locale.
  *
  * @return user's Locale object
  */
 private Locale getCurrentUserLocale() {
   Locale loc = null;
   try {
     // check if locale is requested for specific user
     String userId = M_sm.getCurrentSessionUserId();
     if (userId != null) {
       Preferences prefs = M_ps.getPreferences(userId);
       ResourceProperties locProps = prefs.getProperties(ResourceLoader.APPLICATION_ID);
       String localeString = locProps.getProperty(ResourceLoader.LOCALE_KEY);
       // Parse user locale preference if set
       if (localeString != null) {
         String[] locValues = localeString.split("_");
         if (locValues.length > 1)
           // language, country
           loc = new Locale(locValues[0], locValues[1]);
         else if (locValues.length == 1)
           // language
           loc = new Locale(locValues[0]);
       }
       if (loc == null) loc = Locale.getDefault();
     } else {
       loc =
           (Locale)
               M_sm.getCurrentSession()
                   .getAttribute(ResourceLoader.LOCALE_KEY + M_sm.getCurrentSessionUserId());
     }
   } catch (NullPointerException e) {
     loc = Locale.getDefault();
   }
   return loc;
 }
示例#2
0
  @Override
  public String getDefaultPrivacyState(String userId) {
    String privacy = null;

    if (userId != null) {
      Preferences prefs = preferencesService.getPreferences(userId);
      ResourceProperties props = prefs.getProperties(PRIVACY_PREFS);
      privacy = props.getProperty(PrivacyManager.DEFAULT_PRIVACY_KEY);
    }

    if (privacy == null) {
      // default privacy is visible
      privacy = PrivacyManagerImpl.VISIBLE;
    }

    return privacy;
  }
  /**
   * 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;
  }
示例#4
0
 /**
  * Get the current user preference list value. First attempt Preferences, then defaults from
  * sakai.properties.
  *
  * @param name The property name.
  * @return The preference list value or null if not set.
  */
 private static List getPreferenceList(String name) {
   Preferences prefs = M_ps.getPreferences(M_sm.getCurrentSessionUserId());
   ResourceProperties rp = prefs.getProperties(PREFS_KEY);
   List l = rp.getPropertyList(name);
   return l;
 }
示例#5
0
 /**
  * Get the current user preference value. First attempt Preferences, then defaults from
  * sakai.properties.
  *
  * @param name The property name.
  * @return The preference value or null if not set.
  */
 private static String getPreferenceString(String name) {
   Preferences prefs = M_ps.getPreferences(M_sm.getCurrentSessionUserId());
   ResourceProperties rp = prefs.getProperties(PREFS_KEY);
   String value = rp.getProperty(name);
   return value;
 }