KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > message > impl > StandaloneMessageProtocolPlugin


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.communication.message.impl;
6
7 import java.util.Date JavaDoc ;
8 import org.exoplatform.commons.exception.ExoMessageException;
9 import org.exoplatform.services.communication.message.*;
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Sep 6, 2004
13  * @version $Id: StandaloneMessageProtocolPlugin.java,v 1.6 2004/11/03 01:23:39 tuan08 Exp $
14  */

15 public class StandaloneMessageProtocolPlugin extends BaseMessageProtocolPlugin {
16   
17   public StandaloneMessageProtocolPlugin(MessageService mservice) {
18     super(mservice) ;
19   }
20   
21   public String JavaDoc getProtocol() { return MessageService.STANDALONE_PROTOCOL ; }
22   
23   public void sendMessage(Account account, Message message) throws Exception JavaDoc {
24     String JavaDoc[] tmp = message.getTo().split("#") ;
25     if(tmp.length != 2) {
26       Object JavaDoc[] args = {message.getTo()} ;
27       throw new ExoMessageException("MessageService.invalid-standalone-message-address", args) ;
28     }
29     String JavaDoc user = tmp[0] ;
30     String JavaDoc accountName = tmp[1] ;
31     Account receiverAccount = mservice_.getAccount(user, accountName) ;
32     if(receiverAccount == null) {
33       Object JavaDoc[] args = {message.getTo()} ;
34       throw new ExoMessageException("MessageService.address-not-found", args) ;
35     }
36     Folder folder = mservice_.getFolder(receiverAccount, MessageService.INBOX_FOLDER) ;
37     message.setFrom(formatEmail(account.getReplyToAddress())) ;
38     message.setReceivedDate(new Date JavaDoc()) ;
39     message.addFlag(MessageHeader.RECENT_FLAG) ;
40     mservice_.createMessage(account, folder, message) ;
41     saveSentMessage(account, message) ;
42   }
43
44   public void synchronize(Account account) throws Exception JavaDoc {
45     
46   }
47 }
48
Popular Tags