svn commit: r617035 [2/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/org...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileItemManager.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileItemManager.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileItemManager.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileItemManager.java Wed Jan 30 23:44:03 2008
@@ -16,7 +16,6 @@
  */
 /* $Id$  */
 package org.apache.lenya.ac.file;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
@@ -36,426 +35,423 @@
 import org.apache.lenya.ac.Item;
 import org.apache.lenya.ac.ItemManagerListener;
 import org.apache.lenya.ac.impl.ItemConfiguration;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
- * Abstract superclass for classes that manage items loaded from configuration
- * files.
+ * Abstract superclass for classes that manage items loaded from configuration files.
  */
 public abstract class FileItemManager {
-    private static final Category log = Category.getInstance(FileItemManager.class);
-    public static final String PATH = "config" + File.separator + "ac" + File.separator + "passwd";
-    private Map items = new HashMap();
-    private File configurationDirectory;
-    private DirectoryChangeNotifier notifier;
-    /**
-     * Create a new ItemManager
-     * 
-     * @param configurationDirectory
-     *            where the items are fetched from
-     * @throws AccessControlException
-     *             if the item manager cannot be instantiated
-     */
-    protected FileItemManager(File configurationDirectory) throws AccessControlException {
-        // assert configurationDirectory != null;
-        if (!configurationDirectory.exists() || !configurationDirectory.isDirectory()) {
-            throw new AccessControlException("The directory [" + configurationDirectory.getAbsolutePath() + "] does not exist!");
-        }
-        this.configurationDirectory = configurationDirectory;
-        notifier = new DirectoryChangeNotifier(configurationDirectory, getFileFilter());
-        loadItems();
-    }
-    /**
-     * Reloads the items if an item was changed / added / removed.
-     * 
-     * @throws AccessControlException
-     *             when something went wrong.
-     */
-    protected void loadItems() throws AccessControlException {
-        boolean changed;
-        try {
-            changed = notifier.hasChanged();
-        } catch (IOException e) {
-            throw new AccessControlException(e);
-        }
-        if (changed) {
-            if (log.isDebugEnabled()) {
-                log.debug("Item configuration has changed - reloading.");
+   private static Logger log = Logger.getLogger(FileItemManager.class);
+   public static final String PATH = "config" + File.separator + "ac" + File.separator + "passwd";
+   private Map items = new HashMap();
+   private File configurationDirectory;
+   private DirectoryChangeNotifier notifier;
+   /**
+    * Create a new ItemManager
+    * 
+    * @param configurationDirectory
+    *           where the items are fetched from
+    * @throws AccessControlException
+    *            if the item manager cannot be instantiated
+    */
+   protected FileItemManager(File configurationDirectory) throws AccessControlException {
+      // assert configurationDirectory != null;
+      if(!configurationDirectory.exists() || !configurationDirectory.isDirectory()){
+         throw new AccessControlException("The directory [" + configurationDirectory.getAbsolutePath() + "] does not exist!");
+      }
+      this.configurationDirectory = configurationDirectory;
+      notifier = new DirectoryChangeNotifier(configurationDirectory, getFileFilter());
+      loadItems();
+   }
+   /**
+    * Reloads the items if an item was changed / added / removed.
+    * 
+    * @throws AccessControlException
+    *            when something went wrong.
+    */
+   protected void loadItems() throws AccessControlException {
+      boolean changed;
+      try{
+         changed = notifier.hasChanged();
+      }catch(IOException e){
+         throw new AccessControlException(e);
+      }
+      if(changed){
+         if(log.isDebugEnabled()){
+            log.debug("Item configuration has changed - reloading.");
+         }
+         File[] addedFiles = notifier.getAddedFiles();
+         for(int i = 0; i < addedFiles.length; i++){
+            Item item = loadItem(addedFiles[i]);
+            add(item);
+         }
+         File[] removedFiles = notifier.getRemovedFiles();
+         for(int i = 0; i < removedFiles.length; i++){
+            String fileName = removedFiles[i].getName();
+            String id = fileName.substring(0, fileName.length() - getSuffix().length());
+            Item item = (Item) items.get(id);
+            if(item != null){
+               if(item instanceof Groupable){
+                  ((Groupable) item).removeFromAllGroups();
+               }
+               if(item instanceof Group){
+                  ((Group) item).removeAllMembers();
+               }
+               remove(item);
             }
-            File[] addedFiles = notifier.getAddedFiles();
-            for (int i = 0; i < addedFiles.length; i++) {
-                Item item = loadItem(addedFiles[i]);
-                add(item);
-            }
-            File[] removedFiles = notifier.getRemovedFiles();
-            for (int i = 0; i < removedFiles.length; i++) {
-                String fileName = removedFiles[i].getName();
-                String id = fileName.substring(0, fileName.length() - getSuffix().length());
-                Item item = (Item) items.get(id);
-                if (item != null) {
-                    if (item instanceof Groupable) {
-                        ((Groupable) item).removeFromAllGroups();
-                    }
-                    if (item instanceof Group) {
-                        ((Group) item).removeAllMembers();
-                    }
-                    remove(item);
-                }
-            }
-            File[] changedFiles = notifier.getChangedFiles();
-            for (int i = 0; i < changedFiles.length; i++) {
-                Item item = loadItem(changedFiles[i]);
-                update(item);
-            }
-        }
-    }
-    /**
-     * Loads an item from a file.
-     * 
-     * @param file
-     *            The file.
-     * @return An item.
-     * @throws AccessControlException
-     *             when something went wrong.
-     */
-    protected Item loadItem(File file) throws AccessControlException {
-        Configuration config = getItemConfiguration(file);
-        String fileName = file.getName();
-        String id = fileName.substring(0, fileName.length() - getSuffix().length());
-        Item item = (Item) items.get(id);
-        String klass = getItemClass(config);
-        if (item == null) {
-            try {
-                item = (Item) Class.forName(klass).newInstance();
-            } catch (Exception e) {
-                String errorMsg = "Exception when trying to instanciate: " + klass + " with exception: " + e.fillInStackTrace();
-                // an exception occured when trying to instanciate
-                // a user.
-                log.error(errorMsg);
-                throw new AccessControlException(errorMsg, e);
-            }
-            item.setConfigurationDirectory(configurationDirectory);
-        }
-        try {
-            item.configure(config);
-        } catch (ConfigurationException e) {
-            String errorMsg = "Exception when trying to configure: " + klass;
-            throw new AccessControlException(errorMsg, e);
-        }
-        return item;
-    }
-    /**
-     * Returns the class name of an item.
-     * 
-     * @param config
-     *            The item configuration.
-     * @return The class name.
-     * @throws AccessControlException
-     *             when something went wrong.
-     */
-    protected String getItemClass(Configuration config) throws AccessControlException {
-        String klass = null;
-        try {
-            klass = config.getAttribute(ItemConfiguration.CLASS_ATTRIBUTE);
-        } catch (ConfigurationException e) {
-            String errorMsg = "Exception when extracting class name from identity file: " + klass + config.getAttributeNames();
-            log.error(errorMsg);
-            throw new AccessControlException(errorMsg, e);
-        }
-        return klass;
-    }
-    /**
-     * Loads teh configuration of an item from a file.
-     * 
-     * @param file
-     *            The file.
-     * @return A configuration.
-     * @throws AccessControlException
-     *             when something went wrong.
-     */
-    protected Configuration getItemConfiguration(File file) throws AccessControlException {
-        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-        Configuration config = null;
-        try {
-            // assert file.e///xists();
-            config = builder.buildFromFile(file);
-        } catch (Exception e) {
-            String errorMsg = "Exception when reading the configuration from file: " + file.getName();
-            // an exception occured when trying to read the configuration
-            // from the identity file.
+         }
+         File[] changedFiles = notifier.getChangedFiles();
+         for(int i = 0; i < changedFiles.length; i++){
+            Item item = loadItem(changedFiles[i]);
+            update(item);
+         }
+      }
+   }
+   /**
+    * Loads an item from a file.
+    * 
+    * @param file
+    *           The file.
+    * @return An item.
+    * @throws AccessControlException
+    *            when something went wrong.
+    */
+   protected Item loadItem(File file) throws AccessControlException {
+      Configuration config = getItemConfiguration(file);
+      String fileName = file.getName();
+      String id = fileName.substring(0, fileName.length() - getSuffix().length());
+      Item item = (Item) items.get(id);
+      String klass = getItemClass(config);
+      if(item == null){
+         try{
+            item = (Item) Class.forName(klass).newInstance();
+         }catch(Exception e){
+            String errorMsg = "Exception when trying to instanciate: " + klass + " with exception: " + e.fillInStackTrace();
+            // an exception occured when trying to instanciate
+            // a user.
             log.error(errorMsg);
             throw new AccessControlException(errorMsg, e);
-        }
-        return config;
-    }
-    protected void removeItem(File file) {
-    }
-    /**
-     * Returns an item for a given ID.
-     * 
-     * @param id
-     *            The id.
-     * @return An item.
-     */
-    public Item getItem(String id) {
-        try {
-            loadItems();
-        } catch (AccessControlException e) {
-            throw new IllegalStateException(e.getMessage());
-        }
-        return (Item) items.get(id);
-    }
-    /**
-     * get all items
-     * 
-     * @return an array of items
-     */
-    public Item[] getItems() {
-        try {
-            loadItems();
-        } catch (AccessControlException e) {
-            throw new IllegalStateException(e.getMessage());
-        }
-        return (Item[]) items.values().toArray(new Item[items.values().size()]);
-    }
-    /**
-     * Add an Item to this manager
-     * 
-     * @param item
-     *            to be added
-     * @throws AccessControlException
-     *             when the notification threw this exception.
-     */
-    public void add(Item item) throws AccessControlException {
-        // assert item != null;
-        items.put(item.getId(), item);
-        if (log.isDebugEnabled()) {
-            log.debug("Item [" + item + "] added.");
-        }
-        notifyAdded(item);
-    }
-    /**
-     * Remove an item from this manager
-     * 
-     * @param item
-     *            to be removed
-     * @throws AccessControlException
-     *             when the notification threw this exception.
-     */
-    public void remove(Item item) throws AccessControlException {
-        items.remove(item.getId());
-        if (log.isDebugEnabled()) {
-            log.debug("Item [" + item + "] removed.");
-        }
-        notifyRemoved(item);
-    }
-    /**
-     * Update an item.
-     * 
-     * @param newItem
-     *            The new version of the item.
-     * @throws AccessControlException
-     *             when the notification threw this exception.
-     */
-    public void update(Item newItem) throws AccessControlException {
-        items.remove(newItem.getId());
-        items.put(newItem.getId(), newItem);
-        if (log.isDebugEnabled()) {
-            log.debug("Item [" + newItem + "] updated.");
-        }
-    }
-    /**
-     * Returns if the ItemManager contains an object.
-     * 
-     * @param item
-     *            The object.
-     * @return A boolean value.
-     */
-    public boolean contains(Item item) {
-        try {
-            loadItems();
-        } catch (AccessControlException e) {
-            throw new IllegalStateException(e.getMessage());
-        }
-        return items.containsValue(item);
-    }
-    /**
-     * Get the directory where the items are located.
-     * 
-     * @return a <code>File</code>
-     */
-    public File getConfigurationDirectory() {
-        return configurationDirectory;
-    }
-    /**
-     * Get a file filter which filters for files containing items.
-     * 
-     * @return a <code>FileFilter</code>
-     */
-    protected FileFilter getFileFilter() {
-        FileFilter filter = new FileFilter() {
-            public boolean accept(File pathname) {
-                return (pathname.getName().endsWith(getSuffix()));
-            }
-        };
-        return filter;
-    }
-    /**
-     * Returns the file extension to be used.
-     * 
-     * @return A string.
-     */
-    protected abstract String getSuffix();
-    private List itemManagerListeners = new ArrayList();
-    /**
-     * Attaches an item manager listener to this item manager.
-     * 
-     * @param listener
-     *            An item manager listener.
-     */
-    public void addItemManagerListener(ItemManagerListener listener) {
-        log.debug("Adding listener: [" + listener + "]");
-        if (!itemManagerListeners.contains(listener)) {
-            itemManagerListeners.add(listener);
-        }
-    }
-    /**
-     * Removes an item manager listener from this item manager.
-     * 
-     * @param listener
-     *            An item manager listener.
-     */
-    public void removeItemManagerListener(ItemManagerListener listener) {
-        log.debug("Removing listener: [" + listener + "]");
-        itemManagerListeners.remove(listener);
-    }
-    /**
-     * Notifies the listeners that an item was added.
-     * 
-     * @param item
-     *            The item that was added.
-     * @throws AccessControlException
-     *             if an error occurs.
-     */
-    protected void notifyAdded(Item item) throws AccessControlException {
-        log.debug("Item was added: [" + item + "]");
-        List clone = new ArrayList(itemManagerListeners);
-        for (Iterator i = clone.iterator(); i.hasNext();) {
-            ItemManagerListener listener = (ItemManagerListener) i.next();
-            listener.itemAdded(item);
-        }
-    }
-    /**
-     * Notifies the listeners that an item was removed.
-     * 
-     * @param item
-     *            The item that was removed.
-     * @throws AccessControlException
-     *             if an error occurs.
-     */
-    protected void notifyRemoved(Item item) throws AccessControlException {
-        log.debug("Item was removed: [" + item + "]");
-        List clone = new ArrayList(itemManagerListeners);
-        for (Iterator i = clone.iterator(); i.hasNext();) {
-            ItemManagerListener listener = (ItemManagerListener) i.next();
-            log.debug("Notifying listener: [" + listener + "]");
-            listener.itemRemoved(item);
-        }
-    }
-    /**
-     * Helper class to observe a directory for changes.
-     */
-    public static class DirectoryChangeNotifier {
-        /**
-         * Ctor.
-         * 
-         * @param directory
-         *            The directory to observe.
-         * @param filter
-         *            A filter to specify the file type to observe.
-         */
-        public DirectoryChangeNotifier(File directory, FileFilter filter) {
-            this.directory = directory;
-            this.filter = filter;
-        }
-        private File directory;
-        private FileFilter filter;
-        private Map canonicalPath2LastModified = new HashMap();
-        private static final Category log = Category.getInstance(DirectoryChangeNotifier.class);
-        private Set addedFiles = new HashSet();
-        private Set removedFiles = new HashSet();
-        private Set changedFiles = new HashSet();
-        /**
-         * Checks if the directory has changed (a new file was added, a file was
-         * removed, a file has changed).
-         * 
-         * @return A boolean value.
-         * @throws IOException
-         *             when something went wrong.
-         */
-        public boolean hasChanged() throws IOException {
-            addedFiles.clear();
-            removedFiles.clear();
-            changedFiles.clear();
-            File[] files = directory.listFiles(filter);
-            Set newPathSet = new HashSet();
-            for (int i = 0; i < files.length; i++) {
-                String canonicalPath = files[i].getCanonicalPath();
-                newPathSet.add(canonicalPath);
-                if (!canonicalPath2LastModified.containsKey(canonicalPath)) {
-                    addedFiles.add(new File(canonicalPath));
-                    if (log.isDebugEnabled()) {
-                        log.debug("New file: [" + canonicalPath + "]");
-                    }
-                } else {
-                    Long lastModifiedObject = (Long) canonicalPath2LastModified.get(canonicalPath);
-                    long lastModified = lastModifiedObject.longValue();
-                    if (lastModified < files[i].lastModified()) {
-                        changedFiles.add(files[i]);
-                        if (log.isDebugEnabled()) {
-                            log.debug("File has changed: [" + canonicalPath + "]");
-                        }
-                    }
-                }
-                Long lastModified = new Long(files[i].lastModified());
-                canonicalPath2LastModified.put(canonicalPath, lastModified);
+         }
+         item.setConfigurationDirectory(configurationDirectory);
+      }
+      try{
+         item.configure(config);
+      }catch(ConfigurationException e){
+         String errorMsg = "Exception when trying to configure: " + klass;
+         throw new AccessControlException(errorMsg, e);
+      }
+      return item;
+   }
+   /**
+    * Returns the class name of an item.
+    * 
+    * @param config
+    *           The item configuration.
+    * @return The class name.
+    * @throws AccessControlException
+    *            when something went wrong.
+    */
+   protected String getItemClass(Configuration config) throws AccessControlException {
+      String klass = null;
+      try{
+         klass = config.getAttribute(ItemConfiguration.CLASS_ATTRIBUTE);
+      }catch(ConfigurationException e){
+         String errorMsg = "Exception when extracting class name from identity file: " + klass + config.getAttributeNames();
+         log.error(errorMsg);
+         throw new AccessControlException(errorMsg, e);
+      }
+      return klass;
+   }
+   /**
+    * Loads teh configuration of an item from a file.
+    * 
+    * @param file
+    *           The file.
+    * @return A configuration.
+    * @throws AccessControlException
+    *            when something went wrong.
+    */
+   protected Configuration getItemConfiguration(File file) throws AccessControlException {
+      DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+      Configuration config = null;
+      try{
+         // assert file.e///xists();
+         config = builder.buildFromFile(file);
+      }catch(Exception e){
+         String errorMsg = "Exception when reading the configuration from file: " + file.getName();
+         // an exception occured when trying to read the configuration
+         // from the identity file.
+         log.error(errorMsg);
+         throw new AccessControlException(errorMsg, e);
+      }
+      return config;
+   }
+   protected void removeItem(File file) {
+   }
+   /**
+    * Returns an item for a given ID.
+    * 
+    * @param id
+    *           The id.
+    * @return An item.
+    */
+   public Item getItem(String id) {
+      try{
+         loadItems();
+      }catch(AccessControlException e){
+         throw new IllegalStateException(e.getMessage());
+      }
+      return (Item) items.get(id);
+   }
+   /**
+    * get all items
+    * 
+    * @return an array of items
+    */
+   public Item[] getItems() {
+      try{
+         loadItems();
+      }catch(AccessControlException e){
+         throw new IllegalStateException(e.getMessage());
+      }
+      return (Item[]) items.values().toArray(new Item[items.values().size()]);
+   }
+   /**
+    * Add an Item to this manager
+    * 
+    * @param item
+    *           to be added
+    * @throws AccessControlException
+    *            when the notification threw this exception.
+    */
+   public void add(Item item) throws AccessControlException {
+      // assert item != null;
+      items.put(item.getId(), item);
+      if(log.isDebugEnabled()){
+         log.debug("Item [" + item + "] added.");
+      }
+      notifyAdded(item);
+   }
+   /**
+    * Remove an item from this manager
+    * 
+    * @param item
+    *           to be removed
+    * @throws AccessControlException
+    *            when the notification threw this exception.
+    */
+   public void remove(Item item) throws AccessControlException {
+      items.remove(item.getId());
+      if(log.isDebugEnabled()){
+         log.debug("Item [" + item + "] removed.");
+      }
+      notifyRemoved(item);
+   }
+   /**
+    * Update an item.
+    * 
+    * @param newItem
+    *           The new version of the item.
+    * @throws AccessControlException
+    *            when the notification threw this exception.
+    */
+   public void update(Item newItem) throws AccessControlException {
+      items.remove(newItem.getId());
+      items.put(newItem.getId(), newItem);
+      if(log.isDebugEnabled()){
+         log.debug("Item [" + newItem + "] updated.");
+      }
+   }
+   /**
+    * Returns if the ItemManager contains an object.
+    * 
+    * @param item
+    *           The object.
+    * @return A boolean value.
+    */
+   public boolean contains(Item item) {
+      try{
+         loadItems();
+      }catch(AccessControlException e){
+         throw new IllegalStateException(e.getMessage());
+      }
+      return items.containsValue(item);
+   }
+   /**
+    * Get the directory where the items are located.
+    * 
+    * @return a <code>File</code>
+    */
+   public File getConfigurationDirectory() {
+      return configurationDirectory;
+   }
+   /**
+    * Get a file filter which filters for files containing items.
+    * 
+    * @return a <code>FileFilter</code>
+    */
+   protected FileFilter getFileFilter() {
+      FileFilter filter = new FileFilter() {
+         public boolean accept(File pathname) {
+            return(pathname.getName().endsWith(getSuffix()));
+         }
+      };
+      return filter;
+   }
+   /**
+    * Returns the file extension to be used.
+    * 
+    * @return A string.
+    */
+   protected abstract String getSuffix();
+   private List itemManagerListeners = new ArrayList();
+   /**
+    * Attaches an item manager listener to this item manager.
+    * 
+    * @param listener
+    *           An item manager listener.
+    */
+   public void addItemManagerListener(ItemManagerListener listener) {
+      log.debug("Adding listener: [" + listener + "]");
+      if(!itemManagerListeners.contains(listener)){
+         itemManagerListeners.add(listener);
+      }
+   }
+   /**
+    * Removes an item manager listener from this item manager.
+    * 
+    * @param listener
+    *           An item manager listener.
+    */
+   public void removeItemManagerListener(ItemManagerListener listener) {
+      log.debug("Removing listener: [" + listener + "]");
+      itemManagerListeners.remove(listener);
+   }
+   /**
+    * Notifies the listeners that an item was added.
+    * 
+    * @param item
+    *           The item that was added.
+    * @throws AccessControlException
+    *            if an error occurs.
+    */
+   protected void notifyAdded(Item item) throws AccessControlException {
+      log.debug("Item was added: [" + item + "]");
+      List clone = new ArrayList(itemManagerListeners);
+      for(Iterator i = clone.iterator(); i.hasNext();){
+         ItemManagerListener listener = (ItemManagerListener) i.next();
+         listener.itemAdded(item);
+      }
+   }
+   /**
+    * Notifies the listeners that an item was removed.
+    * 
+    * @param item
+    *           The item that was removed.
+    * @throws AccessControlException
+    *            if an error occurs.
+    */
+   protected void notifyRemoved(Item item) throws AccessControlException {
+      log.debug("Item was removed: [" + item + "]");
+      List clone = new ArrayList(itemManagerListeners);
+      for(Iterator i = clone.iterator(); i.hasNext();){
+         ItemManagerListener listener = (ItemManagerListener) i.next();
+         log.debug("Notifying listener: [" + listener + "]");
+         listener.itemRemoved(item);
+      }
+   }
+   /**
+    * Helper class to observe a directory for changes.
+    */
+   public static class DirectoryChangeNotifier {
+      /**
+       * Ctor.
+       * 
+       * @param directory
+       *           The directory to observe.
+       * @param filter
+       *           A filter to specify the file type to observe.
+       */
+      public DirectoryChangeNotifier(File directory, FileFilter filter) {
+         this.directory = directory;
+         this.filter = filter;
+      }
+      private File directory;
+      private FileFilter filter;
+      private Map canonicalPath2LastModified = new HashMap();
+      private static Logger log = Logger.getLogger(DirectoryChangeNotifier.class);
+      private Set addedFiles = new HashSet();
+      private Set removedFiles = new HashSet();
+      private Set changedFiles = new HashSet();
+      /**
+       * Checks if the directory has changed (a new file was added, a file was removed, a file has changed).
+       * 
+       * @return A boolean value.
+       * @throws IOException
+       *            when something went wrong.
+       */
+      public boolean hasChanged() throws IOException {
+         addedFiles.clear();
+         removedFiles.clear();
+         changedFiles.clear();
+         File[] files = directory.listFiles(filter);
+         Set newPathSet = new HashSet();
+         for(int i = 0; i < files.length; i++){
+            String canonicalPath = files[i].getCanonicalPath();
+            newPathSet.add(canonicalPath);
+            if(!canonicalPath2LastModified.containsKey(canonicalPath)){
+               addedFiles.add(new File(canonicalPath));
+               if(log.isDebugEnabled()){
+                  log.debug("New file: [" + canonicalPath + "]");
+               }
+            }else{
+               Long lastModifiedObject = (Long) canonicalPath2LastModified.get(canonicalPath);
+               long lastModified = lastModifiedObject.longValue();
+               if(lastModified < files[i].lastModified()){
+                  changedFiles.add(files[i]);
+                  if(log.isDebugEnabled()){
+                     log.debug("File has changed: [" + canonicalPath + "]");
+                  }
+               }
             }
-            Set oldPathSet = canonicalPath2LastModified.keySet();
-            String[] oldPaths = (String[]) oldPathSet.toArray(new String[oldPathSet.size()]);
-            for (int i = 0; i < oldPaths.length; i++) {
-                if (!newPathSet.contains(oldPaths[i])) {
-                    removedFiles.add(new File(oldPaths[i]));
-                    canonicalPath2LastModified.remove(oldPaths[i]);
-                    if (log.isDebugEnabled()) {
-                        log.debug("File removed: [" + oldPaths[i] + "]");
-                    }
-                }
+            Long lastModified = new Long(files[i].lastModified());
+            canonicalPath2LastModified.put(canonicalPath, lastModified);
+         }
+         Set oldPathSet = canonicalPath2LastModified.keySet();
+         String[] oldPaths = (String[]) oldPathSet.toArray(new String[oldPathSet.size()]);
+         for(int i = 0; i < oldPaths.length; i++){
+            if(!newPathSet.contains(oldPaths[i])){
+               removedFiles.add(new File(oldPaths[i]));
+               canonicalPath2LastModified.remove(oldPaths[i]);
+               if(log.isDebugEnabled()){
+                  log.debug("File removed: [" + oldPaths[i] + "]");
+               }
             }
-            return !addedFiles.isEmpty() || !removedFiles.isEmpty() || !changedFiles.isEmpty();
-        }
-        /**
-         * Returns the added files.
-         * 
-         * @return An array of files.
-         */
-        public File[] getAddedFiles() {
-            return (File[]) addedFiles.toArray(new File[addedFiles.size()]);
-        }
-        /**
-         * Returns the removed files.
-         * 
-         * @return An array of files.
-         */
-        public File[] getRemovedFiles() {
-            return (File[]) removedFiles.toArray(new File[removedFiles.size()]);
-        }
-        /**
-         * Returns the changed files.
-         * 
-         * @return An array of files.
-         */
-        public File[] getChangedFiles() {
-            return (File[]) changedFiles.toArray(new File[changedFiles.size()]);
-        }
-    }
+         }
+         return !addedFiles.isEmpty() || !removedFiles.isEmpty() || !changedFiles.isEmpty();
+      }
+      /**
+       * Returns the added files.
+       * 
+       * @return An array of files.
+       */
+      public File[] getAddedFiles() {
+         return (File[]) addedFiles.toArray(new File[addedFiles.size()]);
+      }
+      /**
+       * Returns the removed files.
+       * 
+       * @return An array of files.
+       */
+      public File[] getRemovedFiles() {
+         return (File[]) removedFiles.toArray(new File[removedFiles.size()]);
+      }
+      /**
+       * Returns the changed files.
+       * 
+       * @return An array of files.
+       */
+      public File[] getChangedFiles() {
+         return (File[]) changedFiles.toArray(new File[changedFiles.size()]);
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileUser.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileUser.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileUser.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/file/FileUser.java Wed Jan 30 23:44:03 2008
@@ -35,7 +35,8 @@
  * @version $Id$
  */
 public class FileUser extends AbstractUser implements Item, Serializable {
-    private static final Logger log = Logger.getLogger(FileUser.class);
+    private static final long serialVersionUID = 1L;
+   private static final Logger log = Logger.getLogger(FileUser.class);
     public static final String ID = "identity";
     public static final String EMAIL = "email";
     public static final String PASSWORD = "password";

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java Wed Jan 30 23:44:03 2008
@@ -14,373 +14,310 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.ac.impl;
-
 import java.io.File;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Arrays;
-
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.IPRange;
 import org.apache.lenya.ac.Machine;
 import org.apache.lenya.net.InetAddressUtil;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
  * <p>
  * A range of IP addresses, expressed by a network address and a subnet mask.
  * </p>
  * <p>
- * Note: this class does not enforce that the network address and the subnet mask have the same size
- * (i.e. either both IPv4 or both IPv6 addresses). If the the network address and subnet mask have
- * different sizes, the range does not contain any hosts, that is {@link #contains(Machine)} will
- * always return <code>false</code>.
+ * Note: this class does not enforce that the network address and the subnet mask have the same size (i.e. either both IPv4 or both IPv6 addresses). If the the network address and subnet mask have different sizes, the range does not contain any hosts, that is {@link #contains(Machine)} will always return <code>false</code>.
  * </p>
  */
 public abstract class AbstractIPRange extends AbstractGroupable implements IPRange {
-    /*
-     * FIXME by [email protected]: Fixed this class for IPv6. However there are still some general
-     * flaws, partly coming from the IPRange interface. A redesign of (Abstract/File)IPRange and
-     * it's helper class org.apache.lenya.net.InetAddressUtil would be a good idea. Some problems of
-     * this implementation are:
-     *  - The whole initialization seems flawed. Objects can be in an unitialized state and the
-     * class seems not to be aware of this.
-     *  - Network-address and -mask can be set independently. Therefore it cannot be enforced that
-     * these have the same size (i.e. that both are IPv4 or both are IPv6). This shows up in
-     * InetAddressUtil.contains(...), where in a case of mismatch there is no good way to inform the
-     * user about the problem. This should be done once when the AbstractIPRange object is
-     * initialized.
-     *  - Unless this functionality would be needed by other parts of Lenya or external software
-     * (which seems not to be the case ;-), InetAddressUtil should be removed (resp. deprecated)
-     * altogether, because it's mostly an internal implementation detail of AbstractIPRange.
-     * AbstractIPRange should implement the contains(...)-method internally to make use of the fact
-     * that the network- addresses and -masks validity and compatibility has already been checked
-     * when setting these. (Once the above problems have been fixed. ;-)
-     *  - Especially for IPv6 it would be nice to have the possibility to specify the netmask as the
-     * number of bits (as in "::1/128" or "127.0.0.1/24").
-     *  - I think, that logging should probably work the "Cocoon-Way", as explained in
-     * <http://wiki.cocoondev.org/Wiki.jsp?page=JavaLogging>, rather than using
-     * org.apache.log4j.Category. (But I may be wrong. ;-)
-     * 
-     * FIXME II (from the previous version): why are we in the business of implementing IP ranges??
-     */
-
-    private static final Category log = Category.getInstance(AbstractIPRange.class);
-
-    /**
-     * Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).
-     */
-    public AbstractIPRange() {
-        try {
-            networkAddress = InetAddress.getLocalHost();
-            byte[] mask = null;
-            int masklen = networkAddress.getAddress().length;
-            if (masklen == 4) {
-                /* IPv4: */
-                /*
-                 * FIXME? by [email protected]: Should this be { -1, 0, 0, 0 }??
-                 */
-                mask = new byte[] { -1, -1, -1, 0 };
-            } else {
-                /* IPv6 (and others ;-): */
-                mask = new byte[masklen];
-                Arrays.fill(mask, (byte) -1);
-            }
-            subnetMask = InetAddress.getByAddress(mask);
-        } catch (UnknownHostException ignore) {
+   /*
+    * FIXME by [email protected]: Fixed this class for IPv6. However there are still some general flaws, partly coming from the IPRange interface. A redesign of (Abstract/File)IPRange and it's helper class org.apache.lenya.net.InetAddressUtil would be a good idea. Some problems of this implementation are: - The whole initialization seems flawed. Objects can be in an unitialized state and the class seems not to be aware of this. - Network-address and -mask can be set independently. Therefore it cannot be enforced that these have the same size (i.e. that both are IPv4 or both are IPv6). This shows up in InetAddressUtil.contains(...), where in a case of mismatch there is no good way to inform the user about the problem. This should be done once when the AbstractIPRange object is initialized. - U
 nless this functionality would be needed by other parts of Lenya or external software (which seems not to be the case ;-), InetAddressUtil should be removed (resp. deprecated) altogether, be
 cause it's
+    * mostly an internal implementation detail of AbstractIPRange. AbstractIPRange should implement the contains(...)-method internally to make use of the fact that the network- addresses and -masks validity and compatibility has already been checked when setting these. (Once the above problems have been fixed. ;-) - Especially for IPv6 it would be nice to have the possibility to specify the netmask as the number of bits (as in "::1/128" or "127.0.0.1/24"). - I think, that logging should probably work the "Cocoon-Way", as explained in <http://wiki.cocoondev.org/Wiki.jsp?page=JavaLogging>, rather than using org.apache.log4j.Category. (But I may be wrong. ;-)
+    * 
+    * FIXME II (from the previous version): why are we in the business of implementing IP ranges??
+    */
+   private static Logger log = Logger.getLogger(AbstractIPRange.class);
+   /**
+    * Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).
+    */
+   public AbstractIPRange() {
+      try{
+         networkAddress = InetAddress.getLocalHost();
+         byte[] mask = null;
+         int masklen = networkAddress.getAddress().length;
+         if(masklen == 4){
+            /* IPv4: */
             /*
-             * FIXME? by [email protected]: Is it safe to ignore the exception and just leave the
-             * IPRange uninitialized!?
+             * FIXME? by [email protected]: Should this be { -1, 0, 0, 0 }??
              */
-        }
-    }
-
-    /**
-     * Ctor.
-     * @param id The IP range ID.
-     */
-    public AbstractIPRange(String id) {
-        /*
-         * FIXME? by [email protected]: Is it safe not to call the default constructor and just leave
-         * the IPRange uninitialized!?
-         */
-        setId(id);
-    }
-
-    private File configurationDirectory;
-
-    /**
-     * Returns the configuration directory.
-     * @return A file object.
-     */
-    public File getConfigurationDirectory() {
-        return configurationDirectory;
-    }
-
-    /**
-     * @see org.apache.lenya.ac.Item#setConfigurationDirectory(java.io.File)
-     */
-    public void setConfigurationDirectory(File configurationDirectory) {
-        this.configurationDirectory = configurationDirectory;
-    }
-
-    /**
-     * Save the IP range
-     * 
-     * @throws AccessControlException if the save failed
-     */
-    public abstract void save() throws AccessControlException;
-
-    /**
-     * Delete an IP range
-     * 
-     * @throws AccessControlException if the delete failed
-     */
-    public void delete() throws AccessControlException {
-        removeFromAllGroups();
-    }
-
-    private InetAddress networkAddress;
-
-    /**
-     * Sets the network address. This method accepts numeric IPv4 addresses like
-     * <code>"129.168.0.32"</code>, numeric IPv6 addresses like
-     * <code>"1080::8:800:200C:417A"</code> as well as hostnames (if DNS resolution is available)
-     * like <code>"localhost"</code> or <code>"www.apache.com"</code>.
-     * 
-     * @param address a <code>String</code> like <code>"192.168.0.32"</code>,
-     *            <code>"::1"</code>, ...
-     * 
-     * @throws AccessControlException when the conversion of the <code>String</code> to an
-     *             <code>InetAddress</code> failed
-     * 
-     * @see #setNetworkAddress(byte[])
-     */
-    public void setNetworkAddress(String address) throws AccessControlException {
-        try {
-            networkAddress = InetAddress.getByName(address);
-        } catch (UnknownHostException e) {
-            throw new AccessControlException("Failed to convert address [" + address + "]: ", e);
-        }
-    }
-
-    /**
-     * Sets the network address. The method accepts numeric IPv4 addresses (specified by byte arrays
-     * of length 4) or IPv6 addresses (specified by byte arrays of length 16).
-     * 
-     * @param address a byte array of the length 4 or 16
-     * 
-     * @throws AccessControlException when the conversion of the byte array to an InetAddress
-     *             failed.
-     * 
-     * @see #setNetworkAddress(String)
-     */
-    public void setNetworkAddress(byte[] address) throws AccessControlException {
-        try {
-            networkAddress = InetAddress.getByAddress(address);
-        } catch (UnknownHostException e) {
-            throw new AccessControlException("Failed to convert address [" + addr2string(address)
-                    + "]: ", e);
-        }
-    }
-
-    /**
-     * Returns the network address.
-     * 
-     * @return an <code>InetAddress</code> representing the network address
-     */
-    public InetAddress getNetworkAddress() {
-        return networkAddress;
-    }
-
-    private InetAddress subnetMask;
-
-    /**
-     * Sets the subnet mask. See {@link #setNetworkAddress(String)} for the allowed formats of the
-     * <code>mask</code> string. (However, the hostname format will usually not be of much use for
-     * setting the mask.)
-     * <p>
-     * Only valid subnet masks are accepted, for which the binary representation is a sequence of
-     * 1-bits followed by a sequence of 0-bits. For example <code>"255.128.0.0"</code> is valid
-     * while <code>"255.128.0.1"</code> is not.
-     * 
-     * @param mask a <code>String</code> like <code>"255.255.255.0"</code>
-     * 
-     * @throws AccessControlException when the conversion of the String to an
-     *             <code>InetAddress</code> failed.
-     * 
-     * @see #setSubnetMask(byte[])
-     */
-    public void setSubnetMask(String mask) throws AccessControlException {
-        try {
-            /* use setSubnetMask(...) to check the mask-format: */
-            setSubnetMask(InetAddress.getByName(mask).getAddress());
-        } catch (UnknownHostException e) {
-            throw new AccessControlException("Failed to convert mask [" + mask + "]: ", e);
-        }
-
-    }
-
-    /**
-     * Sets the subnet mask.
-     * <p>
-     * Only valid subnet masks are accepted, for which the binary representation is a sequence of
-     * 1-bits followed by a sequence of 0-bits. For example <code>{ 255, 128, 0, 0 }</code> is
-     * valid while <code>{ 255, 128, 0, 1 }</code> is not.
-     * 
-     * @param mask A byte array of the length 4.
-     * 
-     * @throws AccessControlException when the conversion of the byte array to an InetAddress
-     *             failed.
-     * 
-     * @see #setSubnetMask(String)
-     */
-    public void setSubnetMask(byte[] mask) throws AccessControlException {
-        /*
-         * check for correct netmask (i.e. any number of 1-bits followed by 0-bits filling the right
-         * part of the mask) ...
-         * 
-         * FIXME: This "algorithm" is rather unelegant. There should be a better way to do it! ;-)
-         */
-        if (log.isDebugEnabled()) {
-            log.debug("CHECK_NETMASK: check " + addr2string(mask));
-        }
-        int i = 0;
-        CHECK_NETMASK: while (i < mask.length) {
-            int b = mask[i++] & 0xff;
-            /* the initial byte(s) must be 255: */
-            if (b != 0xff) {
-                /* first byte != 255, test all possibilities: */
-                if (log.isDebugEnabled()) {
-                    log.debug("CHECK_NETMASK: first byte != 255: idx: " + (i - 1)
-                            + ", mask[idx]: 0x" + b);
-                }
-                /* check if 0: */
-                if (b == 0) {
-                    break CHECK_NETMASK;
-                }
-                for (int tst = 0xfe; tst != 0; tst = (tst << 1) & 0xff) {
-                    log.debug("CHECK_NETMASK: tst == 0x" + Integer.toHexString(tst));
-                    if (b == tst) {
-                        break CHECK_NETMASK;
-                    }
-                }
-                /*
-                 * Invalid byte found, i.e. one which is not element of { 11111111, 11111110,
-                 * 11111100, 11111000, ..., 00000000 }
-                 */
-                throw new AccessControlException("Invalid byte in mask [" + addr2string(mask) + "]");
+            mask = new byte[]{-1, -1, -1, 0};
+         }else{
+            /* IPv6 (and others ;-): */
+            mask = new byte[masklen];
+            Arrays.fill(mask, (byte) -1);
+         }
+         subnetMask = InetAddress.getByAddress(mask);
+      }catch(UnknownHostException ignore){
+         /*
+          * FIXME? by [email protected]: Is it safe to ignore the exception and just leave the IPRange uninitialized!?
+          */
+      }
+   }
+   /**
+    * Ctor.
+    * 
+    * @param id
+    *           The IP range ID.
+    */
+   public AbstractIPRange(String id) {
+      /*
+       * FIXME? by [email protected]: Is it safe not to call the default constructor and just leave the IPRange uninitialized!?
+       */
+      setId(id);
+   }
+   private File configurationDirectory;
+   /**
+    * Returns the configuration directory.
+    * 
+    * @return A file object.
+    */
+   public File getConfigurationDirectory() {
+      return configurationDirectory;
+   }
+   /**
+    * @see org.apache.lenya.ac.Item#setConfigurationDirectory(java.io.File)
+    */
+   public void setConfigurationDirectory(File configurationDirectory) {
+      this.configurationDirectory = configurationDirectory;
+   }
+   /**
+    * Save the IP range
+    * 
+    * @throws AccessControlException
+    *            if the save failed
+    */
+   public abstract void save() throws AccessControlException;
+   /**
+    * Delete an IP range
+    * 
+    * @throws AccessControlException
+    *            if the delete failed
+    */
+   public void delete() throws AccessControlException {
+      removeFromAllGroups();
+   }
+   private InetAddress networkAddress;
+   /**
+    * Sets the network address. This method accepts numeric IPv4 addresses like <code>"129.168.0.32"</code>, numeric IPv6 addresses like <code>"1080::8:800:200C:417A"</code> as well as hostnames (if DNS resolution is available) like <code>"localhost"</code> or <code>"www.apache.com"</code>.
+    * 
+    * @param address
+    *           a <code>String</code> like <code>"192.168.0.32"</code>, <code>"::1"</code>, ...
+    * 
+    * @throws AccessControlException
+    *            when the conversion of the <code>String</code> to an <code>InetAddress</code> failed
+    * 
+    * @see #setNetworkAddress(byte[])
+    */
+   public void setNetworkAddress(String address) throws AccessControlException {
+      try{
+         networkAddress = InetAddress.getByName(address);
+      }catch(UnknownHostException e){
+         throw new AccessControlException("Failed to convert address [" + address + "]: ", e);
+      }
+   }
+   /**
+    * Sets the network address. The method accepts numeric IPv4 addresses (specified by byte arrays of length 4) or IPv6 addresses (specified by byte arrays of length 16).
+    * 
+    * @param address
+    *           a byte array of the length 4 or 16
+    * 
+    * @throws AccessControlException
+    *            when the conversion of the byte array to an InetAddress failed.
+    * 
+    * @see #setNetworkAddress(String)
+    */
+   public void setNetworkAddress(byte[] address) throws AccessControlException {
+      try{
+         networkAddress = InetAddress.getByAddress(address);
+      }catch(UnknownHostException e){
+         throw new AccessControlException("Failed to convert address [" + addr2string(address) + "]: ", e);
+      }
+   }
+   /**
+    * Returns the network address.
+    * 
+    * @return an <code>InetAddress</code> representing the network address
+    */
+   public InetAddress getNetworkAddress() {
+      return networkAddress;
+   }
+   private InetAddress subnetMask;
+   /**
+    * Sets the subnet mask. See {@link #setNetworkAddress(String)} for the allowed formats of the <code>mask</code> string. (However, the hostname format will usually not be of much use for setting the mask.)
+    * <p>
+    * Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example <code>"255.128.0.0"</code> is valid while <code>"255.128.0.1"</code> is not.
+    * 
+    * @param mask
+    *           a <code>String</code> like <code>"255.255.255.0"</code>
+    * 
+    * @throws AccessControlException
+    *            when the conversion of the String to an <code>InetAddress</code> failed.
+    * 
+    * @see #setSubnetMask(byte[])
+    */
+   public void setSubnetMask(String mask) throws AccessControlException {
+      try{
+         /* use setSubnetMask(...) to check the mask-format: */
+         setSubnetMask(InetAddress.getByName(mask).getAddress());
+      }catch(UnknownHostException e){
+         throw new AccessControlException("Failed to convert mask [" + mask + "]: ", e);
+      }
+   }
+   /**
+    * Sets the subnet mask.
+    * <p>
+    * Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example <code>{ 255, 128, 0, 0 }</code> is valid while <code>{ 255, 128, 0, 1 }</code> is not.
+    * 
+    * @param mask
+    *           A byte array of the length 4.
+    * 
+    * @throws AccessControlException
+    *            when the conversion of the byte array to an InetAddress failed.
+    * 
+    * @see #setSubnetMask(String)
+    */
+   public void setSubnetMask(byte[] mask) throws AccessControlException {
+      /*
+       * check for correct netmask (i.e. any number of 1-bits followed by 0-bits filling the right part of the mask) ...
+       * 
+       * FIXME: This "algorithm" is rather unelegant. There should be a better way to do it! ;-)
+       */
+      if(log.isDebugEnabled()){
+         log.debug("CHECK_NETMASK: check " + addr2string(mask));
+      }
+      int i = 0;
+      CHECK_NETMASK : while(i < mask.length){
+         int b = mask[i++] & 0xff;
+         /* the initial byte(s) must be 255: */
+         if(b != 0xff){
+            /* first byte != 255, test all possibilities: */
+            if(log.isDebugEnabled()){
+               log.debug("CHECK_NETMASK: first byte != 255: idx: " + (i - 1) + ", mask[idx]: 0x" + b);
+            }
+            /* check if 0: */
+            if(b == 0){
+               break CHECK_NETMASK;
             }
-        }
-        /* the remaining byte(s) (if any) must be 0: */
-        while (++i < mask.length) {
-            if (mask[i] != 0) {
-                /*
-                 * Invalid byte found, i.e. some non-zero byte right of the first non-zero byte.
-                 */
-                throw new AccessControlException("Invalid non-zero byte in mask ["
-                        + addr2string(mask) + "]");
+            for(int tst = 0xfe; tst != 0; tst = (tst << 1) & 0xff){
+               log.debug("CHECK_NETMASK: tst == 0x" + Integer.toHexString(tst));
+               if(b == tst){
+                  break CHECK_NETMASK;
+               }
+            }
+            /*
+             * Invalid byte found, i.e. one which is not element of { 11111111, 11111110, 11111100, 11111000, ..., 00000000 }
+             */
+            throw new AccessControlException("Invalid byte in mask [" + addr2string(mask) + "]");
+         }
+      }
+      /* the remaining byte(s) (if any) must be 0: */
+      while(++i < mask.length){
+         if(mask[i] != 0){
+            /*
+             * Invalid byte found, i.e. some non-zero byte right of the first non-zero byte.
+             */
+            throw new AccessControlException("Invalid non-zero byte in mask [" + addr2string(mask) + "]");
+         }
+      }
+      /* convert the checked mask to InetAddress: */
+      try{
+         subnetMask = InetAddress.getByAddress(mask);
+      }catch(UnknownHostException e){
+         throw new AccessControlException("Failed to convert mask [" + addr2string(mask) + "]: ", e);
+      }
+   }
+   /**
+    * Returns the subnet mask.
+    * 
+    * @return An InetAddress value.
+    */
+   public InetAddress getSubnetMask() {
+      return subnetMask;
+   }
+   /**
+    * Checks if a network address / subnet mask combination describes a valid subnet.
+    * 
+    * @param networkAddress
+    *           The network address.
+    * @param subnetMask
+    *           The subnet mask.
+    * @return A boolean value.
+    * 
+    * @deprecated This method is currently not implemented, probably not necessary.and could be removed in the future. Therefore it should not be used.
+    */
+   public static boolean isValidSubnet(InetAddress networkAddress, InetAddress subnetMask) {
+      /*
+       * FIXME? by [email protected]: Is this method really necessary (what for?) and (if so) shouldn't it be an internal (private) utility-method??
+       */
+      // TODO implement class
+      return false;
+   }
+   /**
+    * Checks if this IP range contains a certain machine.
+    * <p>
+    * Note: if the network address and the subnet mask of this IP range have different sizes (i.e. one is IPv4 and one is IPv6), this method will always return <code>false</code>, no matter what machine has been specified!
+    * <p>
+    * Further, if the machine address and the IP range (i.e. network address and subnet mask) have different sizes, the method will return <code>false</code>. (In other words: an IPv4 range never contains an IPv6 address and the other way round.)
+    * <p>
+    * Note that the above can lead to confusion. For example the local subnet in IPv4 ( <code>127.0.0.0/8</code>) will <b>not </b> contain the localhost in IPv6 ( <code>::1</code>), and the localhost in IPv4 (<code>127.0.0.1</code>) will <b>not </b> be contained in the local subnet in IPv6 (<code>::1/128</code>).
+    * 
+    * @param machine
+    *           the machine to check for
+    * @return a boolean value
+    * 
+    * @see InetAddressUtil#contains
+    */
+   public boolean contains(Machine machine) {
+      /*
+       * FIXME? by [email protected]: Maybe some mapping between IPv4/v6 should be done here, p.e. for the localhost (see the javdoc comment above)? (I'm not a TCP/IP-guru, so I'm not sure about this. ;-)
+       */
+      log.debug("Checking IP range: [" + getId() + "]");
+      return InetAddressUtil.contains(networkAddress, subnetMask, machine.getAddress());
+   }
+   /**
+    * Format the specified numeric IP address.
+    * 
+    * @param addr
+    *           the raw numeric IP address
+    * @return the formatted address
+    */
+   private static String addr2string(byte[] addr) {
+      StringBuffer buf = new StringBuffer();
+      if(addr.length > 4){
+         /* IPv6-format if more than 4 bytes: */
+         for(int i = 0; i < addr.length; i++){
+            if(i > 0 && (i & 1) == 0){
+               buf.append(':');
             }
-        }
-
-        /* convert the checked mask to InetAddress: */
-        try {
-            subnetMask = InetAddress.getByAddress(mask);
-        } catch (UnknownHostException e) {
-            throw new AccessControlException(
-                    "Failed to convert mask [" + addr2string(mask) + "]: ", e);
-        }
-    }
-
-    /**
-     * Returns the subnet mask.
-     * @return An InetAddress value.
-     */
-    public InetAddress getSubnetMask() {
-        return subnetMask;
-    }
-
-    /**
-     * Checks if a network address / subnet mask combination describes a valid subnet.
-     * @param networkAddress The network address.
-     * @param subnetMask The subnet mask.
-     * @return A boolean value.
-     * 
-     * @deprecated This method is currently not implemented, probably not necessary.and could be
-     *             removed in the future. Therefore it should not be used.
-     */
-    public static boolean isValidSubnet(InetAddress networkAddress, InetAddress subnetMask) {
-        /*
-         * FIXME? by [email protected]: Is this method really necessary (what for?) and (if so)
-         * shouldn't it be an internal (private) utility-method??
-         */
-        // TODO implement class
-        return false;
-    }
-
-    /**
-     * Checks if this IP range contains a certain machine.
-     * <p>
-     * Note: if the network address and the subnet mask of this IP range have different sizes (i.e.
-     * one is IPv4 and one is IPv6), this method will always return <code>false</code>, no matter
-     * what machine has been specified!
-     * <p>
-     * Further, if the machine address and the IP range (i.e. network address and subnet mask) have
-     * different sizes, the method will return <code>false</code>. (In other words: an IPv4 range
-     * never contains an IPv6 address and the other way round.)
-     * <p>
-     * Note that the above can lead to confusion. For example the local subnet in IPv4 (
-     * <code>127.0.0.0/8</code>) will <b>not </b> contain the localhost in IPv6 (
-     * <code>::1</code>), and the localhost in IPv4 (<code>127.0.0.1</code>) will <b>not </b>
-     * be contained in the local subnet in IPv6 (<code>::1/128</code>).
-     * 
-     * @param machine the machine to check for
-     * @return a boolean value
-     * 
-     * @see InetAddressUtil#contains
-     */
-    public boolean contains(Machine machine) {
-        /*
-         * FIXME? by [email protected]: Maybe some mapping between IPv4/v6 should be done here, p.e. for
-         * the localhost (see the javdoc comment above)? (I'm not a TCP/IP-guru, so I'm not sure
-         * about this. ;-)
-         */
-        log.debug("Checking IP range: [" + getId() + "]");
-        return InetAddressUtil.contains(networkAddress, subnetMask, machine.getAddress());
-    }
-
-    /**
-     * Format the specified numeric IP address.
-     * @param addr the raw numeric IP address
-     * @return the formatted address
-     */
-    private static String addr2string(byte[] addr) {
-        StringBuffer buf = new StringBuffer();
-        if (addr.length > 4) {
-            /* IPv6-format if more than 4 bytes: */
-            for (int i = 0; i < addr.length; i++) {
-                if (i > 0 && (i & 1) == 0) {
-                    buf.append(':');
-                }
-                String hex = Integer.toHexString(addr[i] & 0xff);
-                if (hex.length() == 1) {
-                    buf.append('0');
-                }
-                buf.append(hex);
+            String hex = Integer.toHexString(addr[i] & 0xff);
+            if(hex.length() == 1){
+               buf.append('0');
             }
-        } else {
-            /* IPv4-format: */
-            for (int i = 0; i < addr.length; i++) {
-                if (i > 0) {
-                    buf.append('.');
-                }
-                buf.append(addr[i] & 0xff);
+            buf.append(hex);
+         }
+      }else{
+         /* IPv4-format: */
+         for(int i = 0; i < addr.length; i++){
+            if(i > 0){
+               buf.append('.');
             }
-        }
-        return buf.toString();
-    }
+            buf.append(addr[i] & 0xff);
+         }
+      }
+      return buf.toString();
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractUser.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractUser.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractUser.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/impl/AbstractUser.java Wed Jan 30 23:44:03 2008
@@ -14,141 +14,132 @@
  *  limitations under the License.
  *
  */
-
 package org.apache.lenya.ac.impl;
-
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.Password;
 import org.apache.lenya.ac.User;
-import org.apache.log4j.Category;
-
+import org.apache.log4j.Logger;
 /**
  * Abstract user implementation.
+ * 
  * @version $Id$
  */
 public abstract class AbstractUser extends AbstractGroupable implements User {
-
-    private static Category log = Category.getInstance(AbstractUser.class);
-    private String email;
-    private String encryptedPassword;
-    
-    /**
-     * Creates a new User.
-     */
-    public AbstractUser() {
-    }
-
-    /**
-         * Create a User instance
-         *
-         * @param id the user id
-         * @param fullName the full name of the user
-         * @param email the users email address
-         * @param password the users password
-         */
-    public AbstractUser(String id, String fullName, String email, String password) {
-        setId(id);
-        setName(fullName);
-        this.email = email;
-        setPassword(password);
-    }
-
-    /**
-     * Get the email address
-     *
-     * @return a <code>String</code>
-     */
-    public String getEmail() {
-        return email;
-    }
-
-    /**
-     * Get the full name
-     *
-     * @return a <code>String</code>
-     * @deprecated has been superceded by getName()
-     */
-    public String getFullName() {
-        return getName();
-    }
-
-    /**
-     * Set the email address
-     *
-     * @param email the new email address
-     */
-    public void setEmail(String email) {
-        this.email = email;
-    }
-
-    /**
-     * Set the full name
-     *
-     * @param name the new full name
-     * @deprecated has been superceded by setName(String)
-     */
-    public void setFullName(String name) {
-        setName(name);
-    }
-
-    /**
+   private static Logger log = Logger.getLogger(AbstractUser.class);
+   private String email;
+   private String encryptedPassword;
+   /**
+    * Creates a new User.
+    */
+   public AbstractUser() {
+   }
+   /**
+    * Create a User instance
+    * 
+    * @param id
+    *           the user id
+    * @param fullName
+    *           the full name of the user
+    * @param email
+    *           the users email address
+    * @param password
+    *           the users password
+    */
+   public AbstractUser(String id, String fullName, String email, String password) {
+      setId(id);
+      setName(fullName);
+      this.email = email;
+      setPassword(password);
+   }
+   /**
+    * Get the email address
+    * 
+    * @return a <code>String</code>
+    */
+   public String getEmail() {
+      return email;
+   }
+   /**
+    * Get the full name
+    * 
+    * @return a <code>String</code>
+    * @deprecated has been superceded by getName()
+    */
+   public String getFullName() {
+      return getName();
+   }
+   /**
+    * Set the email address
+    * 
+    * @param email
+    *           the new email address
+    */
+   public void setEmail(String email) {
+      this.email = email;
+   }
+   /**
+    * Set the full name
+    * 
+    * @param name
+    *           the new full name
+    * @deprecated has been superceded by setName(String)
+    */
+   public void setFullName(String name) {
+      setName(name);
+   }
+   /**
     * Sets the password.
-     * @param plainTextPassword The plain text passwrod.
-     */
-    public void setPassword(String plainTextPassword) {
-        encryptedPassword = Password.encrypt(plainTextPassword);
-    }
-
-    /**
-     * This method can be used for subclasses to set the password without it
-     * being encrypted again. Some subclass might have knowledge of the encrypted
-     * password and needs to be able to set it.
-     *
-     * @param encryptedPassword the encrypted password
-     */
-    protected void setEncryptedPassword(String encryptedPassword) {
-        this.encryptedPassword = encryptedPassword;
-    }
-
-    /**
-     * Get the encrypted password
-     *
-     * @return the encrypted password
-     */
-    protected String getEncryptedPassword() {
-        return encryptedPassword;
-    }
-
-    /**
-     * Save the user
-     *
-     * @throws AccessControlException if the save failed
-     */
-    public abstract void save() throws AccessControlException;
-
-    /**
-     * Delete a user
-     *
-     * @throws AccessControlException if the delete failed
-     */
-    public void delete() throws AccessControlException {
-        removeFromAllGroups();
-    }
-
-    /**
-     * Authenticate a user. This is done by encrypting
-     * the given password and comparing this to the
-     * encryptedPassword.
-     *
-     * @param password to authenticate with
-     * @return true if the given password matches the password for this user
-     */
-    public boolean authenticate(String password) {
-        log.debug("Password: " + password);
-        log.debug("pw encypted: " + Password.encrypt(password));
-        log.debug("orig encrypted pw: " + this.encryptedPassword);
-
-        return this.encryptedPassword.equals(Password.encrypt(password));
-    }
-    
+    * 
+    * @param plainTextPassword
+    *           The plain text passwrod.
+    */
+   public void setPassword(String plainTextPassword) {
+      encryptedPassword = Password.encrypt(plainTextPassword);
+   }
+   /**
+    * This method can be used for subclasses to set the password without it being encrypted again. Some subclass might have knowledge of the encrypted password and needs to be able to set it.
+    * 
+    * @param encryptedPassword
+    *           the encrypted password
+    */
+   protected void setEncryptedPassword(String encryptedPassword) {
+      this.encryptedPassword = encryptedPassword;
+   }
+   /**
+    * Get the encrypted password
+    * 
+    * @return the encrypted password
+    */
+   protected String getEncryptedPassword() {
+      return encryptedPassword;
+   }
+   /**
+    * Save the user
+    * 
+    * @throws AccessControlException
+    *            if the save failed
+    */
+   public abstract void save() throws AccessControlException;
+   /**
+    * Delete a user
+    * 
+    * @throws AccessControlException
+    *            if the delete failed
+    */
+   public void delete() throws AccessControlException {
+      removeFromAllGroups();
+   }
+   /**
+    * Authenticate a user. This is done by encrypting the given password and comparing this to the encryptedPassword.
+    * 
+    * @param password
+    *           to authenticate with
+    * @return true if the given password matches the password for this user
+    */
+   public boolean authenticate(String password) {
+      log.debug("Password: " + password);
+      log.debug("pw encypted: " + Password.encrypt(password));
+      log.debug("orig encrypted pw: " + this.encryptedPassword);
+      return this.encryptedPassword.equals(Password.encrypt(password));
+   }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.