/* * Copyright 2004-2005 the original author or authors. * * Licensed 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 jwm.msn; import jwm.*; import jwm.msn.vo.*; import jwm.vo.ImEventVO; import java.io.File; import java.util.*; import net.sf.jml.*; import net.sf.jml.impl.*; import net.sf.jml.message.MsnControlMessage; import net.sf.jml.message.MsnDatacastMessage; import net.sf.jml.message.MsnInstantMessage; /** * @author Roy Tsang * */ public class MsnClient { LoginVO loginVO; MsnMessenger messenger; MsnOwner msnOwner; MyListener myMsnListener; /** * indicate whether the buddy list is synchronized. */ public boolean isBuddyListReady=false,isDownloadContactPhoto=false; protected ImEvent imEvent; private Hashtable switchBoardList=new Hashtable(); private Hashtable groupedBuddyList=new Hashtable(),buddyList=new Hashtable(); private String emailAddress=new String(),id=new String(),status=new String(); public String tempFolder=new String(); /** * MsnClient object constructor * @param l login value object * @param ie Im Event Listener * @throws Exception */ public MsnClient(LoginVO l,ImEvent ie) throws Exception { this.loginVO=l; this.setEmailAddress(this.loginVO.getEmailAddress()); myMsnListener=new MyListener(ie); this.imEvent=ie; messenger = MsnMessengerFactory.createMsnMessenger(this.loginVO.getEmailAddress(),this.loginVO.getPassword()); msnOwner=messenger.getOwner(); messenger.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP15}); msnOwner.setInitStatus(this.loginVO.getInitStatus()); this.setStatus(this.loginVO.getStatus()); myMsnListener.setMsnClient(this); messenger.addMessengerListener(myMsnListener); messenger.addMessageListener(myMsnListener); messenger.addContactListListener(myMsnListener); messenger.addSwitchboardListener(myMsnListener); messenger.addFileTransferListener(myMsnListener); messenger.setLogIncoming(Utility.getSystemParameterBoolean("jwm.printJMLDebugLog")); messenger.setLogOutgoing(Utility.getSystemParameterBoolean("jwm.printJMLDebugLog")); } public boolean haveSuggestedName()throws Exception { DAO dao=new DAO(); boolean result=dao.haveSuggestedName(getEmailAddress()); dao.close(); dao=null; return result; } public void setInitPhoto(String photoPath)throws Exception { MsnObject displayPicture = MsnObject.getInstance(this.emailAddress,photoPath); messenger.getOwner().setInitDisplayPicture(displayPicture); } /** * set the temp. folder for storing contact photo * @param s */ public void setTempFolder(String s) { tempFolder=s; } /* * get IM event Listener * @return IM event listener */ public ImEvent getImEventListener() { return this.imEvent; } /** * add new contact * @param e new contact email address */ public void addContact(String e) { messenger.addFriend(Email.parseStr(e),e); } /** * refuse an add contact request * @param email contact email address */ public void refuseAddContactRequest(String email) { messenger.removeFriend(Email.parseStr(email), true); } /** * add switch board to switchboard list * @param id msn id * @param s msn switchboard */ @SuppressWarnings("unchecked") public void addSwitchBoard(String id,MsnSwitchboard s) { switchBoardList.put(id,s); } /** * remove switch board from switchboar list * @param id msn id * */ public void removeSwitchBoard(String id) { switchBoardList.remove(id); } /** * login msn server * @throws Exception */ public void login()throws Exception { messenger.login(); } /** * logout msn server */ public void logout() { messenger.logout(); messenger=null; File f=new File(tempFolder); if (f.exists()) { File []files=f.listFiles(); for (int i=0;i