1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.scaffold.text; |
18 | |
|
19 | |
import java.text.DateFormat; |
20 | |
import java.text.DecimalFormat; |
21 | |
import java.text.DecimalFormatSymbols; |
22 | |
import java.text.NumberFormat; |
23 | |
import java.text.ParseException; |
24 | |
import java.text.SimpleDateFormat; |
25 | |
|
26 | |
import java.util.Date; |
27 | |
import java.util.Iterator; |
28 | |
import java.util.List; |
29 | |
import java.util.Locale; |
30 | |
import java.util.Map; |
31 | |
import java.util.Map.Entry; |
32 | |
import java.util.Set; |
33 | |
import java.util.StringTokenizer; |
34 | |
|
35 | |
import java.sql.Timestamp; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public class ConvertUtils { |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | private ConvertUtils() { |
65 | |
; |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | public static String STRING_EMPTY = ""; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 0 | public static String EMPTY_STRING = STRING_EMPTY; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static final String STRING_SPACE = " "; |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public static final char SPACE = ' '; |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public static final char HORIZONTAL_TABULATION = '\t'; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public static final char LINE_FEED = '\r'; |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public static final char VERTICAL_TABULATION = '\u000B'; |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public static final char FORM_FEED = '\u000C'; |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public static final char CARRIAGE_RETURN = '\n'; |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public static final char FILE_SEPARATOR = '\u001C'; |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public static final char GROUP_SEPARATOR = '\u001D'; |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
public static final char RECORD_SEPARATOR = '\u001E'; |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public static final char UNIT_SEPARATOR = '\u001F'; |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | 0 | public static final char[] SEPARATORS = { |
155 | |
HORIZONTAL_TABULATION, |
156 | |
LINE_FEED, |
157 | |
VERTICAL_TABULATION, |
158 | |
FORM_FEED, |
159 | |
CARRIAGE_RETURN, |
160 | |
FILE_SEPARATOR, |
161 | |
GROUP_SEPARATOR, |
162 | |
RECORD_SEPARATOR, |
163 | |
UNIT_SEPARATOR |
164 | |
}; |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public static String[] tokensToArray(String tokens, String separator) { |
178 | |
|
179 | 0 | StringTokenizer tokenizer = |
180 | |
new StringTokenizer(tokens,separator); |
181 | 0 | int i = 0; |
182 | 0 | String[] array = new String[tokenizer.countTokens()]; |
183 | 0 | while (tokenizer.hasMoreTokens()) { |
184 | 0 | String token = tokenizer.nextToken().trim(); |
185 | 0 | if ((token==null) || (token.length()==0)) continue; |
186 | 0 | array[i++] = token; |
187 | 0 | } |
188 | 0 | return array; |
189 | |
|
190 | |
} |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public static List tokensToList(String tokens, String separator) { |
202 | |
|
203 | 0 | StringTokenizer tokenizer = |
204 | |
new StringTokenizer(tokens,separator); |
205 | 0 | List list = new java.util.ArrayList(tokenizer.countTokens()); |
206 | 0 | while (tokenizer.hasMoreTokens()) { |
207 | 0 | String token = tokenizer.nextToken().trim(); |
208 | 0 | if ((token==null) || (token.length()==0)) continue; |
209 | 0 | list.add(token); |
210 | 0 | } |
211 | 0 | return list; |
212 | |
|
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
public static boolean isBlank(String s) { |
224 | 0 | return blank(s); |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public static boolean isBlank(Integer key) { |
233 | 0 | return blank(key); |
234 | |
} |
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
public static boolean isBlankValue(String s) { |
242 | 0 | return blankValue(s); |
243 | |
} |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
public static boolean blank(String s) { |
251 | 0 | return ((null==s) || (STRING_EMPTY.equals(s.trim()))); |
252 | |
} |
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public static boolean blank(Number key) { |
260 | 0 | return ((null==key) || (0==key.byteValue())); |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
public static boolean blankValue(String s) { |
269 | 0 | if (null==s) return true; |
270 | 0 | String _s = s.trim(); |
271 | 0 | return ((STRING_EMPTY.equals(_s)) || (STRING_ZERO.equals(_s))); |
272 | |
} |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
public static String toTrimOrEmpty(String string) { |
279 | 0 | if (null==string) return STRING_EMPTY; |
280 | 0 | return string.trim(); |
281 | |
} |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
public static String toUpperOrNull(String string) { |
288 | 0 | if (null!=string) |
289 | 0 | return string.toUpperCase().trim(); |
290 | 0 | return null; |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | 0 | public static String QS_START = "?"; |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | 0 | public static String QS_DELIM = "&"; |
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | 0 | public static String QS_SEP = "="; |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
public static String addParam(String path, String name, String value) { |
316 | 0 | StringBuffer uri = new StringBuffer(path); |
317 | 0 | boolean isQuery = (path.indexOf(QS_START)>=0); |
318 | 0 | if (isQuery) |
319 | 0 | uri.append(QS_DELIM); |
320 | |
else |
321 | 0 | uri.append(QS_START); |
322 | 0 | uri.append(name); |
323 | 0 | uri.append(QS_SEP); |
324 | 0 | uri.append(value); |
325 | 0 | return uri.toString(); |
326 | |
|
327 | |
} |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
public static String addParams(String path, Map parameters) { |
334 | |
|
335 | 0 | if (null==path) path = new String(); |
336 | |
|
337 | 0 | if ((null==parameters) || (parameters.isEmpty())) return path; |
338 | |
|
339 | 0 | StringBuffer uri = new StringBuffer(path); |
340 | 0 | boolean isQuery = (path.indexOf(QS_START)>=0); |
341 | 0 | if (isQuery) |
342 | 0 | uri.append(QS_DELIM); |
343 | |
else |
344 | 0 | uri.append(QS_START); |
345 | |
|
346 | 0 | Set entries = parameters.entrySet(); |
347 | 0 | for (Iterator i = entries.iterator(); i.hasNext(); ) { |
348 | 0 | Entry e = (Entry) i.next(); |
349 | 0 | uri.append(e.getKey()); |
350 | 0 | uri.append(QS_SEP); |
351 | 0 | uri.append(e.getValue()); |
352 | 0 | } |
353 | 0 | return uri.toString(); |
354 | |
|
355 | |
} |
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
public static String renderHiddenFields(Map parameters) { |
362 | |
|
363 | 0 | if ((null==parameters) || (parameters.isEmpty())) return new String(); |
364 | |
|
365 | 0 | StringBuffer html = new StringBuffer(); |
366 | 0 | Set entries = parameters.entrySet(); |
367 | 0 | for (Iterator i = entries.iterator(); i.hasNext(); ) { |
368 | 0 | html.append("<input type='hidden' name='"); |
369 | 0 | Entry e = (Entry) i.next(); |
370 | 0 | html.append(e.getKey()); |
371 | 0 | html.append("' value='"); |
372 | 0 | html.append(e.getValue()); |
373 | 0 | html.append("' />"); |
374 | 0 | } |
375 | 0 | return html.toString(); |
376 | |
|
377 | |
} |
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
private static String stripLn(String string) { |
384 | |
|
385 | |
|
386 | 0 | for (int i=0; i<SEPARATORS.length; i++) { |
387 | 0 | string = string.replace( |
388 | |
SEPARATORS[i], |
389 | |
SPACE |
390 | |
); |
391 | |
} |
392 | 0 | return string; |
393 | |
} |
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | 0 | public static Double DOUBLE_ZERO = new Double(0); |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | 0 | public static Double DOUBLE_ONE = new Double((double) 1.0); |
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | 0 | public static Integer INTEGER_ZERO = new Integer(0); |
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | 0 | public static Integer INTEGER_ONE = new Integer(1); |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | 0 | public static Short SHORT_ZERO = new Short((short) 0); |
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | 0 | public static Short SHORT_ONE = new Short((short) 1); |
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | 0 | public static String STRING_ZERO = "0"; |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | 0 | public static String STRING_ONE = "1"; |
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
public static String getDigits(String s) { |
458 | 0 | if (s==null) return null; |
459 | 0 | int n = s.length(); |
460 | 0 | StringBuffer sb = new StringBuffer(n); |
461 | 0 | for (int i = 0; i < n; i++) { |
462 | 0 | char c = s.charAt(i); |
463 | 0 | if (Character.isDigit(c)) sb.append(c); |
464 | |
} |
465 | 0 | return (sb.toString()); |
466 | |
} |
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
public static String getNumber(Number value, Locale locale) { |
473 | 0 | if (locale==null) |
474 | 0 | return (NumberFormat.getInstance().format(value)); |
475 | 0 | return (NumberFormat.getInstance(locale).format(value)); |
476 | |
} |
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
public static String getPercent(Number value, Locale locale) { |
483 | 0 | if (locale==null) |
484 | 0 | return (NumberFormat.getPercentInstance().format(value)); |
485 | 0 | return (NumberFormat.getPercentInstance(locale).format(value)); |
486 | |
} |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | |
public static boolean luhnCheck(String number) { |
508 | 0 | int no_digit = number.length(); |
509 | 0 | int oddoeven = no_digit & 1; |
510 | 0 | long sum = 0; |
511 | 0 | for (int count = 0; count < no_digit; count++) { |
512 | 0 | int digit = Integer.parseInt( |
513 | |
String.valueOf(number.charAt(count))); |
514 | 0 | if ( ( (count & 1) ^ oddoeven) ==0 ) { |
515 | 0 | digit *= 2; |
516 | 0 | if (digit > 9) digit -= 9; |
517 | |
}; |
518 | 0 | sum += digit; |
519 | |
}; |
520 | 0 | if (sum == 0) return false; |
521 | 0 | if (sum % 10 == 0) return true; |
522 | 0 | return false; |
523 | |
} |
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
public static String addLuhnDigit(String number) { |
533 | |
|
534 | |
|
535 | 0 | char[] digits = {'1','2','3','4','5','6','7','8','9','0'}; |
536 | 0 | int c = number.length(); |
537 | 0 | StringBuffer tryNumber = new StringBuffer(number + digits[0]); |
538 | |
int i; |
539 | 0 | for (i=0; i<10; i++) { |
540 | 0 | tryNumber.setCharAt(c,digits[i]); |
541 | 0 | if (luhnCheck(tryNumber.toString())) |
542 | 0 | break; |
543 | |
} |
544 | 0 | return tryNumber.toString(); |
545 | |
} |
546 | |
|
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | 0 | public static String DECIMAL_PATTERN ="###,###.###"; |
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | |
public static DecimalFormatSymbols getGenericDecimal(Locale locale) { |
562 | 0 | DecimalFormatSymbols symbols = |
563 | |
new DecimalFormatSymbols(locale); |
564 | 0 | symbols.setGroupingSeparator('`'); |
565 | 0 | return symbols; |
566 | |
} |
567 | |
|
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | |
public static String getDecimal(Number value, Locale locale) { |
573 | 0 | if (locale==null) |
574 | 0 | return (DecimalFormat.getInstance().format(value)); |
575 | 0 | return (DecimalFormat.getInstance().format(value)); |
576 | |
} |
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
public static String getDecimal(Number value, Locale locale, String pattern) { |
584 | |
NumberFormat formatter; |
585 | 0 | if (locale==null) |
586 | 0 | formatter = new java.text.DecimalFormat(pattern); |
587 | |
else { |
588 | 0 | formatter = NumberFormat.getNumberInstance(locale); |
589 | 0 | DecimalFormat df = (DecimalFormat) formatter; |
590 | 0 | df.applyPattern(pattern); |
591 | 0 | return df.format(value); |
592 | |
} |
593 | 0 | return (formatter.format(value)); |
594 | |
} |
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
public static String getDecimal(Number value) { |
601 | 0 | return getDecimal(value,(Locale) null,DECIMAL_PATTERN); |
602 | |
} |
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | 0 | public static String CURRENCY_PATTERN ="$" + DECIMAL_PATTERN; |
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
public static String getCurrency(Number value) { |
619 | 0 | return getDecimal(value,null,CURRENCY_PATTERN); |
620 | |
} |
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
|
629 | 0 | public static int DEFAULT = DateFormat.DEFAULT; |
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | 0 | public static int SHORT = DateFormat.SHORT; |
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | 0 | public static int MEDIUM = DateFormat.MEDIUM; |
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | 0 | public static int LONG = DateFormat.LONG; |
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | 0 | public static int FULL = DateFormat.FULL; |
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | 0 | private static boolean LENIENT_DATE = false; |
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | 0 | public static String ESCAPE_DATE_PATTERN = "yyyy-mm-dd"; |
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
public static Date getDate(String dateDisplay, |
676 | |
String format, boolean lenient) { |
677 | 0 | if (dateDisplay == null) { |
678 | 0 | return null; |
679 | |
} |
680 | 0 | DateFormat df = null; |
681 | |
try { |
682 | 0 | if (format==null) { |
683 | 0 | df = new SimpleDateFormat(); |
684 | |
} |
685 | |
else { |
686 | 0 | df = new SimpleDateFormat(format); |
687 | |
} |
688 | |
|
689 | |
|
690 | 0 | df.setLenient(false); |
691 | 0 | return df.parse(dateDisplay); |
692 | |
} |
693 | 0 | catch(ParseException e) { |
694 | 0 | return null; |
695 | |
} |
696 | |
} |
697 | |
|
698 | |
|
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
public static Date getDate(String dateDisplay, String format) { |
706 | 0 | return getDate(dateDisplay,format,LENIENT_DATE); |
707 | |
} |
708 | |
|
709 | |
|
710 | |
|
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
|
716 | |
public static Date getDate(String dateDisplay) { |
717 | 0 | return getDate(dateDisplay,null,LENIENT_DATE); |
718 | |
} |
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
public static Date toDate(String string) { |
727 | 0 | if (string==null) |
728 | 0 | return null; |
729 | |
else try { |
730 | 0 | return getDate(string); |
731 | 0 | } catch (Throwable t) { |
732 | 0 | return null; |
733 | |
} |
734 | |
} |
735 | |
|
736 | |
|
737 | |
|
738 | |
|
739 | |
|
740 | |
|
741 | |
public static String getDate(Date date, Locale locale, int style) { |
742 | 0 | if (locale==null) |
743 | 0 | return (DateFormat.getDateInstance(style).format(date)); |
744 | 0 | return (DateFormat.getDateInstance(style,locale).format(date)); |
745 | |
} |
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
|
751 | |
|
752 | |
public static String getDate(Date date, int style) { |
753 | 0 | return getDate(date,(Locale) null,style); |
754 | |
} |
755 | |
|
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | |
|
761 | |
public static String getDate(Date date) { |
762 | 0 | return getDate(date,(Locale) null,DEFAULT); |
763 | |
} |
764 | |
|
765 | |
|
766 | |
|
767 | |
|
768 | |
|
769 | |
|
770 | |
|
771 | |
public static String toString(Date date) { |
772 | 0 | if (date==null) |
773 | 0 | return null; |
774 | |
else |
775 | 0 | return getDate(date); |
776 | |
} |
777 | |
|
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
public static String toEscape(Date date) { |
785 | 0 | if (date==null) |
786 | 0 | return null; |
787 | 0 | DateFormat df = null; |
788 | |
try { |
789 | 0 | df = new SimpleDateFormat(ESCAPE_DATE_PATTERN); |
790 | 0 | } catch (Throwable t) { |
791 | 0 | return null; |
792 | 0 | } |
793 | 0 | df.setLenient(false); |
794 | 0 | return df.format(date); |
795 | |
} |
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
public static final String DATE_SEPARATOR = "-"; |
804 | |
|
805 | |
|
806 | |
|
807 | |
|
808 | |
|
809 | |
public static final String TIME_SEPARATOR = ":"; |
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
public static final String DATE_TIME_SEPARATOR = STRING_SPACE; |
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
public static final String TIMESTAMP_DATE_ZERO = "0002-11-30"; |
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
|
830 | |
public static final String TIMESTAMP_TIME_ZERO = " 00:00:00.0"; |
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
|
836 | |
|
837 | 0 | public static String ZERO_TIMESTAMP_DISPLAY = "2-11-30 00:00:00"; |
838 | |
|
839 | |
|
840 | |
|
841 | |
|
842 | |
|
843 | 0 | public static Timestamp ZERO_TIMESTAMP = new Timestamp((long) 00000000000000); |
844 | |
|
845 | |
|
846 | |
|
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | 0 | public static String NULL_TIMESTAMP_DISPLAY = "1970-01-01 00:00:00"; |
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
|
857 | 0 | public static String NULL_TIMESTAMP_TEXT = "NULL_TIMESTAMP_DISPLAY"; |
858 | |
|
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | 0 | public static long NULL_TIME = (long) 18000000; |
868 | |
|
869 | |
|
870 | |
|
871 | |
|
872 | |
|
873 | 0 | public static Timestamp NULL_TIMESTAMP = new Timestamp(NULL_TIME); |
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
|
879 | |
|
880 | 0 | public static Timestamp MAX_TIMESTAMP = Timestamp.valueOf("2029-12-31 23:59:59.999"); |
881 | |
|
882 | |
|
883 | |
|
884 | |
|
885 | |
|
886 | |
public static String getTimestampDisplayNull() { |
887 | 0 | return NULL_TIMESTAMP_DISPLAY; |
888 | |
} |
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
public static String getTimestampDisplay() { |
895 | 0 | return getTimestamp(new Timestamp(System.currentTimeMillis())); |
896 | |
} |
897 | |
|
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
public static String getTimestampText() { |
903 | 0 | return getTimestampDisplay(); |
904 | |
} |
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
public static boolean isNull(Timestamp timestamp) { |
912 | 0 | return ((timestamp==null) || (timestamp.getTime()==NULL_TIME)); |
913 | |
} |
914 | |
|
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
public static Timestamp getTimestamp() { |
923 | 0 | return new Timestamp(System.currentTimeMillis()); |
924 | |
} |
925 | |
|
926 | |
|
927 | |
|
928 | |
|
929 | |
|
930 | |
|
931 | |
public static String getTimestamp(Timestamp timestamp, |
932 | |
Locale locale, int style) { |
933 | 0 | Date date = (Date) timestamp; |
934 | 0 | if (locale==null) |
935 | 0 | return (DateFormat.getDateTimeInstance(style,style). |
936 | |
format(date)); |
937 | 0 | return (DateFormat.getDateTimeInstance(style,style,locale). |
938 | |
format(date)); |
939 | |
} |
940 | |
|
941 | |
|
942 | |
|
943 | |
|
944 | |
|
945 | |
|
946 | |
public static String getTimestamp(Timestamp timestamp, |
947 | |
int style) { |
948 | 0 | return getTimestamp(timestamp,(Locale) null,style); |
949 | |
} |
950 | |
|
951 | |
|
952 | |
|
953 | |
|
954 | |
|
955 | |
|
956 | |
public static String getTimestamp(Timestamp timestamp) { |
957 | 0 | return getTimestamp(timestamp,(Locale) null,DEFAULT); |
958 | |
} |
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | |
|
966 | |
public static Timestamp toTimestamp(String string) { |
967 | 0 | if (string==null) |
968 | 0 | return null; |
969 | |
else try { |
970 | 0 | return Timestamp.valueOf(string); |
971 | 0 | } catch (Throwable t) { |
972 | 0 | return null; |
973 | |
} |
974 | |
} |
975 | |
|
976 | |
|
977 | |
|
978 | |
|
979 | |
|
980 | |
|
981 | |
|
982 | |
|
983 | |
|
984 | |
|
985 | |
public static Timestamp toTimestamp(String year, String month, String day) { |
986 | |
|
987 | 0 | if ((null==year) || (null==month) || (null==day)) return null; |
988 | |
|
989 | 0 | StringBuffer sb = new StringBuffer(); |
990 | |
|
991 | 0 | sb.append(year); sb.append(DATE_SEPARATOR); |
992 | 0 | sb.append(month); sb.append(DATE_SEPARATOR); |
993 | 0 | sb.append(day); |
994 | |
|
995 | 0 | sb.append(TIMESTAMP_TIME_ZERO); |
996 | |
|
997 | 0 | return toTimestamp(sb.toString()); |
998 | |
} |
999 | |
|
1000 | |
|
1001 | |
|
1002 | |
|
1003 | |
|
1004 | |
|
1005 | |
|
1006 | |
public static String toString(Timestamp timestamp) { |
1007 | 0 | if (timestamp==null) |
1008 | 0 | return null; |
1009 | |
else |
1010 | 0 | return timestamp.toString(); |
1011 | |
} |
1012 | |
|
1013 | |
|
1014 | |
|
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | |
|
1022 | |
|
1023 | |
public static Integer ipNode(String ipAddress) { |
1024 | 0 | return INTEGER_ZERO; |
1025 | |
} |
1026 | |
|
1027 | |
|
1028 | |
} |
1029 | |
|