portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r911394 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java
Date Thu, 18 Feb 2010 13:37:28 GMT
Author: woonsan
Date: Thu Feb 18 13:37:27 2010
New Revision: 911394

URL: http://svn.apache.org/viewvc?rev=911394&view=rev
Log:
JS2-1108: Reverting CustomConfigModePortlet from my accidental commit.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java?rev=911394&r1=911393&r2=911394&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java
Thu Feb 18 13:37:27 2010
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -34,8 +33,6 @@
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
 
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.om.common.SecurityConstraint;
 import org.apache.jetspeed.om.common.SecurityConstraints;
@@ -43,6 +40,7 @@
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.springframework.util.StringUtils;
 
 /**
  * Common Custom Config Mode Portlet
@@ -52,7 +50,7 @@
 public class CustomConfigModePortlet extends GenericVelocityPortlet
 {
     private static final PortletMode CONFIG_MODE = new PortletMode("config");
-    private static final String DELIMITERS = "[],; \t\r\n";
+    private static final String DELIMITERS = "[],; ";
     
     private PageManager pageManager;
     private String configPage;
@@ -130,6 +128,11 @@
         {
             String path = request.getParameter("path");
             String fragmentId = request.getParameter("fragment");
+            String type = request.getParameter("type");
+            String roles = request.getParameter("roles");
+            String groups = request.getParameter("groups");
+            String users = request.getParameter("users");
+            String permissions = request.getParameter("permissions");
             
             Page page = this.pageManager.getPage(path);
             BaseFragmentElement fragment = page.getFragmentById(fragmentId);
@@ -147,44 +150,37 @@
             }
             
             SecurityConstraint constraint = fragment.newSecurityConstraint();
-            String [] rolesArray = StringUtils.split(request.getParameter("roles"), DELIMITERS);
-            String [] groupsArray = StringUtils.split(request.getParameter("groups"), DELIMITERS);
-            String [] usersArray = StringUtils.split(request.getParameter("users"), DELIMITERS);
+            Set roleSet = convertToSet(roles, DELIMITERS);
+            Set groupSet = convertToSet(groups, DELIMITERS);
+            Set userSet = convertToSet(users, DELIMITERS);
             
-            if (!ArrayUtils.isEmpty(rolesArray))
+            if (!roleSet.isEmpty())
             {
-                constraint.setRoles(Arrays.asList(rolesArray));
+                constraint.setRoles(new ArrayList(roleSet));
             }
-            
-            if (!ArrayUtils.isEmpty(groupsArray))
+            if (!groupSet.isEmpty())
             {
-                constraint.setGroups(Arrays.asList(groupsArray));
+                constraint.setGroups(new ArrayList(groupSet));
             }
-            
-            if (!ArrayUtils.isEmpty(usersArray))
+            if (!userSet.isEmpty())
             {
-                constraint.setUsers(Arrays.asList(usersArray));
+                constraint.setUsers(new ArrayList(userSet));
             }
             
-            String [] permissionArray = StringUtils.split(StringUtils.defaultString(request.getParameter("permissions")),
DELIMITERS);
-            
-            if (!ArrayUtils.isEmpty(permissionArray))
-            {
-                constraint.setPermissions(Arrays.asList(permissionArray));
-            }
+            Set permissionSet = convertToSet(permissions, DELIMITERS);
             
-            List<SecurityConstraint> constraintList = constraints.getSecurityConstraints();
+            constraint.setPermissions(new ArrayList(permissionSet));
+            List constraintList = constraints.getSecurityConstraints();
             
             if (constraintList == null)
             {
-                constraintList = new ArrayList<SecurityConstraint>();
+                constraintList = new ArrayList();
             }
             
             constraintList.add(constraint);
-            constraints.setSecurityConstraints(constraintList);
             
+            constraints.setSecurityConstraints(constraintList);
             fragment.setSecurityConstraints(constraints);
-            
             this.pageManager.updatePage(page);
         }
         catch (Exception e)
@@ -226,17 +222,17 @@
                     {
                         SecurityConstraint constraint = (SecurityConstraint) it.next();
                         
-                        String [] removeRoleArray = StringUtils.split(roles, DELIMITERS);
-                        String [] removeGroupArray = StringUtils.split(groups, DELIMITERS);
-                        String [] removeUserArray = StringUtils.split(users, DELIMITERS);
+                        Set removeRoleSet = convertToSet(roles, DELIMITERS);
+                        Set removeGroupSet = convertToSet(groups, DELIMITERS);
+                        Set removeUserSet = convertToSet(users, DELIMITERS);
                         
-                        List<String> roleList = constraint.getRoles();
-                        List<String> groupList = constraint.getGroups();
-                        List<String> userList = constraint.getUsers();
+                        List roleList = constraint.getRoles();
+                        List groupList = constraint.getGroups();
+                        List userList = constraint.getUsers();
                         
-                        if (hasEqualItems(removeRoleArray, roleList) &&
-                            hasEqualItems(removeGroupArray, groupList) &&
-                            hasEqualItems(removeUserArray, userList))
+                        if (equalsSetAndList(removeRoleSet, roleList) &&
+                            equalsSetAndList(removeGroupSet, groupList) &&
+                            equalsSetAndList(removeUserSet, userList))
                         {
                             it.remove();
                             break;
@@ -251,7 +247,6 @@
             }
             
             fragment.setSecurityConstraints(constraints.isEmpty() ? null : constraints);
-            
             this.pageManager.updatePage(page);
         }
         catch (Exception e)
@@ -283,7 +278,7 @@
                 constraints = fragment.newSecurityConstraints();
             }
             
-            Set<String> constraintRefSet = new HashSet<String>();
+            Set constraintRefSet = new HashSet();
             
             if (securityConstraintRefs != null)
             {
@@ -296,10 +291,8 @@
                 }
             }
             
-            constraints.setSecurityConstraintsRefs(constraintRefSet.isEmpty() ? null : new
ArrayList<String>(constraintRefSet));
-            
+            constraints.setSecurityConstraintsRefs(constraintRefSet.isEmpty() ? null : new
ArrayList(constraintRefSet));
             fragment.setSecurityConstraints(constraints.isEmpty() ? null : constraints);
-            
             this.pageManager.updatePage(page);
         }
         catch (Exception e)
@@ -308,30 +301,37 @@
         }
     }
     
-    private boolean hasEqualItems(String [] array, List<String> list)
+    private Set convertToSet(String s, String delimiters)
     {
-        if (ArrayUtils.isEmpty(array))
+        Set set = new HashSet();
+        
+        String [] tokens = StringUtils.tokenizeToStringArray(s, delimiters, true, true);
+            
+        if (tokens != null)
+        {
+            for (int i = 0; i < tokens.length; i++)
+            {
+                set.add(tokens[i]);
+            }
+        }
+        
+        return set;
+    }
+    
+    private boolean equalsSetAndList(Set set, List list)
+    {
+        if (set == null)
         {
             return (list == null || list.isEmpty());
         }
         else if (list == null)
         {
-            return ArrayUtils.isEmpty(array);
+            return set.isEmpty();
         }
-        else if (ArrayUtils.getLength(array) == list.size())
+        else
         {
-            for (String item : array)
-            {
-                if (!list.contains(item))
-                {
-                    return false;
-                }
-            }
-            
-            return true;
+            return set.equals(new HashSet(list));
         }
-        
-        return false;
     }
     
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message