1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.oscar.server;
20
21 import net.sf.dexterim.oscar.entity.ByteBased;
22 import net.sf.dexterim.oscar.entity.Snac;
23 import net.sf.dexterim.oscar.entity.TLVCollection;
24 import net.sf.dexterim.oscar.entity.TLVFactory;
25 import net.sf.dexterim.oscar.entity.TLVLexer;
26 import net.sf.dexterim.oscar.entity.Word;
27
28
29 public class MessageOfTheDayResponse implements Response {
30 private String message;
31 private int type;
32
33 public MessageOfTheDayResponse(int type, String message) {
34 this.message = message;
35 this.type = type;
36 }
37
38 public String toString() {
39 return "[MOTD Message type " + type + " message " + message + "]";
40 }
41
42 public String getMessage() {
43 return message;
44 }
45
46 public int getType() {
47 return type;
48 }
49
50 /***
51 * @param snac
52 * @return
53 */
54 public static Response create(Snac snac) {
55 Word motdType = Word.createFrom(snac.getData());
56
57 TLVCollection tlvs = TLVLexer.getInstance().lexData(snac.getData(),
58 motdType.getLength());
59
60 TLVCollection motdString = tlvs.getType(TLVFactory.getInstance()
61 .createMOTDString().getType());
62
63 if (!motdString.isSingle()) {
64 return new MessageOfTheDayResponse(motdType.getValue(), new String());
65 } else {
66 ByteBased motdBytes = motdString.getSingle().getData();
67
68 return new MessageOfTheDayResponse(motdType.getValue(),
69 new String(motdBytes.toByteArray()));
70 }
71 }
72 }