KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > config > FieldValue


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/config/FieldValue.java,v 1.19 2005/02/19 21:26:27 hkollmann Exp $
3  * $Revision: 1.19 $
4  * $Date: 2005/02/19 21:26:27 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.config;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import org.dbforms.util.FileHolder;
31 import org.dbforms.util.TimeUtil;
32 import org.dbforms.util.UniqueIDGenerator;
33 import org.dbforms.util.Util;
34
35 // imports for return objects
36
import java.io.Serializable JavaDoc;
37 import java.math.BigDecimal JavaDoc;
38
39 import java.sql.Date JavaDoc;
40 import java.sql.Time JavaDoc;
41 import java.sql.Timestamp JavaDoc;
42
43 import java.text.DecimalFormat JavaDoc;
44 import java.text.SimpleDateFormat JavaDoc;
45
46 import java.util.Calendar JavaDoc;
47 import java.util.Locale JavaDoc;
48
49
50
51 /**
52  * This helper-class was originally used to maintain the mapped values between
53  * Main-Form and Sub-Form in the taglib package. in meantime it is used as
54  * holder of data in many places. <br>
55  * It also performs operations that involve "fields" and associated "values"
56  * (i.e. building blocks of SQL SELECT statements, etc) Now it's handles all
57  * the stuf of parsing the resended strings back into java objects.
58  *
59  * @author Joe Peer
60  * @author Philip Grunikiewicz
61  * @author Henner Kollmann
62  */

63 public class FieldValue implements Cloneable JavaDoc, Serializable JavaDoc {
64    /** field object */
65    private Field field;
66
67    /** holds the FileHolder object */
68    private FileHolder fileHolder;
69
70    /** holds the current locale */
71    private Locale JavaDoc locale;
72
73    /** logging category for this class */
74    private static Log logCat = LogFactory.getLog(FieldValue.class.getName());
75
76    /** a value a field is associated with */
77    private String JavaDoc fieldValue;
78
79    /** old value */
80    private String JavaDoc oldValue;
81
82    /** holds the format object */
83    private String JavaDoc pattern;
84
85    /** specifies whether to OR all values or AND them... */
86    private boolean logicalOR = false;
87
88    /**
89     * If FieldValue is used in a "childFieldValue", it signalizes if it should
90     * be rendered as hidden tag or not (if "stroke out")
91     */

92    private boolean renderHiddenHtmlTag = true;
93
94    /**
95     * if used in a filter argument: the type of filter comparison operator (see
96     * FILTER_ definitions above)
97     */

98    private int operator;
99
100    /** if used in an argument for searching: SHARP || WEAK! */
101    private int searchAlgorithm;
102
103    /** if used in an argument for searching: AND || OR! */
104    private int searchMode;
105
106    /**
107     * Field sor direction. Can be Field.ORDER_ASCENDING or
108     * Field.ORDER_DESCENDING.
109     */

110    private int sortDirection = Constants.ORDER_NONE;
111
112    /**
113     * Creates a new FieldValue object.
114     *
115     * @param field the name of the field
116     * @param fieldValue the string representation of the value of the field
117     */

118    public FieldValue(Field field,
119                      String JavaDoc fieldValue) {
120       this(field);
121       this.fieldValue = fieldValue;
122    }
123
124
125    /**
126     * Creates a new FieldValue object.
127     *
128     * @param field the name of the field
129     */

130    private FieldValue(Field field) {
131       this.field = field;
132    }
133
134    /**
135     * DOCUMENT ME!
136     *
137     * @param field DOCUMENT ME!
138     * @param fieldValue DOCUMENT ME!
139     * @param locale DOCUMENT ME!
140     * @param operator DOCUMENT ME!
141     * @param searchMode DOCUMENT ME!
142     * @param searchAlgorithm DOCUMENT ME!
143     * @param logicalOR DOCUMENT ME!
144     *
145     * @return DOCUMENT ME!
146     */

147    public static FieldValue createFieldValueForSearching(Field field,
148                                                          String JavaDoc fieldValue,
149                                                          Locale JavaDoc locale,
150                                                          int operator,
151                                                          int searchMode,
152                                                          int searchAlgorithm,
153                                                          boolean logicalOR) {
154       FieldValue fv = new FieldValue(field, fieldValue);
155       fv.setLocale(locale);
156       fv.setOperator(operator);
157       fv.setSearchMode(searchMode);
158       fv.setSearchAlgorithm(searchAlgorithm);
159       fv.setLogicalOR(logicalOR);
160
161       return fv;
162    }
163
164
165    /**
166     * DOCUMENT ME!
167     *
168     * @param field DOCUMENT ME!
169     * @param sortDirection DOCUMENT ME!
170     *
171     * @return DOCUMENT ME!
172     */

173    public static FieldValue createFieldValueForSorting(Field field,
174                                                        int sortDirection) {
175       FieldValue fv = new FieldValue(field);
176       fv.setSortDirection(sortDirection);
177
178       return fv;
179    }
180
181
182    /**
183     * Sets the field attribute of the FieldValue object
184     *
185     * @param field The new field value
186     */

187    public void setField(Field field) {
188       this.field = field;
189    }
190
191
192    /**
193     * Gets the field attribute of the FieldValue object
194     *
195     * @return The field value
196     */

197    public Field getField() {
198       return field;
199    }
200
201
202    /**
203     * Sets the fieldValue attribute of the FieldValue object
204     *
205     * @param fieldValue The new fieldValue value
206     */

207    public void setFieldValue(String JavaDoc fieldValue) {
208       this.fieldValue = fieldValue;
209    }
210
211
212    /**
213     * Gets the fieldValue attribute of the FieldValue object
214     *
215     * @return The fieldValue value
216     */

217    public String JavaDoc getFieldValue() {
218       return fieldValue;
219    }
220
221
222    /**
223     * parses the given fieldValue according to the given type and creates an
224     * java object of the needed type. during the parsing the given
225     * locale/format settings will be used.
226     *
227     * @return Object of given type;
228     */

229    public Object JavaDoc getFieldValueAsObject() {
230       if (getField() == null) {
231          return null;
232       }
233
234       return getFieldValueAsObject(getFieldValue(), getField().getType());
235    }
236
237
238    /**
239     * Sets the fileHolder.
240     *
241     * @param fileHolder The fileHolder to set
242     */

243    public void setFileHolder(FileHolder fileHolder) {
244       this.fileHolder = fileHolder;
245    }
246
247
248    /**
249     * Return the fileHolder object for this field.
250     *
251     * @return the fileHolder object of this field
252     */

253    public FileHolder getFileHolder() {
254       return fileHolder;
255    }
256
257
258    /**
259     * DOCUMENT ME!
260     *
261     * @param locale
262     */

263    public void setLocale(Locale JavaDoc locale) {
264       this.locale = locale;
265    }
266
267
268    /**
269     * DOCUMENT ME!
270     *
271     * @return
272     */

273    public Locale JavaDoc getLocale() {
274       return locale;
275    }
276
277
278    /**
279     * Set the logicalOR attribute of this FieldValue object.
280     *
281     * @param newLogicalOR the logicalOR attribute value to set
282     */

283    public void setLogicalOR(boolean newLogicalOR) {
284       logicalOR = newLogicalOR;
285    }
286
287
288    /**
289     * Get the logicalOR attribute of this FieldValue object.
290     *
291     * @return the logicalOR attribute of this FieldValue object
292     */

293    public boolean getLogicalOR() {
294       return logicalOR;
295    }
296
297
298    /**
299     * test if given FieldValue[] is empty
300     *
301     * @param arr FieldValue[] to test
302     *
303     * @return true if array is null or empty
304     */

305    public static final boolean isNull(FieldValue[] arr) {
306       return ((arr == null) || (arr.length == 0));
307    }
308
309
310    /**
311     * Set the oldValue for this Field object.
312     *
313     * @param string the oldValue for this Field object
314     */

315    public void setOldValue(String JavaDoc string) {
316       oldValue = string;
317    }
318
319
320    /**
321     * Get the oldValue of this Field object.
322     *
323     * @return the oldValue of this Field object
324     */

325    public String JavaDoc getOldValue() {
326       return oldValue;
327    }
328
329
330    /**
331     * DOCUMENT ME!
332     *
333     * @return DOCUMENT ME!
334     */

335    public Object JavaDoc getOldValueAsObject() {
336       if (getField() == null) {
337          return null;
338       }
339
340       return getFieldValueAsObject(getOldValue(), getField().getType());
341    }
342
343
344    /**
345     * sets the operator
346     *
347     * @param i
348     */

349    public void setOperator(int i) {
350       operator = i;
351    }
352
353
354    /**
355     * Gets the operator attribute of the FieldValue object
356     *
357     * @return The operator value
358     */

359    public int getOperator() {
360       return operator;
361    }
362
363
364    /**
365     * DOCUMENT ME!
366     *
367     * @param pattern
368     */

369    public void setPattern(String JavaDoc pattern) {
370       this.pattern = pattern;
371    }
372
373
374    /**
375     * DOCUMENT ME!
376     *
377     * @return
378     */

379    public String JavaDoc getPattern() {
380       return pattern;
381    }
382
383
384    /**
385     * Sets the renderHiddenHtmlTag attribute of the FieldValue object
386     *
387     * @param renderHiddenHtmlTag The new renderHiddenHtmlTag value
388     */

389    public void setRenderHiddenHtmlTag(boolean renderHiddenHtmlTag) {
390       this.renderHiddenHtmlTag = renderHiddenHtmlTag;
391    }
392
393
394    /**
395     * Gets the renderHiddenHtmlTag attribute of the FieldValue object
396     *
397     * @return The renderHiddenHtmlTag value
398     */

399    public boolean getRenderHiddenHtmlTag() {
400       return renderHiddenHtmlTag;
401    }
402
403
404    /**
405     * Sets the searchAlgorithm attribute of the FieldValue object
406     *
407     * @param searchAlgorithm The new searchAlgorithm value
408     */

409    public void setSearchAlgorithm(int searchAlgorithm) {
410       this.searchAlgorithm = searchAlgorithm;
411    }
412
413
414    /**
415     * Gets the searchAlgorithm attribute of the FieldValue object
416     *
417     * @return The searchAlgorithm value
418     */

419    public int getSearchAlgorithm() {
420       return searchAlgorithm;
421    }
422
423
424    /**
425     * Sets the searchMode attribute of the FieldValue object
426     *
427     * @param searchMode The new searchMode value
428     */

429    public void setSearchMode(int searchMode) {
430       this.searchMode = searchMode;
431    }
432
433
434    /**
435     * Gets the searchMode attribute of the FieldValue object
436     *
437     * @return The searchMode value
438     */

439    public int getSearchMode() {
440       return searchMode;
441    }
442
443
444    /**
445     * Sets the sortDirection attribute of the FieldValue object
446     *
447     * @param sortDirection The new sortDirection value
448     */

449    public void setSortDirection(int sortDirection) {
450       this.sortDirection = sortDirection;
451    }
452
453
454    /**
455     * Gets the sortDirection attribute of the FieldValue object
456     *
457     * @return The sortDirection value
458     */

459    public int getSortDirection() {
460       return sortDirection;
461    }
462
463
464    /**
465     * Clone this object.
466     *
467     * @return a cloned FieldValue object
468     */

469    public Object JavaDoc clone() {
470       // shallow copy ;=)
471
try {
472          FieldValue fv = (FieldValue) super.clone();
473
474          return fv;
475       } catch (CloneNotSupportedException JavaDoc e) {
476          // should not happen
477
logCat.error("::clone - exception", e);
478       }
479
480       return null;
481    }
482
483
484    /**
485     * Inverts the sorting direction of all FieldValue objects in the given
486     * array [ASC-->DESC et vice versa]
487     *
488     * @param fv the array of FieldValue objects
489     */

490    public static void invert(FieldValue[] fv) {
491       for (int i = 0; i < fv.length; i++) {
492          switch (fv[i].getSortDirection()) {
493             case Constants.ORDER_ASCENDING:
494                fv[i].setSortDirection(Constants.ORDER_DESCENDING);
495
496                break;
497
498             case Constants.ORDER_DESCENDING:
499                fv[i].setSortDirection(Constants.ORDER_ASCENDING);
500
501                break;
502          }
503       }
504    }
505
506
507    /**
508     * Get the String representation of this object.
509     *
510     * @return the String representation of this object
511     *
512     * @todo toString: to be finished
513     */

514    public String JavaDoc toString() {
515       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
516
517       String JavaDoc fieldName = getField()
518                                   .getName();
519       buf.append(" ")
520          .append("field [")
521          .append(fieldName)
522          .append("] has value, oldvalue [")
523          .append(getFieldValue())
524          .append(", ")
525          .append(getOldValue())
526          .append("]\n");
527
528       return buf.toString();
529    }
530
531
532    /**
533     * Dump the input FieldValue array
534     *
535     * @param fieldValues the fieldValues array
536     *
537     * @return the string representation of the FieldValues object
538     */

539    public static String JavaDoc toString(FieldValue[] fieldValues) {
540       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
541       sb.append("FieldValue array size: ")
542         .append(fieldValues.length)
543         .append("; elements are:\n");
544
545       for (int i = 0; i < fieldValues.length; i++) {
546          FieldValue fieldValue = fieldValues[i];
547          sb.append(fieldValue.toString());
548       }
549
550       return sb.toString();
551    }
552
553
554    private Object JavaDoc getFieldValueAsObject(String JavaDoc value,
555                                         int fieldType) {
556       Object JavaDoc res = null;
557
558       switch (fieldType) {
559          case FieldTypes.INTEGER:
560             res = parseINTEGER(value);
561
562             break;
563
564          case FieldTypes.DOUBLE:
565             res = parseDOUBLE(value);
566
567             break;
568
569          case FieldTypes.FLOAT:
570             res = parseFLOAT(value);
571
572             break;
573
574          case FieldTypes.NUMERIC:
575             res = parseNUMERIC(value);
576
577             break;
578
579          case FieldTypes.CHAR:
580             res = parseCHAR(value);
581
582             break;
583
584          case FieldTypes.DATE:
585             res = parseDATE(value);
586
587             break;
588
589          case FieldTypes.TIME:
590             res = parseTIME(value);
591
592             break;
593
594          case FieldTypes.TIMESTAMP:
595             res = parseTIMESTAMP(value);
596
597             break;
598
599          case FieldTypes.BLOB:
600
601             // FileHolder object might not be initialized if textarea is used for blobs
602
if (getFileHolder() == null) {
603                res = value;
604             } else {
605                res = getFileHolder();
606             }
607
608             break;
609
610          case FieldTypes.DISKBLOB:
611             res = parseDISKBLOB();
612
613             break;
614
615          default:
616             break;
617       }
618
619       return res;
620    }
621
622
623    private String JavaDoc parseCHAR(String JavaDoc value) {
624       String JavaDoc res;
625       if ("[NULL]".equals(value)) {
626          res = null;
627       } else {
628          res = value;
629       }
630       return res;
631    }
632
633
634    private Date JavaDoc parseDATE(String JavaDoc value) {
635       String JavaDoc valueStr = value.trim();
636
637       if (Util.isNull(valueStr)) {
638          return null;
639       }
640
641       if (getLocale() != null) {
642          try {
643             SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
644                                                        .getFormat(getPattern(),
645                                                                   getLocale());
646             Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
647             result.set(Calendar.HOUR_OF_DAY, 0);
648             result.set(Calendar.MINUTE, 0);
649             result.set(Calendar.SECOND, 0);
650
651             return new Date JavaDoc(result.getTime().getTime());
652          } catch (Exception JavaDoc e) {
653             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
654                          + ">");
655
656             // Make it more tolerant and try short format too
657
try {
658                SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
659                                                           .getFormat("short",
660                                                                      getLocale());
661                Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
662                result.set(Calendar.HOUR_OF_DAY, 0);
663                result.set(Calendar.MINUTE, 0);
664                result.set(Calendar.SECOND, 0);
665
666                return new Date JavaDoc(result.getTime().getTime());
667             } catch (Exception JavaDoc ex) {
668                logCat.error(ex.getMessage() + " <" + valueStr + "/"
669                             + getPattern() + ">");
670             }
671          }
672       }
673
674       try {
675          // 20031123-HKK: patch suggested by Igor Longagnani [i.longagnani@tiscali.it]:
676
// use only the first part of date string.
677
String JavaDoc[] vStr = StringUtils.split(valueStr, " ");
678          String JavaDoc str = vStr[0];
679
680          return Date.valueOf(str);
681       } catch (Exception JavaDoc e) {
682          logCat.error(e.getMessage() + " <" + valueStr + ">");
683       }
684
685       return null;
686    }
687
688
689    private String JavaDoc parseDISKBLOB() {
690       if (getField()
691                    .hasEncodedSet()) {
692          String JavaDoc fileName = getFileHolder()
693                               .getFileName();
694          int dotIndex = fileName.lastIndexOf('.');
695          String JavaDoc suffix = (dotIndex != -1) ? fileName.substring(dotIndex)
696                                             : "";
697          fileHolder.setFileName(UniqueIDGenerator.getUniqueID() + suffix);
698       }
699
700       return fileHolder.getFileName();
701    }
702
703
704    private Double JavaDoc parseDOUBLE(String JavaDoc value) {
705       String JavaDoc valueStr = value.trim();
706
707       if (Util.isNull(valueStr)) {
708          return null;
709       }
710
711       if (getLocale() != null) {
712          try {
713             DecimalFormat JavaDoc f = (DecimalFormat JavaDoc) getField()
714                                                  .getFormat(getPattern(),
715                                                             getLocale());
716
717             return new Double JavaDoc(f.parse(valueStr).doubleValue());
718          } catch (Exception JavaDoc e) {
719             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
720                          + ">");
721          }
722       }
723
724       try {
725          return new Double JavaDoc(valueStr);
726       } catch (Exception JavaDoc e) {
727          logCat.error(e.getMessage() + " <" + valueStr + ">");
728       }
729
730       return null;
731    }
732
733
734    private Float JavaDoc parseFLOAT(String JavaDoc value) {
735       String JavaDoc valueStr = value.trim();
736
737       if (Util.isNull(valueStr)) {
738          return null;
739       }
740
741       if (getLocale() != null) {
742          try {
743             DecimalFormat JavaDoc f = (DecimalFormat JavaDoc) getField()
744                                                  .getFormat(getPattern(),
745                                                             getLocale());
746
747             return new Float JavaDoc(f.parse(valueStr).floatValue());
748          } catch (Exception JavaDoc e) {
749             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
750                          + ">");
751          }
752       }
753
754       try {
755          return new Float JavaDoc(valueStr);
756       } catch (Exception JavaDoc e) {
757          logCat.error(e.getMessage() + " <" + valueStr + ">");
758       }
759
760       return null;
761    }
762
763
764    private Integer JavaDoc parseINTEGER(String JavaDoc value) {
765       String JavaDoc valueStr = value.trim();
766
767       if (Util.isNull(valueStr)) {
768          return null;
769       }
770
771       if (getLocale() != null) {
772          try {
773             DecimalFormat JavaDoc f = (DecimalFormat JavaDoc) getField()
774                                                  .getFormat(getPattern(),
775                                                             getLocale());
776
777             return new Integer JavaDoc(f.parse(valueStr).intValue());
778          } catch (Exception JavaDoc e) {
779             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
780                          + ">");
781          }
782       }
783
784       try {
785          return new Integer JavaDoc(valueStr);
786       } catch (Exception JavaDoc e) {
787          logCat.error(e.getMessage() + " <" + valueStr + ">");
788       }
789
790       return null;
791    }
792
793
794    private BigDecimal JavaDoc parseNUMERIC(String JavaDoc value) {
795       String JavaDoc valueStr = value.trim();
796
797       if (Util.isNull(valueStr)) {
798          return null;
799       }
800
801       if (getLocale() != null) {
802          try {
803             DecimalFormat JavaDoc f = (DecimalFormat JavaDoc) getField()
804                                                  .getFormat(getPattern(),
805                                                             getLocale());
806
807             return new BigDecimal JavaDoc(f.parse(valueStr).doubleValue());
808          } catch (Exception JavaDoc e) {
809             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
810                          + ">");
811          }
812       }
813
814       try {
815          return new BigDecimal JavaDoc(valueStr);
816       } catch (Exception JavaDoc e) {
817          logCat.error(e.getMessage() + " <" + valueStr + ">");
818       }
819
820       return null;
821    }
822
823
824    private Time JavaDoc parseTIME(String JavaDoc value) {
825       String JavaDoc valueStr = value.trim();
826
827       if (Util.isNull(valueStr)) {
828          return null;
829       }
830
831       if (getLocale() != null) {
832          try {
833             SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
834                                                        .getFormat(getPattern(),
835                                                                   getLocale());
836             Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
837             result.set(Calendar.DAY_OF_MONTH, 0);
838             result.set(Calendar.MONTH, 0);
839             result.set(Calendar.YEAR, 0);
840
841             return new Time JavaDoc(result.getTime().getTime());
842          } catch (Exception JavaDoc e) {
843             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
844                          + ">");
845
846             // Make it more tolerant and try short format too
847
try {
848                SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
849                                                           .getFormat("short",
850                                                                      getLocale());
851                Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
852                result.set(Calendar.DAY_OF_MONTH, 0);
853                result.set(Calendar.MONTH, 0);
854                result.set(Calendar.YEAR, 0);
855
856                return new Time JavaDoc(result.getTime().getTime());
857             } catch (Exception JavaDoc ex) {
858                logCat.error(ex.getMessage() + " <" + valueStr + "/"
859                             + getPattern() + ">");
860             }
861          }
862       }
863
864       try {
865          return Time.valueOf(valueStr);
866       } catch (Exception JavaDoc e) {
867          logCat.error(e.getMessage() + " <" + valueStr + ">");
868       }
869
870       return null;
871    }
872
873
874    private Timestamp JavaDoc parseTIMESTAMP(String JavaDoc value) {
875       String JavaDoc valueStr = value.trim();
876
877       if (Util.isNull(valueStr)) {
878          return null;
879       }
880
881       if (getLocale() != null) {
882          try {
883             SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
884                                                        .getFormat(getPattern(),
885                                                                   getLocale());
886             Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
887
888             return new Timestamp JavaDoc(result.getTime().getTime());
889          } catch (Exception JavaDoc e) {
890             logCat.error(e.getMessage() + " <" + valueStr + "/" + getPattern()
891                          + ">");
892
893             // Make it more tolerant and try short format too
894
try {
895                SimpleDateFormat JavaDoc f = (SimpleDateFormat JavaDoc) getField()
896                                                           .getFormat("short",
897                                                                      getLocale());
898                Calendar JavaDoc result = TimeUtil.parseDate(f, valueStr);
899
900                return new Timestamp JavaDoc(result.getTime().getTime());
901             } catch (Exception JavaDoc ex) {
902                logCat.error(ex.getMessage() + " <" + valueStr + "/"
903                             + getPattern() + ">");
904             }
905          }
906       }
907
908       try {
909          return Timestamp.valueOf(valueStr);
910       } catch (Exception JavaDoc e) {
911          logCat.error(e.getMessage() + " <" + valueStr + ">");
912       }
913
914       return null;
915    }
916 }
917
Popular Tags