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