Update of 
/var/cvs/contributions/CMSContainer_Portlets/portlets-preferences/src/java/com/finalist/preferences/util
In directory 
james.mmbase.org:/tmp/cvs-serv32647/portlets-preferences/src/java/com/finalist/preferences/util

Modified Files:
        ProfileUtil.java 
Log Message:
CMSC-950 - Fixed wrong JSP includes and corrected words; removed dependencies. 
Cleaned code.


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Portlets/portlets-preferences/src/java/com/finalist/preferences/util
See also: http://www.mmbase.org/jira/browse/CMSC-950


Index: ProfileUtil.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Portlets/portlets-preferences/src/java/com/finalist/preferences/util/ProfileUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ProfileUtil.java    23 Jul 2008 03:36:47 -0000      1.4
+++ ProfileUtil.java    27 Nov 2008 14:28:48 -0000      1.5
@@ -1,6 +1,9 @@
 package com.finalist.preferences.util;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -18,7 +21,6 @@
 import com.finalist.cmsc.services.community.preferences.PreferenceService;
 import com.finalist.cmsc.services.community.security.Authentication;
 import com.finalist.cmsc.services.community.security.AuthenticationService;
-
 import com.finalist.preferences.domain.UserProfile;
 
 public class ProfileUtil {
@@ -62,19 +64,18 @@
 
       PreferenceService ps = getPreferenceService();
       Map<String, Map<String, String>> modulePreferenceMap = 
ps.getPreferencesByUserId(getUserIdByAuthenticationId(getCurrentUserId()));
-      if(modulePreferenceMap != null && modulePreferenceMap.size() > 0) {
-
-         Iterator<Map.Entry<String,Map<String,String>>> keyValues = 
modulePreferenceMap.entrySet().iterator();
-         while(keyValues.hasNext()) {
-            Map.Entry<String,Map<String,String>> entry =  keyValues.next();
-
+      if (modulePreferenceMap != null && modulePreferenceMap.size() > 0) {
 
-            Map<String,String> values = entry.getValue();
-            Iterator<Map.Entry<String,String>> keys = 
values.entrySet().iterator();
-            while(keys.hasNext()) {
+         Iterator<Map.Entry<String, Map<String, String>>> keyValues = 
modulePreferenceMap.entrySet().iterator();
+         while (keyValues.hasNext()) {
+            Map.Entry<String, Map<String, String>> entry = keyValues.next();
+
+            Map<String, String> values = entry.getValue();
+            Iterator<Map.Entry<String, String>> keys = 
values.entrySet().iterator();
+            while (keys.hasNext()) {
                PreferenceVO preference = new PreferenceVO();
                preference.setModule(entry.getKey());
-               Map.Entry<String,String> keyvalue =  keys.next();
+               Map.Entry<String, String> keyvalue = keys.next();
                preference.setKey(keyvalue.getKey());
                preference.setValue(keyvalue.getValue());
                preferences.add(preference);
@@ -84,7 +85,7 @@
       return preferences;
    }
 
-   public static UserProfile getUserProfile(Long authId){
+   public static UserProfile getUserProfile(Long authId) {
       Authentication auth = null;
       UserProfile profile = new UserProfile();
 
@@ -97,7 +98,7 @@
          profile.setAccount(auth.getUserId());
 
          PersonService ps = getPersonService();
-         //Returns null when no Person object was found!
+         // Returns null when no Person object was found!
          Person person = ps.getPersonByAuthenticationId(auth.getId());
 
          if (person != null) {
@@ -112,7 +113,7 @@
       return profile;
    }
 
-   public static UserProfile getUserProfile(){
+   public static UserProfile getUserProfile() {
       return getUserProfile(getCurrentUserId());
    }
 
@@ -133,34 +134,36 @@
       return person;
    }
 
-   public static Long getCurrentUserId(){
+   public static Long getCurrentUserId() {
       Person person = getCurrentUser();
-      if(null==person){
+      if (null == person) {
          return new Long(-1);
       }
 
      return person.getAuthenticationId();
    }
 
-   public static boolean isUserLogin(){
+   public static boolean isUserLogin() {
       return null != getCurrentUser();
    }
 
-  public static void addPreferences(List<PreferenceVO> preferences){
+   public static void addPreferences(List<PreferenceVO> preferences) {
 
      PreferenceService ps = getPreferenceService();
-     for(PreferenceVO preference : preferences) {
-        List<String> values =  ps.getPreferenceValues(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference.getAuthenticationId())), 
preference.getKey());
-        if(values == null || values.size() == 0) {
-           ps.createPreference(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference.getAuthenticationId())), 
preference.getKey(),preference.getValue());
-        }
-        else {
-          ps.updatePreference(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference.getAuthenticationId())), 
preference.getKey(),values.get(0),preference.getValue());
+      for (PreferenceVO preference : preferences) {
+         List<String> values = ps.getPreferenceValues(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference
+               .getAuthenticationId())), preference.getKey());
+         if (values == null || values.size() == 0) {
+            ps.createPreference(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference.getAuthenticationId())), 
preference
+                  .getKey(), preference.getValue());
+         } else {
+            ps.updatePreference(preference.getModule(), 
getUserIdByAuthenticationId(Long.parseLong(preference.getAuthenticationId())), 
preference
+                  .getKey(), values.get(0), preference.getValue());
         }
      }
   }
 
-  private static String getUserIdByAuthenticationId(Long authenticationId){
+   private static String getUserIdByAuthenticationId(Long authenticationId) {
      Authentication authentication = 
getAuthenticationService().getAuthenticationById(authenticationId);
      return authentication.getUserId();
   }
@@ -176,10 +179,11 @@
    private static PreferenceService getPreferenceService() {
       return (PreferenceService) 
ApplicationContextFactory.getBean("preferenceService");
    }
-   public static boolean   isEmail(String   s){
-      String   regex="[EMAIL PROTECTED](\\.\\w+)+";
-      Pattern   p=Pattern.compile(regex);
-      Matcher   m=p.matcher(s);
+
+   public static boolean isEmail(String s) {
+      String regex = "[EMAIL PROTECTED](\\.\\w+)+";
+      Pattern p = Pattern.compile(regex);
+      Matcher m = p.matcher(s);
       return   m.matches();
       }
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to