View Javadoc

1   // 
2   // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   // All rights reserved. 
4   //   
5   // Redistribution and use in source and binary forms, with or without modification,  
6   // are permitted provided that the following conditions are met: 
7   //   
8   // * Redistributions of source code must retain the above copyright notice,  
9   // this list of conditions and the following disclaimer. 
10  // * Redistributions in binary form must reproduce the above copyright notice,  
11  // this list of conditions and the following disclaimer in the documentation  
12  // and/or other materials provided with the distribution. 
13  // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  // nor the names of its contributors may be used to endorse or promote products  
15  // derived from this software without specific prior written permission. 
16  // 
17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  // POSSIBILITY OF SUCH DAMAGE. 
27  //
28  
29  package org.objectledge.modules.actions.im;
30  
31  import java.security.Principal;
32  
33  import org.objectledge.authentication.UserManager;
34  import org.objectledge.context.Context;
35  import org.objectledge.im.InstantMessaging;
36  import org.objectledge.im.InstantMessagingContact;
37  import org.objectledge.parameters.Parameters;
38  import org.objectledge.parameters.RequestParameters;
39  import org.objectledge.parameters.directory.DirectoryParameters;
40  import org.objectledge.pipeline.ProcessingException;
41  import org.objectledge.pipeline.Valve;
42  import org.objectledge.templating.TemplatingContext;
43  
44  /***
45   * Removes an IM contact from user's personal data.
46   * 
47   * @author <a href="rafal@caltha.pl">RafaƂ Krzewski</a>
48   * @version $Id: RemoveContact.java,v 1.1 2005/08/01 09:45:25 rafal Exp $
49   */
50  public class RemoveContact
51      implements Valve
52  {
53      private final UserManager userManager;
54  
55      private final InstantMessaging instantMessaging;
56  
57      /***
58       * Creates a new RemoveContact action instance.
59       * 
60       * @param messaging the instant messaging component.
61       * @param manager the user manager component.
62       */
63      public RemoveContact(InstantMessaging messaging, UserManager manager)
64      {
65          instantMessaging = messaging;
66          userManager = manager;
67      }
68  
69      /***
70       * {@inheritDoc}
71       */
72      public void process(Context context)
73          throws ProcessingException
74      {
75          RequestParameters parameters = RequestParameters.getRequestParameters(context);
76          TemplatingContext templatingContext = TemplatingContext.getTemplatingContext(context);
77          String user = parameters.get("user");
78          InstantMessagingContact contact = InstantMessagingContact.fromString(parameters
79              .get("contact"), instantMessaging);
80          Parameters personalData;
81          try
82          {
83              Principal principal = userManager.getUserByLogin(user);
84              personalData = new DirectoryParameters(userManager.getPersonalData(principal));
85          }
86          catch(Exception e)
87          {
88              throw new ProcessingException("failed to access user's personal data", e);
89          }
90          try
91          {
92              instantMessaging.removeContact(personalData, contact);
93          }
94          catch(Exception e)
95          {
96              throw new ProcessingException("failed to remove contact", e);
97          }
98      }
99  }