1 package info.magnolia.cms.gui.controlx.search; 2 3 import info.magnolia.cms.gui.query.DateSearchQueryParameter; 4 import info.magnolia.cms.gui.query.SearchQueryExpression; 5 import info.magnolia.cms.util.AlertUtil; 6 import info.magnolia.context.MgnlContext; 7 8 import java.text.DateFormat ; 9 import java.text.ParseException ; 10 import java.text.SimpleDateFormat ; 11 import java.util.Date ; 12 13 import org.apache.commons.lang.time.FastDateFormat; 14 15 16 20 public class DateSearchControl extends SearchControl { 21 22 25 public static final String RENDER_TYPE = "dateSearchControl"; 26 27 30 public DateSearchControl() { 31 this.setRenderType(RENDER_TYPE); 32 } 33 34 39 public DateSearchControl(SearchControlDefinition definition, String value, String condition) { 40 super(definition, value, condition); 41 this.setRenderType(RENDER_TYPE); 42 } 43 44 47 public SearchQueryExpression getExpression() { 48 Date date = null; 49 if (this.getConstraint().equals(DateSearchQueryParameter.TODAY)) { 50 date = new Date (); 51 } 52 else { 53 String value = getValue(); 54 try { 55 DateFormat format = new SimpleDateFormat ("yyyy-MM-dd"); 56 date = format.parse(value); 57 } 58 catch (ParseException e) { 59 try { 60 DateFormat format = DateFormat.getDateInstance(FastDateFormat.SHORT, MgnlContext.getLocale()); 61 date = format.parse(value); 62 } 63 catch (ParseException e1) { 64 try { 65 DateFormat format = DateFormat.getDateInstance(FastDateFormat.SHORT, MgnlContext.getLocale()); 66 date = format.parse(value); 67 } 68 catch (ParseException e2) { 69 AlertUtil.setMessage("The date is not properly formated [" + value + "] "); 70 } 71 } 72 } 73 } 74 75 return new DateSearchQueryParameter(this.getDefinition().getColumn(), date, this.getConstraint()); 76 } 77 } 78 | Popular Tags |