You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/06/02 19:17:37 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac RoleManager.java GroupManager.java ItemManager.java UserManager.java

egli        2003/06/02 10:17:37

  Modified:    src/java/org/apache/lenya/cms/ac GroupManager.java
                        ItemManager.java UserManager.java
  Added:       src/java/org/apache/lenya/cms/ac RoleManager.java
  Log:
  Reorganize the instantiationof the classes so that the proper
  instances are created and the right files are fetched.
  
  Revision  Changes    Path
  1.2       +26 -4     cocoon-lenya/src/java/org/apache/lenya/cms/ac/GroupManager.java
  
  Index: GroupManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/GroupManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GroupManager.java	2 Jun 2003 09:21:51 -0000	1.1
  +++ GroupManager.java	2 Jun 2003 17:17:37 -0000	1.2
  @@ -49,7 +49,11 @@
    
   package org.apache.lenya.cms.ac;
   
  +import java.io.File;
  +import java.io.FileFilter;
  +import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
   
   import org.apache.lenya.cms.publication.Publication;
   import org.apache.log4j.Category;
  @@ -62,7 +66,9 @@
   public class GroupManager extends ItemManager {
   	static Category log = Category.getInstance(GroupManager.class);
   
  -	protected static final String SUFFIX = "gml";
  +	protected static final String SUFFIX = ".gml";
  +
  +	private static Map instances = new HashMap();
   
   	/**
   	 * @param publication
  @@ -74,9 +80,11 @@
   	}
   
   
  -	public static ItemManager instance(Publication publication)
  +	public static GroupManager instance(Publication publication)
   		throws AccessControlException {
  -		return GroupManager.instance(publication);
  +		if (!instances.containsKey(publication))
  +			instances.put(publication, new GroupManager(publication));
  +		return (GroupManager) instances.get(publication);
   	}
   
   	public Iterator getGroups() {
  @@ -102,4 +110,18 @@
   		}
   		return group;
   	}
  +	
  +	/* (non-Javadoc)
  +	 * @see org.apache.lenya.cms.ac.ItemManager#getFileFilter()
  +	 */
  +	protected FileFilter getFileFilter() {
  +		FileFilter filter = new FileFilter() {
  +
  +			public boolean accept(File pathname) {
  +				return (pathname.getName().endsWith(SUFFIX));
  +			}
  +		};
  +		return filter;
  +	}
  +
   }
  
  
  
  1.2       +21 -20    cocoon-lenya/src/java/org/apache/lenya/cms/ac/ItemManager.java
  
  Index: ItemManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/ItemManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ItemManager.java	2 Jun 2003 09:21:51 -0000	1.1
  +++ ItemManager.java	2 Jun 2003 17:17:37 -0000	1.2
  @@ -52,7 +52,6 @@
   import java.io.File;
   import java.io.FileFilter;
   import java.lang.reflect.Constructor;
  -import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Set;
  @@ -68,31 +67,25 @@
    * 
    * 
    */
  -public class ItemManager {
  +public abstract class ItemManager {
   	static Category log = Category.getInstance(ItemManager.class);
   
   	private static final String PATH =
   		"config" + File.separator + "ac" + File.separator + "passwd";
   
  -	protected static final String SUFFIX = null;
  -
  -	private static HashMap instances = new HashMap();
  -
  -	protected Set items = null;
  +	private Set items = null;
  +	private Publication publication = null;
   
   	protected ItemManager(Publication publication)
   		throws AccessControlException {
   
  +		this.publication = publication;
  +		
   		File groupDir = new File(publication.getDirectory(), PATH);
   		if (!groupDir.exists() || !groupDir.isDirectory()) {
   			//			throw new Execption();
   		}
  -		File[] itemFiles = groupDir.listFiles(new FileFilter() {
  -
  -			public boolean accept(File pathname) {
  -				return (pathname.getName().endsWith(SUFFIX));
  -			}
  -		});
  +		File[] itemFiles = groupDir.listFiles(getFileFilter());
   		items = new HashSet();
   		Configuration config = null;
   		for (int i = 0; i < itemFiles.length; i++) {
  @@ -138,12 +131,6 @@
   		}
   	}
   
  -	public static ItemManager instance(Publication publication)
  -		throws AccessControlException {
  -		if (!instances.containsKey(publication))
  -			instances.put(publication, new ItemManager(publication));
  -		return (UserManager) instances.get(publication);
  -	}
   
   	public Iterator getItems() {
   		return items.iterator();
  @@ -156,4 +143,18 @@
   	public void remove(Object item) {
   		items.remove(item);
   	}
  +	
  +	public File getPath() {
  +		return new File(publication.getDirectory(), PATH);
  +	}
  +	
  +	protected abstract FileFilter getFileFilter();
  +	
  +	/**
  +	 * @return
  +	 */
  +	public Publication getPublication() {
  +		return publication;
  +	}
  +
   }
  
  
  
  1.4       +28 -6     cocoon-lenya/src/java/org/apache/lenya/cms/ac/UserManager.java
  
  Index: UserManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/UserManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UserManager.java	2 Jun 2003 09:21:51 -0000	1.3
  +++ UserManager.java	2 Jun 2003 17:17:37 -0000	1.4
  @@ -49,7 +49,11 @@
   
   package org.apache.lenya.cms.ac;
   
  +import java.io.File;
  +import java.io.FileFilter;
  +import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
   
   import org.apache.lenya.cms.publication.Publication;
   import org.apache.log4j.Category;
  @@ -62,17 +66,21 @@
   public class UserManager extends ItemManager {
   	static Category log = Category.getInstance(UserManager.class);
   
  -	protected static final String SUFFIX = "iml";
  -		
  +	protected static final String SUFFIX = ".iml";
  +
  +	private static Map instances = new HashMap(); 
  +
   	private UserManager(Publication publication)
   		throws AccessControlException {
  -		
  +
   		super(publication);
   	}
   
  -	public static ItemManager instance(Publication publication)
  +	public static UserManager instance(Publication publication)
   		throws AccessControlException {
  -		return UserManager.instance(publication);
  +		if (!instances.containsKey(publication))
  +			instances.put(publication, new UserManager(publication));
  +		return (UserManager) instances.get(publication);
   	}
   
   	public Iterator getUsers() {
  @@ -98,4 +106,18 @@
   		}
   		return user;
   	}
  +
  +	/* (non-Javadoc)
  +	 * @see org.apache.lenya.cms.ac.ItemManager#getFileFilter()
  +	 */
  +	protected FileFilter getFileFilter() {
  +		FileFilter filter = new FileFilter() {
  +
  +			public boolean accept(File pathname) {
  +				return (pathname.getName().endsWith(SUFFIX));
  +			}
  +		};
  +		return filter;
  +	}
  +
   }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/ac/RoleManager.java
  
  Index: RoleManager.java
  ===================================================================
  /*
   * $Id: RoleManager.java,v 1.1 2003/06/02 17:17:37 egli Exp $
   * <License>
   * The Apache Software License
   *
   * Copyright (c) 2003 Wyona. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment: "This product
   *    includes software developed by Wyona (http://www.wyona.com)"
   *
   * 4. The name "Lenya" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact contact@wyona.com
   *
   * 5. Products derived from this software may not be called "Lenya" nor
   *    may "Lenya" appear in their names without prior written permission
   *    of Wyona.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment: "This product includes software developed by Wyona
   *    (http://www.wyona.com)"
   *
   * THIS SOFTWARE IS PROVIDED BY Wyona "AS IS" WITHOUT ANY WARRANTY EXPRESS
   * OR IMPLIED, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED
   * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   * Wyona WILL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY YOU AS A RESULT
   * OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE FOR ANY SPECIAL,
   * INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF Wyona HAS BEEN
   * ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. Wyona WILL NOT BE LIABLE
   * FOR ANY THIRD PARTY CLAIMS AGAINST YOU.
   *
   * Lenya includes software developed by the Apache Software Foundation, W3C,
   * DOM4J Project, BitfluxEditor and Xopus.
   * </License>
   */
   
  package org.apache.lenya.cms.ac;
  
  import java.io.File;
  import java.io.FileFilter;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.lenya.cms.publication.Publication;
  import org.apache.log4j.Category;
  
  /**
   * @author egli
   * 
   * 
   */
  public class RoleManager extends ItemManager {
  	private static Category log = Category.getInstance(RoleManager.class);
  
  	protected static final String SUFFIX = ".rml";
  
  	private static Map instances = new HashMap();
  
  	/**
  	 * @param publication
  	 * @throws AccessControlException
  	 */
  	private RoleManager(Publication publication)
  		throws AccessControlException {
  		super(publication);
  	}
  
  
  	public static RoleManager instance(Publication publication)
  		throws AccessControlException {
  		if (!instances.containsKey(publication))
  			instances.put(publication, new RoleManager(publication));
  		return (RoleManager) instances.get(publication);
  	}
  
  	public Iterator getRoles() {
  		return super.getItems();
  	}
  
  	public void add(Role role) {
  		super.add(role);
  	}
  
  	public void remove(Role role) {
  		super.remove(role);
  	}
  
  	public Role getRole(String roleName) {
  		Role role = null;
  		Iterator iter = getRoles();
  		while (iter.hasNext()) {
  			Role element = (Role) iter.next();
  			if (element.getName().equals(roleName)) {
  				role = element;
  			}
  		}
  		return role;
  	}
  	
  
     /* (non-Javadoc)
  	 * @see org.apache.lenya.cms.ac.ItemManager#getFileFilter()
  	 */
  	protected FileFilter getFileFilter() {
  		FileFilter filter = new FileFilter() {
  
  			public boolean accept(File pathname) {
  				return (pathname.getName().endsWith(SUFFIX));
  			}
  		};
  		return filter;
  	}
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org