You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/12/11 18:41:28 UTC

svn commit: r485769 [2/3] - in /lenya/trunk/src: impl/test/org/apache/lenya/cms/publication/ impl/test/org/apache/lenya/transaction/ java/org/apache/lenya/ac/ java/org/apache/lenya/cms/observation/ java/org/apache/lenya/cms/repository/ java/org/apache/...

Modified: lenya/trunk/src/modules-core/ac-impl/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java Mon Dec 11 09:41:23 2006
@@ -51,6 +51,7 @@
 import org.apache.lenya.ac.ItemManagerListener;
 import org.apache.lenya.ac.Machine;
 import org.apache.lenya.ac.PolicyManager;
+import org.apache.lenya.ac.Role;
 
 /**
  * Default access controller implementation.
@@ -446,7 +447,10 @@
             getLogger().debug("Item was removed: [" + item + "]");
             getLogger().debug("Notifying policy manager");
         }
-        getPolicyManager().accreditableRemoved(getAccreditableManager(), (Accreditable) item);
+        
+        if (!(item instanceof Role)) {
+            getPolicyManager().accreditableRemoved(getAccreditableManager(), (Accreditable) item);
+        }
     }
 
 }

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileGroupTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileGroupTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileGroupTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileGroupTest.java Mon Dec 11 09:41:23 2006
@@ -44,14 +44,14 @@
 
     /**
      * Runs the test
-     *
+     * 
      * @throws AccessControlException if an AC error occurs
      * @throws ConfigurationException if an error with the configuration occurs
      * @throws SAXException if a parsing error occurs
      * @throws IOException if an IO error occurs
      */
-    final public void testFileGroup()
-        throws AccessControlException, ConfigurationException, SAXException, IOException {
+    final public void testFileGroup() throws AccessControlException, ConfigurationException,
+            SAXException, IOException {
 
         FileGroup group = getGroup();
         group.save();
@@ -65,7 +65,7 @@
         assertNotNull(config);
 
         FileGroup newGroup = null;
-        newGroup = new FileGroup();
+        newGroup = new FileGroup(getAccreditableManager().getGroupManager(), getLogger());
         newGroup.setConfigurationDirectory(getAccreditablesDirectory());
         newGroup.configure(config);
         assertNotNull(newGroup);
@@ -78,18 +78,19 @@
      * Test getGroup
      * 
      * @return a <code>FileGroup</code>
-     * @throws AccessControlException 
+     * @throws AccessControlException
      */
     protected FileGroup getGroup() throws AccessControlException {
         File configurationDirectory = getAccreditablesDirectory();
         getLogger().info("Configuration directory: " + configurationDirectory);
-        FileGroup group = new FileGroup(configurationDirectory, GROUP_ID);
+        FileGroup group = new FileGroup(getAccreditableManager().getGroupManager(), getLogger(),
+                GROUP_ID);
         return group;
     }
 
     /**
      * Tests the removeAllMembers() method.
-     * @throws AccessControlException 
+     * @throws AccessControlException
      */
     public void testRemoveAllMembers() throws AccessControlException {
         Group group = getGroup();

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileRoleTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileRoleTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileRoleTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileRoleTest.java Mon Dec 11 09:41:23 2006
@@ -37,11 +37,11 @@
     final public void testFileRole() throws AccessControlException {
         String name = "test";
         File configDir = getAccreditablesDirectory();
-        FileRole role = new FileRole(configDir, name);
+        FileRole role = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
         role.save();
 
         File path = null;
-        path = FileRoleManager.instance(configDir, getLogger())
+        path = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger())
                 .getConfigurationDirectory();
 
         File roleFile = new File(path, name + FileRoleManager.SUFFIX);
@@ -57,11 +57,11 @@
     final public void testSave() throws AccessControlException {
         File configDir = getAccreditablesDirectory();
         String name = "test";
-        FileRole role = new FileRole(configDir, name);
+        FileRole role = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
         role.save();
 
         File path = null;
-        path = FileRoleManager.instance(configDir, getLogger())
+        path = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger())
                 .getConfigurationDirectory();
 
         File roleFile = new File(path, name + FileRoleManager.SUFFIX);
@@ -75,8 +75,7 @@
      */
     final public void testGetId() throws AccessControlException {
         String id = "test";
-        File configDir = getAccreditablesDirectory();
-        FileRole role = new FileRole(configDir, id);
+        FileRole role = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), id);
         assertTrue(role.getId().equals(id));
     }
 
@@ -86,9 +85,8 @@
      */
     final public void testEqualsObject() throws AccessControlException {
         String name = "test";
-        File configDir = getAccreditablesDirectory();
-        FileRole role1 = new FileRole(configDir, name);
-        FileRole role2 = new FileRole(configDir, name);
+        FileRole role1 = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
+        FileRole role2 = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
         assertEquals(role1, role2);
     }
 }

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileUserTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileUserTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileUserTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/file/FileUserTest.java Mon Dec 11 09:41:23 2006
@@ -71,19 +71,21 @@
      */
     final public FileUser createAndSaveUser(String userName, String fullName, String email,
             String password) throws AccessControlException {
-        File configDir = getAccreditablesDirectory();
 
         String editorGroupName = "editorGroup";
         String adminGroupName = "adminGroup";
 
-        FileGroup editorGroup = new FileGroup(configDir, editorGroupName);
+        FileGroup editorGroup = new FileGroup(getAccreditableManager().getGroupManager(),
+                getLogger(), editorGroupName);
         ContainerUtil.enableLogging(editorGroup, getLogger());
-        FileGroup adminGroup = new FileGroup(configDir, adminGroupName);
+        FileGroup adminGroup = new FileGroup(getAccreditableManager().getGroupManager(),
+                getLogger(), adminGroupName);
         ContainerUtil.enableLogging(adminGroup, getLogger());
         this.groups.put(editorGroupName, editorGroup);
         this.groups.put(adminGroupName, adminGroup);
 
-        FileUser user = new FileUser(configDir, userName, fullName, email, password);
+        FileUser user = new FileUser(getAccreditableManager().getUserManager(), getLogger(),
+                userName, fullName, email, password);
         ContainerUtil.enableLogging(user, getLogger());
 
         editorGroup.add(user);
@@ -102,12 +104,12 @@
     /**
      * Returns the file user manager.
      * @return A file user manager.
-     * @throws AccessControlException if an error occurs. 
+     * @throws AccessControlException if an error occurs.
      */
     protected FileUserManager getUserManager() throws AccessControlException {
         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
-        FileUserManager _manager = FileUserManager.instance(getAccreditablesDirectory(), userTypes,
-                getLogger());
+        FileUserManager _manager = FileUserManager.instance(getAccreditableManager(),
+                getAccreditablesDirectory(), userTypes, getLogger());
         return _manager;
     }
 

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/GroupManagerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/GroupManagerTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/GroupManagerTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/GroupManagerTest.java Mon Dec 11 09:41:23 2006
@@ -37,11 +37,11 @@
     public final void testInstance() throws AccessControlException {
         FileGroupManager _manager = null;
         File configDir = getAccreditablesDirectory();
-        _manager = FileGroupManager.instance(configDir, getLogger());
+        _manager = FileGroupManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(_manager);
 
         FileGroupManager anotherManager = null;
-        anotherManager = FileGroupManager.instance(configDir, getLogger());
+        anotherManager = FileGroupManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(anotherManager);
         assertEquals(_manager, anotherManager);
     }

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/RoleManagerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/RoleManagerTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/RoleManagerTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/RoleManagerTest.java Mon Dec 11 09:41:23 2006
@@ -37,10 +37,10 @@
      */
     final public void testInstance() throws AccessControlException {
         File configDir = getAccreditablesDirectory();
-        FileRoleManager _manager = FileRoleManager.instance(configDir, getLogger());
+        FileRoleManager _manager = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(_manager);
 
-        FileRoleManager anotherManager = FileRoleManager.instance(configDir, getLogger());
+        FileRoleManager anotherManager = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(anotherManager);
         assertEquals(_manager, anotherManager);
     }
@@ -60,9 +60,9 @@
         File configDir = getAccreditablesDirectory();
         String name = "test";
         FileRoleManager _manager = null;
-        _manager = FileRoleManager.instance(configDir, getLogger());
+        _manager = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(_manager);
-        Role role = new FileRole(_manager.getConfigurationDirectory(), name);
+        Role role = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
         _manager.add(role);
 
         assertTrue(_manager.getRoles().length > 0);
@@ -75,11 +75,11 @@
     final public void testRemoveRole() throws AccessControlException {
         File configDir = getAccreditablesDirectory();
         String name = "test2";
-        Role role = new FileRole(configDir, name);
+        Role role = new FileRole(getAccreditableManager().getRoleManager(), getLogger(), name);
         FileRoleManager _manager = null;
 
         try {
-            _manager = FileRoleManager.instance(configDir, getLogger());
+            _manager = FileRoleManager.instance(getAccreditableManager(), configDir, getLogger());
         } catch (AccessControlException e) {
             e.printStackTrace();
         }

Modified: lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/UserManagerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/UserManagerTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/UserManagerTest.java (original)
+++ lenya/trunk/src/modules-core/ac-impl/java/test/org/apache/lenya/ac/impl/UserManagerTest.java Mon Dec 11 09:41:23 2006
@@ -69,24 +69,28 @@
         String editorRoleId = "editorRole";
         String adminRoleId = "adminRole";
 
-        FileRole editorRole = new FileRole(configDir, editorRoleId);
-        FileRole adminRole = new FileRole(configDir, adminRoleId);
+        FileRole editorRole = new FileRole(getAccreditableManager().getRoleManager(), getLogger(),
+                editorRoleId);
+        FileRole adminRole = new FileRole(getAccreditableManager().getRoleManager(), getLogger(),
+                adminRoleId);
 
-        User user = new FileUser(configDir, userName, "Alice in Wonderland", "alice@test.com",
-                "secret");
+        User user = new FileUser(getAccreditableManager().getUserManager(), getLogger(), userName,
+                "Alice in Wonderland", "alice@test.com", "secret");
 
         editorRole.save();
         adminRole.save();
 
-        Group editorGroup = new FileGroup(configDir, editorGroupId);
+        Group editorGroup = new FileGroup(getAccreditableManager().getGroupManager(), getLogger(),
+                editorGroupId);
 
-        //		editorGroup.addRole(editorRole);
+        // editorGroup.addRole(editorRole);
         editorGroup.add(user);
 
-        FileGroup adminGroup = new FileGroup(configDir, adminGroupId);
+        FileGroup adminGroup = new FileGroup(getAccreditableManager().getGroupManager(),
+                getLogger(), adminGroupId);
 
-        //		adminGroup.addRole(editorRole);
-        //		adminGroup.addRole(adminRole);
+        // adminGroup.addRole(editorRole);
+        // adminGroup.addRole(adminRole);
         editorGroup.save();
         adminGroup.save();
         adminGroup.add(user);
@@ -96,7 +100,7 @@
         UserManager userManager = getAccreditableManager().getUserManager();
         assertNotNull(userManager);
 
-        groupManager = FileGroupManager.instance(configDir, getLogger());
+        groupManager = FileGroupManager.instance(getAccreditableManager(), configDir, getLogger());
         assertNotNull(groupManager);
 
         Group fetchedGroup = groupManager.getGroup(editorGroupId);
@@ -114,11 +118,11 @@
         FileAccreditableManager accrMgr = (FileAccreditableManager) getAccreditableManager();
         File configDir = accrMgr.getConfigurationDirectory();
         String userName = "aliceTest";
-        FileUser user = new FileUser(configDir, userName, "Alice in Wonderland",
-                "alice@wonderland.com", "secret");
+        FileUser user = new FileUser(getAccreditableManager().getUserManager(), getLogger(),
+                userName, "Alice in Wonderland", "alice@wonderland.com", "secret");
         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
-        FileUserManager _manager = FileUserManager.instance(configDir, userTypes,
-                getLogger());
+        FileUserManager _manager = FileUserManager.instance(getAccreditableManager(), configDir,
+                userTypes, getLogger());
         assertNotNull(_manager);
         _manager.add(user);
 

Modified: lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/AddUser.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/AddUser.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/AddUser.java (original)
+++ lenya/trunk/src/modules-core/administration/java/src/org/apache/lenya/cms/ac/usecases/AddUser.java Mon Dec 11 09:41:23 2006
@@ -17,12 +17,11 @@
  */
 package org.apache.lenya.cms.ac.usecases;
 
-import java.io.File;
-
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.ItemUtil;
 import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.UserManager;
 import org.apache.lenya.ac.file.FileUser;
 import org.apache.lenya.ac.file.FileUserManager;
 import org.apache.lenya.ac.ldap.LDAPUser;
@@ -64,8 +63,7 @@
         }
 
         if (className.equals(LDAPUser.class.getName())) {
-            LDAPUser ldapUser = new LDAPUser(((FileUserManager) getUserManager())
-                    .getConfigurationDirectory());
+            LDAPUser ldapUser = new LDAPUser(getUserManager(), getLogger());
             ContainerUtil.enableLogging(ldapUser, getLogger());
 
             try {
@@ -97,7 +95,7 @@
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
      */
     protected void doExecute() throws Exception {
-        File configDir = ((FileUserManager) getUserManager()).getConfigurationDirectory();
+        UserManager userManager = (FileUserManager) getUserManager();
 
         String userId = getParameterAsString(UserProfile.USER_ID);
         String fullName = getParameterAsString(UserProfile.FULL_NAME);
@@ -108,10 +106,10 @@
         User user;
         if (className.equals(LDAPUser.class.getName())) {
             String ldapId = getParameterAsString(LDAP_ID);
-            user = new LDAPUser(configDir, userId, email, ldapId, getLogger());
+            user = new LDAPUser(userManager, getLogger(), userId, email, ldapId, getLogger());
         } else {
             String password = getParameterAsString(AbstractChangePassword.NEW_PASSWORD);
-            user = new FileUser(configDir, userId, fullName, email, "");
+            user = new FileUser(userManager, getLogger(), userId, fullName, email, "");
             user.setName(fullName);
             user.setPassword(password);
         }

Modified: lenya/trunk/src/modules-core/janitor/java/src/org/apache/lenya/cms/janitor/ContentJanitor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/janitor/java/src/org/apache/lenya/cms/janitor/ContentJanitor.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/janitor/java/src/org/apache/lenya/cms/janitor/ContentJanitor.java (original)
+++ lenya/trunk/src/modules-core/janitor/java/src/org/apache/lenya/cms/janitor/ContentJanitor.java Mon Dec 11 09:41:23 2006
@@ -1,19 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
 package org.apache.lenya.cms.janitor;
 
 import java.io.File;
 
-import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.environment.Request;
 import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.observation.AbstractRepositoryListener;
 import org.apache.lenya.cms.observation.DocumentEvent;
-import org.apache.lenya.cms.observation.ObservationRegistry;
-import org.apache.lenya.cms.observation.RepositoryListener;
+import org.apache.lenya.cms.observation.RepositoryEvent;
 import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.DocumentUtil;
 import org.apache.lenya.cms.publication.Publication;
@@ -21,13 +32,19 @@
 /**
  * The content janitor cleans up empty directories after a document is removed.
  */
-public class ContentJanitor extends AbstractLogEnabled implements Serviceable, Startable,
-        ThreadSafe, RepositoryListener {
-
-    public void documentChanged(DocumentEvent event) {
-    }
+public class ContentJanitor extends AbstractRepositoryListener {
 
-    public void documentRemoved(DocumentEvent event) {
+    public void eventFired(RepositoryEvent repoEvent) {
+        
+        if (!(repoEvent instanceof DocumentEvent)) {
+            return;
+        }
+        DocumentEvent event = (DocumentEvent) repoEvent;
+        
+        if (!event.getDescriptor().equals(DocumentEvent.REMOVED)) {
+            return;
+        }
+        
         ContextUtility util = null;
         try {
             util = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
@@ -44,27 +61,6 @@
                 this.manager.release(util);
             }
         }
-    }
-
-    public void start() throws Exception {
-        ObservationRegistry registry = null;
-        try {
-            registry = (ObservationRegistry) this.manager.lookup(ObservationRegistry.ROLE);
-            registry.registerListener(this);
-        } finally {
-            if (registry != null) {
-                this.manager.release(registry);
-            }
-        }
-    }
-
-    public void stop() throws Exception {
-    }
-
-    private ServiceManager manager;
-
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
     }
 
 }

Modified: lenya/trunk/src/modules-core/ldap/java/src/org/apache/lenya/ac/ldap/LDAPUser.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ldap/java/src/org/apache/lenya/ac/ldap/LDAPUser.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ldap/java/src/org/apache/lenya/ac/ldap/LDAPUser.java (original)
+++ lenya/trunk/src/modules-core/ldap/java/src/org/apache/lenya/ac/ldap/LDAPUser.java Mon Dec 11 09:41:23 2006
@@ -38,9 +38,9 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.ItemManager;
 import org.apache.lenya.ac.file.FileUser;
 
 import com.sun.jndi.ldap.LdapCtxFactory;
@@ -51,17 +51,17 @@
  */
 public class LDAPUser extends FileUser {
     /**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
+     * 
+     */
+    private static final long serialVersionUID = 1L;
 
-	private Properties defaultProperties = null;
+    private Properties defaultProperties = null;
 
     /**
      * <code>LDAP_ID</code> The LDAP id
      */
     public static final String LDAP_ID = "ldapid";
-    private static String LDAP_PROPERTIES_FILE = "ldap.properties"; 
+    private static String LDAP_PROPERTIES_FILE = "ldap.properties";
     private static String PROVIDER_URL_PROP = "provider-url";
     private static String MGR_DN_PROP = "mgr-dn";
     private static String MGR_PW_PROP = "mgr-pw";
@@ -87,40 +87,34 @@
 
     /**
      * Creates a new LDAPUser object.
+     * @param itemManager The item manager.
+     * @param logger The logger.
      */
-    public LDAPUser() {
-        // do nothing
-    }
-
-    /**
-     * Creates a new LDAPUser object.
-     * @param configurationDirectory The configuration directory.
-     */
-    public LDAPUser(File configurationDirectory) {
-        setConfigurationDirectory(configurationDirectory);
+    public LDAPUser(ItemManager itemManager, Logger logger) {
+        super(itemManager, logger);
     }
 
     /**
      * Create an LDAPUser
-     * @param configurationDirectory where the user will be attached to
+     * @param itemManager The item manager.
+     * @param logger The logger.
      * @param id user id of LDAPUser
      * @param email of LDAPUser
      * @param _ldapId of LDAPUser
      * @param _logger The logger.
      * @throws ConfigurationException if the properties could not be read
      */
-    public LDAPUser(File configurationDirectory, String id, String email, String _ldapId, Logger _logger)
-            throws ConfigurationException {
-        super(configurationDirectory, id, null, email, null);
-        ContainerUtil.enableLogging(this, _logger);
+    public LDAPUser(ItemManager itemManager, Logger logger, String id, String email,
+            String _ldapId, Logger _logger) throws ConfigurationException {
+        super(itemManager, logger, id, null, email, null);
         this.ldapId = _ldapId;
-
         initialize();
     }
 
     /**
      * Create a new LDAPUser from a configuration
-     * @param config the <code>Configuration</code> specifying the user details
+     * @param config the <code>Configuration</code> specifying the user
+     *        details
      * @throws ConfigurationException if the user could not be instantiated
      */
     public void configure(Configuration config) throws ConfigurationException {
@@ -133,8 +127,9 @@
     /**
      * Checks if a user exists.
      * @param _ldapId The LDAP id.
-     * @return A boolean value indicating whether the user is found in the directory
-     * @throws AccessControlException when an error occurs. 
+     * @return A boolean value indicating whether the user is found in the
+     *         directory
+     * @throws AccessControlException when an error occurs.
      */
     public boolean existsUser(String _ldapId) throws AccessControlException {
 
@@ -162,14 +157,13 @@
     }
 
     /**
-     * Initializes this user.
-     * The current (already authenticated) ldapId is queried in the directory, 
-     * in order to retrieve additional information, such as the user name.
-     * In current implementation, only the user name is actually retrieved, but
-     * other attributes may be used in the future (such as groups ?)
-     * TODO: should the code be changed to not throw an exception when something
-     * goes wrong ? After all, it's only used to get additional info for display?
-     * This is a design decision, I'm not sure what's best.
+     * Initializes this user. The current (already authenticated) ldapId is
+     * queried in the directory, in order to retrieve additional information,
+     * such as the user name. In current implementation, only the user name is
+     * actually retrieved, but other attributes may be used in the future (such
+     * as groups ?) TODO: should the code be changed to not throw an exception
+     * when something goes wrong ? After all, it's only used to get additional
+     * info for display? This is a design decision, I'm not sure what's best.
      * @throws ConfigurationException when something went wrong.
      */
     protected void initialize() throws ConfigurationException {
@@ -182,24 +176,26 @@
             if (entry != null) {
                 StringBuffer name = new StringBuffer();
                 /* users full name */
-                String usrNameAttr = 
-                    defaultProperties.getProperty(USR_NAME_ATTR_PROP, USR_NAME_ATTR_DEFAULT);
+                String usrNameAttr = defaultProperties.getProperty(USR_NAME_ATTR_PROP,
+                        USR_NAME_ATTR_DEFAULT);
 
                 if (getLogger().isDebugEnabled())
-                    getLogger().debug("initialize() got entry, going to look for attribute " + usrNameAttr + " in entry, which is: " + entry);
-            
+                    getLogger().debug(
+                            "initialize() got entry, going to look for attribute " + usrNameAttr
+                                    + " in entry, which is: " + entry);
+
                 Attributes attributes = entry.getAttributes();
                 if (attributes != null) {
                     Attribute userNames = attributes.get(usrNameAttr);
                     if (userNames != null)
-            	       for (NamingEnumeration enumeration = userNames.getAll(); enumeration.hasMore(); enumeration.next())
-            	           name.append((String)userNames.get());
+                        for (NamingEnumeration enumeration = userNames.getAll(); enumeration
+                                .hasMore(); enumeration.next())
+                            name.append((String) userNames.get());
                 }
                 this.ldapName = name.toString();
                 if (getLogger().isDebugEnabled())
                     getLogger().debug("initialize() set name to " + this.ldapName);
-            }
-            else {
+            } else {
                 this.ldapName = "";
             }
         } catch (final NamingException e1) {
@@ -240,11 +236,10 @@
     }
 
     /**
-     * Authenticate a user against the directory.
-     * The principal to be authenticated is either constructed by use of the
-     * configured properties, or by lookup of this ID in the directory. 
-     * This principal then attempts to authenticate against the directory with
-     * the provided password.
+     * Authenticate a user against the directory. The principal to be
+     * authenticated is either constructed by use of the configured properties,
+     * or by lookup of this ID in the directory. This principal then attempts to
+     * authenticate against the directory with the provided password.
      * @see org.apache.lenya.ac.User#authenticate(java.lang.String)
      */
     public boolean authenticate(String password) {
@@ -255,13 +250,12 @@
 
         try {
             principal = getPrincipal();
-	    
+
             if (getLogger().isDebugEnabled())
                 getLogger().debug("Authenticating with principal [" + principal + "]");
 
-            ctx = bind(principal, password,
-                       defaultProperties.getProperty(USR_AUTH_TYPE_PROP, 
-                                                     USR_AUTH_TYPE_DEFAULT));
+            ctx = bind(principal, password, defaultProperties.getProperty(USR_AUTH_TYPE_PROP,
+                    USR_AUTH_TYPE_DEFAULT));
             authenticated = true;
             close(ctx);
             if (getLogger().isDebugEnabled())
@@ -289,9 +283,9 @@
     }
 
     /**
-     * LDAP Users fetch their name information from the LDAP server, so we don't store it locally.
-     * Since we only have read access we basically can't set the name, i.e. any request to change
-     * the name is ignored.
+     * LDAP Users fetch their name information from the LDAP server, so we don't
+     * store it locally. Since we only have read access we basically can't set
+     * the name, i.e. any request to change the name is ignored.
      * @param string is ignored
      */
     public void setName(String string) {
@@ -321,9 +315,11 @@
      * @param credentials the credentials for the LDAP connection
      * @param authMethod the authentication method
      * @return a <code>DirContext</code>
-     * @throws NamingException if there are problems establishing the Ldap connection
+     * @throws NamingException if there are problems establishing the Ldap
+     *         connection
      */
-    private DirContext bind(String principal, String credentials, String authMethod) throws NamingException {
+    private DirContext bind(String principal, String credentials, String authMethod)
+            throws NamingException {
 
         if (getLogger().isInfoEnabled())
             getLogger().info("Binding principal: [" + principal + "]");
@@ -334,27 +330,23 @@
                 .getAbsolutePath()
                 + File.separator + defaultProperties.getProperty(KEY_STORE_PROP));
 
-
         env.put(Context.INITIAL_CONTEXT_FACTORY, LdapCtxFactory.class.getName());
 
         String prop = defaultProperties.getProperty(PROVIDER_URL_PROP);
         if (prop == null)
-            throw new RuntimeException("LDAP configuration error: property " +
-                                       PROVIDER_URL_PROP + 
-                                       " is not set in property file " + 
-                                       LDAP_PROPERTIES_FILE);
+            throw new RuntimeException("LDAP configuration error: property " + PROVIDER_URL_PROP
+                    + " is not set in property file " + LDAP_PROPERTIES_FILE);
         env.put(Context.PROVIDER_URL, prop);
 
         prop = defaultProperties.getProperty(SECURITY_PROTOCOL_PROP);
         if (prop == null)
-            throw new RuntimeException("LDAP configuration error: property " +
-                                       SECURITY_PROTOCOL_PROP + 
-                                       " is not set in property file " + 
-                                       LDAP_PROPERTIES_FILE);
+            throw new RuntimeException("LDAP configuration error: property "
+                    + SECURITY_PROTOCOL_PROP + " is not set in property file "
+                    + LDAP_PROPERTIES_FILE);
         env.put(Context.SECURITY_PROTOCOL, prop);
 
         env.put(Context.SECURITY_AUTHENTICATION, authMethod);
-        if (authMethod != null && ! authMethod.equals("none")) {
+        if (authMethod != null && !authMethod.equals("none")) {
             env.put(Context.SECURITY_PRINCIPAL, principal);
             env.put(Context.SECURITY_CREDENTIALS, credentials);
         }
@@ -370,7 +362,8 @@
     /**
      * Close the connection to the LDAP server
      * @param ctx the context that was returned from the bind
-     * @throws NamingException if there is a problem communicating to the LDAP server
+     * @throws NamingException if there is a problem communicating to the LDAP
+     *         server
      */
     private void close(Context ctx) throws NamingException {
         if (ctx != null)
@@ -400,46 +393,41 @@
         }
     }
 
-    /** 
+    /**
      * Wrapping of the decision whether a recursive search is wanted or not.
-     * Implementation: 
-     * If the USR_BRANCH_PROP is present, this is the new style of configuration
-     * (starting Lenya 1.2.2); if it has a value, then a specific branch is wanted:
-     * no recursive search. If the property is present, but has no value,
-     * search recursively.
+     * Implementation: If the USR_BRANCH_PROP is present, this is the new style
+     * of configuration (starting Lenya 1.2.2); if it has a value, then a
+     * specific branch is wanted: no recursive search. If the property is
+     * present, but has no value, search recursively.
      * @return Recursive search
      */
     private boolean isSubtreeSearch() {
-	boolean recurse = false;
-	String usrBranchProp = defaultProperties.getProperty(USR_BRANCH_PROP);
-	if (usrBranchProp != null)
-	    if (usrBranchProp.trim().length() == 0)
-		recurse = true;
-	
-	return recurse;
-    }
+        boolean recurse = false;
+        String usrBranchProp = defaultProperties.getProperty(USR_BRANCH_PROP);
+        if (usrBranchProp != null)
+            if (usrBranchProp.trim().length() == 0)
+                recurse = true;
 
+        return recurse;
+    }
 
-    private SearchResult getDirectoryEntry(String userId) 
-        throws NamingException, IOException
-    {
+    private SearchResult getDirectoryEntry(String userId) throws NamingException, IOException {
         DirContext context = null;
         String searchFilter = "";
         String objectName = "";
         boolean recursiveSearch;
         SearchResult result = null;
- 
+
         try {
             readProperties();
-	    
-            context = bind(defaultProperties.getProperty(MGR_DN_PROP), 
-                           defaultProperties.getProperty(MGR_PW_PROP),
-                           defaultProperties.getProperty(SECURITY_AUTHENTICATION_PROP));
+
+            context = bind(defaultProperties.getProperty(MGR_DN_PROP), defaultProperties
+                    .getProperty(MGR_PW_PROP), defaultProperties
+                    .getProperty(SECURITY_AUTHENTICATION_PROP));
 
             // Get search information and user attribute from properties
             // provide defaults if not present (backward compatibility)
-            String userAttribute = 
-               defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT);
+            String userAttribute = defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT);
             searchFilter = "(" + userAttribute + "=" + userId + ")";
             SearchControls scope = new SearchControls();
 
@@ -447,42 +435,47 @@
             if (recursiveSearch) {
                 scope.setSearchScope(SearchControls.SUBTREE_SCOPE);
                 objectName = defaultProperties.getProperty(PROVIDER_URL_PROP);
-            }
-            else {
+            } else {
                 scope.setSearchScope(SearchControls.ONELEVEL_SCOPE);
                 objectName = defaultProperties.getProperty(USR_BRANCH_PROP, USR_BRANCH_DEFAULT);
-	    }
-	
+            }
+
             if (getLogger().isDebugEnabled())
-                getLogger().debug("searching object " + objectName + " filtering with " + searchFilter + ", recursive search ? " + recursiveSearch);
+                getLogger().debug(
+                        "searching object " + objectName + " filtering with " + searchFilter
+                                + ", recursive search ? " + recursiveSearch);
 
             NamingEnumeration results = context.search(objectName, searchFilter, scope);
             if (results != null && results.hasMore())
-                result = (SearchResult)results.next();
+                result = (SearchResult) results.next();
 
-	    // sanity check: if more than one entry is returned
-	    // for a user-id, then the directory is probably flawed,
-	    // so it would be nice to warn the administrator.
-	    //
-	    // This block is commented out for now, because of possible
-	    // side-effects, such as unexpected exceptions.
-// 		try {
-// 		    if (results.hasMore()) {
-// 			getLogger().warn("Found more than one entry in the directory for user " + userId + ". You probably should deactivate recursive searches. The first entry was used as a work-around.");
-// 		    }
-// 		}
-// 		catch (javax.naming.PartialResultException e) {
-// 		    if (getLogger().isDebugEnabled())
-// 			getLogger().debug("Catching and ignoring PartialResultException, as this means LDAP server does not support our sanity check");
-// 		}
+            // sanity check: if more than one entry is returned
+            // for a user-id, then the directory is probably flawed,
+            // so it would be nice to warn the administrator.
+            //
+            // This block is commented out for now, because of possible
+            // side-effects, such as unexpected exceptions.
+            // try {
+            // if (results.hasMore()) {
+            // getLogger().warn("Found more than one entry in the directory for
+            // user " + userId + ". You probably should deactivate recursive
+            // searches. The first entry was used as a work-around.");
+            // }
+            // }
+            // catch (javax.naming.PartialResultException e) {
+            // if (getLogger().isDebugEnabled())
+            // getLogger().debug("Catching and ignoring PartialResultException,
+            // as this means LDAP server does not support our sanity check");
+            // }
 
-        }
-        catch (NamingException e) {
+        } catch (NamingException e) {
             if (getLogger().isDebugEnabled())
-                getLogger().debug("NamingException caught when searching on objectName = " + objectName + " and searchFilter=" + searchFilter + ", this exception will be propagated: " + e);
+                getLogger().debug(
+                        "NamingException caught when searching on objectName = " + objectName
+                                + " and searchFilter=" + searchFilter
+                                + ", this exception will be propagated: " + e);
             throw e;
-        } 
-        finally {
+        } finally {
             try {
                 if (context != null) {
                     close(context);
@@ -497,14 +490,13 @@
     /**
      * Encapsulation of the creation of a principal: we need to distinguish
      * three cases, in order to support different modes of using a directory.
-     * The first is the use of a domain-name (requirement of MS Active Directory):
-     * if this property is set, this is used to construct the principal.
-     * The second case is where a user-id is somewhere in a domain, but not in a
-     * specific branch: in this case, a subtree search is performed to retrieve
-     * the complete path.
-     * The third case is where a specific branch of the directory is to be used;
-     * this is the case where usr-branch is set to a value. In this case, this branch
-     * is used to construct the principal.
+     * The first is the use of a domain-name (requirement of MS Active
+     * Directory): if this property is set, this is used to construct the
+     * principal. The second case is where a user-id is somewhere in a domain,
+     * but not in a specific branch: in this case, a subtree search is performed
+     * to retrieve the complete path. The third case is where a specific branch
+     * of the directory is to be used; this is the case where usr-branch is set
+     * to a value. In this case, this branch is used to construct the principal.
      * @return The principal
      * @throws IOException
      * @throws NamingException
@@ -517,17 +509,15 @@
         String domainProp = defaultProperties.getProperty(DOMAIN_NAME_PROP);
         if (domainProp != null && domainProp.trim().length() > 0) {
             principal = domainProp + "\\" + getLdapId();
-        }
-        else {
+        } else {
             if (isSubtreeSearch()) {
                 // 2. Principal is constructed from directory entry
                 SearchResult entry = getDirectoryEntry(getLdapId());
                 principal = entry.getName();
                 if (entry.isRelative())
                     if (principal.length() > 0)
-                        principal = principal +","+ defaultProperties.getProperty(BASE_DN_PROP);
-            }
-	    else
+                        principal = principal + "," + defaultProperties.getProperty(BASE_DN_PROP);
+            } else
                 // 3. Principal is constructed from properties
                 principal = constructPrincipal(getLdapId());
         }
@@ -536,18 +526,15 @@
     }
 
     /**
-     * Construct the principal for a user, by using the given userId along
-     * with the configured properties.
+     * Construct the principal for a user, by using the given userId along with
+     * the configured properties.
      * @param userId The user id
      * @return The principal
      */
     private String constructPrincipal(String userId) {
         StringBuffer principal = new StringBuffer();
-        principal
-            .append(defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT))
-            .append("=")
-            .append(userId)
-            .append(",");
+        principal.append(defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT))
+                .append("=").append(userId).append(",");
 
         String baseDn = defaultProperties.getProperty(BASE_DN_PROP);
         if (baseDn != null && baseDn.length() > 0) {
@@ -556,15 +543,14 @@
             if (usrBranch != null) {
                 if (usrBranch.trim().length() > 0)
                     principal.append(usrBranch).append(",");
-            }
-            else
+            } else
                 principal.append(USR_BRANCH_DEFAULT).append(",");
-		
+
             principal.append(defaultProperties.getProperty(BASE_DN_PROP));
-        }
-        else {
+        } else {
             // try for backwards compatibility of ldap properties
-            getLogger().warn("getPrincipal() read a deprecated format in ldap properties, please update");
+            getLogger().warn(
+                    "getPrincipal() read a deprecated format in ldap properties, please update");
             principal.append(defaultProperties.getProperty(PARTIAL_USER_DN_PROP));
         }
 

Modified: lenya/trunk/src/modules-core/ldap/java/test/org/apache/lenya/ac/ldap/AbstractLDAPUserTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ldap/java/test/org/apache/lenya/ac/ldap/AbstractLDAPUserTest.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/ldap/java/test/org/apache/lenya/ac/ldap/AbstractLDAPUserTest.java (original)
+++ lenya/trunk/src/modules-core/ldap/java/test/org/apache/lenya/ac/ldap/AbstractLDAPUserTest.java Mon Dec 11 09:41:23 2006
@@ -34,8 +34,8 @@
 import org.apache.lenya.cms.publication.PublicationException;
 
 /**
- * LDAP user test.
- * The name "Abstract..." is used to prevent it from being executed.
+ * LDAP user test. The name "Abstract..." is used to prevent it from being
+ * executed.
  * 
  * @version $Id$
  */
@@ -68,19 +68,19 @@
         String editorRoleName = "editorRole";
         String adminRoleName = "adminRole";
 
-        File configDir = getAccreditablesDirectory();
-        FileRole editorRole = new FileRole();
+        FileRole editorRole = new FileRole(getAccreditableManager().getRoleManager(), getLogger());
         editorRole.setName(editorRoleName);
-        editorRole.setConfigurationDirectory(configDir);
 
-        FileRole adminRole = new FileRole();
+        FileRole adminRole = new FileRole(getAccreditableManager().getRoleManager(), getLogger());
         adminRole.setName(adminRoleName);
-        adminRole.setConfigurationDirectory(configDir);
 
-        FileGroup editorGroup = new FileGroup(configDir, editorGroupName);
-        FileGroup adminGroup = new FileGroup(configDir, adminGroupName);
+        FileGroup editorGroup = new FileGroup(getAccreditableManager().getGroupManager(),
+                getLogger(), editorGroupName);
+        FileGroup adminGroup = new FileGroup(getAccreditableManager().getGroupManager(),
+                getLogger(), adminGroupName);
 
-        LDAPUser user = new LDAPUser(configDir, userName, email, ldapId, getLogger());
+        LDAPUser user = new LDAPUser(getAccreditableManager().getUserManager(), getLogger(),
+                userName, email, ldapId, getLogger());
 
         editorRole.save();
         adminRole.save();
@@ -105,13 +105,12 @@
      */
     final public LDAPUser loadUser(String userName) throws AccessControlException {
         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
-        FileUserManager _manager = FileUserManager.instance(getAccreditablesDirectory(), userTypes,
-                getLogger());
+        FileUserManager _manager = FileUserManager.instance(getAccreditableManager(),
+                getAccreditablesDirectory(), userTypes, getLogger());
 
         return (LDAPUser) _manager.getUser(userName);
     }
 
-
     /**
      * Test the ldap id getter
      * 
@@ -168,9 +167,9 @@
 
     /**
      * Test the deletion of a ldap user
-     *  
+     * 
      */
     final public void testDelete() {
-        //TODO Implement delete().
+        // TODO Implement delete().
     }
 }

Modified: lenya/trunk/src/modules-core/observation-impl/java/src/org/apache/lenya/cms/observation/ObservationManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/java/src/org/apache/lenya/cms/observation/ObservationManager.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/java/src/org/apache/lenya/cms/observation/ObservationManager.java (original)
+++ lenya/trunk/src/modules-core/observation-impl/java/src/org/apache/lenya/cms/observation/ObservationManager.java Mon Dec 11 09:41:23 2006
@@ -119,34 +119,22 @@
         protected abstract void notify(RepositoryListener listener, RepositoryEvent event);
     }
 
-    public void nodeChanged(RepositoryEvent event) {
+    public void eventFired(RepositoryEvent event) {
         Assert.notNull("event", event);
+        Set listeners;
         if (event instanceof DocumentEvent) {
-            final DocumentEvent docEvent = (DocumentEvent) event;
-            DocumentIdentifier id = getIdentifier(docEvent);
-            Set allListeners = getAllListeners(id);
-            Notifier notifier = new Notifier(allListeners, event) {
-                public void notify(RepositoryListener listener, RepositoryEvent event) {
-                    listener.documentChanged(docEvent);
-                }
-            };
-            new Thread(notifier).run();
+            DocumentIdentifier id = getIdentifier((DocumentEvent) event);
+            listeners = getAllListeners(id);
         }
-    }
-
-    public void nodeRemoved(RepositoryEvent event) {
-        Assert.notNull("event", event);
-        if (event instanceof DocumentEvent) {
-            final DocumentEvent docEvent = (DocumentEvent) event;
-            DocumentIdentifier id = getIdentifier(docEvent);
-            Set allListeners = getAllListeners(id);
-            Notifier notifier = new Notifier(allListeners, event) {
-                public void notify(RepositoryListener listener, RepositoryEvent event) {
-                    listener.documentRemoved(docEvent);
-                }
-            };
-            new Thread(notifier).run();
+        else {
+            listeners = this.listeners;
         }
+        Notifier notifier = new Notifier(listeners, event) {
+            public void notify(RepositoryListener listener, RepositoryEvent event) {
+                listener.eventFired(event);
+            }
+        };
+        new Thread(notifier).run();
     }
 
     private ServiceManager manager;

Modified: lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java (original)
+++ lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/TestListener.java Mon Dec 11 09:41:23 2006
@@ -8,8 +8,17 @@
     private boolean changed = false;
     private boolean removed = false;
 
-    public void documentChanged(DocumentEvent event) {
-        this.changed = true;
+    public void eventFired(RepositoryEvent repoEvent) {
+        if (!(repoEvent instanceof DocumentEvent)) {
+            return;
+        }
+        DocumentEvent event = (DocumentEvent) repoEvent;
+        if (event.getDescriptor().equals(DocumentEvent.CHANGED)) {
+            this.changed = true;
+        }
+        else if (event.getDescriptor().equals(DocumentEvent.REMOVED)) {
+            this.removed = true;
+        }
     }
     
     public boolean wasChanged() {
@@ -25,8 +34,4 @@
         this.removed = false;
     }
 
-    public void documentRemoved(DocumentEvent event) {
-        this.removed = true;
-    }
-    
 }

Added: lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/WorkflowNotifier.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/WorkflowNotifier.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/WorkflowNotifier.java (added)
+++ lenya/trunk/src/modules-core/workflow-impl/java/src/org/apache/lenya/cms/workflow/WorkflowNotifier.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.workflow;
+
+import org.apache.lenya.cms.observation.AbstractRepositoryListener;
+import org.apache.lenya.cms.observation.DocumentEvent;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.workflow.Version;
+
+/**
+ * Notify users of workflow changes.
+ */
+public class WorkflowNotifier extends AbstractRepositoryListener {
+
+    public void eventFired(RepositoryEvent event) {
+        if (!(event instanceof DocumentEvent)) {
+            return;
+        }
+        DocumentEvent docEvent = (DocumentEvent) event;
+        if (!(docEvent.getDescriptor() instanceof WorkflowEventDescriptor)) {
+            return;
+        }
+
+        WorkflowEventDescriptor descriptor = (WorkflowEventDescriptor) docEvent.getDescriptor();
+        Version version = descriptor.getVersion();
+    }
+
+}

Modified: lenya/trunk/src/modules/contactform/java/src/org/apache/lenya/cms/contactform/ContactForm.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/contactform/java/src/org/apache/lenya/cms/contactform/ContactForm.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules/contactform/java/src/org/apache/lenya/cms/contactform/ContactForm.java (original)
+++ lenya/trunk/src/modules/contactform/java/src/org/apache/lenya/cms/contactform/ContactForm.java Mon Dec 11 09:41:23 2006
@@ -79,9 +79,11 @@
         Message message = new Message("Contact form submitted by " + name + " (" + from + ")",
                 new String[0],
                 body,
-                new String[0]);
-
-        NotificationUtil.notify(this.manager, recipients, sender, message);
+                new String[0],
+                sender,
+                recipients);
+        
+        NotificationUtil.notify(this.manager, message);
 
         setDefaultTargetURL(getSourceURL() + "?sent=true");
     }

Modified: lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java (original)
+++ lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Importer.java Mon Dec 11 09:41:23 2006
@@ -161,7 +161,7 @@
                 String value = DocumentHelper.getSimpleElementText(dcElements[i]);
                 meta.setValue(key, value);
             }
-
+            
         } catch (Exception e) {
             throw new RuntimeException(e);
         } finally {

Modified: lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdaterImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdaterImpl.java?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdaterImpl.java (original)
+++ lenya/trunk/src/modules/lucene/java/src/org/apache/lenya/cms/lucene/IndexUpdaterImpl.java Mon Dec 11 09:41:23 2006
@@ -29,6 +29,7 @@
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
 import org.apache.lenya.cms.observation.DocumentEvent;
 import org.apache.lenya.cms.observation.ObservationRegistry;
+import org.apache.lenya.cms.observation.RepositoryEvent;
 import org.apache.lenya.cms.publication.ResourceType;
 
 /**
@@ -37,25 +38,22 @@
 public class IndexUpdaterImpl extends AbstractLogEnabled implements IndexUpdater, Startable,
         Serviceable, ThreadSafe {
 
-    public void documentChanged(DocumentEvent event) {
-        try {
-            index(event.getResourceType(),
-                    event.getPublicationId(),
-                    event.getArea(),
-                    event.getUuid(),
-                    event.getLanguage());
-        } catch (IndexException e) {
-            throw new RuntimeException(e);
+    public void eventFired(RepositoryEvent repoEvent) {
+
+        if (!(repoEvent instanceof DocumentEvent)) {
+            return;
         }
-    }
+        DocumentEvent event = (DocumentEvent) repoEvent;
 
-    public void documentRemoved(DocumentEvent event) {
         try {
-            delete(event.getResourceType(),
-                    event.getPublicationId(),
-                    event.getArea(),
-                    event.getUuid(),
-                    event.getLanguage());
+            if (event.getDescriptor().equals(DocumentEvent.CHANGED)) {
+                index(event.getResourceType(), event.getPublicationId(), event.getArea(), event
+                        .getUuid(), event.getLanguage());
+            } else if (event.getDescriptor().equals(DocumentEvent.REMOVED)) {
+                delete(event.getResourceType(), event.getPublicationId(), event.getArea(), event
+                        .getUuid(), event.getLanguage());
+            }
+
         } catch (IndexException e) {
             throw new RuntimeException(e);
         }
@@ -73,9 +71,10 @@
                 uri = "cocoon://modules/lucene/" + operation + "-document/" + docString;
                 SourceUtil.readDOM(uri, this.manager);
             } else {
-                getLogger().info("Document [" + pubId + ":" + area + ":" + uuid + ":" + language
-                        + "] is not being indexed because resource type [" + resourceType.getName()
-                        + "] does not support indexing!");
+                getLogger().info(
+                        "Document [" + pubId + ":" + area + ":" + uuid + ":" + language
+                                + "] is not being indexed because resource type ["
+                                + resourceType.getName() + "] does not support indexing!");
             }
         } catch (Exception e) {
             getLogger().error("Invoking indexing failed for URL [" + uri + "]: ", e);

Added: lenya/trunk/src/modules/notification/config/cocoon-xconf/inboxmanager.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/inboxmanager.xconf?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/inboxmanager.xconf (added)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/inboxmanager.xconf Mon Dec 11 09:41:23 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.inbox.InboxManager']">
+
+  <component logger="lenya.inbox"
+    role="org.apache.lenya.inbox.InboxManager"
+    class="org.apache.lenya.inbox.xml.XmlSourceInboxManager"/>
+  
+</xconf>

Added: lenya/trunk/src/modules/notification/config/cocoon-xconf/notificationlistener.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/notificationlistener.xconf?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/notificationlistener.xconf (added)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/notificationlistener.xconf Mon Dec 11 09:41:23 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.notification.NotificationListener']">
+
+  <component role="org.apache.lenya.notification.NotificationListener"
+    class="org.apache.lenya.notification.NotificationListener"
+    logger="lenya.notification"/>
+  
+</xconf>

Modified: lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf?view=diff&rev=485769&r1=485768&r2=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf (original)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf Mon Dec 11 09:41:23 2006
@@ -20,8 +20,10 @@
 
 <xconf xpath="/cocoon" unless="/cocoon/notifier">
 
-  <notifier>
+  <component logger="lenya.notification"
+    role="org.apache.lenya.notification.Notifier"
+    class="org.apache.lenya.notification.EmailNotifier">
     <smtp-host>mail.yourdomain.com</smtp-host>
-  </notifier>
+  </component>
   
 </xconf>

Added: lenya/trunk/src/modules/notification/config/cocoon-xconf/tab.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/tab.xconf?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/tab.xconf (added)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/tab.xconf Mon Dec 11 09:41:23 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+  <xconf xpath="/cocoon/gui-manager/tab-group[@name = 'admin']"
+    unless="/cocoon/gui-manager/tab-group[@name = 'admin']/tab[@name = 'inbox']">
+    <tab name="inbox" label="Inbox" usecase="notification.inbox"/>
+  </xconf>

Added: lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-inbox.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-inbox.xconf?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-inbox.xconf (added)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-inbox.xconf Mon Dec 11 09:41:23 2006
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'notification.inbox']">
+
+    <component-instance name="notification.inbox" logger="lenya.notification"
+      class="org.apache.lenya.inbox.usecases.Inbox">
+      <view template="modules/notification/usecases/inbox.jx" menu="true">
+        <tab group="admin" name="inbox"/>
+      </view>
+      <exit usecase="notification.inbox"/>
+    </component-instance>
+
+</xconf>

Added: lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-sendMessage.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-sendMessage.xconf?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-sendMessage.xconf (added)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/usecase-sendMessage.xconf Mon Dec 11 09:41:23 2006
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'notification.sendMessage']">
+
+    <component-instance name="notification.sendMessage" logger="lenya.notification"
+      class="org.apache.lenya.inbox.usecases.SendMessage">
+      <view template="modules/notification/usecases/sendMessage.jx" menu="true">
+        <tab group="admin" name="inbox"/>
+      </view>
+      <exit usecase="notification.inbox"/>
+    </component-instance>
+
+</xconf>

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/AbstractInboxManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/AbstractInboxManager.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/AbstractInboxManager.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/AbstractInboxManager.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.lenya.ac.User;
+
+/**
+ * Abstract base class for inbox managers.
+ */
+public abstract class AbstractInboxManager extends AbstractLogEnabled implements InboxManager,
+        ThreadSafe {
+
+    private Map inboxes = new HashMap();
+
+    public synchronized Inbox getInbox(User user) {
+        Inbox inbox = (Inbox) this.inboxes.get(user);
+        if (inbox == null) {
+            inbox = doGetInbox(user);
+            this.inboxes.put(user, inbox);
+        }
+        return inbox;
+    }
+
+    protected abstract Inbox doGetInbox(User user);
+
+}

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/Inbox.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/Inbox.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/Inbox.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/Inbox.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox;
+
+import org.apache.lenya.notification.Message;
+
+/**
+ * An inbox.
+ */
+public interface Inbox {
+    
+    /**
+     * @return All messages in this inbox.
+     */
+    Message[] getMessages();
+    
+    /**
+     * @param message The message to add.
+     */
+    void add(Message message);
+
+    /**
+     * @param message The message to remove.
+     */
+    void remove(Message message);
+
+}

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxManager.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxManager.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxManager.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox;
+
+import org.apache.lenya.ac.User;
+
+/**
+ * Inbox manager.
+ */
+public interface InboxManager {
+    
+    /**
+     * The Avalon service role.
+     */
+    String ROLE = InboxManager.class.getName();
+
+    /**
+     * @param user The user.
+     * @return The inbox of this user.
+     */
+    Inbox getInbox(User user);
+    
+}

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.lenya.ac.Group;
+import org.apache.lenya.ac.Groupable;
+import org.apache.lenya.ac.Identifiable;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.notification.AbstractNotifier;
+import org.apache.lenya.notification.Message;
+import org.apache.lenya.notification.NotificationException;
+
+/**
+ * Notifier which adds the message to the recipients' inboxes.
+ */
+public class InboxNotifier extends AbstractNotifier {
+
+    public void notify(Message message) throws NotificationException {
+        Identifiable[] recipients = message.getRecipients();
+
+        Set users = new HashSet();
+        for (int i = 0; i < recipients.length; i++) {
+            if (recipients[i] instanceof User) {
+                users.add(recipients[i]);
+            } else if (recipients[i] instanceof Group) {
+                Group group = (Group) recipients[i];
+                Groupable[] members = group.getMembers();
+                for (int m = 0; m < members.length; m++) {
+                    if (members[m] instanceof User) {
+                        users.add(members[m]);
+                    }
+                }
+            } else {
+                throw new NotificationException("Unsupported recipient type ["
+                        + recipients[i].getClass() + "]");
+            }
+        }
+
+        InboxManager inboxManager = null;
+        try {
+            inboxManager = (InboxManager) this.manager.lookup(InboxManager.ROLE);
+            for (Iterator i = users.iterator(); i.hasNext();) {
+                User user = (User) i.next();
+                Inbox inbox = inboxManager.getInbox(user);
+                inbox.add(message);
+            }
+        } catch (ServiceException e) {
+            throw new NotificationException(e);
+        } finally {
+            if (inboxManager != null) {
+                this.manager.release(inboxManager);
+            }
+        }
+
+    }
+
+}

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/Inbox.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/Inbox.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/Inbox.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/Inbox.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox.usecases;
+
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
+import org.apache.lenya.inbox.InboxManager;
+
+/**
+ * Show and manage an inbox.
+ */
+public class Inbox extends AbstractUsecase {
+
+    protected void initParameters() {
+        super.initParameters();
+        
+        User user = getSession().getIdentity().getUser();
+        setParameter("user", user);
+        
+        InboxManager inboxManager = null;
+        try {
+            inboxManager = (InboxManager) this.manager.lookup(InboxManager.ROLE);
+            org.apache.lenya.inbox.Inbox inbox = inboxManager.getInbox(user);
+            setParameter("inbox", inbox);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        finally {
+            if (inboxManager != null) {
+                this.manager.release(inboxManager);
+            }
+        }
+        
+    }
+
+    protected void doExecute() throws Exception {
+        super.doExecute();
+    }
+
+}

Added: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/SendMessage.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/SendMessage.java?view=auto&rev=485769
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/SendMessage.java (added)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/usecases/SendMessage.java Mon Dec 11 09:41:23 2006
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.inbox.usecases;
+
+import org.apache.lenya.ac.Identifiable;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.UserManager;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
+import org.apache.lenya.notification.Message;
+import org.apache.lenya.notification.NotificationUtil;
+import org.apache.lenya.util.Assert;
+
+/**
+ * Show and manage an inbox.
+ */
+public class SendMessage extends AbstractUsecase {
+
+    protected void initParameters() {
+        super.initParameters();
+
+        User user = getSession().getIdentity().getUser();
+        setParameter("user", user);
+
+        try {
+            UserManager userManager = user.getAccreditableManager().getUserManager();
+            User[] users = userManager.getUsers();
+            setParameter("users", users);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    protected void doCheckExecutionConditions() throws Exception {
+        super.doCheckExecutionConditions();
+
+        if (getRecipient().equals("")) {
+            addErrorMessage("Please choose a recipient.");
+        }
+
+        if (getSubject().equals("")) {
+            addErrorMessage("Please choose a subject.");
+        }
+    }
+
+    protected String getSubject() {
+        return getParameterAsString("subject");
+    }
+
+    protected String getRecipient() {
+        return getParameterAsString("recipient");
+    }
+
+    protected String getBody() {
+        return getParameterAsString("body");
+    }
+
+    protected void doExecute() throws Exception {
+        super.doExecute();
+
+        String recipientId = getRecipient();
+        User sender = getSession().getIdentity().getUser();
+        User recipient;
+
+        try {
+            UserManager userManager = sender.getAccreditableManager().getUserManager();
+            recipient = userManager.getUser(recipientId);
+            Assert.notNull("user " + recipientId, recipient);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        Identifiable[] recipients = { recipient };
+        String subject = getSubject();
+        String body = getBody();
+
+        Message message = new Message(subject, new String[0], body, new String[0], sender,
+                recipients);
+        NotificationUtil.notify(this.manager, message);
+
+    }
+
+}



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