View Javadoc
1   //////////////////////////////////////////////////////////////////////////////
2   // dexterIM - Instant Messaging Framework
3   // Copyright (C) 2003 Christoph Walcher
4   //
5   // This program is free software; you can redistribute it and/or modify
6   // it under the terms of the GNU General Public License as published by
7   // the Free Software Foundation; either version 2 of the License, or
8   // (at your option) any later version.
9   //
10  // This program is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  // GNU General Public License for more details.
14  //
15  // You should have received a copy of the GNU General Public License
16  // along with this program; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  //////////////////////////////////////////////////////////////////////////////
19  package net.sf.dexterim.msn.message;
20  
21  import java.util.regex.Matcher;
22  import java.util.regex.Pattern;
23  
24  import net.sf.dexterim.msn.MsnConnection;
25  import net.sf.dexterim.msn.util.SpecialCharacters;
26  
27  /***
28   * Description of the Class
29   * 
30   * @author christoph
31   */
32  public class ContactListMessage extends SingleLineMessage {
33  
34  	private String account;
35  	private String nick;
36  	private String list;
37  	private int contactNumber = 0;
38  	private int contactCount = 0;
39  
40  	private static final Pattern contactListPattern = Pattern
41  			.compile("LST( N=(//S*))?( F=(//S*))?");
42  
43  	/***
44  	 * Constructor for the ContactListMessage object
45  	 */
46  	public ContactListMessage() {
47  	}
48  
49  	/***
50  	 * Gets the messageCommand attribute of the ContactListMessage object
51  	 * 
52  	 * @return The messageCommand value
53  	 */
54  	public String getMessageCommand() {
55  		return MsnMessageFactory.CMD_LIST;
56  	}
57  
58  	/***
59  	 * Getter for property account.
60  	 * 
61  	 * @return Value of property account.
62  	 */
63  	public java.lang.String getAccount() {
64  		return account;
65  	}
66  
67  	/***
68  	 * Getter for property nick.
69  	 * 
70  	 * @return Value of property nick.
71  	 */
72  	public java.lang.String getNick() {
73  		return nick != null ? nick : account;
74  	}
75  
76  	/***
77  	 * Getter for property list.
78  	 * 
79  	 * @return Value of property list.
80  	 */
81  	public java.lang.String getList() {
82  		return list;
83  	}
84  
85  	/***
86  	 * Adds a feature to the Line attribute of the ContactListMessage object
87  	 * 
88  	 * @param line
89  	 *          The feature to be added to the Line attribute
90  	 * @return Description of the Return Value
91  	 * @exception MessageFormatException
92  	 *              Description of the Exception
93  	 */
94  	public MsnMessage addLine(String line) throws MessageFormatException {
95  		Matcher matcher = contactListPattern.matcher(line);
96  
97  		while (matcher.find()) {
98  			String identity = matcher.group(2);
99  
100 			if (identity != null) {
101 				this.account = SpecialCharacters.getInstance().decode(identity, true);
102 			}
103 
104 			String friendlyName = matcher.group(4);
105 
106 			if (friendlyName != null) {
107 				this.nick = SpecialCharacters.getInstance().decode(friendlyName, true);
108 			}
109 		}
110 
111 		return this;
112 	}
113 
114 	/***
115 	 * Getter for property contactNumber.
116 	 * 
117 	 * @return Value of property contactNumber.
118 	 */
119 	public int getContactNumber() {
120 		return contactNumber;
121 	}
122 
123 	/***
124 	 * Getter for property contactCount.
125 	 * 
126 	 * @return Value of property contactCount.
127 	 */
128 	public int getContactCount() {
129 		return contactCount;
130 	}
131 
132 	/*
133 	 * (non-Javadoc)
134 	 * 
135 	 * @see net.sf.dexterim.msn.message.MsnMessage#process(net.sf.dexterim.msn.MsnConnection)
136 	 */
137 	public void process(MsnConnection connection) {
138 		connection.processContact(this);
139 	}
140 }