1 24 package org.riotfamily.website.generic.model.hibernate; 25 26 import java.util.GregorianCalendar ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 30 31 public class SplitDateParameterResolver extends AbstractParameterResolver { 32 33 private String yearParam = "year"; 34 35 private String monthParam = "month"; 36 37 private String dayParam = "day"; 38 39 public String getDayParam() { 40 return dayParam; 41 } 42 43 public void setDayParam(String dayParam) { 44 this.dayParam = dayParam; 45 } 46 47 public void setMonthParam(String monthParam) { 48 this.monthParam = monthParam; 49 } 50 51 public void setYearParam(String yearParam) { 52 this.yearParam = yearParam; 53 } 54 55 public Object getValueInternal(HttpServletRequest request) { 56 Integer year = getIntegerParameter(request, yearParam); 57 Integer month = getIntegerParameter(request, monthParam); 58 Integer day = getIntegerParameter(request, dayParam); 59 60 if (year != null) { 61 if (month != null && month.intValue() >= 1 && month.intValue() <= 12) { 62 if (day != null && day.intValue() >= 1 && day.intValue() <= 31) { 63 return new GregorianCalendar (year.intValue(), month.intValue() - 1, day.intValue()).getTime(); 64 } 65 return new GregorianCalendar (year.intValue(), month.intValue() - 1, 1).getTime(); 66 } 67 } 68 69 return null; 70 } 71 72 private Integer getIntegerParameter(HttpServletRequest request, String param) { 73 try { 74 String s = request.getParameter(param); 75 return Integer.valueOf(s); 76 } 77 catch (NumberFormatException e) { 78 } 79 return null; 80 } 81 82 } 83 | Popular Tags |