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  
22  /***
23   *@author     christoph
24   */
25  public class MsnMessageFactory {
26    /***
27     *  Description of the Field
28     */
29    public final static String MAGIC_STRING = "Q1P7W2E4J9R8U3S5";
30  
31    /***
32     *  Description of the Field
33     */
34    public final static String CMD_RING = "RNG";
35  
36    /***
37     *  Description of the Field
38     */
39    public final static String CMD_REFER = "XFR";
40  
41    /***
42     *  Description of the Field
43     */
44    public final static String CMD_CHECK = "CHL";
45  
46    /***
47     *  Description of the Field
48     */
49    public final static String CMD_OFFLINE = "FLN";
50  
51    /***
52     *  Description of the Field
53     */
54    public final static String CMD_ONLINE = "NLN";
55  
56    /***
57     *  Description of the Field
58     */
59    public final static String CMD_STATUS_CHANGE = "ILN";
60  
61    /***
62     *  Description of the Field
63     */
64    public final static String CMD_NEW_MAIL = "MSN";
65  
66    /***
67     *  Description of the Field
68     */
69    public final static String CMD_LIST = "LST";
70  
71    /***
72     *  Description of the Field
73     */
74    public final static String CMD_USER_MESSAGE = "MSG";
75  
76    /***
77     *  Description of the Field
78     */
79    public final static String CMD_USER_TYPING = "TypingUser";
80  
81    /***
82     *  Description of the Field
83     */
84    public final static String CMD_USER_JOINED = "JOI";
85  
86    /***
87     *  Description of the Field
88     */
89    public final static String CMD_USER_JOINING = "IRO";
90  
91    /***
92     *  Description of the Field
93     */
94    public final static String CMD_USER_LEFT = "BYE";
95  
96    /***
97     *  Description of the Field
98     */
99    public final static String CMD_PERSONAL_PHONE_NUMBER = "PRP";
100 
101   /***
102    *  Description of the Field
103    */
104   public final static String CMD_BUDDY_PHONE_NUMBER = "BPR";
105 
106   /***
107    *  Description of the Field
108    */
109   public final static String CMD_REMOVE_FROM_LIST = "REM";
110 
111   /***
112    *  Description of the Field
113    */
114   public final static String CMD_ADD_TO_LIST = "ADD";
115 
116   /***
117    *  Description of the Field
118    */
119   public final static String CMD_CHANGE_SCREEN_NAME = "REA";
120 
121   /***
122    *  Description of the Field
123    */
124   public final static String CMD_HOTMAIL_PROFILE = "MSG";
125   private static MsnMessageFactory instance = null;
126   private MsnMessage workingMessage = null;
127 
128   /***
129    *  Creates a new instance of MsnMessage
130    */
131   protected MsnMessageFactory() {
132   }
133 
134   /***
135    *  Description of the Method
136    *
137    *@param  messageString               Description of the Parameter
138    *@return                             Description of the Return Value
139    *@exception  MessageFormatException  Description of the Exception
140    */
141   public synchronized MsnMessage createMsnMessage(String messageString)
142     throws MessageFormatException {
143     if (messageString == null) {
144       return null;
145     }
146 
147     if (workingMessage == null) {
148       workingMessage = createWorkMessage(messageString);
149 
150       if (workingMessage == null) {
151         return null;
152       }
153     }
154 
155     workingMessage.addLine(messageString);
156 
157     if (workingMessage.isCompleted()) {
158       MsnMessage tmpMessage = workingMessage;
159 
160       workingMessage = null;
161 
162       return tmpMessage;
163     }
164 
165     return null;
166   }
167 
168   /***
169    *  Description of the Method
170    *
171    *@param  messageString  Description of the Parameter
172    *@return                Description of the Return Value
173    */
174   protected MsnMessage createWorkMessage(String messageString) {
175     if (messageString.startsWith(CMD_REFER)) {
176       return new net.sf.dexterim.msn.message.SwitchBoardMessage();
177     }
178     else if (messageString.startsWith(CMD_RING)) {
179       return new net.sf.dexterim.msn.message.StartConversationMessage();
180     }
181     else if (messageString.startsWith(CMD_CHECK)) {
182       return new net.sf.dexterim.msn.message.CheckMessage();
183     }
184     else if (messageString.startsWith(CMD_OFFLINE)) {
185       return new net.sf.dexterim.msn.message.OfflineMessage();
186     }
187     else if (messageString.startsWith(CMD_ONLINE)) {
188       return new net.sf.dexterim.msn.message.OnlineMessage();
189     }
190     else if (messageString.startsWith(CMD_STATUS_CHANGE)) {
191       return new net.sf.dexterim.msn.message.ChangeStatusMessage();
192     }
193     else if (messageString.startsWith(CMD_PERSONAL_PHONE_NUMBER)) {
194       return new net.sf.dexterim.msn.message.PersonalInformationMessage();
195     }
196     else if (messageString.startsWith(CMD_BUDDY_PHONE_NUMBER)) {
197       return new net.sf.dexterim.msn.message.BuddyPhoneMessage();
198     }
199     else if (messageString.startsWith(CMD_REMOVE_FROM_LIST)) {
200       return new net.sf.dexterim.msn.message.RemoveFromListMessage();
201     }
202     else if (messageString.startsWith(CMD_ADD_TO_LIST)) {
203       return new net.sf.dexterim.msn.message.AddToListMessage();
204     }
205     else if (messageString.startsWith(CMD_CHANGE_SCREEN_NAME)) {
206       return new net.sf.dexterim.msn.message.ChangeScreenNameMessage();
207     }
208     else if (messageString.startsWith(CMD_HOTMAIL_PROFILE)) {
209       return new net.sf.dexterim.msn.message.HotmailProfileMessage();
210     }
211     else if (messageString.startsWith(CMD_LIST)) {
212       try {
213         return new net.sf.dexterim.msn.message.ContactListMessage();
214       }
215       catch (Exception ex) {
216         return null;
217       }
218     }
219 
220     return null;
221   }
222 
223   /***
224    *  Gets the instance attribute of the MsnMessageFactory class
225    *
226    *@return    The instance value
227    */
228   public static synchronized MsnMessageFactory getInstance() {
229     if (instance == null) {
230       instance = new MsnMessageFactory();
231     }
232 
233     return instance;
234   }
235 }