1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.core.api.datetime.DateTimeService;
23
24 import java.sql.Date;
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Calendar;
28
29 public class ElectronicInvoiceUtils {
30
31 private final static Logger LOG = Logger.getLogger(ElectronicInvoiceUtils.class);
32
33 public static Date getDate(String invoiceDateString) {
34
35 boolean formatInvalid = true;
36 String formattedDateString = "";
37 String stringToParse = null;
38
39 if (StringUtils.isNotEmpty(invoiceDateString)) {
40
41 String dateToConvert = null;
42
43 formattedDateString = invoiceDateString.replaceAll("\\d", "0");
44
45 if (PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.CXML_DATE_FORMAT).equals(formattedDateString)) {
46
47 formatInvalid = false;
48 stringToParse = invoiceDateString;
49 } else if (PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.KUALI_DATE_FORMAT).equals(formattedDateString)) {
50 try {
51 java.util.Date javaDate = SpringContext.getBean(DateTimeService.class).convertToDate(invoiceDateString);
52 return org.kuali.ole.sys.util.KfsDateUtils.convertToSqlDate(javaDate);
53 } catch (ParseException e) {
54 return null;
55 }
56 } else if (PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.CXML_DATE_FORMAT).length() != formattedDateString.length()) {
57
58 formattedDateString = formattedDateString.substring(0, PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.CXML_DATE_FORMAT).length());
59
60 if (PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.CXML_DATE_FORMAT).equals(formattedDateString)) {
61
62 formatInvalid = false;
63 stringToParse = invoiceDateString.substring(0, PurApDateFormatUtils.getFormattingString(PurapConstants.NamedDateFormats.CXML_DATE_FORMAT).length());
64 } else {
65
66 }
67 } else {
68
69
70
71
72 }
73 }
74
75 if (formatInvalid) {
76 return null;
77 } else {
78
79 SimpleDateFormat sdf = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_DATE_FORMAT);
80 try {
81 return org.kuali.ole.sys.util.KfsDateUtils.convertToSqlDate(sdf.parse(stringToParse));
82 } catch (ParseException e) {
83 return null;
84 }
85 }
86
87 }
88
89 public static String getDateDisplayText(java.util.Date date) {
90 Calendar c = Calendar.getInstance();
91 c.setTime(date);
92
93 String monthPart = (c.get(Calendar.MONTH) + 1) + "";
94 String dayPart = c.get(Calendar.DATE) + "";
95 if (monthPart.length() == 1) {
96 monthPart = "0" + monthPart;
97 }
98
99 if (dayPart.length() == 1) {
100 dayPart = "0" + dayPart;
101 }
102
103 String useDate = monthPart + "/" + dayPart + "/" + c.get(Calendar.YEAR);
104 String actualDate = (date != null) ? date.toString() : "empty given date";
105 return useDate;
106 }
107
108 public static String stripSplChars(String data) {
109 if (data != null) {
110 StringBuffer result = new StringBuffer();
111 for (int i = 0; i < data.length(); i++) {
112 if (Character.isLetterOrDigit(data.charAt(i))) {
113 result.append(data.charAt(i));
114 }
115 }
116 return result.toString();
117 } else {
118 return null;
119 }
120 }
121
122 }