00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 package org.mpcl.text.html;
00028
00029 import java.text.DateFormatSymbols;
00030 import java.util.GregorianCalendar;
00031 import java.util.Locale;
00032
00033
00034 public class THtmlDate
00035 {
00036
00037 protected boolean gEnableMultiple;
00038
00039 protected int iDay;
00040
00041 protected int iMonth;
00042
00043 protected int iYear;
00044
00045 protected GregorianCalendar tCalendar;
00046
00047 protected Locale tLocale;
00048
00049 protected String yNamePrefix;
00050
00051
00052
00053
00054
00055
00056 protected void setCalendar()
00057 {
00058 if ( ( iDay > 0 ) && ( iMonth > 0 ) && (iYear > 0) )
00059 {
00060 tCalendar.set (iYear, iMonth, iDay);
00061 }
00062 }
00063
00064
00065
00066
00067
00068
00069 public THtmlDate (String yDAY, String yMONTH, String yYEAR, String yNAME_PREFIX)
00070 {
00071 tLocale = Locale.getDefault();
00072 tCalendar = new GregorianCalendar (tLocale);
00073 setDay (yDAY);
00074 setMonth (yMONTH);
00075 setYear (yYEAR);
00076 setNamePrefix (yNAME_PREFIX);
00077 setCalendar();
00078 }
00079
00080 public void setDay (String yDAY)
00081 {
00082
00083 try
00084 {
00085 iDay = Integer.parseInt (yDAY);
00086 if ( iDay < 0 )
00087 {
00088 iDay = 0;
00089 }
00090 if ( iDay > 31 )
00091 {
00092 iDay = 0;
00093 }
00094 }
00095 catch (NumberFormatException tEXCEPTION)
00096 {
00097 iDay = -1;
00098 }
00099
00100 }
00101
00102 public void setEnableMultple (boolean gENABLE)
00103 {
00104 gEnableMultiple = gENABLE;
00105 }
00106
00107 public void setMonth (String yMONTH)
00108 {
00109
00110 try
00111 {
00112 iMonth = Integer.parseInt (yMONTH);
00113 if ( iMonth < 0 )
00114 {
00115 iMonth = 0;
00116 }
00117 if ( iMonth > 11 )
00118 {
00119 iMonth = 0;
00120 }
00121 }
00122 catch (NumberFormatException tEXCEPTION)
00123 {
00124 iMonth = -1;
00125 }
00126
00127 }
00128
00129 public void setYear (String yYEAR)
00130 {
00131 try
00132 {
00133 iYear = Integer.parseInt (yYEAR);
00134 }
00135 catch (NumberFormatException tEXCEPTION)
00136 {
00137 iYear = -1;
00138 }
00139 }
00140
00141 public void setLocale (Locale tLOCALE)
00142 {
00143 if ( tLOCALE != null )
00144 {
00145 tLocale = tLOCALE;
00146 tCalendar = new GregorianCalendar (tLocale);
00147 }
00148 else
00149 {
00150 throw new NullPointerException();
00151 }
00152 }
00153
00154 public void setNamePrefix (String yNAME_PREFIX)
00155 {
00156 yNamePrefix = ( yNAME_PREFIX != null ) ? yNAME_PREFIX : "";
00157 }
00158
00159
00160
00161
00162
00163
00164 protected StringBuffer getDays()
00165 {
00166
00167 StringBuffer yRet = new StringBuffer()
00168 .append ("<select name='").append (yNamePrefix).append ("Day'>\n")
00169 .append ("<option value=''>--</option>\n");
00170 for (int I = 1; I <= tCalendar.getMaximum (GregorianCalendar.DAY_OF_MONTH) ; I++)
00171 {
00172 yRet = yRet.append ("<option value='").append (I).append ("'");
00173 if ( I == iDay )
00174 {
00175 yRet = yRet.append (" selected");
00176 }
00177 yRet = yRet.append (">").append (I).append ("</option>\n");
00178 }
00179 yRet = yRet.append ("</select>");
00180 return yRet;
00181
00182 }
00183
00184 protected StringBuffer getMonths()
00185 {
00186
00187 StringBuffer yRet = new StringBuffer()
00188 .append ("<select name='").append (yNamePrefix).append ("Month'>\n")
00189 .append ("<option value=''>------</option>\n");
00190 String ayMonths[] = (new DateFormatSymbols (tLocale)).getMonths();
00191
00192 for (int I = 0; I < 12 ; I++)
00193 {
00194 yRet = yRet.append ("<option value='").append (I).append ("'");
00195 if ( I == iMonth )
00196 {
00197 yRet = yRet.append (" selected");
00198 }
00199 yRet = yRet.append (">").append (ayMonths [I]).append ("</option>\n");
00200 }
00201 yRet = yRet.append ("</select>");
00202 return yRet;
00203
00204 }
00205
00206 protected StringBuffer getYears()
00207 {
00208
00209 int iYearCurrent;
00210 int iYearFrom;
00211 int iYearUntil;
00212 StringBuffer yRet = new StringBuffer()
00213 .append ("<select name='").append (yNamePrefix).append ("Year'>\n")
00214 .append ("<option value=''>----</option>\n");
00215
00216
00217 iYearCurrent = ( iYear > 0 ) ? iYear : tCalendar.get (GregorianCalendar.YEAR);
00218 iYearFrom = iYearCurrent - 10;
00219 iYearUntil = iYearCurrent + 10;
00220
00221 for (int I = iYearFrom; I <= iYearUntil ; I++)
00222 {
00223 yRet = yRet.append ("<option value='").append (I).append ("'");
00224 if ( I == iYear )
00225 {
00226 yRet = yRet.append (" selected");
00227 }
00228 yRet = yRet.append (">").append (I).append ("</option>\n");
00229 }
00230 yRet = yRet.append ("</select>");
00231 return yRet;
00232
00233 }
00234
00235 public StringBuffer toHtml()
00236 {
00237 StringBuffer yRet;
00238
00239 yRet = new StringBuffer()
00240 .append ("<td>\n").append (getDays()).append ("</td>\n<td>\n")
00241 .append (getMonths()).append ("\n</td>\n<td>\n")
00242 .append (getYears()).append ("\n</td>");
00243 return yRet;
00244 }
00245
00246 }