This repository was archived by the owner on Apr 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMessage.java
275 lines (242 loc) · 5.37 KB
/
Message.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.Spryng.SpryngJavaSDK;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Represents a SMS message.
*/
public class Message implements Constants
{
/**
* The destination phone number.
*/
protected String destination;
/**
* The body of the SMS message.
*/
protected String body;
/**
* The service parameter, used for filtering.
*/
protected String service;
/**
* Parameter to specify the route to be used.
*/
protected String route;
/**
* Indicates whether it's OK to send multiple messages.
*/
protected boolean allowLong = false;
/**
* The Reference parameter, used to identify a message when receiving a delivery report.
*/
protected String reference;
/**
* Enable rawEncoding to send UTF-8 strings directly to API without converting first.
*/
protected boolean rawEncoding = false;
/**
* Instantiates a new Message.
*
* @param destination the destination
* @param body the body
* @param service the service
* @param route the route
* @param allowLong to allow long
* @param rawEncoding to enable raw encoding
* @param reference the reference
*/
public Message(String destination, String body, String service, String route, boolean allowLong, boolean rawEncoding, String reference)
{
this.destination = destination;
this.body = body;
this.service = service;
this.route = route;
this.allowLong = allowLong;
this.rawEncoding = rawEncoding;
this.reference = reference;
}
/**
* Instantiates a new Message.
*
* @param the destination
* @param the body
* @param the service
* @param the route
* @param to allowLong
* @param the reference
*/
public Message(String destination, String body, String service, String route, boolean allowLong, String reference)
{
this(destination, body, service, route, allowLong, false, reference);
}
/**
* Empty constructor
*/
public Message()
{
}
/**
* Checks if the supplied data is valid.
*
* @return the boolean
*/
public boolean isValid()
{
if (this.getDestination() == null)
{
return false;
}
else
{
Pattern p = Pattern.compile("^[1-9]{1}[0-9]{3,14}$");
Matcher m = p.matcher(this.getDestination());
if (!m.find())
{
return false;
}
}
if (this.getBody() == null || (this.isAllowLong() && this.getBody().length() > MAX_BODY_LENGTH_WITH_ALLOW_LONG) ||
(!this.isAllowLong() && this.getBody().length() > DEFAULT_MAX_BODY_LENGTH))
{
return false;
}
if (this.getRoute() == null)
{
return false;
}
if (this.getReference() != null)
{
if (this.getReference().length() < 1 || this.getReference().length() > REFERENCE_MAX_LENGTH)
{
return false;
}
}
return true;
}
/**
* Gets destination.
*
* @return the destination
*/
public String getDestination()
{
return destination;
}
/**
* Sets destination.
*
* @param destination the destination
*/
public void setDestination(String destination)
{
this.destination = destination;
}
/**
* Gets body.
*
* @return the body
*/
public String getBody()
{
return body;
}
/**
* Sets body.
*
* @param body the body
*/
public void setBody(String body)
{
this.body = body;
}
/**
* Gets service.
*
* @return the service
*/
public String getService()
{
return service;
}
/**
* Sets service.
*
* @param service the service
*/
public void setService(String service)
{
this.service = service;
}
/**
* Gets route.
*
* @return the route
*/
public String getRoute()
{
return route;
}
/**
* Sets route.
*
* @param route the route
*/
public void setRoute(String route)
{
this.route = route;
}
/**
* Is allow long boolean.
*
* @return the boolean
*/
public boolean isAllowLong()
{
return allowLong;
}
/**
* Sets allow long.
*
* @param allowLong the allow long
*/
public void setAllowLong(boolean allowLong)
{
this.allowLong = allowLong;
}
/**
* Gets reference.
*
* @return the reference
*/
public String getReference()
{
return reference;
}
/**
* Sets reference.
*
* @param reference the reference
*/
public void setReference(String reference)
{
this.reference = reference;
}
/**
* Gets rawEncoding setting
*
* @return
*/
public boolean isRawEncoding() {
return rawEncoding;
}
/**
* Sets if rawEncoding should be used
*
* @param rawEncoding
*/
public void setRawEncoding(boolean rawEncoding) {
this.rawEncoding = rawEncoding;
}
}