Author: ludovic
Date: 2008-01-12 10:15:18 +0100 (Sat, 12 Jan 2008)
New Revision: 6795

Modified:
   
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java
Log:
CURRIKI-1345 Rights in groups implementation

Modified: 
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java
    2008-01-12 08:44:52 UTC (rev 6794)
+++ 
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/impl/SpaceManagerImpl.java
    2008-01-12 09:15:18 UTC (rev 6795)
@@ -45,30 +45,30 @@
  * Manages spaces
  */
 public class SpaceManagerImpl extends XWikiDefaultPlugin implements 
SpaceManager {
-       
-       public final static String SPACEMANAGER_EXTENSION_CFG_PROP = 
"xwiki.spacemanager.extension";
-       public final static String SPACEMANAGER_DEFAULT_EXTENSION = 
"org.xwiki.plugin.spacemanager.impl.SpaceManagerExtensionImpl";
-       public final static String SPACEMANAGER_DEFAULT_MAIL_NOTIFICATION = "1";
-       
-       /**
-        * The extension that defines specific functions for this space manager
-        */
+
+    public final static String SPACEMANAGER_EXTENSION_CFG_PROP = 
"xwiki.spacemanager.extension";
+    public final static String SPACEMANAGER_DEFAULT_EXTENSION = 
"org.xwiki.plugin.spacemanager.impl.SpaceManagerExtensionImpl";
+    public final static String SPACEMANAGER_DEFAULT_MAIL_NOTIFICATION = "1";
+
+    /**
+     * The extension that defines specific functions for this space manager
+     */
     protected SpaceManagerExtension spaceManagerExtension;
-    
+
     protected boolean mailNotification;
 
     /**
-        * Space manager constructor
-        * @param name
-        * @param className
-        * @param context
-        */
+     * Space manager constructor
+     * @param name
+     * @param className
+     * @param context
+     */
     public SpaceManagerImpl(String name, String className, XWikiContext 
context)
     {
         super(name, className, context);
         String mailNotificationCfg =
-            context.getWiki().Param("xwiki.spacemanager.mailnotification",
-                
SpaceManagerImpl.SPACEMANAGER_DEFAULT_MAIL_NOTIFICATION).trim();
+                context.getWiki().Param("xwiki.spacemanager.mailnotification",
+                        
SpaceManagerImpl.SPACEMANAGER_DEFAULT_MAIL_NOTIFICATION).trim();
         mailNotification = "1".equals(mailNotificationCfg);
     }
 
@@ -80,16 +80,16 @@
     }
 
     /**
-     * 
+     *
      * @param context Xwiki context
      * @return Returns the Space Class as defined by the extension
      * @throws XWikiException
      */
     protected BaseClass getSpaceClass(XWikiContext context) throws 
XWikiException {
-       XWikiDocument doc;
+        XWikiDocument doc;
         XWiki xwiki = context.getWiki();
         boolean needsUpdate = false;
-        
+
         try {
             doc = xwiki.getDocument(getSpaceClassName(), context);
         } catch (Exception e) {
@@ -97,14 +97,14 @@
             doc.setFullName(getSpaceClassName());
             needsUpdate = true;
         }
-        
+
         BaseClass bclass = doc.getxWikiClass();
         bclass.setName(getSpaceClassName());
-        
+
         needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_DISPLAYTITLE, 
"Display Name", 64);
         needsUpdate |= bclass.addTextAreaField(SpaceImpl.SPACE_DESCRIPTION, 
"Description", 45, 4);
         needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_TYPE, "Group or 
plain space", 32);
-        needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_URLSHORTCUT, "URL 
Shortcut", 128);
+        needsUpdate |= bclass.addTextField(SpaceImpl.SPACE_URLSHORTCUT, "URL 
Shortcut", 40);
         needsUpdate |= bclass.addStaticListField(SpaceImpl.SPACE_POLICY, 
"Membership Policy", 1, false, "open=Open membership|closed=Closed 
membership","radio");
         needsUpdate |= bclass.addStaticListField(SpaceImpl.SPACE_LANGUAGE, 
"Language", 
"en=English|zh=Chinese|nl=Dutch|fr=French|de=German|it=Italian|jp=Japanese|kr=Korean|po=Portuguese|ru=Russian|sp=Spanish");
 
@@ -143,17 +143,17 @@
         return getSpaceManagerExtension().hasCustomMapping();
     }
 
-    
+
     /**
      * Initializes the plugin on the main wiki
      * @param context Xwiki context
      */
     public void init(XWikiContext context) {
         try {
-               getSpaceManagerExtension(context);
-               getSpaceManagerExtension().init(context);
+            getSpaceManagerExtension(context);
+            getSpaceManagerExtension().init(context);
             SpaceManagers.addSpaceManager(this);
-               getSpaceClass(context);
+            getSpaceClass(context);
             SpaceUserProfileImpl.getSpaceUserProfileClass(context);
         } catch (Exception e) {
             e.printStackTrace();
@@ -166,13 +166,13 @@
      */
     public void virtualInit(XWikiContext context) {
         try {
-               getSpaceClass(context);
-               getSpaceManagerExtension().virtualInit(context);
+            getSpaceClass(context);
+            getSpaceManagerExtension().virtualInit(context);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
-    
+
     /**
      * Gets the space plugin Api
      * @param plugin The plugin interface
@@ -182,19 +182,19 @@
     public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) 
{
         return new SpaceManagerPluginApi((SpaceManager) plugin, context);
     }
-       
-       /**
-       * Loads the SpaceManagerExtension specified in the config file
-       * @return Returns the space manager extension
-        * @throws SpaceManagerException 
-       */
-       public SpaceManagerExtension getSpaceManagerExtension(XWikiContext 
context) throws SpaceManagerException
-       {
+
+    /**
+     * Loads the SpaceManagerExtension specified in the config file
+     * @return Returns the space manager extension
+     * @throws SpaceManagerException
+     */
+    public SpaceManagerExtension getSpaceManagerExtension(XWikiContext 
context) throws SpaceManagerException
+    {
         if (spaceManagerExtension==null) {
             String extensionName = 
context.getWiki().Param(SPACEMANAGER_EXTENSION_CFG_PROP,SPACEMANAGER_DEFAULT_EXTENSION);
             try {
                 if (extensionName!=null)
-                 spaceManagerExtension = (SpaceManagerExtension) 
Class.forName(extensionName).newInstance();
+                    spaceManagerExtension = (SpaceManagerExtension) 
Class.forName(extensionName).newInstance();
             } catch (Throwable e){
                 try{
                     spaceManagerExtension = (SpaceManagerExtension) 
Class.forName(SPACEMANAGER_DEFAULT_EXTENSION).newInstance();
@@ -209,12 +209,12 @@
 
         return spaceManagerExtension;
     }
-       
-       public SpaceManagerExtension getSpaceManagerExtension(){
-               return spaceManagerExtension;
-       }
-       
-       /**
+
+    public SpaceManagerExtension getSpaceManagerExtension(){
+        return spaceManagerExtension;
+    }
+
+    /**
      * Gets the name of the space manager
      * @return
      */
@@ -227,7 +227,7 @@
     private Object notImplemented() throws SpaceManagerException {
         throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER, 
SpaceManagerException.ERROR_XWIKI_NOT_IMPLEMENTED, "not implemented");
     }
-    
+
     /**
      * Returns the wikiname of a space
      * @param spaceTitle The name of the space
@@ -245,9 +245,9 @@
      * @return
      */
     protected String getSpaceDocumentName(String spaceName) {
-               return spaceName + ".WebPreferences";
-       }
-    
+        return spaceName + ".WebPreferences";
+    }
+
     /**
      * Gives a group certain rights over a space
      * @param spaceName Name of the space
@@ -256,83 +256,85 @@
      * @param allow True if the right is allow, deny if not
      */
     protected boolean giveRightToGroup( String spaceName, String groupName, 
String level, boolean allow, boolean global, XWikiContext context) throws 
XWikiException {
-       final String rightsClass = global ? "XWiki.XWikiRights" : 
"XWiki.XWikiRights";
-       final String prefDocName = spaceName+".WebPreferences";
-       final String groupsField = "groups";
-       final String levelsField = "levels";
-       final String allowField = "allow";
-       
-       XWikiDocument prefDoc;
+        final String rightsClass = global ? "XWiki.XWikiRights" : 
"XWiki.XWikiRights";
+        final String prefDocName = spaceName+".WebPreferences";
+        final String groupsField = "groups";
+        final String levelsField = "levels";
+        final String allowField = "allow";
+
+        XWikiDocument prefDoc;
         prefDoc = context.getWiki().getDocument(prefDocName,context);
 
         //checks to see if the right is not already given
-       boolean exists = false;
-       boolean isUpdated = false;
-       int indx = -1;
-       boolean foundlevel = false;
-       int allowInt;
-       if(allow)       allowInt = 1;
-       else    allowInt = 0;
-       List objs = prefDoc.getObjects(rightsClass);
-       for(int i=0; i<objs.size(); i++){
-               BaseObject bobj = (BaseObject) objs.get(i);
-               if(bobj==null)
-                       continue;
-               String groups = bobj.getStringValue(groupsField);
-            String levels = bobj.getStringValue(levelsField);
-            int allowDeny = bobj.getIntValue(allowField);
-            boolean allowdeny = (bobj.getIntValue(allowField) == 1);
-            String[] levelsarray = levels.split( " ,|" );
-            String[] groupsarray = groups.split( " ,|" );
-            if( ArrayUtils.contains(groupsarray,groupName) ){
-               exists = true;
-               if(!foundlevel)
-                       indx = i;
-               if( ArrayUtils.contains(levelsarray,level) ){
-                       foundlevel = true;
-                       if(allowInt == allowDeny){
-                               isUpdated = true;
-                               break;
-                       }
-               }
+        boolean exists = false;
+        boolean isUpdated = false;
+        int indx = -1;
+        boolean foundlevel = false;
+        int allowInt;
+        if(allow)      allowInt = 1;
+        else   allowInt = 0;
+        List objs = prefDoc.getObjects(rightsClass);
+        if (objs!=null) {
+            for(int i=0; i<objs.size(); i++){
+                BaseObject bobj = (BaseObject) objs.get(i);
+                if(bobj==null)
+                    continue;
+                String groups = bobj.getStringValue(groupsField);
+                String levels = bobj.getStringValue(levelsField);
+                int allowDeny = bobj.getIntValue(allowField);
+                boolean allowdeny = (bobj.getIntValue(allowField) == 1);
+                String[] levelsarray = levels.split( " ,|" );
+                String[] groupsarray = groups.split( " ,|" );
+                if( ArrayUtils.contains(groupsarray,groupName) ){
+                    exists = true;
+                    if(!foundlevel)
+                        indx = i;
+                    if( ArrayUtils.contains(levelsarray,level) ){
+                        foundlevel = true;
+                        if(allowInt == allowDeny){
+                            isUpdated = true;
+                            break;
+                        }
+                    }
+                }
             }
-       }
-       
-       //sets the rights. the aproach is to break rules/levels in as many 
XWikiRigts elements so
-       //we don't have to handle lots of situation when we change rights
-       if( !exists ){
-               BaseObject bobj = new BaseObject();
-               bobj.setStringValue(groupsField, groupName); 
-               bobj.setStringValue(levelsField, level);
-               bobj.setIntValue(allowField, allowInt);
-               prefDoc.addObject(rightsClass,bobj);
-           context.getWiki().saveDocument(prefDoc, context);
-               return true;
-       }else{
-               if(isUpdated){
-                       return true;
-               }else{
-                       BaseObject bobj = (BaseObject) objs.get(indx);
-                       String groups = bobj.getStringValue(groupsField);
+        }
+
+        //sets the rights. the aproach is to break rules/levels in as many 
XWikiRigts elements so
+        //we don't have to handle lots of situation when we change rights
+        if( !exists ){
+            BaseObject bobj = new BaseObject();
+            bobj.setStringValue(groupsField, groupName);
+            bobj.setStringValue(levelsField, level);
+            bobj.setIntValue(allowField, allowInt);
+            prefDoc.addObject(rightsClass,bobj);
+            context.getWiki().saveDocument(prefDoc, context);
+            return true;
+        }else{
+            if(isUpdated){
+                return true;
+            }else{
+                BaseObject bobj = (BaseObject) objs.get(indx);
+                String groups = bobj.getStringValue(groupsField);
                 String levels = bobj.getStringValue(levelsField);
                 String[] levelsarray = levels.split( " ,|" );
                 String[] groupsarray = groups.split( " ,|" );
-                       
+
                 if( levelsarray.length == 1 && groupsarray.length == 1 && 
levelsarray[0] == level ){
-                       //if there is only this group and this level in the 
rule update this rule
+                    //if there is only this group and this level in the rule 
update this rule
                 } else {
-                       //if there are more groups/levels, extract this one(s)
-                       bobj = new BaseObject();
-                       bobj.setStringValue(levelsField, level);
-                       bobj.setIntValue(allowField, allowInt);
-                       bobj.setStringValue(groupsField, groupName);
+                    //if there are more groups/levels, extract this one(s)
+                    bobj = new BaseObject();
+                    bobj.setStringValue(levelsField, level);
+                    bobj.setIntValue(allowField, allowInt);
+                    bobj.setStringValue(groupsField, groupName);
                 }
-                
-                       prefDoc.addObject(rightsClass,bobj);
-                       context.getWiki().saveDocument(prefDoc, context);
-                       return true;
-               }
-       }
+
+                prefDoc.addObject(rightsClass,bobj);
+                context.getWiki().saveDocument(prefDoc, context);
+                return true;
+            }
+        }
     }
 
     protected void setGroupRights(Space newspace, XWikiContext context) throws 
XWikiException {
@@ -347,10 +349,10 @@
      * @param spaceTitle The name(display title) of the new space
      * @param context The XWiki Context
      * @return Returns the newly created space
-     * @throws SpaceManagerException 
+     * @throws SpaceManagerException
      */
-    public Space createSpace(String spaceTitle, XWikiContext context) throws 
SpaceManagerException {   
-       // Init out space object by creating the space
+    public Space createSpace(String spaceTitle, XWikiContext context) throws 
SpaceManagerException {
+        // Init out space object by creating the space
         // this will throw an exception when the space exists
         Space newspace = newSpace(null, spaceTitle, true, context);
         // Make sure we set the type
@@ -375,9 +377,9 @@
      * @param templateSpaceName The name of the space that will be cloned
      * @param context The XWiki Context
      * @return Returns the newly created space
-     * @throws SpaceManagerException 
+     * @throws SpaceManagerException
      */
-       public Space createSpaceFromTemplate(String spaceTitle, String 
templateSpaceName, XWikiContext context) throws SpaceManagerException {
+    public Space createSpaceFromTemplate(String spaceTitle, String 
templateSpaceName, XWikiContext context) throws SpaceManagerException {
         // Init out space object by creating the space
         // this will throw an exception when the space exists
         Space newspace = newSpace(null, spaceTitle, false, context);
@@ -411,9 +413,9 @@
         return newspace;
     }
 
-       /**
-        * 
-        */
+    /**
+     *
+     */
     public Space createSpaceFromApplication(String spaceTitle, String 
applicationName, XWikiContext context) throws SpaceManagerException {
         notImplemented();
         return null;
@@ -424,9 +426,9 @@
      * Creates a new space based on the data send in the request (possibly 
from a form) 
      * @param context The XWiki Context
      * @return Returns the newly created space
-     * @throws SpaceManagerException 
+     * @throws SpaceManagerException
      */
-       public Space createSpaceFromRequest(String templateSpaceName, 
XWikiContext context) throws SpaceManagerException {
+    public Space createSpaceFromRequest(String templateSpaceName, XWikiContext 
context) throws SpaceManagerException {
         // Init out space object by creating the space
         // this will throw an exception when the space exists
         String spaceTitle = 
context.getRequest().get(spaceManagerExtension.getSpaceClassName() + 
"_0_displayTitle");
@@ -455,7 +457,7 @@
         // Make sure we set the type
         newspace.setType(getSpaceTypeName());
         // we need to do it twice because data could have been overwritten by 
copyWikiWeb
-               newspace.updateSpaceFromRequest();
+        newspace.updateSpaceFromRequest();
         try {
             newspace.saveWithProgrammingRights();
             // we need to add the creator as a member and as an admin
@@ -468,7 +470,7 @@
 
         sendMail(SpaceAction.CREATE, newspace, context);
         return newspace;
-       }
+    }
 
     protected Space newSpace(String spaceName, String spaceTitle, boolean 
create, XWikiContext context) throws SpaceManagerException {
         return new SpaceImpl(spaceName, spaceTitle, create, this, context );
@@ -480,17 +482,17 @@
      * @return Returns the newly created space
      * @throws SpaceManagerException
      */
-       public Space createSpaceFromRequest(XWikiContext context) throws 
SpaceManagerException {
+    public Space createSpaceFromRequest(XWikiContext context) throws 
SpaceManagerException {
         return createSpaceFromRequest(null, context);
-       }
+    }
 
     /**
-        * Deletes a space
-        * @param spaceName The name of the space to be deleted
-        * @param deleteData Full delete (all the space data will be deleted)
-        * @param context The XWiki Context
-     * @throws SpaceManagerException  
-        */
+     * Deletes a space
+     * @param spaceName The name of the space to be deleted
+     * @param deleteData Full delete (all the space data will be deleted)
+     * @param context The XWiki Context
+     * @throws SpaceManagerException
+     */
     public void deleteSpace(String spaceName, boolean deleteData, XWikiContext 
context) throws SpaceManagerException {
         if (deleteData) {
             // we are not implementing full delete yet
@@ -502,73 +504,73 @@
             try {
                 space.saveWithProgrammingRights();
             } catch (XWikiException e) {
-                throw new SpaceManagerException(e);                
+                throw new SpaceManagerException(e);
             }
         }
 
     }
 
     /**
-        * Deletes a space without deleting the data
-        * @param spaceName The name of the space to be deleted
-        * @param context The XWiki Context
-     * @throws SpaceManagerException  
-        */
+     * Deletes a space without deleting the data
+     * @param spaceName The name of the space to be deleted
+     * @param context The XWiki Context
+     * @throws SpaceManagerException
+     */
     public void deleteSpace(String spaceName, XWikiContext context) throws 
SpaceManagerException {
         deleteSpace(spaceName, false, context);
     }
 
     /**
-        * Restores a space that hasn't been fully deleted
-        * @param spaceName The name of the space to be restored
-        * @param context The XWiki Context
-     * @throws SpaceManagerException  
-        */
-       public void undeleteSpace(String spaceName, XWikiContext context) 
throws SpaceManagerException {
+     * Restores a space that hasn't been fully deleted
+     * @param spaceName The name of the space to be restored
+     * @param context The XWiki Context
+     * @throws SpaceManagerException
+     */
+    public void undeleteSpace(String spaceName, XWikiContext context) throws 
SpaceManagerException {
         Space space = getSpace(spaceName, context);
         if (space.isDeleted()) {
-             space.setType(getSpaceTypeName());
+            space.setType(getSpaceTypeName());
             try {
                 space.saveWithProgrammingRights();
             } catch (XWikiException e) {
                 throw new SpaceManagerException(e);
             }
-        }      
-       }
+        }
+    }
 
-       /**
-        * Returns the space with the spaceName
-        * @param spaceName The name of the space to be deleted
-        * @param context The XWiki Context
-     * @throws SpaceManagerException  
-        */
+    /**
+     * Returns the space with the spaceName
+     * @param spaceName The name of the space to be deleted
+     * @param context The XWiki Context
+     * @throws SpaceManagerException
+     */
     public Space getSpace(String spaceName, XWikiContext context) throws 
SpaceManagerException {
         // Init the space object but do not create anything if it does not 
exist
         return newSpace(spaceName, spaceName, false, context);
     }
 
     /**
-        * Returns a list of nb spaces starting at start
-        * @param nb Number of spaces to be returned
-        * @param start Index at which we will start the search
-        * @param context The XWiki Context
-        * @return list of Space objects
-     * @throws SpaceManagerException  
-        */
+     * Returns a list of nb spaces starting at start
+     * @param nb Number of spaces to be returned
+     * @param start Index at which we will start the search
+     * @param context The XWiki Context
+     * @return list of Space objects
+     * @throws SpaceManagerException
+     */
     public List getSpaces(int nb, int start, XWikiContext context) throws 
SpaceManagerException {
         List spaceNames = getSpaceNames(nb, start, context);
         return getSpaceObjects(spaceNames, context);
     }
 
     /**
-        * Returns a list of nb space names starting at start
-        * @param context The XWiki Context
-        * @return list of Space objects
-     * @throws SpaceManagerException  
-        */
+     * Returns a list of nb space names starting at start
+     * @param context The XWiki Context
+     * @return list of Space objects
+     * @throws SpaceManagerException
+     */
     protected List getSpaceObjects(List spaceNames, XWikiContext context) 
throws SpaceManagerException {
         if (spaceNames==null)
-         return null;
+            return null;
         List spaceList = new ArrayList();
         for (int i=0;i<spaceNames.size();i++) {
             String spaceName = (String) spaceNames.get(i);
@@ -579,20 +581,20 @@
     }
 
     /**
-        * Gets the names of nb spaces starting at start 
-        * @param nb Number of spaces to be returned
-        * @param start Index at which we will start the search
-        * @param context The XWiki Context
-        * @return list of Strings (space names)
-     * @throws SpaceManagerException  
-        */
+     * Gets the names of nb spaces starting at start
+     * @param nb Number of spaces to be returned
+     * @param start Index at which we will start the search
+     * @param context The XWiki Context
+     * @return list of Strings (space names)
+     * @throws SpaceManagerException
+     */
     public List getSpaceNames(int nb, int start, XWikiContext context) throws 
SpaceManagerException {
         String type = getSpaceTypeName();
         String className = getSpaceClassName();
         String sql;
         if (hasCustomMapping())
             sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, " + className + " as space where doc.fullName = obj.name and 
obj.className='"
-                 + className + "' and obj.id = space.id and space.type='" + 
type + "'";
+                    + className + "' and obj.id = space.id and space.type='" + 
type + "'";
         else
             sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, StringProperty typeprop where doc.fullName=obj.name and 
obj.className = '"
                     + className + "' and obj.id=typeprop.id.id and 
typeprop.id.name='type' and typeprop.value='" + type + "'";
@@ -605,37 +607,37 @@
         }
         return spaceList;
     }
-    
+
     /**
-        * Performs a hql search and returns the matching Space objects  
-        * @param fromsql
+     * Performs a hql search and returns the matching Space objects
+     * @param fromsql
      [EMAIL PROTECTED] wherehql
      * @param nb Number of objects to be returned
      * @param start Index at which we will start the search
      * @param context The XWiki Context @return list of Space objects
-     * @throws SpaceManagerException  
-        */
+     * @throws SpaceManagerException
+     */
     public List searchSpaces(String fromsql, String wherehql, int nb, int 
start, XWikiContext context) throws SpaceManagerException {
         List spaceNames = searchSpaceNames(fromsql, wherehql, nb, start, 
context);
         return getSpaceObjects(spaceNames, context);
     }
 
     /**
-        * Performs a hql search and returns the matching space names  
-        * @param fromsql
+     * Performs a hql search and returns the matching space names
+     * @param fromsql
      [EMAIL PROTECTED] wheresql
      * @param nb Number of objects to be returned
      * @param start Index at which we will start the search
      * @param context The XWiki Context @return list of Strings (space names)
-     * @throws SpaceManagerException  
-        */
+     * @throws SpaceManagerException
+     */
     public List searchSpaceNames(String fromsql, String wheresql, int nb, int 
start, XWikiContext context) throws SpaceManagerException {
         String type = getSpaceTypeName();
         String className = getSpaceClassName();
         String sql;
         if (hasCustomMapping())
             sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, " + className + " as space" + fromsql + " where doc.fullName 
= obj.name and obj.className='"
-                 + className + "' and obj.id = space.id and space.type='" + 
type + "'" + wheresql;
+                    + className + "' and obj.id = space.id and space.type='" + 
type + "'" + wheresql;
         else
             sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, StringProperty as typeprop" + fromsql + " where 
doc.fullName=obj.name and obj.className = '"
                     + className + "' and obj.id=typeprop.id.id and 
typeprop.id.name='type' and typeprop.value='" + type + "'" + wheresql;
@@ -650,35 +652,35 @@
     }
 
     /**
-        * Gets a list of spaces in which a specific user has a specific role  
-        * @param userName The username of the targeted user
-        * @param role The role which the user must have
-        * @param context The XWiki Context
-        * @return list of Space objects
-     * @throws SpaceManagerException  
-        */
+     * Gets a list of spaces in which a specific user has a specific role
+     * @param userName The username of the targeted user
+     * @param role The role which the user must have
+     * @param context The XWiki Context
+     * @return list of Space objects
+     * @throws SpaceManagerException
+     */
     public List getSpaces(String userName, String role, XWikiContext context) 
throws SpaceManagerException {
         List spaceNames = getSpaceNames(userName, role, context);
         return getSpaceObjects(spaceNames, context);
     }
 
     /**
-        * Gets a list of spaces names in which a specific user has a specific 
role  
-        * @param userName The username of the targeted user
-        * @param role The role which the user must have
-        * @param context The XWiki Context
-        * @return list of Strings (space names)
-     * @throws SpaceManagerException  
-        */
+     * Gets a list of spaces names in which a specific user has a specific role
+     * @param userName The username of the targeted user
+     * @param role The role which the user must have
+     * @param context The XWiki Context
+     * @return list of Strings (space names)
+     * @throws SpaceManagerException
+     */
     public List getSpaceNames(String userName, String role, XWikiContext 
context) throws SpaceManagerException {
         String sql;
         if (role==null)
-         sql = "select distinct doc.web from XWikiDocument as doc, BaseObject 
as obj, StringProperty as memberprop where doc.name='MemberGroup' and 
doc.fullName=obj.name and obj.className = 'XWiki.XWikiGroups'"
-                + " and obj.id=memberprop.id.id and 
memberprop.id.name='member' and memberprop.value='" + userName + "'";
+            sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, StringProperty as memberprop where doc.name='MemberGroup' 
and doc.fullName=obj.name and obj.className = 'XWiki.XWikiGroups'"
+                    + " and obj.id=memberprop.id.id and 
memberprop.id.name='member' and memberprop.value='" + userName + "'";
         else {
             String roleGroupName = getRoleGroupName("", role).substring(1);
             sql = "select distinct doc.web from XWikiDocument as doc, 
BaseObject as obj, StringProperty as memberprop where doc.name='" + 
roleGroupName + "' and doc.fullName=obj.name and obj.className = 
'XWiki.XWikiGroups'"
-                   + " and obj.id=memberprop.id.id and 
memberprop.id.name='member' and memberprop.value='" + userName + "'";
+                    + " and obj.id=memberprop.id.id and 
memberprop.id.name='member' and memberprop.value='" + userName + "'";
 
         }
         List spaceList = null;
@@ -737,11 +739,11 @@
 
     /**
      * [EMAIL PROTECTED]
-     * 
+     *
      * @see SpaceManager#removeAdmin(String, String, XWikiContext)
      */
     public void removeAdmin(String spaceName, String userName, XWikiContext 
context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         try {
             removeUserFromGroup(userName, getAdminGroupName(spaceName), 
context);
@@ -749,9 +751,9 @@
             throw new SpaceManagerException(e);
         }
     }
-    
+
     public boolean isAdmin(String spaceName, String userName, XWikiContext 
context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         try {
             return isMemberOfGroup(userName, getAdminGroupName(spaceName), 
context);
@@ -784,7 +786,7 @@
         }
     }
 
-    
+
     public boolean isMember(String spaceName, String username, XWikiContext 
context) throws SpaceManagerException {
         try {
             return isMemberOfGroup(username, getMemberGroupName(spaceName), 
context);
@@ -793,26 +795,26 @@
         }
     }
 
-       public void addUserToRoles(String spaceName, String username, List 
roles, XWikiContext context) throws SpaceManagerException {
+    public void addUserToRoles(String spaceName, String username, List roles, 
XWikiContext context) throws SpaceManagerException {
         for(int i=0;i<roles.size();i++) {
             addUserToRole(spaceName, username, (String) roles.get(i), context);
         }
     }
 
 
-       public void addUsersToRoles(String spaceName, List usernames, List 
roles, XWikiContext context) throws SpaceManagerException {
+    public void addUsersToRoles(String spaceName, List usernames, List roles, 
XWikiContext context) throws SpaceManagerException {
         for(int i=0;i<usernames.size();i++) {
             addUserToRoles(spaceName, (String) usernames.get(i), roles, 
context);
         }
     }
 
-       /**
+    /**
      * [EMAIL PROTECTED]
-     * 
+     *
      * @see SpaceManager#removeUserFromRoles(String, String, List, 
XWikiContext)
      */
     public void removeUserFromRoles(String spaceName, String userName, List 
roles,
-        XWikiContext context) throws SpaceManagerException
+                                    XWikiContext context) throws 
SpaceManagerException
     {
         for (int i = 0; i < roles.size(); i++) {
             removeUserFromRole(spaceName, userName, (String) roles.get(i), 
context);
@@ -820,7 +822,7 @@
     }
 
     public void removeUserFromRole(String spaceName, String userName, String 
role,
-        XWikiContext context) throws SpaceManagerException
+                                   XWikiContext context) throws 
SpaceManagerException
     {
         try {
             removeUserFromGroup(userName, getRoleGroupName(spaceName, role), 
context);
@@ -829,7 +831,7 @@
         }
     }
 
-       public void addMember(String spaceName, String username, XWikiContext 
context) throws SpaceManagerException {
+    public void addMember(String spaceName, String username, XWikiContext 
context) throws SpaceManagerException {
         try {
             addUserToGroup(username, getMemberGroupName(spaceName), context);
         } catch (XWikiException e) {
@@ -837,13 +839,13 @@
         }
     }
 
-       /**
+    /**
      * [EMAIL PROTECTED]
-     * 
+     *
      * @see SpaceManager#removeMember(String, String, XWikiContext)
      */
     public void removeMember(String spaceName, String userName, XWikiContext 
context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         try {
             // remove admin role
@@ -887,7 +889,7 @@
     {
         // don't add if he is already a member
         if (isMemberOfGroup(username, groupName, context))
-         return;
+            return;
 
         XWiki xwiki = context.getWiki();
         BaseClass groupClass = xwiki.getGroupClass(context);
@@ -900,9 +902,9 @@
         groupDoc.addObject(groupClass.getName(), memberObject);
         String content = groupDoc.getContent();
         if ((content == null)||(content.equals("")))
-         groupDoc.setContent("#includeForm(\"XWiki.XWikiGroupSheet\")");
+            groupDoc.setContent("#includeForm(\"XWiki.XWikiGroupSheet\")");
         xwiki.saveDocument(groupDoc, 
context.getMessageTool().get("core.comment.addedUserToGroup"),
-                 context);
+                context);
         /*
         if (groupDoc.isNew()) {
         } else {
@@ -913,10 +915,10 @@
             xwiki.getGroupService(context).addUserToGroup(username, 
context.getDatabase(), groupName, context);
         } catch (Exception e) {}
         */
-   }
+    }
 
     private void removeUserFromGroup(String userName, String groupName, 
XWikiContext context)
-        throws XWikiException
+            throws XWikiException
     {
         // don't remove if he's not a member
         if (!isMemberOfGroup(userName, groupName, context)) {
@@ -932,7 +934,7 @@
         }
         groupDoc.removeObject(memberObject);
         xwiki.saveDocument(groupDoc, context.getMessageTool()
-            .get("core.comment.removedUserFromGroup"), context);
+                .get("core.comment.removedUserFromGroup"), context);
     }
 
     public void addMembers(String spaceName, List usernames, XWikiContext 
context) throws SpaceManagerException {
@@ -942,7 +944,7 @@
     }
 
 
-       public Collection getMembers(String spaceName, XWikiContext context) 
throws SpaceManagerException {
+    public Collection getMembers(String spaceName, XWikiContext context) 
throws SpaceManagerException {
         try {
             return 
getGroupService(context).getAllMembersNamesForGroup(getMemberGroupName(spaceName),
 0, 0, context);
         } catch (XWikiException e) {
@@ -964,15 +966,15 @@
     }
 
     protected XWikiGroupService getGroupService(XWikiContext context) throws 
XWikiException {
-       return context.getWiki().getGroupService(context);
+        return context.getWiki().getGroupService(context);
     }
 
     public SpaceUserProfile getSpaceUserProfile(String spaceName, String 
username, XWikiContext context) throws SpaceManagerException {
         return newUserSpaceProfile(username, spaceName, context);
     }
-    
+
     private void deleteSpaceUserProfile(String spaceName, String userName, 
XWikiContext context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         try {
             String docName = getSpaceUserProfilePageName(userName, spaceName);
@@ -1022,15 +1024,15 @@
         String sql;
         if (hasCustomMapping())
             sql = "select count(*) from XWikiDocument as doc, BaseObject as 
obj, " + className + " as space"
-                 + " where doc.fullName = obj.name and obj.className='" + 
className + "' and obj.id = space.id and space.type='" + type + "'";
+                    + " where doc.fullName = obj.name and obj.className='" + 
className + "' and obj.id = space.id and space.type='" + type + "'";
         else
             sql = "select count(*) from XWikiDocument as doc, BaseObject as 
obj, StringProperty as typeprop"
-                 + " where doc.fullName=obj.name and obj.className = '" + 
className + "' and obj.id=typeprop.id.id and typeprop.id.name='type' and 
typeprop.value='" + type + "'";
-        
+                    + " where doc.fullName=obj.name and obj.className = '" + 
className + "' and obj.id=typeprop.id.id and typeprop.id.name='type' and 
typeprop.value='" + type + "'";
+
         try {
             List result = context.getWiki().search(sql, context);
             Integer res = (Integer) result.get(0);
-            return res.intValue();                            
+            return res.intValue();
         } catch (XWikiException e) {
             throw new SpaceManagerException(e);
         }
@@ -1051,7 +1053,7 @@
     }
 
     private void sendMail(String action, Space space, XWikiContext context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         if (!mailNotification) {
             return;
@@ -1072,8 +1074,8 @@
 
         if (fromUser == null) {
             throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER,
-                SpaceManagerException.ERROR_SPACE_SENDER_EMAIL_INVALID,
-                "Sender email is invalid");
+                    SpaceManagerException.ERROR_SPACE_SENDER_EMAIL_INVALID,
+                    "Sender email is invalid");
         }
 
         boolean toUsersValid = toUsers.length > 0;
@@ -1088,8 +1090,8 @@
 
         if (!toUsersValid) {
             throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER,
-                SpaceManagerException.ERROR_SPACE_TARGET_EMAIL_INVALID,
-                "Target email is invalid");
+                    SpaceManagerException.ERROR_SPACE_TARGET_EMAIL_INVALID,
+                    "Target email is invalid");
         }
         String strToUsers = join(toUsers, ",");
 
@@ -1097,39 +1099,39 @@
 
         try {
             String templateDocFullName =
-                getTemplateMailPageName(space.getSpaceName(), action, context);
+                    getTemplateMailPageName(space.getSpaceName(), action, 
context);
             XWikiDocument mailDoc = 
context.getWiki().getDocument(templateDocFullName, context);
             XWikiDocument translatedMailDoc = 
mailDoc.getTranslatedDocument(context);
             mailSender.prepareVelocityContext(fromUser, strToUsers, "", 
vContext, context);
             vContext.put("xwiki", new 
com.xpn.xwiki.api.XWiki(context.getWiki(), context));
             String mailSubject =
-                XWikiVelocityRenderer.evaluate(translatedMailDoc.getTitle(), 
templateDocFullName,
-                    vContext);
+                    
XWikiVelocityRenderer.evaluate(translatedMailDoc.getTitle(), 
templateDocFullName,
+                            vContext);
             String mailContent =
-                XWikiVelocityRenderer.evaluate(translatedMailDoc.getContent(),
-                    templateDocFullName, vContext);
+                    
XWikiVelocityRenderer.evaluate(translatedMailDoc.getContent(),
+                            templateDocFullName, vContext);
 
             Mail mail =
-                new Mail(fromUser, strToUsers, null, null, mailSubject, 
mailContent, null);
+                    new Mail(fromUser, strToUsers, null, null, mailSubject, 
mailContent, null);
             mailSender.sendMail(mail, context);
         } catch (Exception e) {
             throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER,
-                SpaceManagerException.ERROR_SPACE_SENDING_EMAIL_FAILED,
-                "Sending notification email failed",
-                e);
+                    SpaceManagerException.ERROR_SPACE_SENDING_EMAIL_FAILED,
+                    "Sending notification email failed",
+                    e);
         }
     }
 
     private MailSenderPlugin getMailSenderPlugin(XWikiContext context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         MailSenderPlugin mailSender =
-            (MailSenderPlugin) context.getWiki().getPlugin("mailsender", 
context);
+                (MailSenderPlugin) context.getWiki().getPlugin("mailsender", 
context);
 
         if (mailSender == null)
             throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER,
-                
SpaceManagerException.ERROR_SPACE_MANAGER_REQUIRES_MAILSENDER_PLUGIN,
-                "SpaceManager requires the mail sender plugin");
+                    
SpaceManagerException.ERROR_SPACE_MANAGER_REQUIRES_MAILSENDER_PLUGIN,
+                    "SpaceManager requires the mail sender plugin");
 
         return mailSender;
     }
@@ -1155,7 +1157,7 @@
 
     // code duplicated from InvitationManagerImpl !!!
     private String getEmailAddress(String user, XWikiContext context)
-        throws SpaceManagerException
+            throws SpaceManagerException
     {
         try {
             String wikiuser = (user.startsWith("XWiki.")) ? user : "XWiki." + 
user;
@@ -1181,9 +1183,9 @@
             return email;
         } catch (Exception e) {
             throw new 
SpaceManagerException(SpaceManagerException.MODULE_PLUGIN_SPACEMANAGER,
-                SpaceManagerException.ERROR_SPACE_CANNOT_FIND_EMAIL_ADDRESS,
-                "Cannot find email address of user " + user,
-                e);
+                    
SpaceManagerException.ERROR_SPACE_CANNOT_FIND_EMAIL_ADDRESS,
+                    "Cannot find email address of user " + user,
+                    e);
         }
     }
 
@@ -1207,7 +1209,7 @@
     private String getDefaultResourceSpace(XWikiContext context)
     {
         return context.getWiki().Param("xwiki.spacemanager.resourcespace",
-            SpaceManager.DEFAULT_RESOURCE_SPACE);
+                SpaceManager.DEFAULT_RESOURCE_SPACE);
     }
 
     public boolean isMailNotification()

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to