taylor      01/07/29 20:50:08

  Modified:    src/java/org/apache/jetspeed/services Profiler.java
                        PsmlManager.java
               src/java/org/apache/jetspeed/services/profiler
                        JetspeedProfilerService.java ProfilerService.java
               src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java
                        PsmlManagerService.java
               src/java/org/apache/jetspeed/services/security
                        JetspeedDBSecurityService.java
  Log:
  - implemented PsmlManager methods in CastorPsmlManager:
        query, removeUserDocuments, removeRoleDocuments, removeGroupDocuments
  
  Revision  Changes    Path
  1.11      +5 -4      
jakarta-jetspeed/src/java/org/apache/jetspeed/services/Profiler.java
  
  Index: Profiler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/Profiler.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Profiler.java     2001/07/17 16:44:35     1.10
  +++ Profiler.java     2001/07/30 03:50:07     1.11
  @@ -56,6 +56,7 @@
   
   import org.apache.jetspeed.om.profile.Profile;
   import org.apache.jetspeed.om.profile.ProfileLocator;
  +import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.om.profile.ProfileException;
   import org.apache.jetspeed.services.profiler.ProfilerService;
   import org.apache.turbine.services.TurbineServices;
  @@ -74,7 +75,7 @@
    * @see org.apache.jetspeed.services.profiler.Profiler
    * @see org.apache.jetspeed.services.profiler.ProfilerService
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
  - * @version $Id: Profiler.java,v 1.10 2001/07/17 16:44:35 taylor Exp $
  + * @version $Id: Profiler.java,v 1.11 2001/07/30 03:50:07 taylor Exp $
    */
   public class Profiler
   {
  @@ -180,11 +181,11 @@
       }
   
       /**
  -     * @see ProfilerService#list
  +     * @see ProfilerService#query
        */
  -    public static Iterator list( ProfileLocator locator )
  +    public static Iterator query( QueryLocator locator )
       {
  -        return getService().list( locator );
  +        return getService().query( locator );
       }
   
   }
  
  
  
  1.5       +36 -2     
jakarta-jetspeed/src/java/org/apache/jetspeed/services/PsmlManager.java
  
  Index: PsmlManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/PsmlManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PsmlManager.java  2001/07/17 16:44:36     1.4
  +++ PsmlManager.java  2001/07/30 03:50:07     1.5
  @@ -58,7 +58,12 @@
   import org.apache.jetspeed.om.profile.PSMLDocument;
   import org.apache.turbine.services.TurbineServices;
   import org.apache.jetspeed.om.profile.ProfileLocator;
  +import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.om.profile.Profile;
  +import org.apache.turbine.om.security.User;
  +import org.apache.turbine.om.security.Role;
  +import org.apache.turbine.om.security.Group;
  +
   import java.util.Iterator;
   import java.util.List;
   
  @@ -66,7 +71,7 @@
    * Static accessor for the PsmlManagerService
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Raphaël Luta</a>
  - * @version $Id: PsmlManager.java,v 1.4 2001/07/17 16:44:36 taylor Exp $
  + * @version $Id: PsmlManager.java,v 1.5 2001/07/30 03:50:07 taylor Exp $
    */
   public class PsmlManager
   {
  @@ -155,11 +160,40 @@
           getService().removeDocument( locator );
       }
   
  +    /** Removes all documents for a given user.
  +     *
  +     * @param user The user object.
  +     */
  +    public static void removeUserDocuments( User user )
  +    {
  +        getService().removeUserDocuments( user );
  +    }
  +
  +    /** Removes all documents for a given group.
  +     *
  +     * @param group The group object.
  +     */
  +    public static void removeGroupDocuments( Group group )
  +    {
  +        getService().removeGroupDocuments( group );
  +    }
  +
  +
  +    /** Removes all documents for a given role.
  +     *
  +     * @param role The role object.
  +     */
  +    public static void removeRoleDocuments( Role role )
  +    {
  +        getService().removeRoleDocuments( role );
  +    }
  +
  +
       /** Query for a collection of profiles given a profile locator criteria.
        *
        * @param locator The profile locator criteria.
        */
  -    public static Iterator query( ProfileLocator locator )
  +    public static Iterator query( QueryLocator locator )
       {
           return getService().query( locator );
       }
  
  
  
  1.13      +3 -3      
jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java
  
  Index: JetspeedProfilerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/JetspeedProfilerService.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JetspeedProfilerService.java      2001/07/29 13:42:00     1.12
  +++ JetspeedProfilerService.java      2001/07/30 03:50:07     1.13
  @@ -131,7 +131,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Santiago Gala</a>
  - * @version $Id: JetspeedProfilerService.java,v 1.12 2001/07/29 13:42:00 raphael 
Exp $
  + * @version $Id: JetspeedProfilerService.java,v 1.13 2001/07/30 03:50:07 taylor Exp 
$
    */
   
   public class JetspeedProfilerService  extends TurbineBaseService
  @@ -696,12 +696,12 @@
           PsmlManager.removeDocument(locator);
       }
   
  -    /** Get a list of profiles given a profile locator criteria.
  +    /** Query for a collection of profiles given a profile locator criteria.
        *
        * @param locator The profile locator criteria.
        * @return The list of profiles matching the locator criteria.
        */
  -    public Iterator list( ProfileLocator locator )
  +    public Iterator query( QueryLocator locator )
       {
           return PsmlManager.query( locator );
       }
  
  
  
  1.10      +3 -3      
jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/ProfilerService.java
  
  Index: ProfilerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/profiler/ProfilerService.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ProfilerService.java      2001/07/17 16:44:45     1.9
  +++ ProfilerService.java      2001/07/30 03:50:07     1.10
  @@ -70,7 +70,7 @@
    * 
    * @see org.apache.jetspeed.om.profile.Profile
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
  - * @version $Id: ProfilerService.java,v 1.9 2001/07/17 16:44:45 taylor Exp $
  + * @version $Id: ProfilerService.java,v 1.10 2001/07/30 03:50:07 taylor Exp $
    */
   
   public interface ProfilerService extends Service
  @@ -158,11 +158,11 @@
       public void removeProfile( ProfileLocator locator )
           throws ProfileException;
   
  -    /** Get a list of profiles given a profile locator criteria.
  +    /** Query for a collection of profiles given a profile locator criteria.
        *
        * @param locator The profile locator criteria.
        * @return The list of profiles matching the locator criteria.
        */
  -    public Iterator list( ProfileLocator locator );
  +    public Iterator query( QueryLocator locator );
   
   }
  
  
  
  1.8       +575 -22   
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CastorPsmlManagerService.java     2001/07/26 20:50:39     1.7
  +++ CastorPsmlManagerService.java     2001/07/30 03:50:07     1.8
  @@ -57,7 +57,10 @@
   //Jetspeed stuff
   import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
   import org.apache.jetspeed.om.profile.ProfileLocator;
  +import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.util.FileCopy;
  +import org.apache.jetspeed.util.DirectoryUtils;
  +import org.apache.jetspeed.services.JetspeedSecurity;
   
   //Castor defined API
   import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
  @@ -93,6 +96,7 @@
   import java.util.Date;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.LinkedList;
   import java.util.Map;
   import java.util.HashMap;
   import java.lang.ref.WeakReference;
  @@ -104,7 +108,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Raphaël Luta</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Santiago Gala</a>
  - * @version $Id: CastorPsmlManagerService.java,v 1.7 2001/07/26 20:50:39 sgala Exp $
  + * @version $Id: CastorPsmlManagerService.java,v 1.8 2001/07/30 03:50:07 taylor Exp 
$
    */
   public class CastorPsmlManagerService extends TurbineBaseService
       implements PsmlManagerService
  @@ -117,9 +121,11 @@
   
       // configuration keys
       private final static String CONFIG_ROOT             = "root";
  +    private final static String CONFIG_EXT              = "ext";
   
       // default configuration values
       public final static String DEFAULT_ROOT             = "/WEB-INF/psml";
  +    public final static String DEFAULT_EXT              = ".psml";
   
       // default resource
       public final static String DEFAULT_RESOURCE         = "default.psml";
  @@ -128,6 +134,8 @@
       private String root;
       // base store directory
       private File rootDir = null;
  +    // file extension
  +    private String ext;
   
       /** The documents loaded by this manager */
       private Map documents = new HashMap();
  @@ -148,10 +156,10 @@
       public void init( ServletConfig conf ) throws InitializationException
       {
   
  -     if(getInit())
  +    if(getInit())
           {
  -         return;
  -     }
  +        return;
  +    }
   
           // get configuration parameters from Jetspeed Resources
           ResourceService serviceConf = 
((TurbineServices)TurbineServices.getInstance())
  @@ -160,17 +168,20 @@
           this.root = serviceConf.getString( CONFIG_ROOT, DEFAULT_ROOT );
           this.rootDir = new File(root);
   
  -     //If the rootDir does not exist, treat it as context relative
  +        //If the rootDir does not exist, treat it as context relative
           if ( !rootDir.exists() )
           {
               this.rootDir = new File(conf.getServletContext().getRealPath(root));
           }
  -     //If it is still missing, try to create it
  +        //If it is still missing, try to create it
           if (!rootDir.exists())
           {
               rootDir.mkdirs();
           }
   
  +        // get default extension
  +        this.ext = serviceConf.getString( CONFIG_EXT, DEFAULT_EXT );        
  +
           // create the serializer output format        
           this.format = new OutputFormat();
           format.setIndenting(true);
  @@ -181,6 +192,10 @@
   
           //Mark that we are done
           setInit(true);
  +
  +        // Test
  +        //testCases();
  +
       }
   
   
  @@ -199,6 +214,7 @@
                   Log.error( ie );
               }
           }
  +
       }
   
       
  @@ -228,7 +244,7 @@
               throw new IllegalArgumentException( message );
           }
   
  -     Log.debug( "PSMLManager: asked for " + name );
  +        Log.debug( "PSMLManager: asked for " + name );
   
           PSMLDocument doc = null;
           WeakReference ref = null;
  @@ -262,6 +278,11 @@
        *
        * @param locator The locator descriptor of the document to be retrieved.
        */
  +    /**
  +     * Returns a PSML document for the given locator
  +     *
  +     * @param locator The locator descriptor of the document to be retrieved.
  +     */
       public PSMLDocument getDocument( ProfileLocator locator )
       {
           if (locator == null)
  @@ -278,6 +299,7 @@
   
           PSMLDocument doc = null;
           WeakReference ref = null;
  +        Profile profile = null;
   
           synchronized (documents)
           {
  @@ -286,24 +308,29 @@
           
           if (ref != null)
           {
  -            doc = (PSMLDocument)ref.get();
  +            profile = (Profile)ref.get();
           }
           
  -        if (doc == null)
  +        if (profile == null)
           {
               doc = loadDocument(name);
               if (null == doc)
  -         {
  -             Log.note( "CastorPsmlManager: about to return null doc: "  );
  +            {
  +                Log.note( "CastorPsmlManager: about to return null doc: "  );
                   return null;
  -         }
  +            }
   
               synchronized (documents)
               {
                   // store the document in the hash and reference it to the watcher
  -                documents.put(name, new WeakReference(doc));
  +                Profile newProfile = new BaseProfile(locator);
  +                newProfile.setDocument(doc);
  +                documents.put(name, new WeakReference(profile));
               }
           }
  +        else
  +            doc = profile.getDocument();
  +
           return doc;
       }
   
  @@ -664,26 +691,171 @@
           
           return doc;
       }
  +    
  +    /** Removes a document.
  +     *
  +     * @param locator The description of the profile resource to be removed.
  +     */
  +    public void removeDocument( ProfileLocator locator )
  +    {
  +        // remove a single document
  +        String fileName = mapLocatorToFile(locator);
   
  -    /** Query for a collection of profiles given a profile locator criteria.
  +        File base = this.rootDir;
  +        File file = new File(base, fileName);
  +        String name = file.getAbsolutePath();
  +
  +        synchronized (documents)
  +        {
  +            documents.remove(name);
  +        }
  +// TODO:   this.watcher.removeFile(file);
  +
  +        file.delete();
  +
  +    }
  +
  +    /** Removes all documents for a given user.
        *
  -     * @param locator The profile locator criteria.
  +     * @param user The user object.
        */
  -    public Iterator query( ProfileLocator locator )
  +    public void removeUserDocuments( User user )
       {
  -        // IMPLEMENT ME:
  -        return null;
  +        ProfileLocator locator = new BaseProfileLocator();
  +        locator.setUser(user);
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(PATH_USER);
  +        String name = user.getUserName();
  +        if (null != name && name.length() > 0)
  +        {
  +            buffer.append(File.separator)
  +                .append(name);
  +        }
  +        else
  +            return; // don't delete the entire user directories
  +
  +        String path = buffer.toString();
  +        File base = this.rootDir;
  +        File file = new File(base, path);
  +        name = file.getAbsolutePath();
  +
  +        synchronized (documents)
  +        {
  +            DirectoryUtils.rmdir(name);
  +            Iterator it = documents.entrySet().iterator();
  +            while (it.hasNext())
  +            {
  +                Map.Entry entry = (Map.Entry)it.next();
  +                WeakReference ref = (WeakReference)entry.getValue();
  +                if (null == ref)
  +                    continue;
  +                Profile profile = (Profile)ref.get();
  +                if (null == profile)
  +                    continue;
  +                User pUser = profile.getUser();
  +                if (null != pUser && pUser.getUserName().equals(user.getUserName()))
  +                {
  +                    documents.remove(profile.getDocument().getName());
  +                }
  +            }
  +        }
  +
       }
   
  -    /** Removes a document.
  +    /** Removes all documents for a given role.
        *
  -     * @param locator The description of the profile resource to be removed.
  +     * @param role The role object.
        */
  -    public void removeDocument( ProfileLocator locator )
  +    public void removeRoleDocuments( Role role )
       {
  -        
  +        ProfileLocator locator = new BaseProfileLocator();
  +        locator.setRole(role);
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(PATH_ROLE);
  +        String name = role.getName();
  +        if (null != name && name.length() > 0)
  +        {
  +            buffer.append(File.separator)
  +                .append(name);
  +        }
  +        else
  +            return; // don't delete the entire role directories
  +
  +        String path = buffer.toString();
  +        File base = this.rootDir;
  +        File file = new File(base, path);
  +        name = file.getAbsolutePath();
  +
  +        synchronized (documents)
  +        {
  +            DirectoryUtils.rmdir(name);
  +            Iterator it = documents.entrySet().iterator();
  +            while (it.hasNext())
  +            {
  +                Map.Entry entry = (Map.Entry)it.next();
  +                WeakReference ref = (WeakReference)entry.getValue();
  +                if (null == ref)
  +                    continue;
  +                Profile profile = (Profile)ref.get();
  +                if (null == profile)
  +                    continue;
  +                Role pRole = profile.getRole();
  +                if (null != pRole && pRole.getName().equals(role.getName()))
  +                {
  +                    documents.remove(profile.getDocument().getName());
  +                }
  +            }
  +        }
  +    }
  +
  +    /** Removes all documents for a given group.
  +     *
  +     * @param group The group object.
  +     */
  +    public void removeGroupDocuments( Group group )
  +    {
  +        ProfileLocator locator = new BaseProfileLocator();
  +        locator.setGroup(group);
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(PATH_GROUP);
  +        String name = group.getName();
  +        if (null != name && name.length() > 0)
  +        {
  +            buffer.append(File.separator)
  +                .append(name);
  +        }
  +        else
  +            return; // don't delete the entire group directories
  +
  +        String path = buffer.toString();
  +        File base = this.rootDir;
  +        File file = new File(base, path);
  +        name = file.getAbsolutePath();
  +
  +        synchronized (documents)
  +        {
  +            DirectoryUtils.rmdir(name);
  +            Iterator it = documents.entrySet().iterator();
  +            while (it.hasNext())
  +            {
  +                Map.Entry entry = (Map.Entry)it.next();
  +                WeakReference ref = (WeakReference)entry.getValue();
  +                if (null == ref)
  +                    continue;
  +                Profile profile = (Profile)ref.get();
  +                if (null == profile)
  +                    continue;
  +                Group pGroup = profile.getGroup();
  +                if (null != pGroup && pGroup.getName().equals(group.getName()))
  +                {
  +                    documents.remove(profile.getDocument().getName());
  +                }
  +            }
  +        }
  +
       }
   
  +
       /**
        * Maps a ProfileLocator to a file.
        * 
  @@ -770,6 +942,387 @@
           }
   
           return  path.toString();
  +    }
  +
  +    private static int STATE_INIT = 0;
  +    private static int STATE_BASE = 1;
  +    private static int STATE_NAME = 2;
  +    private static int STATE_MEDIA = 3;
  +    private static int STATE_LANGUAGE = 4;
  +    private static int STATE_COUNTRY = 5;
  +
  +    /** Query for a collection of profiles given a profile locator criteria.
  +     *
  +     * @param locator The profile locator criteria.
  +     */
  +    public Iterator query( QueryLocator locator )
  +    {
  +        List list = new LinkedList();
  +
  +        Role role = locator.getRole();
  +        Group group = locator.getGroup();
  +        User user = locator.getUser();
  +    
  +        // search thru anonymous directories?
  +        int qm = locator.getQueryMode();
  +        if ((qm & QueryLocator.QUERY_ANON) == QueryLocator.QUERY_ANON)
  +        {
  +            Profile profile = new BaseProfile();
  +            profile.setAnonymous(true);
  +            StringBuffer path = new StringBuffer();
  +            path.append(PATH_ANON);
  +            File base = this.rootDir;
  +            File file = new File(base, path.toString());
  +            String absPath = file.getAbsolutePath();
  +            QueryState qs = new QueryState( QUERY_BY_ANON,
  +                                             profile,
  +                                             locator,
  +                                             list,
  +                                             null,
  +                                             STATE_BASE);
  +            subQuery(qs, absPath);
  +        }
  +        if ((qm & QueryLocator.QUERY_USER) == QueryLocator.QUERY_USER)
  +        {
  +            Profile profile = new BaseProfile();
  +            StringBuffer path = new StringBuffer();
  +            path.append(PATH_USER);
  +            String name = null;
  +            int state = STATE_INIT;
  +            if (null != user)
  +            {
  +                name = user.getUserName();
  +                profile.setUser( user );
  +                if (null != name)
  +                {
  +                    path.append(File.separator).append(name);
  +                    state = STATE_BASE;
  +                }
  +            }
  +            File base = this.rootDir;
  +            File file = new File(base, path.toString());
  +            String absPath = file.getAbsolutePath();
  +            QueryState qs = new QueryState( QUERY_BY_USER,
  +                                             profile,
  +                                             locator,
  +                                             list,
  +                                             name,
  +                                             state);
  +            subQuery(qs, absPath);
  +        }
  +        if ((qm & QueryLocator.QUERY_ROLE) == QueryLocator.QUERY_ROLE)
  +        {
  +            Profile profile = new BaseProfile();
  +            StringBuffer path = new StringBuffer();
  +            path.append(PATH_ROLE);
  +            String name = null;
  +            int state = STATE_INIT;
  +            if (null != role)
  +            {
  +                name = role.getName();
  +                profile.setRole( role );
  +                if (null != name)
  +                {
  +                    path.append(File.separator).append(name);
  +                    state = STATE_BASE;
  +                }
  +            }
  +            File base = this.rootDir;
  +            File file = new File(base, path.toString());
  +            String absPath = file.getAbsolutePath();
  +            QueryState qs = new QueryState( QUERY_BY_ROLE,
  +                                             profile,
  +                                             locator,
  +                                             list,
  +                                             name,
  +                                             state);
  +            subQuery(qs, absPath);
  +        }
  +        if ((qm & QueryLocator.QUERY_GROUP) == QueryLocator.QUERY_GROUP)
  +        {
  +            Profile profile = new BaseProfile();
  +            StringBuffer path = new StringBuffer();
  +            path.append(PATH_GROUP);
  +            String name = null;
  +            int state = STATE_INIT;
  +            if (null != group)
  +            {
  +                name = group.getName();
  +                profile.setGroup( group );
  +                if (null != name)
  +                {
  +                    path.append(File.separator).append(name);
  +                    state = STATE_BASE;
  +                }
  +            }
  +            File base = this.rootDir;
  +            File file = new File(base, path.toString());
  +            String absPath = file.getAbsolutePath();
  +            QueryState qs = new QueryState( QUERY_BY_GROUP,
  +                                             profile,
  +                                             locator,
  +                                             list,
  +                                             name,
  +                                             state);
  +            subQuery(qs, absPath);
  +        }
  +
  +        return list.iterator();
  +    }
  +
  +    /** Query for a collection of profiles given a profile locator criteria.
  +     *  To specify 'all' - use '*' in the criteria
  +     *
  +     * @param locator The profile locator criteria.
  +     */
  +    private void subQuery(QueryState qs, String path)
  +    {
  +        File file = new File(path);
  +        if (file.isFile()) 
  +        {
  +            try 
  +            {
  +                String filename = file.getName();
  +                if (!filename.endsWith(this.ext))
  +                    return;
  +
  +                Profile clone = (Profile)qs.profile.clone();
  +                clone.setName(filename);
  +                qs.list.add( clone );
  +            }
  +            catch (Exception e)
  +            {
  +                Log.error("Failed to clone profile: " + path + " : " + 
e.toString());
  +            }
  +        } 
  +        else if (file.isDirectory()) 
  +        {
  +            String dirName = file.getName();
  +            qs.state++;
  +
  +            // filter out based on name, mediatype, language, country
  +            if (qs.state == STATE_NAME)
  +            {
  +                if (null != qs.name)
  +                {
  +                    if (!dirName.equals(qs.name))
  +                        return;
  +                }
  +                try
  +                {
  +                    if (QUERY_BY_USER == qs.queryBy)
  +                    {
  +                        User user = qs.profile.getUser();
  +                        if (null == user)
  +                        {
  +                            user = JetspeedSecurity.getUser(dirName);
  +                            qs.clearName = true;
  +                            qs.profile.setUser(user);
  +                        }
  +                    }
  +                    else if (QUERY_BY_ROLE == qs.queryBy)
  +                    {
  +                        Role role = qs.profile.getRole();
  +                        if (null == role)
  +                        {
  +                            role = JetspeedSecurity.getRole(dirName);
  +                            qs.clearName = true;
  +                            qs.profile.setRole(role);
  +                        }
  +                    }
  +                    else if (QUERY_BY_GROUP == qs.queryBy)
  +                    {
  +                        Group group = qs.profile.getGroup();
  +                        if (null == group)
  +                        {
  +                            group = JetspeedSecurity.getGroup(dirName);
  +                            qs.clearName = true;
  +                            qs.profile.setGroup(group);
  +                        }
  +                    }
  +                }
  +                catch (Exception e)
  +                {}
  +
  +
  +            }
  +            else if (qs.state == STATE_MEDIA)
  +            {
  +                String media = qs.locator.getMediaType();
  +                if (null != media)
  +                {
  +                    if (!dirName.equals(media))
  +                        return;
  +                }
  +                else
  +                {
  +                    qs.profile.setMediaType(dirName);
  +                    qs.clearMedia = true;
  +                }
  +            }
  +            else if (qs.state == STATE_LANGUAGE)
  +            {
  +                String language = qs.locator.getLanguage();
  +                if (null != language)
  +                {
  +                    if (!dirName.equals(language))
  +                        return;
  +                }
  +                else
  +                {
  +                    qs.profile.setLanguage(dirName);
  +                    qs.clearLanguage = true;
  +                }
  +            }
  +            else if (qs.state == STATE_COUNTRY)
  +            {
  +                String country = qs.locator.getCountry();
  +                if (null != country)
  +                {
  +                    if (!dirName.equals(country))
  +                        return;
  +                }
  +                else
  +                {
  +                    qs.profile.setCountry(dirName);
  +                    qs.clearCountry = true;
  +                }
  +            }
  +
  +            if (!path.endsWith(File.separator))
  +                path += File.separator;
  +
  +            String files[] = file.list();
  +
  +
  +            // Process all files recursivly
  +            for(int ix = 0; files != null && ix < files.length; ix++)
  +            {
  +                subQuery(qs, path + files[ix]);
  +            }
  +
  +            // clear state
  +            if (qs.state == STATE_NAME && true == qs.clearName)
  +            {
  +                if (QUERY_BY_USER == qs.queryBy)
  +                    qs.profile.setUser(null);
  +                else if (QUERY_BY_ROLE == qs.queryBy)
  +                    qs.profile.setRole(null);
  +                else if (QUERY_BY_GROUP == qs.queryBy)
  +                    qs.profile.setGroup(null);
  +                qs.clearName = false;
  +            }
  +            else if (qs.state == STATE_MEDIA && true == qs.clearMedia)
  +            {
  +                qs.profile.setMediaType(null);
  +                qs.clearMedia = false;
  +            }
  +            else if (qs.state == STATE_LANGUAGE && true == qs.clearLanguage)
  +            {
  +                qs.profile.setLanguage(null);
  +                qs.clearLanguage = false;
  +            }
  +            else if (qs.state == STATE_COUNTRY && true == qs.clearCountry)
  +            {
  +                qs.profile.setCountry(null);
  +                qs.clearCountry = false;
  +            }
  +
  +            qs.state--;
  +
  +        }
  +
  +    }
  +
  +     static int QUERY_BY_USER = 0;
  +     static int QUERY_BY_ROLE = 1;
  +     static int QUERY_BY_GROUP = 2;
  +     static int QUERY_BY_ANON = 3;
  +
  +    protected class QueryState
  +    {
  +
  +        QueryState( int queryBy,
  +                    Profile profile,
  +                    ProfileLocator locator,
  +                    List list,
  +                    String name,
  +                    int state)
  +        {
  +            this.queryBy = queryBy;
  +            this.profile = profile;
  +            this.locator = locator;
  +            this.list = list;
  +            this.name = name;
  +            this.state = state;
  +        }
  +
  +        private int queryBy;
  +        private Profile profile;
  +        private ProfileLocator locator;
  +        private List list;
  +        private String name;
  +        private int state;
  +
  +        private boolean clearName = false;
  +        private boolean clearMedia = false;
  +        private boolean clearLanguage = false;
  +        private boolean clearCountry = false;
  +
  +    }
  +
  +    private void testCases()
  +    {
  +        try
  +        {
  +            QueryLocator locator = new QueryLocator( QueryLocator.QUERY_USER );
  +            Iterator x1 = query( locator );
  +            dump( x1 );
  +    
  +            QueryLocator locator2 = new QueryLocator( QueryLocator.QUERY_USER );
  +            locator2.setUser( JetspeedSecurity.getUser("turbine") );
  +            Iterator x2 = query( locator2 );
  +            dump( x2 );
  +    
  +            QueryLocator locator3 = new QueryLocator( QueryLocator.QUERY_ANON );
  +            Iterator x3 = query( locator3 );
  +            dump( x3 );
  +    
  +            QueryLocator locator4 = new QueryLocator( QueryLocator.QUERY_GROUP );
  +//            locator4.setGroup( JetspeedSecurity.getGroup("apache") );
  +            Iterator x4 = query( locator4 );
  +            dump( x4 );
  +          }
  +        catch (Exception e)
  +        {
  +            System.out.println( "Exception in Debug:" + e);
  +        }
  +    }
  +
  +    private void dump( Iterator it )
  +    {
  +        System.out.println("===============================================");
  +        while (it.hasNext() )
  +        {
  +            Profile profile = (Profile)it.next();
  +            User user = profile.getUser();
  +            Group group = profile.getGroup();
  +            Role role = profile.getRole();
  +            if (profile.getAnonymous() == true)
  +                System.out.println("ANON USER");
  +            System.out.println("RESOURCE = " + profile.getName());
  +            if (null != user)
  +                System.out.println("USER = " + user.getUserName() );
  +            if (null != group)
  +                System.out.println("GROUP = " + group.getName() );
  +            if (null != role)
  +                System.out.println("ROLE = " + role.getName() );
  +            System.out.println("MEDIA TYPE = " + profile.getMediaType());
  +            System.out.println("LANGUAGE = " + profile.getLanguage());
  +            System.out.println("COUNTRY = " + profile.getCountry());
  +            System.out.println("----------------------");
  +        }
  +        System.out.println("===============================================");
       }
   
   }
  
  
  
  1.5       +25 -2     
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlManagerService.java
  
  Index: PsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlManagerService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PsmlManagerService.java   2001/07/17 16:44:50     1.4
  +++ PsmlManagerService.java   2001/07/30 03:50:07     1.5
  @@ -59,13 +59,17 @@
   import org.apache.turbine.services.Service;
   import org.apache.jetspeed.om.profile.PSMLDocument;
   import org.apache.jetspeed.om.profile.ProfileLocator;
  +import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.om.profile.Profile;
  +import org.apache.turbine.om.security.User;
  +import org.apache.turbine.om.security.Role;
  +import org.apache.turbine.om.security.Group;
   
   /**
    * This service is responsible for loading and saving PSML documents.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Raphaël Luta</a>
  - * @version $Id: PsmlManagerService.java,v 1.4 2001/07/17 16:44:50 taylor Exp $
  + * @version $Id: PsmlManagerService.java,v 1.5 2001/07/30 03:50:07 taylor Exp $
    */
   public interface PsmlManagerService extends Service
   {
  @@ -128,10 +132,29 @@
        */
       public void removeDocument( ProfileLocator locator );
   
  +    /** Removes all documents for a given user.
  +     *
  +     * @param user The user object.
  +     */
  +    public void removeUserDocuments( User user );
  +
  +    /** Removes all documents for a given group.
  +     *
  +     * @param group The group object.
  +     */
  +    public void removeGroupDocuments( Group group );
  +
  +    /** Removes all documents for a given role.
  +     *
  +     * @param role The role object.
  +     */
  +    public void removeRoleDocuments( Role role );
  +
       /** Query for a collection of profiles given a profile locator criteria.
        *
        * @param locator The profile locator criteria.
        */
  -    public Iterator query( ProfileLocator locator );
  +    public Iterator query( QueryLocator locator );
  +
   }
   
  
  
  
  1.9       +3 -6      
jakarta-jetspeed/src/java/org/apache/jetspeed/services/security/JetspeedDBSecurityService.java
  
  Index: JetspeedDBSecurityService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/security/JetspeedDBSecurityService.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JetspeedDBSecurityService.java    2001/07/29 13:42:01     1.8
  +++ JetspeedDBSecurityService.java    2001/07/30 03:50:08     1.9
  @@ -73,6 +73,7 @@
   import org.apache.jetspeed.om.profile.BaseProfileLocator;
   import org.apache.jetspeed.om.profile.ProfileException;
   import org.apache.jetspeed.services.Profiler;
  +import org.apache.jetspeed.services.PsmlManager;
   
   /**
    * <p>This is an implementation of the <code>JetspeedSecurityService</code> 
interface.
  @@ -80,7 +81,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Santiago Gala</a>
  - * @version $Id: JetspeedDBSecurityService.java,v 1.8 2001/07/29 13:42:01 raphael 
Exp $
  + * @version $Id: JetspeedDBSecurityService.java,v 1.9 2001/07/30 03:50:08 taylor 
Exp $
    */
   
   
  @@ -205,11 +206,7 @@
       public void removeUser( User user, RunData data )
           throws Exception
       {
  +        PsmlManager.removeUserDocuments(user);
           removeUser(user);
  -
  -        ProfileLocator locator = new BaseProfileLocator();
  -        locator.setUser(user);
  -        locator.setName("*");
  -        Profiler.removeProfile(locator);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to