Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

DateServiceUtil.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 package org.openmobileis.services.common;
00026 
00027 import java.util.Calendar;
00028 
00029 import freemarker.template.SimpleHash;
00030 import freemarker.template.SimpleList;
00031 
00039 public final class DateServiceUtil {
00040 
00041 
00087   public static SimpleHash getForTemplateInputDate(
00088     int selectedDay,
00089     int selectedMonth,
00090     int selectedYear,
00091     int selectedHours,
00092     int selectedMinutes,
00093     int selectedDuration) {
00094 
00095     SimpleHash inputDate = new SimpleHash();
00096     int cpt;
00097     SimpleList list;
00098     SimpleHash element;
00099     // fill day
00100     list = new SimpleList();
00101     for (cpt = 1; cpt <= 31; cpt++) {
00102       element = new SimpleHash();
00103       element.put("select", selectedDay == cpt);
00104       element.put("value", formatDateDec(cpt));
00105       list.add(element);
00106     }
00107     inputDate.put("dayList", list);
00108     // fill month
00109     list = new SimpleList();
00110     for (cpt = 1; cpt <= 12; cpt++) {
00111       element = new SimpleHash();
00112       element.put("select", selectedMonth + 1 == cpt);
00113       element.put("value", formatDateDec(cpt));
00114       list.add(element);
00115     }
00116     inputDate.put("monthList", list);
00117 
00118     list = new SimpleList();
00119     Calendar cal = Calendar.getInstance();
00120     int currentYear = cal.get(Calendar.YEAR);
00121     for (cpt = currentYear - 1; cpt <= currentYear + 5; cpt++) {
00122       element = new SimpleHash();
00123       element.put("value", String.valueOf(cpt));
00124       element.put("select", selectedYear == cpt);
00125       list.add(element);
00126     }
00127     inputDate.put("yearList", list);
00128     // fill hours
00129     list = new SimpleList();
00130     for (cpt = 0; cpt <= 23; cpt++) {
00131       element = new SimpleHash();
00132       element.put("value", formatDateDec(cpt));
00133       element.put("select", selectedHours == cpt);
00134       list.add(element);
00135     }
00136     inputDate.put("hourList", list);
00137     // fill minutes
00138     list = new SimpleList();
00139     for (cpt = 0; cpt <= 59; cpt += 5) {
00140       element = new SimpleHash();
00141       element.put("value", formatDateDec(cpt));
00142       element.put("select", selectedMinutes == cpt);
00143       list.add(element);
00144     }
00145     inputDate.put("minutesList", list);
00146 
00147     // return the input date
00148     return inputDate;
00149   }
00150 
00151   private static String formatDateDec(int value) {
00152     if (value < 10) {
00153       return "0" + value;
00154     } else {
00155       return String.valueOf(value);
00156     }
00157   }
00158 
00159 }

Generated on Wed Dec 14 21:05:32 2005 for OpenMobileIS by  doxygen 1.4.4