1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.marre.sms;
36
37 import java.io.*;
38
39 /***
40 * Represents a text message.
41 * <p>
42 * The text can be sent in unicode (max 70 chars/SMS), 8-bit (max 140 chars/SMS)
43 * or GSM encoding (max 160 chars/SMS).
44 *
45 * @author Markus Eriksson
46 * @version $Id: SmsTextMessage.java,v 1.27 2005/05/12 07:49:41 c95men Exp $
47 */
48 public class SmsTextMessage extends SmsConcatMessage
49 {
50 private String text_;
51 private SmsDcs dcs_;
52
53 /***
54 * Creates an SmsTextMessage with the given dcs.
55 *
56 * @param theMsg The message
57 * @param theDcs The data coding scheme
58 */
59 public SmsTextMessage(String theMsg, SmsDcs theDcs)
60 {
61 setText(theMsg, theDcs);
62 }
63
64 /***
65 * Creates an SmsTextMessage with the given alphabet and message class.
66 * <p>
67 * theAlphabet can be any of:<br>
68 * - SmsConstants.ALPHABET_GSM<br>
69 * - SmsConstants.ALPHABET_8BIT<br>
70 * - SmsConstants.ALPHABET_UCS2<br>
71 * <p>
72 * theMessageClass can be any of:<br>
73 * - SmsConstants.MSG_CLASS_0 (Often called a FLASH message)<br>
74 * - SmsConstants.MSG_CLASS_1<br>
75 * - SmsConstants.MSG_CLASS_2<br>
76 * - SmsConstants.MSG_CLASS_3<br>
77 *
78 * @param theMsg The message
79 * @param theAlphabet The alphabet
80 * @param theMessageClass The messageclass
81 */
82 public SmsTextMessage(String theMsg, int theAlphabet, byte theMessageClass)
83 {
84 this(theMsg, SmsDcs.getGeneralDataCodingDcs(theAlphabet, theMessageClass));
85 }
86
87 /***
88 * Creates an SmsTextMessage with default 7Bit GSM Alphabet
89 *
90 * @param theMsg The message
91 */
92 public SmsTextMessage(String theMsg)
93 {
94 this(theMsg, SmsDcs.ALPHABET_GSM, SmsDcs.MSG_CLASS_UNKNOWN);
95 }
96
97 /***
98 * Returns the text message.
99 */
100 public String getText()
101 {
102 return text_;
103 }
104
105 /***
106 * Sets the text.
107 *
108 * @param text
109 */
110 public void setText(String text)
111 {
112 if (text == null)
113 {
114 throw new IllegalArgumentException("Text cannot be null, use an empty string instead.");
115 }
116
117 text_ = text;
118 }
119
120 /***
121 * Sets the text.
122 *
123 * @param text
124 */
125 public void setText(String text, SmsDcs dcs)
126 {
127
128 if (text == null)
129 {
130 throw new IllegalArgumentException("text cannot be null, use an empty string instead.");
131 }
132
133 if (dcs == null)
134 {
135 throw new IllegalArgumentException("dcs cannot be null.");
136 }
137
138 text_ = text;
139 dcs_ = dcs;
140 }
141
142 /***
143 * Returns the dcs.
144 */
145 public SmsDcs getDcs()
146 {
147 return dcs_;
148 }
149
150 /***
151 * Returns the user data.
152 * @return user data
153 */
154 public SmsUserData getUserData()
155 {
156 SmsUserData ud;
157
158 try
159 {
160 switch (dcs_.getAlphabet())
161 {
162 case SmsDcs.ALPHABET_GSM:
163 ud = new SmsUserData(SmsPduUtil.getSeptets(text_), text_.length(), dcs_);
164 break;
165
166 case SmsDcs.ALPHABET_8BIT:
167 ud = new SmsUserData(text_.getBytes("ISO-8859-1"), text_.length(), dcs_);
168 break;
169
170 case SmsDcs.ALPHABET_UCS2:
171 ud = new SmsUserData(text_.getBytes("UTF-16BE"), text_.length() * 2, dcs_);
172 break;
173
174 default:
175 ud = null;
176 break;
177 }
178 }
179 catch (UnsupportedEncodingException ex)
180 {
181
182
183
184 throw new RuntimeException(ex);
185 }
186
187 return ud;
188 }
189
190 /***
191 * Returns null.
192 */
193 public SmsUdhElement[] getUdhElements()
194 {
195 return null;
196 }
197 }