1 package org.kuali.ole.sip2.sip2Server;
2
3 import java.text.ParseException;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
6 import java.util.Date;
7
8
9
10
11
12
13 public class MessageUtil {
14
15
16
17
18
19
20
21 public static String computeChecksum(String str) {
22 char[] message = str.toCharArray();
23 int checksum = 0;
24 int i = 0;
25
26 while (i < str.length()) {
27 checksum += (int) message[i];
28 i++;
29 }
30
31
32 checksum = -(checksum & 0xFFFF);
33
34 return Integer.toHexString(checksum).substring(4, 8).toUpperCase();
35 }
36
37
38
39
40
41
42
43 public static String getSipDateTime() {
44 SimpleDateFormat simpleDf = new SimpleDateFormat("yyyyMMdd HHmmss");
45 return simpleDf.format(new Date());
46 }
47
48
49
50
51
52
53
54
55 public static Date parseSipDateTime(String dateStr) {
56 SimpleDateFormat simpleDf = new SimpleDateFormat("yyyyMMdd HHmmss");
57 try {
58 return simpleDf.parse(dateStr);
59 } catch (ParseException pe) {
60 return null;
61 }
62 }
63
64
65
66
67
68
69
70
71 public static String toSipDateTime(Date date) {
72 SimpleDateFormat simpleDf = new SimpleDateFormat("yyyyMMdd HHmmss");
73 return simpleDf.format(date);
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87 public static String createFutureDate(int days, int months) {
88 Calendar date = Calendar.getInstance();
89 date.setTime(new Date());
90 date.add(Calendar.DATE, days);
91 date.add(Calendar.MONTH, months);
92 return toSipDateTime(date.getTime());
93 }
94 }